description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m < s / 9:
print(-1, -1)
elif s == 0 and m == 1:
print(0, 0)
elif s == 0:
print(-1, -1)
else:
q = s // 9
r = s - q * 9
mul = m - (q + 1)
if mul < 0:
maxx = [9] * q
else:
maxx = [9] * q + [r] + [0] * (m - (q + 1))
if maxx[-1] != 0:
minn = maxx[::-1]
else:
minn = maxx.copy()
minn = minn[::-1]
minn[0] = 1
for i in range(1, len(minn)):
if minn[i] == 0:
continue
else:
minn[i] -= 1
break
y = "".join(str(i) for i in maxx)
z = "".join(str(i) for i in minn)
print(int(z), int(y)) | 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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST NUMBER VAR LIST VAR BIN_OP LIST NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split(" "))
if s == 0 and m == 1:
print("0" + " " + "0")
elif s == 0 and m != 1:
print("-1" + " " + "-1")
elif s > m * 9:
print("-1" + " " + "-1")
else:
l = []
while s > 9:
l.append(9)
s -= 9
l.append(s)
l = l + [0] * (m - len(l))
minimum = l[::-1]
for i in range(m):
l[i] = str(l[i])
maximum = "".join(l)
if minimum[0] == 0:
minimum[minimum.count(0)] -= 1
minimum[0] = 1
for i in range(m):
minimum[i] = str(minimum[i])
minimum = "".join(minimum)
print(minimum + " " + maximum) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING STRING ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER 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 BIN_OP BIN_OP VAR STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = list(map(int, input().split()))
if s > m * 9 or m != 1 and s == 0:
print("-1 -1")
elif m == 1 and s <= 9:
print(s, s)
else:
a = [9] * (s // 9)
if s % 9 > 0:
a += [s % 9]
l = len(a)
if l == m:
a.sort()
b = list(reversed(a))
print(*a, sep="", end=" ")
print(*b, sep="")
else:
b = a[:]
t = min(a)
a.remove(t)
a.append(t - 1)
a += [0] * (m - (l + 1))
a.sort()
print(1, *a, sep="", end=" ")
b += [0] * (m - l)
b.sort()
b = list(reversed(b))
print(*b, sep="") | ASSIGN VAR VAR FUNC_CALL 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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR LIST BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER VAR STRING STRING VAR BIN_OP LIST NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m == 1 and s == 0:
print(0, 0)
elif 9 * m < s or s < 1 and m > 1:
print(-1, -1)
else:
l = [0] * m
scopy = s
for i in range(m):
if s < 0:
break
k = min(9, s)
l[i] = str(k)
s = s - k
max_val = "".join(l)
l1 = ["0"] * m
l1[0] = "1"
s = scopy
s = s - 1
for i in range(m):
if s <= 0:
break
k1 = min(9, s)
if i != m - 1:
l1[m - i - 1] = str(k1)
else:
l1[m - i - 1] = str(k1 + 1)
s = s - k1
min_val = "".join(l1)
print(min_val, max_val) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN 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 m == 1 and s == 0:
print(0, 0)
return
if s == 0 and m > 1 or s > m * 9:
print(-1, -1)
else:
n = (s - 1) // 9
if n == m - 1:
print(s - n * 9, "9" * n, sep="", end=" ")
print("9" * n, s - n * 9, sep="")
else:
print("1", "0" * (m - n - 2), s - n * 9 - 1, "9" * n, sep="", end=" ")
print("9" * n, s - n * 9, "0" * (m - n - 1), sep="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP STRING VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP STRING VAR STRING STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
temp = m
m = s
s = temp
numbers = [9] * s
difference = 9 * s - m
low = ""
high = ""
i = 0
if s == 0 or m == 0:
if s == 1:
print(0, 0)
else:
print(-1, -1)
elif 9 * s < m:
print(-1, -1)
else:
while i < len(numbers):
if difference >= 9:
numbers[i] = 0
difference -= 9
if difference == 0:
break
else:
numbers[i] = 9 - difference
break
i += 1
i = 0
while i < len(numbers):
low += str(numbers[i])
i += 1
i = -1
while i >= -len(numbers):
high += str(numbers[i])
i -= 1
if numbers[0] == 0:
j = 0
while low[j] == "0":
j += 1
numbers[0] = 1
numbers[j] -= 1
numbers = list(map(str, numbers))
low = "".join(numbers)
print(low, high) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(x) for x in input().split()]
def mini(m, s):
num = ["0" for i in range(m)]
m -= 1
while s > 9:
num[m] = "9"
s -= 9
m -= 1
if s > 0:
if m != 0:
num[m] = str(s - 1)
num[0] = "1"
else:
num[m] = str(s)
return "".join(num)
def maxi(m, s):
limit = s // 9 if s // 9 < m else m
if limit == 0:
num = str(s) + "0" * (m - 1)
return num
else:
num = "9" * limit
s -= limit * 9
if s > 0:
num += str(s)
num += "0" * (m - len(num))
return num
if s > 9 * m or s == 0 and m != 1:
print(-1, -1)
else:
print(mini(m, s), maxi(m, s)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP STRING VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | temparr = input()
temparr = temparr.split()
numofdigit = int(temparr[0])
totalsum = int(temparr[1])
smalltotalsum = int(temparr[1])
getfinalaaa = ""
def check(digit, sumleft, strs):
if digit == 0 and sumleft > 0:
return -1
if digit == 0 and sumleft == 0:
return strs
if sumleft < 0:
return -1
if sumleft > 9 * digit:
return -1
for i in range(0, 10):
newsum = sumleft - i
strstemp = strs[:] + str(i)
ansleft = check(digit - 1, newsum, strstemp)
if ansleft != -1:
return ansleft
for i in range(1, 10):
sumleft = smalltotalsum - i
strs = str(i)
ansleft = check(numofdigit - 1, sumleft, strs)
if ansleft != -1:
break
getfinalaaa += str(ansleft)
getfinalaaa += " "
if ansleft == -1:
if totalsum == 0 and numofdigit == 1:
print("0", "0")
else:
print("-1 -1")
else:
def checkmost(digit, sumleft, strs):
if digit == 0 and sumleft > 0:
return -1
if digit == 0 and sumleft == 0:
return strs
if sumleft < 0:
return -1
if sumleft > 9 * digit:
return -1
for i in range(9, -1, -1):
newsum = sumleft - i
strstemp = strs[:] + str(i)
ansleft = checkmost(digit - 1, newsum, strstemp)
if ansleft != -1:
return ansleft
for i in range(9, 0, -1):
sumleft = totalsum - i
strs = str(i)
ansleft = checkmost(numofdigit - 1, sumleft, strs)
if ansleft != -1:
break
getfinalaaa += str(ansleft)
print(getfinalaaa) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n = str(input()).split()
l = int(n[0])
s = int(n[1])
if s == 0:
if l == 1:
print(0, 0)
quit()
else:
print(-1, -1)
quit()
if l * 9 < s:
print(-1, -1)
quit()
def mx(l, s):
x = s
r = ""
for i in range(0, l):
if x == 0:
r = r + "0"
else:
nextChar = min(9, x)
r = r + str(nextChar)
x = x - nextChar
return r
def mn(l, s):
x = s
r = ""
for i in range(0, l):
if i == l - 1:
r = str(x) + r
elif x == 1:
r = "0" + r
else:
nextChar = min(9, x - 1)
r = str(nextChar) + r
x = x - nextChar
return r
print(mn(l, s), mx(l, s)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP 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 | m, s = [int(i) for i in input().split()]
a = m * [0]
a[0] = 1
sum = 1
temp = 0
while sum < s and s > 0 and m * 9 >= s:
if a[temp] < 9:
a[temp] = a[temp] + 1
sum = sum + 1
else:
temp += 1
for i in range(m):
a[i] = str(a[i])
max = "".join(a)
a = m * [0]
a[0] = 1
sum = 1
temp = m - 1
while sum < s and s > 0 and m * 9 >= s:
if a[temp] < 9:
a[temp] = a[temp] + 1
sum = sum + 1
else:
temp = temp - 1
for i in range(m):
a[i] = str(a[i])
min = "".join(a)
if s == 0 and m == 1:
print(0, 0)
elif m * 9 < s or s <= 0:
print(-1, -1)
else:
print(min, max) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s1 = list(map(int, input().split()))
if s1 == 0 and m > 1 or m * 9 < s1:
print("-1 -1")
else:
a = list(0 for i in range(m))
a[0] = 1
s = s1 - 1
for i in range(m):
if s <= 9:
a[m - i - 1] = s
s = 0
if s == 0:
break
if s > 9:
a[m - i - 1] = 9
s -= 9
b = list(0 for i in range(m))
s = s1
for i in range(m):
if s <= 9:
b[i] = s
s = 0
if s == 0:
break
if s > 9:
b[i] = 9
s -= 9
if sum(a) != s1:
a[0] += 1
print("".join(map(str, a)), "".join(map(str, b))) | ASSIGN VAR VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
min_num = 1
max_num = 2
if s == 0 and m > 1 or s > 9 * m:
print("-1 -1")
elif s == 0:
print("0 0")
elif s <= 9:
min_num = 1 * 10 ** (m - 1) + s - 1
max_num = s * 10 ** (m - 1)
print(min_num, max_num)
else:
min_list = [1] + [0] * (m - 1)
max_list = [9] + [0] * (m - 1)
k = s - 1
s -= 9
j = m - 1
i = 1
while s != 0:
if s >= 9:
max_list[i] = 9
s -= 9
i += 1
else:
max_list[i] = s
s = 0
while k != 0:
if k >= 9:
min_list[j] = 9
j -= 1
k -= 9
else:
min_list[j] += k
k = 0
min_num = "".join(map(str, min_list))
max_num = "".join(map(str, max_list))
print(min_num, max_num) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def find_length_sum_digits(m, s):
if m * 9 < s or s == 0 and m != 1:
return "-1 -1"
min_n = find_min(m, s)
max_n = find_max(m, s)
return min_n + " " + max_n
def find_min(m, s):
min_n = ""
length = m - 1
while length != 0:
for i in range(9, -1, -1):
if 1 <= s - i <= 9 * length:
s -= i
min_n = str(i) + min_n
break
length -= 1
min_n = str(s) + min_n
return min_n
def find_max(m, s):
max_n = ""
length = m
while length != 0:
diff = min(s, 9)
s -= diff
max_n += str(diff)
length -= 1
return max_n
m, s = [int(e) for e in input().split()]
print(find_length_sum_digits(m, s)) | FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP VAR STRING VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
s1 = s
if m == 1:
if s > 9:
print(-1, -1)
else:
print(s, s)
elif s > m * 9 or s < 1:
print(-1, -1)
else:
s1 -= 1
popa = ["0"] * m
popa[0] = "1"
for i in range(m):
if s1 < 9:
popa[m - 1 - i] = str(int(popa[m - 1 - i]) + s1)
s1 = 0
else:
s1 -= 9
popa[m - 1 - i] = "9"
n1 = "".join(popa)
popa = ["0"] * m
s1 = s
for i in range(m):
if s1 < 9:
popa[i] = str(int(popa[i]) + s1)
s1 = 0
else:
s1 -= 9
popa[i] = "9"
n2 = "".join(popa)
print(n1, n2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR 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 | m, s = map(int, input().split())
if s <= 9 * m:
if m > 1 and s == 0:
print(-1, -1)
elif m == 1:
print(s, s)
elif s == 1:
val = pow(10, m - 1)
print(val, val)
else:
li = [0] * m
li[0] = 1
li[m - 1] = s - 1
i = m - 1
while i > 0:
if li[i] > 9:
li[i - 1] = li[i - 1] + (li[i] - 9)
li[i] = 9
i = i - 1
min = int("".join(str(n) for n in li))
li = [0] * m
li[0] = s
i = 0
while i < m - 1:
if li[i] > 9:
li[i + 1] = li[i + 1] + (li[i] - 9)
li[i] = 9
i = i + 1
max = int("".join(str(n) for n in li))
print(min, max)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP 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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | s, m = map(int, input().split())
if m == 0 or m > 9 * s:
if s == 1 and m == 0:
print("0 0")
else:
print("-1 -1")
else:
max = "9" * (m // 9) + (str(m % 9) if m % 9 != 0 else "")
min = list(max)
min.reverse()
if len(max) == s:
min = "".join(min)
else:
max += "0" * (s - len(max))
min[0] = str(int(min[0]) - 1)
min = "1" + "0" * (s - len(min) - 1) + "".join(min)
print(min + " " + max) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL STRING 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 | line = input()
a, b = [int(i) for i in line.split()]
if b == 0 and a > 1 or b > 9 * a:
print("-1 -1")
else:
nummax = ""
numnin = ""
for i in range(a):
digit = min(9, b)
b = b - digit
nummax += str(digit)
nummin = nummax[::-1]
if nummin[0] == "0":
count = 0
for i in range(a):
if nummin[i] == "0":
count += 1
if a == 1:
nummin = 0
if a == 2:
nummin = "1" + (count - 1) * "0" + str(int(nummin[count]) - 1)
if a > 2:
c = int(nummin[count])
nummin = "1" + (count - 1) * "0" + str(c - 1) + nummin[count + 1 :]
print(int(nummin), int(nummax)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP 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 | line = str(input()).split()
length = int(line[0])
sum_digit = int(line[1])
sum_digit2 = sum_digit
A = []
B = []
C = []
if sum_digit == 1:
A.append("1")
for i in range(length - 1):
A.append("0")
print("".join(A), "".join(A))
elif sum_digit != 0 and length * 9 >= sum_digit:
while sum_digit >= 9:
A.append("9")
sum_digit = sum_digit - 9
if sum_digit != 0:
A.append(str(sum_digit))
last_num = length - len(A)
for i in range(last_num):
A.append("0")
max_num = "".join(A)
if "0" in A:
sum_digit2 = sum_digit2 - 1
while sum_digit2 >= 9:
B.append("9")
sum_digit2 = sum_digit2 - 9
if sum_digit2 != 0:
B.append(str(sum_digit2))
last_num = length - len(B)
for i in range(last_num - 1):
B.append("0")
B.append("1")
for j in range(length):
C.append(B[length - j - 1])
else:
for i in range(length):
C.append(A[length - i - 1])
min_num = "".join(C)
print(min_num, max_num)
elif length == 1 and sum_digit == 0:
print(0, 0)
else:
print(-1, -1) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF STRING VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR 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 | def maxn(n, s):
p = list("0" * n)
i = 0
while s:
if s < 10:
p[i] = str(s)
s = 0
else:
p[i] = "9"
s -= 9
i += 1
return p
n, s = [int(x) for x in input().split()]
if n > 1 and s == 0 or s > 9 * n:
print("-1 -1")
else:
p = maxn(n, s)
q = list(reversed(maxn(n, s - 1)))
q[0] = str(int(q[0]) + 1)
print("".join(q), "".join(p)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER VAR NUMBER RETURN VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
k = 1
if s == 0 and m == 1:
print(s, s)
exit()
elif s == 0:
print(-1, -1)
exit()
if s // 9 + int(s % 9 != 0) > m:
print(-1, -1)
exit()
smax = []
for i in range(s // 9):
smax.append(9)
if s % 9 != 0:
smax.append(s % 9)
k = 0
for i in range(m - s // 9 - int(s % 9 != 0)):
k += 1
smax.append(0)
smin = smax[:]
smin.sort()
if k != 0:
smin[0] = 1
smin[k] -= 1
for i in smin:
print(i, end="")
print(" ", end="")
for i in smax:
print(i, end="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NUMBER 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 | m, s = map(int, input().split())
if m == 1 and s == 0:
print("0 0")
exit()
if m * 9 < s or s == 0:
print(str(-1) + " " + str(-1))
exit()
max_n = ""
t = s
for _ in range(m):
n = min(t, 9)
max_n += str(n)
t -= n
min_n_r = ""
t = s
for i in range(m):
n = min(t, 9)
t -= n
if t == 0 and i != m - 1:
min_n_r += str(n - 1)
t += 1
else:
min_n_r += str(n)
min_n = ""
for c in reversed(min_n_r):
min_n += c
print(min_n, max_n) | 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 BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
n = ""
t = ""
if s == 0 and m == 1:
n, t = 0, 0
elif s >= 1 and s <= 9 * m:
if s // 9 == m:
n, t = "9" * m, "9" * m
elif s // 9 == m - 1:
if s % 9 > 0:
n += str(s % 9) + "9" * (m - 1)
else:
n += "1" + "8" + "9" * (m - 2)
t += "9" * (m - 1) + str(s % 9)
else:
k = (s - 1) // 9
n += "1" + "0" * (m - 2 - k) + str((s - 1) % 9) + "9" * k
k = s // 9
t += "9" * k + str(s % 9) + "0" * (m - k - 1)
else:
n, t = "-1", "-1"
print(n, t) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP STRING VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING STRING BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR 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 | line = input()
M, S = line.split()
m = int(M)
s = int(S)
hi = ""
if m == 1 and s == 0:
print(0, 0)
elif m * 9 < s or s == 0:
print(-1, end=" ")
print(-1)
elif m == 1:
print(s, s)
else:
t = s % 9
k = s // 9
if t == 0:
if k == m:
print(int("9" * k), end=" ")
print(int("9" * k))
else:
min1 = "1" + "0" * (m - k - 1) + "8" + "9" * (k - 1)
max1 = "9" * k + "0" * (m - k)
print(int(min1), end=" ")
print(int(max1))
elif k == 0:
print(int("1" + "0" * (m - 2) + str(s - 1)), end=" ")
print(int(str(s) + "0" * (m - 1)))
elif k == m - 1:
min2 = str(t) + "9" * k
max2 = "9" * k + str(t)
print(int(min2), end=" ")
print(int(max2))
else:
max3 = "9" * k + str(t) + "0" * (m - k - 1)
min3 = "1" + "0" * (m - k - 2) + str(t - 1) + "9" * k
print(int(min3), end=" ")
print(int(max3)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | num = [int(i) for i in input().split()]
maxi = []
if num[0] != 1 and num[1] == 0 or num[1] > 9 * num[0]:
print("-1 -1")
else:
for j in range(num[0]):
maxi.append(min(9, num[1]))
num[1] -= min(9, num[1])
mini = maxi[::-1]
if mini[0] == 0 and num[0] != 1:
for k in range(0, num[0]):
if mini[k] != 0:
mini[k] -= 1
break
mini[0] = 1
for a in range(num[0]):
print(mini[a], end="")
print(" ", end="")
for b in range(num[0]):
print(maxi[b], end="") | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
def high(num_digits, total):
if num_digits * 9 < total or total == 0 and num_digits > 1:
return -1
if total < 10 and total >= 0:
lst = ["0"] * (num_digits - 1)
return str(total) + "".join(lst)
else:
return "9" + high(num_digits - 1, total - 9)
def low(num_digits, total):
if num_digits * 9 < total or total == 0 and num_digits > 1:
return -1
if total < 10 and total >= 0 and num_digits > 1:
lst = ["0"] * (num_digits - 2)
return "1" + "".join(lst) + str(total - 1)
elif total < 10 and total >= 0 and num_digits == 1:
return str(total)
else:
return low(num_digits - 1, total - 9) + "9"
print(low(m, s), high(m, s)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL STRING VAR RETURN BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST STRING BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP STRING FUNC_CALL STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER 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 | n, m = map(int, input().split())
if m <= 0:
if n == 1:
print(0, 0)
else:
print(-1, -1)
else:
a = 9 * n
if m > a:
print(-1, -1)
else:
s = int("1" + "0" * (n - 1))
k = m
m = m - 1
t = 1
s = ""
for i in reversed(range(0, n)):
if m > 9:
s += "9"
m = m - 9
else:
if i == 0:
s += str(m + 1)
else:
s += str(m)
m = 0
s1 = ""
m = k
for i in range(0, n):
if m > 9:
s1 += "9"
m -= 9
else:
s1 += str(m)
m = 0
print(s[::-1], s1) | 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 BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | import sys
def validate(i, m, s):
if i == 0 and s == 0 and m > 1:
return False
return 0 <= s <= m * 9
def solve(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, "r")
n, s = map(int, f.readline().split())
golds = list()
if validate(0, n, s):
z = s
a = ""
for i in range(n):
for d in range(10):
if (i > 0 or d > 0 or n == 1 and d == 0) and validate(
i + 1, n - i - 1, z - d
):
z -= d
a += f"{d}"
break
z = s
b = ""
for i in range(n):
for d in range(9, -1, -1):
if (i > 0 or d > 0 or n == 1 and d == 0) and validate(
i + 1, n - i - 1, z - d
):
z -= d
b += f"{d}"
break
golds.append(f"{a} {b}")
else:
golds.append("-1 -1")
return golds
def main():
for line in solve():
print(line)
main() | IMPORT FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF NONE IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR STRING RETURN VAR FUNC_DEF FOR VAR FUNC_CALL 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 | ms = input().split()
m = int(ms[0])
s = int(ms[1])
def go(b, m, s):
if s >= 10:
b.append(9)
go(b, m - 1, s - 9)
elif m == 1:
b.append(s)
elif m > 1:
b.append(s - 1)
for i in range(m - 2):
b.append(0)
b.append(1)
a = []
b = []
if 9 * m >= s >= 1:
for i in range(s // 9):
a.append(9)
if s % 9 != 0:
a.append(s % 9)
while len(a) < m:
a.append(0)
go(b, m, s)
c = reversed(b)
for i in c:
print("{}".format(i), end="")
print(" ", end="")
for i in a:
print("{}".format(i), end="")
elif m == 1 and s == 0:
print("0 0")
else:
print("-1 -1") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | from sys import stdin
a = [int(i) for i in stdin.readline().split()]
max_number = ""
min_number = ""
if a[1] > 9 * a[0] or a[0] > 1 and a[1] == 0:
print(-1, -1)
elif a[0] == 1:
print(a[1], a[1])
else:
nines = (a[1] - 1) // 9
if nines > 0:
for i in range(nines):
min_number += "9"
if a[0] - len(min_number) == 1:
number = a[1] - len(min_number) * 9
min_number += str(number)
else:
next = a[1] - len(min_number) * 9 - 1
min_number += str(next)
length = len(min_number)
for i in range(a[0] - length - 1):
min_number += "0"
min_number += "1"
nines = a[1] // 9
r = a[1] % 9
for i in range(nines):
max_number += "9"
if a[0] == len(max_number):
print(int(min_number[::-1]), int(max_number))
else:
max_number += str(r)
if a[0] == len(max_number):
print(int(min_number[::-1]), int(max_number))
else:
length = len(max_number)
for i in range(a[0] - length):
max_number += "0"
print(int(min_number[::-1]), int(max_number)) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, s = tuple(map(int, input().split()))
def biggest(n, s):
if s == 0 and n > 1 or s > 9 * n:
return -1
else:
res = ""
while s != 0:
res += str(min(9, s))
s -= min(9, s)
res += "0" * (n - len(res))
return res
def smallest(n, s):
if s == 0 and n > 1 or s > 9 * n:
return -1
elif s == 0 and n == 1:
return 0
else:
big = list(reversed(biggest(n, s)))
if big[0] == "0":
big[0] = "1"
i = 1
while big[i] == "0":
i += 1
big[i] = str(int(big[i]) - 1)
return "".join(big)
print(smallest(n, s), biggest(n, s)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR STRING WHILE VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL STRING 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 | n, s = tuple(map(int, input().split(" ")))
x = n * [0]
if s == 0 and n != 1 or s / n > 9:
print("-1 -1")
exit()
elif s == 0 and n == 1:
print("0 0")
exit()
for i in range(n):
if s < 9:
x[i] = s
break
else:
x[i] = 9
s -= 9
x.sort(reverse=True)
largest = 0
for i in range(n):
largest += x[i] * 10 ** (n - i - 1)
i = 0
x.sort()
if x[0] == 0:
while x[i] == 0:
i += 1
x[i] -= 1
x[0] = 1
smallest = 0
for i in range(n):
smallest += x[i] * 10 ** (n - i - 1)
print(str(smallest) + " " + str(largest)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR LIST NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR 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 FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL 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 ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER 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 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 | n, sm = input().strip().split(" ")
n = int(n)
sm = int(sm)
por1 = sm // 9
por = por1
ost = sm % 9
if ost != 0:
por += 1
if por > n or por <= 0 and n > 1:
print("-1 -1")
elif por == n:
print(ost + (1 + por1 - por) * 9, end="")
for i in range(n - 1):
print(9, end="")
print(end=" ")
for i in range(n - 1):
print(9, end="")
print(ost + (1 + por1 - por) * 9, end="")
else:
if sm != 0:
print(1, end="")
else:
print(0, end="")
for i in range(n - por - 1):
print(0, end="")
if por != por1:
print(ost - 1, end="")
for i in range(por1):
print(9, end="")
else:
if sm != 0:
print(8, end="")
for i in range(por - 1):
print(9, end="")
print(end=" ")
for i in range(por1):
print(9, end="")
print(ost, end="")
for i in range(n - por1 - 1):
print(0, end="") | ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
low = [0] * m
high = [0] * m
if s <= 0 or s > 9 * m:
low = high = -1
else:
t = s - 1
low[0] = 1
for i in range(1, m + 1):
if t > 9:
low[-i] += 9
t -= 9
else:
low[-i] += t
t = 0
low = int("".join(map(str, low)))
t = s
for i in range(m):
if t > 9:
high[i] += 9
t -= 9
else:
high[i] += t
t = 0
high = int("".join(map(str, high)))
if m == 1 and s == 0:
low = high = 0
print(low, high) | 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 IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def check(l, s):
return 0 <= s <= l * 9
l, s = map(int, input().split())
x = s
a = l
minn = ""
a = s
for i in range(l):
for d in range(0, 10):
if (i > 0 or d > 0 or l == 1 and d == 0) and check(l - i - 1, s - d):
minn += str(d)
s -= d
break
maxx = ""
for i in range(l):
for d in range(9, -1, -1):
if check(l - i - 1, a - d):
maxx += str(d)
a -= d
break
s = x
if (
s == 0
and l != 1
or minn == ""
or maxx == ""
or minn.count("0") == len(minn)
and (l != 1 and s != 0)
):
print(-1, -1)
else:
print(minn, maxx) | FUNC_DEF RETURN NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR 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 VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR STRING VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
temp = s
largest = [-1] * m
for i in range(m):
if temp >= 9:
largest[i] = 9
temp -= 9
else:
largest[i] = temp
temp = 0
tempTwo = s - 1
smallest = [0] * m
smallest[0] = 1
for i in range(m - 1, 0, -1):
if tempTwo < 0:
break
elif tempTwo >= 9:
smallest[i] = 9
tempTwo -= 9
else:
smallest[i] = tempTwo
tempTwo = 0
smallest[0] += tempTwo
if temp != 0 or largest[0] == 0 and (s > 0 or m > 1):
print(-1, -1)
else:
answerOne = ""
answerTwo = ""
for i in range(m):
answerOne += str(largest[i])
answerTwo += str(smallest[i])
print(answerTwo, answerOne) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR 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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required 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 find_max(num_of_digits, sum_of_digits):
if sum_of_digits == 0:
if num_of_digits == 1:
return 0
else:
return -1
if sum_of_digits > 9 * num_of_digits:
return -1
T = [[(0) for i in range(sum_of_digits + 1)] for j in range(num_of_digits + 1)]
for i in range(min(sum_of_digits + 1, 10)):
T[1][i] = i
for i in range(2, num_of_digits + 1):
for s in range(1, sum_of_digits + 1):
if s > 9:
T[i][s] = T[i - 1][s - 9] + 9 * 10 ** (i - 1)
else:
T[i][s] = T[i - 1][0] + s * 10 ** (i - 1)
return T[num_of_digits][sum_of_digits]
def find_min(num_of_digits, sum_of_digits):
if sum_of_digits == 0:
if num_of_digits == 1:
return 0
else:
return -1
if sum_of_digits > 9 * num_of_digits:
return -1
q = sum_of_digits // 9
if sum_of_digits % 9 != 0:
res = "9" * q
rem = sum_of_digits % 9
if num_of_digits - q > 1:
res = "1" + "0" * (num_of_digits - q - 2) + str(rem - 1) + res
else:
res = str(rem) + res
else:
q = q - 1
res = "9" * q
rem = 9
if num_of_digits - q > 1:
res = "1" + "0" * (num_of_digits - q - 2) + str(rem - 1) + res
else:
res = str(rem) + res
return res
m, s = map(int, input().split())
max_num = find_max(m, s)
min_num = find_min(m, s)
print(str(min_num) + " " + str(max_num)) | 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 FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR BIN_OP NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 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())
D = [([-1] * (s + 1)) for i in range(m + 1)]
D[1][0] = 0
for i in range(1, min(s + 1, 10)):
D[1][i] = i
for i in range(2, m + 1):
for j in range(1, s + 1):
if j < 9 * i + 1:
if D[i - 1][j] == -1:
D[i][j] = D[i][j - 1] + 1
else:
D[i][j] = D[i - 1][j] * 10
k = D[-1][-1]
if k == 0:
print("0 0")
elif k != -1:
l = str(k)[-1::-1]
p = "1"
if l[0] == "0":
for i in range(1, m):
if l[i] != "0":
p = p + str(int(l[i]) - 1)
break
else:
p = p + l[i]
p = p + l[i + 1 :]
else:
p = l
print(p, k)
else:
print("-1 -1") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
def small(m, s):
if s == 0:
if m == 1:
return 0
else:
return -1
if s > 9 * m:
return -1
a = [(0) for i in range(m + 1)]
s = s - 1
for i in range(m - 1, 0, -1):
if s > 9:
a[i] = 9
s = s - 9
else:
a[i] = s
s = 0
a[0] = s + 1
return a
def large(m, s):
if s == 0:
if m == 1:
return 0
else:
return -1
if s > 9 * m:
return -1
a = [(0) for i in range(m + 1)]
for i in range(0, m):
if s >= 9:
a[i] = 9
s = s - 9
else:
a[i] = s
s = 0
return a
z1 = small(m, s)
z2 = large(m, s)
if type(z1) == list or type(z2) == list:
for i in range(len(z1) - 1):
print(z1[i], end="")
print(end=" ")
for i in range(len(z2) - 1):
print(z2[i], end="")
else:
print(z1, z2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 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 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 FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR 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 s == 0 and m > 1:
print("-1 -1")
else:
Min, Max = "", ""
t = s
while len(Max) < m:
if t > 9:
Max += "9"
t -= 9
else:
Max += chr(t + ord("0"))
t -= t
if t > 0:
print("-1 -1")
else:
t = s - 1
while len(Min) < m - 1:
if t > 9:
Min = "9" + Min
t -= 9
else:
Min = chr(t + ord("0")) + Min
t -= t
if t + 1 > 9:
print("-1 -1")
else:
Min = chr(t + ord("1")) + Min
print(Min, Max) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if s == 0 and m > 1 or s > m * 9:
print(-1, -1)
exit()
mi = 0
ma = 0
t = s
s -= 1
for i in range(m):
if i < m - 1:
a = min(9, s)
s -= a
mi += a * 10**i
else:
mi += (s + 1) * 10 ** (m - 1)
for i in range(m):
b = min(9, t)
ma += b * 10 ** (m - i - 1)
t -= b
print(mi, ma) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER 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 BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, n = [int(i) for i in input().split()]
if m == 1 and n == 0:
print("0 0")
elif n == 0 or m * 9 < n:
print("-1 -1")
else:
a = (n - 1) // 9
b = str((n - 1) % 9)
d = str(int(b) + 1)
if a + 1 == m:
list_min = [d]
for i in range(m - 1):
list_min.append("9")
else:
c = 0
p = "".join(list_min)
list_min.reverse()
q = "".join(list_min)
else:
list_min = ["1"]
if m == 1:
p = q = n
elif m == 2:
p = 10 + n - 1
q = 10 * n
else:
for i in range(m - a - 2):
list_min.append("0")
else:
c = 0
list_min.append(b)
for i in range(a):
list_min.append("9")
p = "".join(list_min)
list_min.reverse()
q = int("".join(list_min))
q = q - 1 + 10 ** (m - a - 1)
print(p, q) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST STRING IF VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER 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 | p = []
m = []
max1 = str()
min1 = str()
x, y = map(int, input().split())
for i in range(x):
p.append(str(0))
if y == 0 and x != 1 or 9 * x < y:
print("-1 -1")
elif x == 1 and y == 0:
print(y, y)
elif x == 1:
print(y, y)
else:
if y % x == 0 and y % 9 == 0 and y / x % 9 == 0:
for i in range(x):
max1 = max1 + str(9)
else:
a = int(y / 9)
b = y - a * 9
for i in range(a):
p[i] = str(9)
p[a] = str(b)
for i in range(x):
max1 = max1 + p[i]
if y == 1:
p[0] = str(1)
for i in range(x):
min1 = min1 + p[i]
else:
a = 9 * x - y
if a >= 8:
p[0] = str(1)
b = int((a - 8) / 9)
c = a - 8 - b * 9
for i in range(1, b + 1):
p[i] = str(0)
p[b + 1] = str(9 - c)
for i in range(b + 2, x):
p[i] = str(9)
for i in range(x):
min1 = min1 + p[i]
if a < 8:
min1 = min1 + str(9 - a)
for i in range(1, x):
min1 = min1 + str(9)
print(min1, max1) | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL 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()]
smallestnum = int("1" + "0" * (m - 1))
if m == 1:
smallestnum = 0
bigestnum = int("9" * m)
smallnum = smallestnum
bignum = bigestnum
ninesum = s - 1
if m == 1:
ninesum = s
nines = []
while True:
if ninesum < 0:
smallnum = -1
break
if ninesum == 0:
break
if ninesum < 9:
nines.append(ninesum)
break
else:
nines.append(9)
ninesum -= 9
flag = 0
if len(nines) > 0:
smallstring = list(str(smallnum))
for i in range(len(nines)):
try:
smallstring[-(i + 1)] = str(int(smallstring[-(i + 1)]) + nines[i])
except:
smallnum = -1
flag = 1
break
if flag == 0:
smallout = ""
for i in smallstring:
smallout += i
smallnum = int(smallout)
ninesum = 0
for i in str(bigestnum):
ninesum += int(i)
ninesum = ninesum - s
nines = []
while True:
if ninesum < 0:
bignum = -1
break
if ninesum == 0:
break
if ninesum < 9:
nines.append(ninesum)
break
else:
nines.append(9)
ninesum -= 9
flag = 0
if len(nines) > 0:
bigstring = list(str(bignum))
for i in range(len(nines)):
try:
bigstring[-(i + 1)] = str(int(bigstring[-(i + 1)]) - nines[i])
except:
bignum = -1
flag = 1
break
if flag == 0:
bigout = ""
for i in bigstring:
bigout += i
bignum = int(bigout)
if bignum < smallestnum:
bignum = -1
if smallnum > bigestnum:
smallnum = -1
print(smallnum, bignum) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST WHILE NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF 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 | n, k = map(int, input().split())
if n == 1 and k == 0:
print("0 0")
exit()
if k == 0 or 9 * n < k:
print("-1 -1")
elif k <= 9 and n == 1:
print(k, k)
elif k > 9:
t = k // 9
res = "9" * min(t, n)
if n == t and k - 9 * min(t, n) == 0:
print(res, res)
else:
mn = 0
dif = k - 9 * min(t, n)
dig = n - min(t, n)
if dig == 1:
print(str(dif) + res, res + str(dif))
else:
if dif == 0:
mn = "1" + "0" * (dig - 1) + "8" + res[0:-1]
else:
mn = "1" + "0" * (dig - 2) + str(dif - 1) + res
print(mn, res + str(dif) + "0" * (dig - 1))
else:
t = min(n, k)
res1 = "1" + "0" * (n - 2) + str(k - 1)
res2 = str(k) + "0" * (n - 1)
print(res1, res2) | 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 NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER STRING VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER 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 < 1 and m > 1:
print("-1", "-1")
else:
t = s
u = s
num = ""
num_k = ""
for i in range(m):
if t >= 9:
t -= 9
num += str(9) + " "
num_k += str(9)
else:
num += str(t) + " "
num_k += str(t)
t = 0
num_l = num.split()
if int(num_l[m - 1]) == 0 and m > 1:
num_l[m - 1] = 1
for i in range(m - 2, -1, -1):
if int(num_l[i]) != 0:
num_l[i] = int(num_l[i]) - 1
break
for i in range(m - 1, -1, -1):
print(num_l[i], end="")
print(" " + num_k)
print() | 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 STRING STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER STRING VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER 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 VAR EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m == 1:
if 0 <= s <= 9:
print(s, s)
else:
print(-1, -1)
elif m * 9 == s:
print("9" * m, "9" * m)
elif 1 <= s <= 9 * m:
a = ""
a += "9" * (s // 9)
a += str(s % 9)
a += "0" * (m - len(a))
b = ""
if 1 <= s <= 9 * (m - 1) + 1:
b += "1"
c = "9" * ((s - 1) // 9)
if 1 + len(c) == m:
b += c
else:
d = str((s - 1) % 9) + c
b = b + "0" * (m - len(b) - len(d)) + d
else:
b += str(s % 9)
b += "9" * (s // 9)
print(b, a)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR 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 IF NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR STRING VAR BIN_OP STRING 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 STRING IF NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a, b = map(int, input().split())
if a == 1 and b == 0:
print("0 0")
elif b < 1 or b > 9 * a:
print("-1 -1")
else:
c = 9 * a - b
n = 0
int(n)
while True:
if c < 9:
break
else:
c -= 9
n += 1
pass
x = 0
y = 0
if n >= 1:
x += 8 * 10 ** (a - 1)
for i in range(1, n):
x += 9 * 10 ** (a - i - 1)
x += (c + 1) * 10 ** (a - n - 1)
else:
x += c * 10 ** (a - 1)
minimum = 10**a - 1 - x
d = b
m = 0
int(m)
while True:
if d < 9:
break
else:
d -= 9
m += 1
pass
if m >= 1:
for i in range(1, m + 1):
y += 9 * 10 ** (a - i)
if d == 0:
pass
else:
y += d * 10 ** (a - m - 1)
else:
y += d * 10 ** (a - 1)
print(minimum, y) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR IF VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = list(map(int, input().split()))
n = s
_max = 0
if s != 0 and s / 9 <= m:
for i in range(m):
if s > 9:
_max += 9
_max *= 10
s -= 9
else:
_max += s
_max *= 10 ** (m - 1 - i)
break
_min = 0
k = 1
for i in range(m):
if n > 9:
_min += 9 * k
k *= 10
n -= 9
elif i < m - 1:
_min += (n - 1) * k
_min = 10 ** (m - 1) + _min
break
else:
_min += n * k
print(_min, _max)
elif m == 1 and s / 9 <= m:
print(0, 0)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
if s == 0 and m != 1 or 9 * m < s:
print("-1 -1")
elif m == 1 and s == 0:
print("0 0")
else:
mx = ""
ms = s
while ms != 0:
if ms > 9:
mx += "9"
ms -= 9
else:
mx += str(ms)
ms = 0
mx += "0" * (m - len(mx))
mn = ""
while s != 1:
if s > 9:
mn += "9"
s -= 9
else:
mn += str(s - 1)
s = 1
mn += "0" * (m - len(mn))
mn = (mn[:-1] + str(int(mn[-1]) + 1))[::-1]
print(mn, mx) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 = [int(i) for i in input().split()]
s0 = s
if m > 1 and s < 1 or s > m * 9:
print(-1, -1)
exit()
for i in range(1, m + 1):
if i == 1 and s - 1 <= 9 * (m - 1) and s != 0:
print("1", end="")
s -= 1
continue
temp = max(0, s - 9 * (m - i))
print(temp, end="")
s -= temp
s = s0
print(" ", end="")
for i in range(m):
if s >= 10:
s -= 9
print("9", end="")
elif 0 < s <= 9:
print(s, end="")
s = 0
elif s == 0:
print("0", end="") | 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 NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING IF NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)
def read_int():
return int(stdin.readline())
def read_ints():
return [int(x) for x in stdin.readline().split()]
def read_str():
return input()
def read_strs():
return [x for x in stdin.readline().split()]
lens, sum_needed = read_ints()
if lens == 1 and sum_needed == 0:
print(0, 0)
elif 9 * lens < sum_needed or sum_needed == 0:
print(-1, -1)
else:
answer = 10 ** (lens - 1)
for i in range(sum_needed - 1):
answer += 10 ** (i // 9)
print(answer, end=" ")
answer = 0
for i in range(sum_needed):
answer += 10 ** (lens - 1 - i // 9)
print(answer, end=" ") | ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER 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 | cnt, digsum = [int(x) for x in input().strip().split(" ")]
if digsum == 0 and cnt == 1:
print("0 0")
elif 0 < digsum <= 9 * cnt:
max_list = []
max_sum = digsum
min_list = []
min_sum = digsum
for x in range(cnt):
if max_sum > 9:
max_list.append(9)
max_sum -= 9
else:
max_list.append(max_sum)
max_sum = 0
for x in range(cnt):
if min_sum > 9:
min_list.append(9)
min_sum -= 9
elif x == cnt - 1:
min_list.append(min_sum)
else:
min_list.append(min_sum - 1)
min_sum -= min_sum - 1
print(*min_list[::-1], sep="", end=" ")
print(*max_list, sep="", end=" ")
else:
print("-1 -1") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR VAR STRING 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 | inputs = [int(i) for i in input().split()]
ll = inputs[0]
sod = inputs[1]
mn = -1
mx = -1
if ll == 1 and sod < 10:
print("{} {}".format(sod, sod))
elif sod == 0:
print("-1 -1")
elif ll < sod / 9:
print("-1 -1")
elif ll == sod / 9:
c = "9" * ll
print("{} {}".format(c, c))
else:
for smallnr in range(9):
if (sod - smallnr) % 9 == 0:
numbers = []
while sod - smallnr - 9 > sum(numbers):
numbers.append(9)
numbers.append(sod - smallnr - sum(numbers))
while numbers.count(0) > 0:
numbers.remove(0)
numbers.sort()
mx = int(
str(int("".join([str(i) for i in numbers]) + str(smallnr))).ljust(
ll, "0"
)
)
if len(numbers) < ll - 1:
if smallnr != 0:
numbers.append(smallnr - 1)
else:
numbers[0] -= 1
numbers.sort()
mn = int("1" + "".join([str(i) for i in numbers]).rjust(ll - 1, "0"))
else:
mn = int(
str(smallnr) + "".join([str(i) for i in numbers]).rjust(ll - 1, "0")
)
numbers.reverse()
break
print("{} {}".format(mn, mx)) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | line = input().split()
n = int(line[0])
s = int(line[1])
list = []
b = 0
c = 0
if s > 9 * n:
print(-1, -1)
elif s == 0 and n == 1:
print(0, 0)
elif s == 0 and n != 1:
print(-1, -1)
else:
for i in range(n):
if s >= 9:
s -= 9
list.append(9)
b += 1
elif s < 9 and s > 0:
list.append(s)
s = 0
a = i
else:
list.append(0)
c += 1
max = ""
for i in range(n):
max += str(list[i])
min = ""
if b == n:
for i in range(n):
min += "9"
elif b + c == n:
min += "1"
for i in range(c - 1):
min += "0"
min += "8"
for i in range(b - 1):
min += "9"
elif list[a] == 1:
min += str(list[a])
for i in range(c):
min += "0"
for i in range(b):
min += "9"
elif c != 0:
min += "1"
for i in range(c - 1):
min += "0"
min += "%d" % (list[a] - 1)
for i in range(b):
min += "9"
else:
min += "%d" % list[a]
for i in range(b):
min += "9"
print(int(min), int(max)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING IF BIN_OP VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING IF VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP STRING BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING VAR BIN_OP STRING VAR VAR FOR VAR FUNC_CALL VAR VAR 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 prov(n, s):
if s == 0:
if n == 1:
return 1
else:
return 0
elif n * 9 < s:
return 0
else:
return 2
def prov2(s):
i = 0
f = 0
while i < len(s):
if s[i] != 0:
f = 1
break
i += 1
if f == 1 and 0 in s:
s[i] -= 1
s[0] = 1
return s
def main():
n, s = [int(i) for i in input().split()]
res = prov(n, s)
if res == 0:
print(-1, -1)
return 0
elif res == 1:
print(0, 0)
return 0
d1 = s // 9
p1 = s % 9
q1 = n - d1 - (p1 > 0) * 1
st = d1 * [9]
if p1:
st = [p1] + st
if q1:
st = [0] * q1 + st
ans2 = st[::-1] * 1
ans1 = prov2(st)
print(*ans1, sep="", end=" ")
print(*ans2, sep="", end=" ")
main() | FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER 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 EXPR FUNC_CALL VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER IF VAR ASSIGN VAR BIN_OP LIST VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR 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 | digit, total = map(int, input().split())
if total == 0 and digit == 1:
print(0, 0)
elif total == 0 or total > 9 * digit:
print(-1, -1)
else:
nine = total // 9
rem = total % 9
if rem != 0:
mx = "9" * nine + str(rem)
else:
mx = "9" * nine
mx = mx + "0" * (digit - len(mx))
if mx[-1] != "0":
mn = mx[::-1]
else:
zeros = mx.count("0")
mx_rev = mx[::-1]
change = mx_rev[zeros]
new = str(int(change) - 1)
mn = mx_rev.replace(change, new, 1)
mn = mn.replace("0", "1", 1)
print(mn, mx) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR 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 BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, m = map(int, input().split())
if m == 0 and n != 1 or m > 9 * n:
print("-1 -1")
elif m == 0 and n == 1:
print("0 0")
else:
ans_max = ""
while m:
if m >= 9:
m -= 9
ans_max += "9"
else:
ans_max += str(m)
m = 0
ans_max += "0" * (n - len(ans_max))
ans_min = ""
if ans_max[n - 1] == "0":
ans_min += "1"
a = ans_max[::-1]
for i in range(1, len(a)):
if a[i] == "0":
ans_min += "0"
else:
ans_min += str(int(a[i]) - 1)
break
for j in range(i + 1, n):
ans_min += a[j]
else:
ans_min = ans_max[::-1]
print(ans_min, ans_max) | 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 STRING WHILE VAR IF VAR NUMBER VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR BIN_OP VAR NUMBER STRING VAR STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | s = input().split()
m = int(s[0])
tot = int(s[1])
ans = []
if m == 1 and tot == 0:
print("0 0")
exit()
for i in range(m):
if tot <= 9:
ans.append(tot)
tot = 0
else:
ans.append(9)
tot = tot - 9
if ans[0] == 0 or tot > 0:
print("-1 -1")
exit()
if ans[m - 1] == 0:
boo = True
print("1", end="")
for i in range(m - 1):
if boo == True and ans[m - 2 - i] > 0:
boo = False
print(ans[m - 2 - i] - 1, end="")
else:
print(ans[m - 2 - i], end="")
else:
for i in range(m):
print(ans[m - 1 - i], end="")
print(" ", end="")
for i in range(m):
print(ans[i], end="")
print() | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | line = input()
m, s = [int(i) for i in line.split()]
s_max = s
s_min = s
if m * 9 < s:
print(-1, -1)
elif s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
else:
min = ""
max = ""
for i in range(m):
if s_max - 9 <= 0:
max += str(s_max)
s_max = 0
else:
max += "9"
s_max -= 9
if s_min == 1:
if i == m - 1:
min = "1" + min
else:
min = "0" + min
elif s_min - 9 <= 0:
if m - i == 1:
min = str(s_min) + min
else:
min = str(s_min - 1) + min
s_min = 1
else:
min = "9" + min
s_min -= 9
print(min, max) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR 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 STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR STRING VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP STRING 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 = [int(i) for i in input().split()]
if m == 1 and s == 0:
print("0 0")
elif s == 0 or s > m * 9:
print("-1 -1")
else:
o = []
p = []
a = s // 9
b = s % 9
if b > 0:
for i in range(a):
o.append(str(9))
o.append(str(b))
for i in range(m - a - 1):
o.append(str(0))
max = "".join(o)
if m - a == 1:
p.append(str(b))
for i in range(a):
p.append(str(9))
else:
p.append(str(1))
p.append(str(b - 1))
for i in range(a):
p.append(str(9))
for i in range(m - a - 2):
p.insert(1, str(0))
min = "".join(p)
elif s == m * 9:
for i in range(a):
o.append(str(9))
max = "".join(o)
min = "".join(o)
else:
for i in range(a):
o.append(str(9))
for i in range(m - a):
o.append(str(0))
max = "".join(o)
p.append(str(1))
p.append(str(8))
for i in range(a - 1):
p.append(str(9))
for i in range(m - a - 1):
p.insert(1, str(0))
min = "".join(p)
print(min, max) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a = [int(x) for x in input().split()]
safer = a[1]
mini = 0
maxi = 0
last_not_nime = 0
for x in range(a[0]):
if a[1] > 9:
maxi += 10 ** (a[0] - x - 1) * 9
a[1] -= 9
else:
if a[1] != 0:
last_not_nime = a[0] - x
maxi += 10 ** (a[0] - x - 1) * a[1]
a[1] = 0
if maxi == 0 and a[0] != 1 or a[1] != 0:
print("-1 -1")
else:
if maxi <= 10 or safer == 1:
mini = maxi
elif maxi % 10 == 0:
mini = maxi + 1 - 10 ** (last_not_nime - 1)
mini = str(mini)
mini = mini[::-1]
else:
mini = maxi
mini = str(mini)
mini = mini[::-1]
print(mini, maxi) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a = input().split()
num = int(a[1])
c = int(a[0])
m = 0
s = []
n = []
output = []
if num == 0:
if c == 1:
print(0, 0)
else:
print(-1, -1)
if num > 9 * c:
print(-1, -1)
if 0 < num <= 9 * c:
while num >= 9:
s.append("9")
num -= 9
c -= 1
m += 1
if num > 0:
s.append(str(num))
if c > 1:
n.append("1")
if c == 1:
n.append(str(num))
c -= 1
if c == 0:
for j in range(m):
n.append("9")
output.append(str("".join(n)))
output.append(str("".join(s)))
if c > 0:
for i in range(c):
s.append("0")
if c > 1:
if num == 0:
n.append("1")
for l in range(c - 1):
n.append("0")
n.append("8")
for k in range(m - 1):
n.append("9")
if num > 0:
for l in range(c - 1):
n.append("0")
n.append(str(num - 1))
for k in range(m):
n.append("9")
if c == 1:
num -= 1
n.append(str(num))
for p in range(m):
n.append("9")
output.append(str("".join(n)))
output.append(str("".join(s)))
print(" ".join(output)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST 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 IF NUMBER VAR BIN_OP NUMBER VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, l = input().split(" ")
l = int(l)
n = int(n)
if n == 1 and l == 0:
print("0 0")
elif l > n * 9 or l == 0:
print(-1, -1)
else:
mx = {
(0): 0,
(1): 0,
(2): 0,
(3): 0,
(4): 0,
(5): 0,
(6): 0,
(7): 0,
(8): 0,
(9): 0,
}
for i in range(9, 0, -1):
mx[i] = l // i
l %= i
a = ""
for i in range(9, 0, -1):
if mx[i] != 0:
a += str(i) * mx[i]
temp = n - len(a)
if temp == 0:
for i in range(0, 10):
print(str(i) * mx[i], end="")
print(" ", end="")
elif mx[1] > 0:
print(1, end="")
mx[1] -= 1
print("0" * temp, end="")
for i in range(0, 10):
print(str(i) * mx[i], end="")
print(" ", end="")
else:
print(1, end="")
print("0" * (temp - 1), end="")
flag = True
for i in range(0, 10):
if mx[i] > 0 and flag:
print(i - 1, end="")
mx[i] -= 1
print(str(i) * mx[i], end="")
flag = False
else:
print(str(i) * mx[i], end="")
print(" ", end="")
if len(a) < n:
print(a, "0" * temp, sep="")
else:
print(a) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP STRING 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 | import sys
def largest(n, s):
ans = ""
if s < 10:
return str(s) + "0" * (n - 1)
if s >= 10:
ans = "9" * (s // 9)
if s % 9 != 0:
ans += str(s % 9)
ans += "0" * (n - len(ans))
return ans
def smallest(n, s):
if s == 1:
return "1" + "0" * (n - 1)
ans = "1"
rest = ""
if s <= 10:
return "1" + "0" * (n - 2) + str(s - 1)
else:
rest = "9" * (s // 9)
if s % 9 != 0:
rest = str(s % 9) + rest
if len(rest) == n:
return rest
else:
return "1" + "0" * (n - len(rest) - 1) + str(int(rest[0]) - 1) + rest[1:]
n, s = map(int, input().split())
ans = ""
if s > 9 * n or s < 1 and n > 1:
print(-1, -1)
sys.exit(0)
elif s < 1 and n == 1:
print(0, 0)
elif n == 1 and s < 10:
print(s, s)
else:
print(smallest(n, s), largest(n, s)) | IMPORT FUNC_DEF ASSIGN VAR STRING IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER RETURN BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR BIN_OP NUMBER VAR 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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR 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 | x = input().split()
m = int(x[0])
s = int(x[1])
if s > 9 * m:
print("-1 -1")
elif s == 0 and m > 1:
print("-1 -1")
elif m == 1 and s == 0:
print("0 0")
else:
a = s // 9
q = "9" * a + str(s - 9 * a) * min(1, m - a) + "0" * (m - a - 1)
if s > (m - 1) * 9:
p = str(s - a * 9) * (m - a) + "9" * a
elif s % 9 == 0:
p = "1" + "0" * (m - a - 1) + "8" + "9" * (a - 1)
else:
p = "1" + "0" * (m - a - 2) + str(s - a * 9 - 1) + "9" * a
print(p, q) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP 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 BIN_OP BIN_OP STRING VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | A = input().split()
m = int(A[0])
s = int(A[1])
if m == 1:
if s >= 10:
print(-1, -1)
else:
print(s, s)
elif s > 9 * m or s == 0:
print(-1, -1)
else:
k = s // 9
l = s % 9
q = (s - 1) % 9
a = 0
b = 0
if l != 0:
if 9 * m > s > 9 * (m - 1):
for i in range(m - 1):
a = a + 9 * 10**i
b = b + 9 * 10 ** (m - 1 - i)
a = a + l * 10 ** (m - 1)
b = b + l
if s < 9 * (m - 1):
for i in range(k):
a = a + 9 * 10**i
b = b + 9 * 10 ** (m - 1 - i)
a = a + q * 10**k + 10 ** (m - 1)
b = b + (q + 1) * 10 ** (m - k - 1)
if l == 0:
for i in range(k - 1):
a = a + 9 * 10**i
b = b + 9 * 10 ** (m - 1 - i)
a = a + 8 * 10 ** (k - 1) + 10 ** (m - 1)
b = b + 9 * 10 ** (m - k)
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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = (int(x) for x in input().split())
if m == 1 and s == 0:
print(0, 0)
exit()
if s < 1 or s > m * 9:
print(-1, -1)
exit()
s1 = s
for i in range(m):
d = max(s1 - (m - i - 1) * 9, 1 if i == 0 else 0)
s1 -= d
print(d, end="")
print(" ", end="")
s2 = s
for i in range(m):
d = min(s2, 9)
s2 -= d
print(d, end="")
print() | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(x) for x in input().split()]
def imax(m, s):
if s > 9 * m:
return -1
elif s == 0:
if m == 1:
return 0
else:
return -1
else:
k = s // 9
l = s - k * 9
if l == 0:
return (10**k - 1) * 10 ** (m - k)
else:
return (10 ** (k + 1) - 10 + l) * 10 ** (m - k - 1)
def imin(m, s):
if s > 9 * m:
return -1
elif s == 0:
if m == 1:
return 0
else:
return -1
elif s > m * 9 - 8:
l = s - 9 * m + 9
return (l + 1) * 10 ** (m - 1) - 1
else:
k = (s - 1) // 9
l = s - 1 - k * 9
return 10 ** (m - 1) + (l + 1) * 10**k - 1
print(int(imin(m, s)), int(imax(m, s))) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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())
remainder_str = str(s % 9) if s % 9 > 0 else ""
min_num = remainder_str + "9" * (s // 9)
max_num = "9" * (s // 9) + remainder_str
if len(min_num) == 0:
min_num = max_num = 0 if m == 1 else -1
elif len(min_num) > m:
min_num = max_num = -1
elif len(min_num) < m:
min_num = (
"1" + "0" * (m - len(min_num) - 1) + str(int(min_num[0]) - 1) + min_num[1:]
)
max_num = max_num + "0" * (m - len(max_num))
print(min_num, max_num) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
s1 = s
s2 = s
list1 = [0] * m
if s == 0 and m != 1:
print(-1, -1)
if s > 9 * m and m != 1:
print(-1, -1)
if s != 0 and s <= 9 * m and m != 1:
for i in range(m):
for t in range(10):
if t <= s1:
list1[i] = t
s1 = s1 - list1[i]
list1 = [str(i) for i in list1]
maximun = "".join(list1)
maximun = int(maximun)
list2 = [0] * m
list2[0] = 1
for i in range(m - 1, 0, -1):
for t in range(10):
if t <= s2 - 1:
list2[i] = t
s2 = s2 - list2[i]
if s2 >= 2:
list2[0] = s2
list2 = [str(i) for i in list2]
minimun = "".join(list2)
minimun = int(minimun)
print(minimun, maximun)
if m == 1:
if s > 9:
print(-1, -1)
else:
print(s, s) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a, b = map(int, input().split())
output1 = ""
backupb = b
output2 = ""
if b <= 0 and a != 1 or b > a * 9:
print("-1 -1")
elif a == 1 and b == 0:
print(0, 0)
else:
for i in range(a):
output1 = output1 + str(min(9, b))
if b - 9 > 0:
b = b - 9
else:
b = 0
b = backupb
if (a - 1) * 9 > b - 1:
for i in range(1, a + 1):
if b != 1:
output2 = output2 + str(min(9, b - 1))
if b - 9 > 1:
b = b - 9
else:
b = 1
elif i != a:
output2 = output2 + "0"
else:
output2 += "1"
else:
for i in range(1, a + 1):
if b >= 10:
output2 = output2 + "9"
b = b - 9
else:
output2 += str(b)
print(output2[::-1], output1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR STRING VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = input().split()
m = int(m)
s = int(s)
if 9 * m < s:
print("-1 -1")
elif s == 0 and m != 1:
print("-1 -1")
elif s == 0 and m == 1:
print("0 0")
else:
i = 2
A = []
s1 = s - 1
while i <= m:
if s1 >= 9:
A.extend([9])
s1 -= 9
i += 1
elif s1 < 9 and s1 > 0:
A.extend([s1])
s1 = 0
i += 1
else:
A.extend([0])
i += 1
A.sort()
A1 = [str(x) for x in A]
print(str(1 + s1) + "".join(A1), end=" ")
i = 1
A = []
s1 = s
while i <= m:
if s1 >= 9:
A.extend([9])
s1 -= 9
i += 1
elif s1 < 9 and s1 > 0:
A.extend([s1])
s1 = 0
i += 1
else:
A.extend([0])
i += 1
A.sort(reverse=True)
A1 = [str(x) for x in A]
print("".join(A1), end=" ") | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR 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 NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_CALL STRING VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | [m, s] = [int(s) for s in input().split()]
a = [(0) for i in range(m)]
b = [(0) for i in range(m)]
sa = s
i = m - 1
while i >= 0:
if sa > 9:
a[i] = 9
sa = sa - 9
else:
a[i] = sa
sa = 0
i -= 1
fail = sa > 0
if not fail:
if m > 1 and a[0] == 0:
a[0] = 1
found = False
for i in range(1, m):
if a[i] > 0:
a[i] -= 1
found = True
break
fail = not found
if fail:
print(-1, -1)
else:
sb = s
for i in range(m):
if sb > 9:
b[i] = 9
sb = sb - 9
else:
b[i] = sb
sb = 0
print("{0} {1}".format("".join(map(str, a)), "".join(map(str, b)))) | ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if 9 * m < s or s == 0 and m > 1:
print(-1, -1)
elif s == 0:
print(0, 0)
else:
dig9 = (s - 1) // 9
redun = s - 9 * dig9
if dig9 <= m - 2:
mini = "1" + (m - 2 - dig9) * "0" + str(redun - 1) + dig9 * "9"
else:
mini = str(redun) + dig9 * "9"
maxi = dig9 * "9" + str(redun) + (m - dig9 - 1) * "0"
print(mini, maxi) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP BIN_OP VAR NUMBER VAR STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER 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 | def numbers(l, s):
if l == 1 and s > 9 or s == 0 and l > 1:
return "-1 -1"
if l == 1 and s < 10:
return str(s) + " " + str(s)
max = []
s1 = s
for i in range(l):
if s1 >= 9:
max.append(9)
s1 -= 9
else:
max.append(s1)
s1 -= s1
if s1 != 0:
return "-1 -1"
min = max[::-1]
if min[0] == 0:
min[0] = 1
for i in range(1, l):
if min[i] != 0:
min[i] = min[i] - 1
break
max_s = ""
for i in max:
max_s += str(i)
min_s = ""
for i in min:
min_s += str(i)
return min_s + " " + max_s
l, s = map(int, input().split())
print(numbers(l, s)) | FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP VAR STRING 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 = input().split(" ")
m = int(m)
s = int(s)
if s == 0:
if m == 1:
print("0 0")
exit()
a = [1]
while len(a) < m:
a.append(0)
b = [9] * m
diff = sum(b) - s
if diff < 0:
print("-1 -1")
exit()
i = m - 1
while diff > 0:
if diff >= 9:
b[i] -= 9
i -= 1
else:
b[i] -= diff
diff = sum(b) - s
diff = s - sum(a)
if diff < 0:
print("-1 -1")
exit()
i = m - 1
while diff > 0:
if diff <= 9:
a[i] += diff
else:
a[i] = 9
i -= 1
diff = s - sum(a)
print("".join(map(str, a)), "".join(map(str, b))) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
lm = sum([9] * m)
if s < 1 and m != 1 or s > lm:
print(-1, -1)
else:
mx = int(s / 9)
mx2 = int(s % 9)
l = [9] * mx
if mx2 > 0:
l.append(mx2)
if len(l) < m:
for i in range(len(l), m):
l.append(0)
l2 = l[::-1]
if l2[0] == 0:
for i, j in enumerate(l2):
if j != 0:
l2[i] = l2[i] - 1
l2[0] = 1
break
mi = int("".join(map(str, l2)))
mxm = int("".join(map(str, l)))
print(mi, mxm) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def maximal(m, s):
if s > 9 * m:
return "*"
if s == 0:
if m == 1:
return str(0)
else:
return "*"
if m == 1:
if s in range(0, 10):
return str(s)
else:
return "*"
elif s < 10:
return str(s * 10 ** (m - 1))
else:
return str(9) + maximal(m - 1, s - 9)
def minimal(m, s, m_start):
if s > 9 * m:
return "*"
if s == 0:
if m == m_start:
if m == 1:
return str("0")
else:
return "*"
else:
if m == 1:
return str("0")
return str(0) + minimal(m - 1, s, m_start)
if m == 1:
if s in range(10):
return str(s)
else:
return "*"
elif m == m_start:
index_list = [(s - i <= 9 * (m - 1)) for i in range(1, 10)]
if True in index_list:
index_ = index_list.index(True) + 1
return str(index_) + minimal(m - 1, s - index_, m_start)
else:
return "*"
else:
index_list = [(s - i <= 9 * (m - 1)) for i in range(10)]
if True in index_list:
index_ = index_list.index(True)
return str(index_) + minimal(m - 1, s - index_, m_start)
else:
return "*"
input_ = list(map(int, input().split()))
m, s = input_[0], input_[1]
out_1, out_2 = maximal(m, s), minimal(m, s, m)
if "*" in list(out_1) or "*" in list(out_2):
print(str(-1) + " " + str(-1))
else:
print(out_2, end=" ")
print(out_1) | FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN STRING IF VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER RETURN STRING IF VAR NUMBER IF VAR FUNC_CALL VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR RETURN STRING IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN STRING IF VAR NUMBER IF VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR STRING RETURN STRING IF VAR NUMBER RETURN FUNC_CALL VAR STRING RETURN BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER IF VAR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR VAR RETURN STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER IF NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN STRING ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER IF NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, m = map(int, input().split())
if m == 1:
x = "1" + "0" * (n - 1)
print(x, x)
elif m == 0:
if n == 1:
print(0, 0)
else:
print(-1, -1)
elif m <= 9:
if n == 1:
print(m, m)
else:
y = str(m) + "0" * (n - 1)
z = "1" + "0" * (n - 2) + str(m - 1)
print(z, y)
else:
c = "9"
m -= 9
while m > 0:
if m > 9:
c += str(9)
m -= 9
else:
c += str(m)
m = 0
k = len(c)
if k > n:
print(-1, -1)
elif k == n:
print(c[::-1], c)
elif c[-1] == "1":
x = c[::-1]
print("1" + "0" * (n - k) + x[1:], c + "0" * (n - k))
else:
y = c[-1]
p = c[::-1]
z = "1" + "0" * (n - k - 1) + str(int(y) - 1) + p[1:]
print(z, c + "0" * (n - k)) | 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 IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR VAR VAR NUMBER BIN_OP VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP STRING BIN_OP 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()]
def find(rev=False):
if m == 1 and s == 0:
return 0
sum, result = s, ""
for i in range(m):
j = 1 if i == 0 else 0
ok = False
for v in range(j, 10) if rev else reversed(range(j, 10)):
if (m - i - 1) * 9 >= sum - v >= 0:
ok = True
sum -= v
result += str(v)
break
if not ok:
return -1
return result
print(find(True), find(False)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR IF VAR RETURN NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL 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 maxgen(m, s):
ans = [(0) for i in range(m)]
for i in range(m):
if s >= 9:
ans[i] = 9
s = s - 9
else:
ans[i] = s
break
return ans
m, s = list(map(int, input().split()))
if m == 1 and s == 0:
print(0, 0)
elif s < 1 or s > 9 * m:
print(-1, -1)
else:
mina = [(0) for i in range(m)]
mina[0] = max(s - 9 * (m - 1), 1)
maxa = maxgen(m, s)
t = maxgen(m - 1, s - 1)
t.reverse()
for i in range(1, m):
mina[i] = t[i - 1]
ansa = "".join(str(x) for x in mina)
ansb = "".join(str(x) for x in maxa)
print(ansa, ansb) | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | len, sm = map(int, input().split())
sm1 = sm
if sm == 0 and len > 1:
print("-1 -1")
exit()
if sm > len * 9:
print("-1 -1 ")
exit()
maxi = ""
for i in range(len):
if sm == 0:
maxi += "0"
continue
elif sm >= 9:
sm -= 9
maxi += "9"
else:
maxi += str(sm)
sm = 0
mini = ""
sm = sm1
for i in range(len):
if i == 0:
if sm == 0:
mini += "0"
elif sm <= (len - i - 1) * 9:
mini += "1"
sm -= 1
elif sm == 9 * (len - i):
mini += "9"
sm -= 9
else:
mini += str(9 - (9 * (len - i) - sm))
sm = 9 * (len - i - 1)
continue
if sm == 0:
mini += "0"
elif sm < (len - i - 1) * 9:
mini += "0"
elif sm == 9 * (len - i):
mini += "9"
sm -= 9
else:
mini += str(9 - (9 * (len - i) - sm))
sm = 9 * (len - i - 1)
print(mini, maxi) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING IF VAR NUMBER VAR NUMBER VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR STRING IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR STRING IF VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR STRING IF VAR BIN_OP NUMBER BIN_OP VAR VAR VAR STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN 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 | m, s = map(int, input().split())
list1 = ["0"] * m
list2 = ["0"] * m
list1[-1] = "1"
list2[0] = "1"
if m == 1 and s == 0:
print("0 0")
exit()
if m * 9 < s or s == 0:
print("-1 -1")
elif m * 9 == s:
list1 = ["9"] * m
print("".join(list1), "".join(list1))
exit()
elif m == 1:
print(s, s)
else:
for i in range(0, (s - 1) // 9):
list1[i] = "9"
list1[(s - 1) // 9] = str((s - 1) % 9)
for i in range(0, s // 9):
list2[i] = "9"
list2[s // 9] = str(s % 9)
if s == 1:
print("".join(list2), "".join(list2))
elif s > 9 * (m - 1):
list1[-1] = str(s % 9)
print("".join(list(reversed(list1))), "".join(list2))
elif m > 2 and s > 9:
print("".join(list(reversed(list1))), "".join(list2))
elif m > 2 and s <= 9:
list1[0] = str(s - 1)
list2[0] = str(s)
print("".join(list(reversed(list1))), "".join(list2))
elif m == 2 and s > 9:
print("".join(list(reversed(list2))), "".join(list2))
else:
list1 = ["1", str(s - 1)]
list2 = [str(s), "0"]
print("".join(list1), "".join(list2)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING VAR ASSIGN VAR LIST STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def maxn(a, b):
ans = ""
if b < 9:
ans += str(b)
ans += "0" * (a - 1)
else:
ans += "9"
b = b - 9
a = a - 1
if a > 0:
d = b // 9
os = b % 9
ans += "9" * d
if os % 9 != 0:
ans += str(os)
if a - len(ans) + 1 > 0:
ans += "0" * (a - len(ans) + 1)
return ans
def minn(a, b):
ans = ""
if b > (a - 1) * 9:
if b % 9 != 0:
ans += str(b % 9)
else:
ans += "9"
ans += "9" * (a - 1)
else:
ans += "1"
b = b - 1
a = a - 1
if a > 0:
d = b // 9
os = b % 9
if a - d - 1 > 0:
ans += "0" * (a - d - 1)
ans += str(os)
ans += "9" * d
return ans
x, y = map(int, input().split(" "))
if x == 1 and y == 0:
print("0 0")
elif 9 * x < y or y == 0:
print("-1 -1")
else:
print(minn(x, y), maxn(x, y)) | FUNC_DEF ASSIGN VAR STRING IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR STRING IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP STRING BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP STRING VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | ms = input().split()
m = int(ms[0])
s = int(ms[1])
if m * 9 < s or s == 0 and m > 1:
print("-1 -1")
elif s == 0:
print("0 0")
else:
min9 = (s - 1) // 9
minx = s - 1 - min9 * 9
max9 = s // 9
maxx = s - max9 * 9
if min9 + 2 <= m:
minNum = "1" + "0" * (m - 2 - min9) + str(minx) + "9" * min9
else:
minNum = str(minx + 1) + "9" * min9
if max9 + 1 <= m:
maxNum = "9" * max9 + str(maxx) + "0" * (m - 1 - max9)
else:
maxNum = "9" * max9
print(minNum, maxNum) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split(" "))
smll, lrg = 0, 0
if s == 0 and m == 1:
smll, lrg = 0, 0
elif s > m * 9 or s == 0 and m != 0:
smll, lrg = -1, -1
else:
s1 = s
smll = ""
nines = 0
while s1 > 9:
smll += "9"
nines += 1
s1 -= 9
smll += str(s1)
smll += "0" * (m - len(smll))
lrg = smll[::-1]
if lrg[0] == "0":
lrg = (
lrg[0 : m - nines - 1] + chr(ord(lrg[m - nines - 1]) - 1) + lrg[m - nines :]
)
lrg = "1" + lrg[1:]
print(lrg, " ", smll) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP STRING VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | l, s = list(map(int, input().split()))
if s > 9 * l or s < 1 and l != 1:
maxm = -1
minm = -1
else:
r = s % 9
q = s // 9
maxm = str(9) * q + "0" * (l - q)
maxm = int(maxm) + int(r * 10 ** (l - q - 1))
minm = int(str(r) + str(9) * q)
minm = minm - 10 ** (len(str(minm)) - 1)
minm = 10 ** (l - 1) + minm
print(minm, maxm) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER 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 | __author__ = "Utena"
l, v0 = list(map(int, input().split()))
if v0 > l * 9:
print("-1 -1")
elif v0 == 0:
if l == 1:
print("0 0")
else:
print("-1 -1")
else:
a = ""
v = v0
for i in range(l):
if i < l - 1:
x = min(9, v - 1)
a = "%d" % x + a
v -= x
else:
a = "%d" % v + a
b = ""
v = v0
for i in range(l):
b += "%d" % min(9, v)
v -= min(9, v)
print(a + " " + b) | ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP STRING FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER 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:
if m == 1:
print("0 0")
else:
print("-1 -1")
else:
maxi = ""
mini = ""
for i in range(m):
k = str(min(9, s))
maxi += k
s -= int(k)
if s > 0:
print("-1 -1")
else:
x = list(maxi[::-1])
j = 0
while x[j] == "0":
j += 1
if j > 0:
x[0] = "1"
x[j] = str(int(x[j]) - 1)
for i in x:
mini += i
print(mini, maxi) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | import sys
n, s = map(int, input().split())
if s == 0 or 9 * n < s:
if s == 0 and n == 1:
print(0, 0)
else:
print(-1, -1)
sys.exit()
mi = 10 ** (n - 1)
x = s - 1
for i in range(n):
if x > 9:
mi += 10**i * 9
x -= 9
else:
mi += 10**i * x
break
ma = 0
x = s
for i in range(n)[::-1]:
if x > 9:
ma += 10**i * 9
x -= 9
else:
ma += 10**i * x
break
print(mi, ma) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split(" ")]
smallest = 10 ** (m - 1)
largest = 10**m - 1
small_sum = 1
large_sum = 9 * m
if s == 0 and m == 1:
print(0, 0)
elif small_sum > s or large_sum < s:
print(-1, -1)
else:
i = 0
while small_sum < s:
smallest += 10**i * min(s - small_sum, 9)
small_sum = sum(int(digit) for digit in str(smallest))
i += 1
i = 0
while large_sum > s:
largest -= 10**i * min(large_sum - s, 9)
large_sum = sum(int(digit) for digit in str(largest))
i += 1
print(smallest, largest) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR 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 | l = [int(i) for i in input().split()]
result = []
refer = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if l[0] * 9 < l[1]:
print(-1, -1)
elif l[0] != 1 and l[1] == 0:
print(-1, -1)
else:
for i in range(10):
while l[1] >= refer[-(i + 1)]:
l[1] = l[1] - refer[-(i + 1)]
result.append(refer[-(i + 1)])
if len(result) > 2:
if result[-2] == 0:
break
a = str(result[0])
if len(result) - 2 < l[0]:
b = "1"
for i in range(1, len(result) - 1):
a = a + str(result[i])
a = a.ljust(l[0], "0")
b = b.ljust(l[0] - (len(result) - 2), "0")
result[-3] = result[-3] - 1
for i in range(len(result) - 2):
b += str(result[-(i + 3)])
print(b, a)
else:
b = str(result[-3])
for i in range(1, len(result) - 2):
a = a + str(result[i])
for i in range(1, len(result) - 2):
b = b + str(result[-(i + 3)])
print(b, a) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = input().split()
m = int(m)
s = int(s)
x = 1
min1 = max1 = 0
if s > 9 * m or m > 1 and s == 0:
print(-1, -1)
else:
if m == 1 and s == 0:
min1 = max1 = 0
else:
n9 = int(s / 9)
s = s % 9
m = m - n9
if s == 0:
if m == 0:
for i in range(n9):
min1 = min1 + 9 * x
x = x * 10
max1 = min1
else:
min1 = 10 ** (m - 1)
for i in range(m + n9):
if i < n9:
max1 = max1 * 10 + 9
else:
max1 = max1 * 10
if i == m:
min1 = min1 * 10 + 8
if i > m:
min1 = min1 * 10 + 9
else:
if m > 1:
for i in range(m + n9):
if i < m - 1:
min1 = 10**i
if i == m - 1:
min1 = min1 * 10 + s - 1
if i > m - 1:
min1 = min1 * 10 + 9
if i < n9:
max1 = max1 * 10 + 9
if i == n9:
max1 = max1 * 10 + s
if i > n9:
max1 = max1 * 10
if m == 1:
min1 = s
max1 = s
for i in range(n9):
min1 = min1 * 10 + 9
max1 = max1 + 10 ** (i + 1) * 9
print(min1, max1) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP 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, n = map(int, input().split())
s = n
res1 = [(0) for i in range(m)]
res2 = [0] * m
if n > 9 * m or s < 1 and m != 1:
print(-1, end=" ")
print(-1, end="")
else:
s = n - 1
for i in range(m - 1, 0, -1):
if s > 9:
res1[i] = 9
s = s - 9
else:
res1[i] = s
s = 0
res1[0] = s + 1
s = n
for i in range(0, m):
if s > 9:
res2[i] = 9
s -= 9
else:
res2[i] = s
s = 0
for i in range(0, m):
print(res1[i], end="")
print(" ", end="")
for i in range(0, m):
print(res2[i], end="") | 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 BIN_OP LIST NUMBER VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING 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 ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING 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 | m, s = [int(x) for x in input().split()]
if s == 0 and m > 1:
print("-1 -1")
exit(0)
max_lim = m * 9
if s > max_lim:
print("-1 -1")
exit(0)
smallest = ""
largest = ""
if m == 1:
smallest = str(s)
largest = smallest
elif s < 10:
smallest = "1" + "0" * (m - 2) + str(s - 1)
largest = str(s) + "0" * (m - 1)
else:
q = s // 9
r = s % 9
if q + 1 == m:
if r:
smallest = str(r) + "9" * q
largest = smallest[::-1]
else:
smallest = "18" + "9" * (q - 1)
largest = "9" * q + "0"
elif q == m:
largest = smallest = "9" * q
else:
smallest = "1"
if r:
smallest += "0" * (m - q - 2) + str(r - 1) + "9" * q
else:
smallest += "0" * (m - q - 1) + "8" + "9" * (q - 1)
largest = "9" * q + str(r) + "0" * (m - q - 1)
print("{0} {1}".format(smallest, largest)) | 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 NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING IF VAR VAR ASSIGN VAR VAR BIN_OP STRING VAR ASSIGN VAR STRING IF VAR VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def largest(m, s):
if m == 0 and s == 0:
return True, ""
if s >= 0 and s <= 9 * m:
for digit in range(9, -1, -1):
flag, gen = largest(m - 1, s - digit)
if flag:
return True, str(digit) + gen
return False, ""
else:
return False, ""
def smallest(m, s, first):
if m == 0 and s == 0:
return True, ""
if s >= 0 and s <= 9 * m:
if first:
for digit in range(1, 10):
flag, gen = smallest(m - 1, s - digit, False)
if flag:
return True, str(digit) + gen
else:
for digit in range(10):
flag, gen = smallest(m - 1, s - digit, False)
if flag:
return True, str(digit) + gen
return False, ""
else:
return False, ""
def f(m, s):
if m == 1 and s == 0:
return 0, 0
mxflag, mx = largest(m, s)
mnflag, mn = smallest(m, s, True)
if not (mnflag and mxflag):
return -1, -1
else:
return mn, mx
m, s = map(int, input().split())
mx, mn = f(m, s)
print(mx, mn) | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR RETURN NUMBER BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER STRING RETURN NUMBER STRING FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR RETURN NUMBER BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR RETURN NUMBER BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER STRING RETURN NUMBER STRING FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if s == 0 and m > 1:
print("-1 -1")
elif s == 0 and m == 1:
print("0 0")
else:
nmax = ""
nmin = ""
ts = s
for i in range(m - 1):
if ts > 9:
nmin = "9" + nmin
ts -= 9
else:
nmin = chr(ts + 47) + nmin
ts = 1
if s > 9:
nmax = nmax + "9"
s -= 9
else:
nmax = nmax + chr(s + 48)
s = 0
if ts > 9:
print("-1 -1")
else:
nmin = chr(ts + 48) + nmin
nmax = nmax + chr(s + 48)
print(nmin, nmax) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, j = map(int, input().split())
p = j % 9
q = j // 9
if n < q or n == q and p != 0 or j == 0 and n != 1:
print("-1 -1")
elif n == 1 and j == 0:
print("0 0")
elif p == 0 and q == n:
print("9" * q, "9" * q)
else:
t = j % 9
w = j // 9
if n > w + 1:
t = t - 1
if t < 0:
t = 9 + t
w = w - 1
else:
w = w
k = 1
x = n - w - k - 1
else:
w = w
x, k = 0, 0
print("1" * k, end="")
print("0" * x, end="")
print(t, end="")
print("9" * w, end=" ")
r = n - q - 1
print("9" * q, end="")
print(p, end="")
print("0" * r, end=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP 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 != 1 and s == 0 or s > 9 * m:
print("-1 -1")
else:
rem = s
i = m - 1
maxi = 0
while i >= 0:
maxi += min(rem, 9) * 10**i
rem -= min(rem, 9)
i -= 1
rem = s - 1
mini = 0
for j in range(0, m - 1):
mini += min(max(0, rem), 9) * 10**j
rem -= min(max(0, rem), 9)
mini += (rem + 1) * 10 ** (m - 1)
print(mini, maxi) | 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 ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | string = input()
numbers = string.split()
m = int(numbers[0])
s = int(numbers[1])
if s < 1 and m != 1 or s > m * 9:
smallest = "-1"
largest = "-1"
else:
digits = []
if m == 1:
n = 0
total = 0
else:
n = 10 ** (m - 1)
total = 1
for x in str(n):
digits.append(int(x))
x = m - 1
while total != s:
digits[x] += 1
total += 1
if digits[x] == 9:
x -= 1
smallest = ""
for x in digits:
smallest += str(x)
digits = []
for x in str(10**m - 1):
digits.append(int(x))
total = m * 9
x = m - 1
while total != s:
digits[x] -= 1
total -= 1
if digits[x] == 0:
x -= 1
largest = ""
for x in digits:
largest += str(x)
print("%s %s" % (smallest, largest)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.