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 = list(map(int, input().split()))
t = s
if m == 1 and s == 0:
print("0 0")
elif s <= sum([int(i) for i in "9" * m]) and s > 0:
z = list(str(10 ** (m - 1)))
k = -1
for i in range(m):
if s > 9:
z[k] = "9"
s -= 9
elif z[k] != z[0]:
if s - 1 > 0:
z[k] = str(s - 1)
s = 0
elif z[k] == z[0] and s > 0:
z[k] = str(s)
k += -1
g = int("".join(z))
if t <= 9:
n = str(t) + "0" * (m - 1)
else:
r = list("9" * m)
for i in range(m):
if t >= 9:
t -= 9
elif t > 0:
r[i] = str(t)
t = 0
else:
r[i] = "0"
n = "".join(r)
print("{} {}".format(g, n))
else:
print("-1 -1") | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR STRING VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 | inp = input().split(" ")
m = int(inp[0])
s = int(inp[1])
s_max = s
s_min = s
max_val = ""
min_val = ""
if s == 0 and m != 1 or m * 9 < s:
max_val = -1
min_val = -1
m = 0
for i in range(m):
if s_max >= 9:
max_val += "9"
s_max -= 9
else:
max_val += str(s_max)
s_max -= s_max
possible = s_min - 1
possible = possible if possible > 0 else 0
if possible >= 9:
min_val += "9"
s_min -= 9
elif i != m - 1:
min_val += str(possible)
s_min -= possible
else:
min_val += str(s_min)
if m != 0:
min_val = min_val[::-1]
print(min_val, max_val) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF 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 | n, m = map(int, input().split())
ma = ""
mas = m
mi = ""
mis = m
done = False
for i in range(n):
for j in range(9, (not bool(i)) - 1 if i != n - 1 else -1, -1):
if 0 <= mas - j <= (n - i - 1) * 9:
ma += str(j)
mas -= j
break
else:
break
for j in range(not bool(i) if i != n - 1 else 0, 10):
if 0 <= mis - j <= (n - i - 1) * 9:
mi += str(j)
mis -= j
break
else:
break
else:
print(mi, ma)
done = True
if not done:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF 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 = input().split()
m = int(a[0])
z = int(a[0])
s = int(a[1])
x = int(a[1])
q = 0
p = 0
if s > 9 * m or m > 1 and s == 0:
print("-1 -1")
elif m == 1 and s == 0:
print("0 0")
else:
while s >= 9:
s = s - 9
q = q + 10 ** (m - 1) * 9
m = m - 1
if s >= 0:
q = q + int(10 ** (m - 1) * s)
m = m - 1
if x <= 9 * (z - 1) + 1:
p = p + 10 ** (z - 1)
x = x - 1
for i in range(0, z - 1):
if x >= 9:
p = p + 10**i * 9
x = x - 9
else:
p = p + 10**i * x
x = 0
else:
x = x - 9
p = 10 ** (z - 1) * (x - 9 * (z - 2) + 1) - 1
print(int(p), q) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | from sys import stdin
m, s = stdin.readline().split(" ")
m = int(m)
s = int(s)
if m == 1 and s / 10 == 0:
print(s, s)
else:
temp_s = s
numa = 0
numb = 10 ** (m - 1)
bool = True
if m != 0 and s != 0 and s / 9 <= m:
j = 1
while j < m + 1:
a = min(9, temp_s)
numa = numa + a * 10 ** (m - j)
temp_s = temp_s - a
j += 1
i = 1
temp_s = s - 1
while i < 10 ** (m - 1):
a = min(9, temp_s)
numb = numb + a * i
temp_s = temp_s - a
i = i * 10
if temp_s > 0:
numb += temp_s * 10 ** (m - 1)
else:
bool = False
if bool:
print(numb, numa)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF 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 | lenght_and_summ = input()
lenght = int(lenght_and_summ.split()[0])
summ = int(lenght_and_summ.split()[1])
if summ == 0 and lenght > 1 or summ > 9 * lenght:
print("-1 -1")
quit()
if summ == 0 and lenght == 1:
print("0 0")
quit()
min_str = ""
max_str = ""
b = 0
c = 0
for i in range(lenght):
a = 0
while b < summ and a < summ and a < 9:
a += 1
b += 1
max_str = max_str + " " + str(a)
min_str = max_str.split()
min_str.reverse()
min_str_new = list()
if min_str[0] == "0":
min_str_new.append("1")
ok = True
count = 0
for i in min_str:
count += 1
if count == 1:
continue
elif i == "0":
min_str_new.append(i)
elif i != "0" and ok:
min_str_new.append(str(int(i) - 1))
ok = False
else:
min_str_new.append(i)
min_str_last = ""
for i in min_str_new:
min_str_last = min_str_last + i
else:
min_str_last = ""
for i in min_str:
min_str_last = min_str_last + i
max_str_last = ""
for i in max_str.split():
max_str_last = max_str_last + i
print(min_str_last, max_str_last) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR ASSIGN VAR 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 = map(int, input().split())
if s == 0 and m > 1 or 9 * m < s:
print("-1 -1")
else:
mayor = ""
for i in range(m):
if s >= 9:
mayor += "9"
s -= 9
else:
mayor += str(s)
s -= s
menor = ""
temp = 0
for i in range(m):
d = mayor[-(i + 1)]
if i == 0 and d == "0":
if m == 1:
menor += d
else:
menor += "1"
temp = 1
elif d != "0" and temp != 0:
menor += str(int(d) - 1)
temp = 0
else:
menor += d
print(menor, mayor) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR STRING IF VAR NUMBER VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN 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, s = map(int, input().strip().split())
mx = ""
mn = ""
if s > 9 * m or s == 0 and m > 1:
print(-1, -1)
elif s == 0 and m == 1:
print(0, 0)
else:
q = int(s / 9)
r = s % 9
for i in range(q):
mx += str(9)
if r != 0:
mx += str(r)
while len(mx) < m:
mx += "0"
q = int((s - 1) / 9)
r = (s - 1) % 9
for i in range(q):
mn += "9"
if r != 0:
if len(mn) < m - 1:
mn = str(r) + mn
else:
mn = str(r + 1) + mn
while len(mn) < m - 1:
mn = "0" + mn
if len(mn) == m - 1:
mn = "1" + mn
print(mn, mx) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 = [int(x) for x in input().split()]
if m == 1 and s == 0:
print(0, 0)
elif s == 0 or 9 * m < s:
print(-1, -1)
else:
a = []
s1 = s - 1
for i in range(m):
a.append(0)
for i in range(m):
a[i] += min(s, 9)
s -= min(s, 9)
if s <= 0:
break
a1 = ""
for i in range(m):
a1 += str(a[i])
a[i] = 0
a[m - 1] = 1
for i in range(m):
if i == m - 1:
a[i] += min(s1, 8)
s1 -= min(s1, 8)
else:
a[i] += min(s1, 9)
s1 -= min(s1, 9)
if s1 <= 0:
break
a.reverse()
a2 = ""
for i in range(m):
a2 += str(a[i])
print(a2, a1) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(x) for x in input().split()]
ans1 = []
if s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
elif 9 * m < s:
print(-1, -1)
else:
for i in range(m - 1):
ans1.insert(0, max(min(9, s - sum(ans1) - 1), 0))
ans1.insert(0, min(9, s - sum(ans1)))
ans2 = []
for i in range(m):
ans2.append(min(9, s - sum(ans2)))
ans11 = ""
for v in ans1:
ans11 += str(v)
ans22 = ""
for v in ans2:
ans22 += str(v)
print(ans11, ans22) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, s = map(int, input().split())
if n == 1 and s == 0:
print(0, 0)
elif 9 * n < s or s == 0:
print(-1, -1)
else:
res1 = 10 ** (n - 1)
for i in range(s - 1):
res1 += 10 ** (i // 9)
res2 = 0
for i in range(s):
res2 += 10 ** (n - 1 - i // 9)
print(res1, res2) | 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 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 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 VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, m = list(map(int, input().split()))
l = []
f = 0
w = n
if m > 9 * n or m == 0 and n != 1:
print("-1 -1")
f = 1
if m == 0 and n == 1:
print("0 0")
f = 1
while m > 0 or n > 0:
if m <= 0 and n > 0:
l.append("0" * n)
break
elif m - 9 <= 0:
l.append(str(m))
else:
l.append("9")
n = n - 1
m = m - 9
if f == 0:
t = " ".join(l).split(" ")
k = " ".join(l).split(" ")
t.sort()
k.sort(reverse=True)
if int("1" + "0" * (w - 1)) <= int("".join(t)) <= int("9" * w):
print("".join(t) + " " + "".join(k))
elif len(t) > 2:
print(
"1" + "0" * (n - 1) + str(int(t[1]) - 1) + "".join(t[2:]) + " " + "".join(k)
)
else:
print("1" + "0" * (n - 1) + str(int(t[1]) - 1) + " " + "".join(k)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL STRING VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR STRING FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL STRING VAR NUMBER STRING FUNC_CALL STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER STRING FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a = input().split()
l = int(a[0])
m = int(a[1])
if m > 9 * l or m == 0 and l != 1:
print("-1 -1")
elif m == 9 * l:
for i in range(l):
print(9, end="")
print(" ", end="")
for i in range(l):
print(9, end="")
print(" ", end="")
elif l == 1:
print(m, m)
else:
b = [(0) for i in range(l)]
b[0] = 1
t = (m - 1) // 9
for i in range(l - t, l):
b[i] = 9
if l - t - 1 == 0:
b[l - t - 1] = m % 9
else:
b[l - t - 1] = (m - 1) % 9
for i in range(l):
print(b[i], end="")
print(" ", end="")
if b[l - 1] == 0:
for i in range(l):
print(b[i], end="")
elif b[0] == 1:
b[0] = 0
b[l - t - 1] += 1
for i in range(l - 1, -1, -1):
print(b[i], end="")
else:
for i in range(l - 1, -1, -1):
print(b[i], end="") | 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 VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING IF VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER 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(" "))
st = [0] * m
st[0] = 1
mx = [0] * m
b = s - 1
z = s
if s > 1:
i = m - 1
while i > -1:
if b > 9:
st[i] += 9
b -= 9
else:
st[i] += b
b = 0
break
i -= 1
st2 = 0
mx2 = 0
j = 0
while j < m:
if s > 9:
mx[j] = 9
s -= 9
else:
mx[j] = s
s = 0
j += 1
sm = sum(mx)
for i in range(m):
st2 = st2 * 10 + st[i]
mx2 = mx2 * 10 + mx[i]
st1 = str(st2)
mx1 = str(mx2)
if b != 0:
if m == 1 and b == -1:
print("0 0")
else:
print("-1 -1")
elif sm != z:
print("-1 -1")
else:
print(st1 + " " + mx1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(x) for x in input().split()]
if s == 0 and m == 1:
print(0, 0)
elif s == 0 or s > m * 9:
print(-1, -1)
else:
s2 = s
output = ""
if s - (m - 1) * 9 < 0:
output += "1"
s -= 1
for i in range(1, m):
a = max(0, s - (m - i - 1) * 9)
output += str(a)
s -= a
else:
for i in range(m):
a = max(0, s - (m - i - 1) * 9)
output += str(a)
s -= a
output += " "
for i in range(m):
a = min(9, s2)
output += str(a)
s2 -= a
print(output) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR STRING IF BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, m = map(int, input().split())
if m == 0:
if n == 1:
print(0, 0)
else:
print(-1, -1)
quit()
if n * 9 < m:
print(-1, -1)
quit()
mm = m - 1
d = 0
num_min = 10 ** (n - 1)
while mm > 9:
num_min += 9 * 10**d
d += 1
mm -= 9
num_min += mm * 10**d
num_max = int("9" + "0" * (n - 1))
m -= 9
d = n - 2
while m > 0:
num_max += 9 * 10**d
d -= 1
m -= 9
num_max += m * 10 ** (d + 1)
print(num_min, num_max) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR NUMBER 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 | line = input()
lines = line.split()
a = int(lines[0])
b = int(lines[1])
x = a
y = b
t = 0
s = 0
if b < 1 or b > 9 * a:
if a == 1 and b == 0:
print("0 0")
else:
print("-1 -1")
elif a > 1:
if b <= 9 * a - 8:
while y > 10:
y -= 9
t += 1
x -= 1
y -= 1
print("1", end="")
for i in range(x - 2):
print("0", end="")
print(y, end="")
for i in range(t):
print("9", end="")
print(" ", end="")
while b > 9:
b -= 9
s += 1
a -= 1
for i in range(s):
print("9", end="")
print(b, end="")
for i in range(a - 1):
print("0", end="")
else:
q = b + 9 - 9 * a
print(q, end="")
for i in range(a - 1):
print("9", end="")
print(" ", end="")
for i in range(a - 1):
print("9", end="")
print(q)
else:
print(b, b) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING WHILE VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR 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 | g = input()
s = []
k = 0
q = ""
f = ""
r = ""
u = ""
s = list(map(int, g.split()))
su = s[1]
no = s[0]
if su != 0:
k = su // 9
r = su % 9
if r != 0:
t = "9" * k + chr(48 + r) + "0" * (no - (k + 1))
else:
t = "9" * k + "0" * (no - k)
for i in range(0, no):
q = q + t[no - i - 1]
z = 1
if q[0] == "0":
while q[z] == "0":
z += 1
r = q[0:z]
u = q[z + 1 : len(q)]
f = chr(ord(q[z]) - 1)
q = r + f + u
q = chr(ord(q[0]) + 1) + q[1 : len(t)]
if len(t) == no:
print(q, t)
else:
print("-1 -1")
elif no > 1:
print("-1 -1")
else:
print("0 0") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP STRING BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER STRING WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF 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 | n, s = map(int, input().split())
S1 = ["0" for i in range(n)]
S2 = ["0" for i in range(n)]
j = 0
c = 0
if s == 0 and n != 1 or n * 9 < s:
print(-1, -1)
c = 1
if s == 0 and n == 1:
print(0, 0)
c = 1
for i in range(s):
if c == 1:
break
S1[j] = str(int(S1[j]) + 1)
if S1[j] == "9":
j = j + 1
j = 0
for i in range(s):
if c == 1:
break
S2[j] = str(int(S2[j]) + 1)
if S2[j] == "9":
j = j + 1
for i in range(1, n):
if c == 1:
break
if S1[0] == "1":
break
while S1[i] != "9" and S1[0] != "1":
S1[i] = str(int(S1[i]) + 1)
S1[0] = str(int(S1[0]) - 1)
for i in range(1, n - 1):
if c == 1:
break
for j in range(i + 1, n):
while S1[j] != "9" and S1[i] != "0":
S1[j] = str(int(S1[j]) + 1)
S1[i] = str(int(S1[i]) - 1)
if c == 0:
print("".join(S1), "".join(S2)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER IF VAR NUMBER STRING WHILE VAR VAR STRING VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | import sys
m, s = list(map(int, input().split()))
if m == 1 and s == 0:
print("0 0")
sys.exit()
if s > 9 * m or s <= 0:
print("-1 -1")
sys.exit()
max, min = "", ""
minS = s
for i in range(m):
if s - 9 >= 0:
max = max + "9"
s = s - 9
else:
max = max + "{0}".format(s)
s = 0
s = minS
for i in range(m - 1):
if s - 1 >= 9:
min = min + "9"
s = s - 9
else:
min = min + "{0}".format(s - 1)
s = 1
if s == 1:
min = min + "1"
else:
min = min + "{0}".format(s)
print(min[::-1], max) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL STRING 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 s == 0 and m > 1 or s > m * 9:
print(-1, -1)
elif s == 0 and m == 1:
print(0, 0)
else:
maximum = ""
x = s
while x > 0:
if x >= 9:
maximum += "9"
x -= 9
else:
maximum += str(x)
x = 0
while len(maximum) < m:
maximum += "0"
minimum = ""
y = s
if (m - 1) * 9 >= s - 1:
minimum += "1"
y -= 1
elif m * 9 != s:
minimum += str(s % 9)
y -= s % 9
else:
minimum += "9"
y -= 9
complement = ""
if y == 0:
while len(minimum) < m:
minimum += "0"
else:
while y > 0:
if y > 9:
complement = "9" + complement
y -= 9
else:
complement = str(y) + complement
y = 0
while len(minimum) + len(complement) < m:
minimum += "0"
minimum = minimum + complement
print(minimum, maximum) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR STRING WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR 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 = map(int, input().split())
num = ""
if s == 0 and m > 1 or s > 9 * m:
print("-1 -1")
else:
def f(x, y):
global num
if x > 1:
if y == 0:
return num + "0" * x
elif y < 9:
num += str(y)
y = 0
else:
num += "9"
y -= 9
return f(x - 1, y)
elif x == 1:
return num + str(y)
b = f(m, s)
a = b[::-1]
if a[0] == "0" and m > 1:
c = list(a)
c[0] = "1"
for i in range(1, m):
if c[i] != "0":
c[i] = str(int(c[i]) - 1)
break
a = "".join(c)
print(a, b) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN BIN_OP VAR BIN_OP STRING VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR STRING VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, m = map(int, input().split())
if 1 <= m and m <= n * 9:
f = m // 9
v = m % 9
s = ""
c = ""
if v > 0:
h = n - f - 1
s += str(9) * f + str(v) + str(0) * h
if h > 0:
c += str(1) + str(0) * (h - 1) + str(v - 1) + str(9) * f
else:
c += str(v) + str(9) * f
else:
h = n - f
s += str(9) * f + str(0) * h
if h > 0:
c += str(1) + str(0) * (h - 1) + str(8) + str(9) * (f - 1)
else:
c += str(9) * f
print(c, s)
elif n == 1 and m == 0:
print(0, 0)
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER 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 | s = input().split()
a = int(s[0])
b = int(s[1])
b1 = b
b2 = b
output1 = ""
if b1 > 1:
b1 = b1 - 1
for i in range(a):
if b1 > 9:
b1 = b1 - 9
output1 = output1 + "9"
elif b1 <= 9:
output1 = output1 + str(b1)
b1 = 0
output1 = str(int(output1) + 1)
elif b1 == 0:
output1 = "1-"
else:
output1 = (a - 1) * "0" + "1"
output1 = output1[::-1]
output2 = ""
if b2 > 0:
for i in range(a):
if b2 > 9:
b2 = b2 - 9
output2 = output2 + "9"
elif b2 <= 9:
output2 = output2 + str(b2)
b2 = 0
else:
output2 = "-1"
if b > 9 * a:
output1 = output2 = -1
if a == 1 and b == 0:
output1 = output2 = 0
print("%s %s" % (output1, output2)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER STRING STRING ASSIGN VAR VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | lg, s = map(int, input().split())
minNr = -1
maxNr = -1
if s == 0 and lg == 0:
minNr = 0
maxNr = 0
print(minNr, maxNr)
elif s in range(1, lg * 9 + 1) and lg > 0:
if lg == 1:
minNr = s
print(minNr, end=" ")
else:
s -= 1
minNr = ["9"] * int(s / 9) + [str(int(s % 9))]
minNr += ["0"] * (lg - len(minNr))
minNr[-1] = str(int(minNr[-1]) + 1)[0]
s += 1
print("".join(minNr[::-1]), end=" ")
maxNr = "9" * int(s / 9) + str(int(s % 9))
maxNr += "0" * (lg - len(maxNr))
print(maxNr[0:lg])
elif s == 0 and lg == 1:
print(0, 0)
else:
print(minNr, maxNr) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST STRING FUNC_CALL VAR BIN_OP VAR NUMBER LIST FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP LIST STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR IF 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 | def large(m, s):
if m == 1 and s == 0:
return 0
l = []
for i in range(1, m + 1):
for k in range(0, 10):
if s - k < 0:
return -1
if s - k <= (m - i) * 9 or k == s:
l.append(k)
s -= k
flag = 1
break
if len(l) == 0:
return -1
t = ""
l.sort(reverse=True)
if l[0] == 0:
return -1
for i in range(m):
t += str(l[i])
return t
def small(m, s):
if m == 1 and s == 0:
return 0
l = []
for i in range(1, m + 1):
for k in range(0, 10):
if s - k < 0:
return -1
if s - k <= (m - i) * 9 or k == s:
if len(l) == 0 and k == 0:
continue
l.append(k)
s -= k
flag = 1
break
if len(l) == 0:
return -1
u = ""
t = ""
for i in range(m):
u += str(l[i])
return u
m, s = [int(x) for x in input().split()]
a = small(m, s)
b = large(m, s)
print(a, b) | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR 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 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 adder(n):
cnt = 0
while n:
cnt += n % 10
n //= 10
return cnt
def suml2(l, s):
base = int("9" * (l - 1))
lim = int("1" + "0" * l)
for i in range(base + 1, lim):
if adder(i) == s:
lst = [j for j in str(i)]
return i
def suml(l, s):
if s == 0 and l > 1:
print(-1, -1)
return ""
if s < 20 and l > 1:
mini = suml2(l, s)
if l == 1 and s == 0:
print(0, 0)
return ""
dp = [0] * l
curr = 0
for i in range(l):
dp[i] = min(9, s - curr)
curr += dp[i]
if sum(dp) != s:
print(-1, -1)
return ""
lst1 = sorted(dp)
if lst1[lst1.count(0)] != 1 and lst1.count(0) > 0:
middle = [0] * lst1.count(0)
middle[-1] = lst1[lst1.count(0)] - 1
temp = [1] + middle + lst1[lst1.count(0) + 1 :]
else:
temp = [lst1[lst1.count(0)]] + [0] * lst1.count(0) + lst1[lst1.count(0) + 1 :]
if s < 20 and l > 1:
print(mini, "".join(map(str, lst1[::-1])))
return ""
print("".join(map(str, temp)), "".join(map(str, lst1[::-1])))
return ""
a, b = map(int, input().strip().split())
print(suml(a, b)) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP STRING BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER RETURN STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP LIST VAR FUNC_CALL VAR NUMBER BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, s = map(int, input().split())
if s < 1 and n > 1 or n * 9 < s:
print(-1, -1)
else:
m = s
ma = [0] * n
for i in range(n):
if m >= 9:
ma[i] += 9
m -= 9
else:
ma[i] += m
m -= m
mi = ma[::-1]
if mi[0] == 0:
if len(set(mi)) <= 2:
mi[mi.index(max(mi))] -= 1
mi[0] += 1
else:
mi[mi.index(max(mi)) - 1] -= 1
mi[0] += 1
print("".join(map(str, mi)), "".join(map(str, ma))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER 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())
if m != 1 and s == 0 or s > 9 * m:
print("-1 -1")
elif (m, s) == (1, 0):
print("0 0")
else:
rem = s
for i in range(1, m + 1):
if i == 1:
b = 1
else:
b = 0
d = max(b, rem - 9 * (m - i))
print(d, end="")
rem -= d
print(" ", end="")
rem = s
for i in range(1, m + 1):
d = min(9, rem)
print(d, end="")
rem -= d | 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 VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def outmax(x):
if x <= 9:
return x
else:
return 9
def outmaxnum(m, s):
if s == 0 or s > 9 * m:
return None
else:
maxnum = []
while True:
maxnum.append(str(outmax(s)))
s -= outmax(s)
if len(maxnum) == m:
break
else:
pass
return "".join(maxnum)
m, s = map(int, input().split())
if s == 0 and m != 1 or s > 9 * m:
print(-1, -1)
elif s == 0 and m == 1:
print(0, 0)
else:
output_max = int(outmaxnum(m, s))
if outmaxnum(m - 1, s - 1) != None:
a = outmaxnum(m - 1, s - 1)
output_min = "1" + outmaxnum(m - 1, s - 1)[::-1]
else:
output_min = outmaxnum(m, s)[::-1]
if output_min[0] == "0":
output_min = outmaxnum(m, s)[0] + outmaxnum(m, s)[1:][::-1]
print(output_min, output_max) | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER VAR RETURN NONE ASSIGN VAR LIST WHILE NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN FUNC_CALL STRING VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NONE ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | from sys import stdin, stdout
def get():
a = list(map(int, stdin.readline().split()))
if len(a) == 1:
return a[0]
else:
return a
def pln(a=None, b=None, c=None, d=None, e=None, f=None):
a = [a, b, c, d, e, f]
out = ""
for i in a:
if i != None:
out += str(i) + " "
stdout.write(str(out) + "\n")
def pls(a=None, b=None, c=None, d=None, e=None, f=None):
a = [a, b, c, d, e, f]
out = ""
for i in a:
if i != None:
out += str(i) + " "
stdout.write(str(out))
n, sum = get()
if sum == 0:
if n == 1:
pln(0, 0)
else:
pln(-1, -1)
exit()
mn = "1" + "0" * (n - 1)
mx = str(min(sum, 9)) + "0" * (n - 1)
s2 = sum
sum -= min(sum, 9)
for i in range(1, n):
mx = mx[:i] + str(min(sum, 9)) + mx[i + 1 :]
sum -= min(sum, 9)
sum = s2 - 1
for i in range(n - 1, 0, -1):
mn = mn[:i] + str(min(sum, 9)) + mn[i + 1 :]
sum -= min(sum, 9)
if sum > 0:
i = 0
mn = mn[:i] + str(min(sum + 1, 9)) + mn[i + 1 :]
def sod(n):
n = str(n)
sum = 0
for x in n:
sum += int(x)
return sum
if sod(mn) == sod(mx) and sod(mn) == s2:
pln(mn, mx)
else:
pln(-1, -1) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR NUMBER RETURN VAR FUNC_DEF NONE NONE NONE NONE NONE NONE ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR NONE VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF NONE NONE NONE NONE NONE NONE ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR NONE VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 | m, s = map(int, input().split())
lis = []
lis1 = []
b = s - 1
if s == 0 and m > 1 or s > m * 9:
print("-1 -1")
exit()
for i in range(m):
if s > 9:
s -= 9
lis.append(9)
else:
lis.append(s)
s -= s
for i in range(m - 1):
if b > 9:
lis1.append(9)
b -= 9
else:
lis1.append(b)
b = 0
if b != 0:
lis1.append(b + 1)
else:
lis1.append(1)
print(*lis1[::-1], sep="", end=" ")
print(*lis, sep="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING EXPR FUNC_CALL VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m != 1:
if s > 9 and s <= m * 9:
answerupper = str(9) * (s // 9) + str(s % 9) + str(0) * (m - s // 9 - 1)
if (s - 1) // (m - 1) < 9:
answerlower = (
str(1)
+ str(0) * (m - (s - 1) // 9 - 2)
+ str((s - 1) % 9)
+ str(9) * ((s - 1) // 9)
)
elif s % 9 != 0:
answerlower = str(s % 9) + str(9) * (s // 9)
else:
answerlower = str(9) * (s // 9)
if len(answerupper) > m:
answerupper = answerupper.strip(answerupper[len(answerupper) - 1])
else:
answerupper = answerupper
print(answerlower, answerupper)
elif s <= 9 and s > 0:
answerupper = str(s) + str(0) * (m - 1)
answerlower = str(1) + str(0) * (m - 2) + str(s - 1)
print(answerlower, answerupper)
else:
print("%d %d" % (-1, -1))
if m == 1:
if s > 9:
print("%d %d" % (-1, -1))
else:
print(s, s) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING 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(x) for x in input().split()]
def min_and_max(som, l):
if som == 0 and l > 1:
return [-1, -1]
if som <= 9:
return [1 * 10 ** (l - 1) + som - 1, som * 10 ** (l - 1)]
if som > l * 10 - l:
return [-1, -1]
else:
[k1, k2] = min_and_max(som - 9, l - 1)
return [9 + k1 * 10, 9 * 10 ** (l - 1) + k2]
print(*min_and_max(s, m), sep=" ") | ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN LIST NUMBER NUMBER IF VAR NUMBER RETURN LIST BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN LIST NUMBER NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN LIST BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR 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 = input().split(" ")
m = int(m)
s = int(s)
if s == 0:
if m != 1:
print("-1 -1")
else:
print("0 0")
elif s <= 9:
max = 10 ** (m - 1) * s
min = 10 ** (m - 1) + s - 1
print(str(min) + " " + str(max))
else:
y = s % 9
n = int(s / 9)
if n > m:
print("-1 -1")
elif n == m and y > 0:
print("-1 -1")
elif n == m and y == 0:
max = min = 10**m - 1
print(str(min) + " " + str(max))
else:
max = int(int(str(10**n - 1) + str(y)) * 10 ** (m - n - 1))
if y == 0:
if n == m:
min = max
else:
min = int(10 ** (m - 1) + 10**n - 10 ** (n - 1) - 1)
else:
min = int(10 ** (m - 1) + 10**n * (y - 1) + 10**n - 1)
print(str(min) + " " + str(max)) | 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 STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER 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 | m, s = map(int, input().split())
if s == 0 and m == 1:
print("0 0")
elif s == 1:
print("1" + (m - 1) * "0", "1" + (m - 1) * "0")
elif s == 0 or s > m * 9:
print("-1 -1")
else:
s -= 1
s1 = s
minn = [1] + (m - 1) * [0]
maxx = [1] + (m - 1) * [0]
i = 0
while s != 0:
if i == 0:
maxx[i] += min(8, s)
s -= min(8, s)
else:
maxx[i] += min(9, s)
s -= min(9, s)
i += 1
i = 0
while s1 != 0:
if m - i - 1 == 0:
minn[m - i - 1] += min(8, s1)
s1 -= min(8, s1)
else:
minn[m - i - 1] += min(9, s1)
s1 -= min(9, s1)
i += 1
print("".join(map(str, minn)), "".join(map(str, maxx))) | 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 EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | s = input()
l = s.split()
l = list(map(int, l))
raqam = l[0]
majmo = l[1]
if majmo == 0 and raqam == 1:
print("0 0")
elif majmo < 1 or majmo > raqam * 9:
print("-1 -1")
else:
min = ""
m = majmo - 1
for i in range(0, raqam - 1):
if m > 9:
min = "9" + min
m -= 9
else:
min = str(m) + min
m = 0
min = str(m + 1) + min
max = ""
m = majmo
for i in range(0, raqam):
if m > 9:
max = max + "9"
m -= 9
else:
max = max + str(m)
m = 0
print("%s %s" % (min, max)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | N = input().split()
m = int(N[0])
s = int(N[1])
ans1 = []
ans = []
if s == 0 and m == 1:
print("0 0")
elif s == 0 or s / m > 9:
print("-1 -1")
else:
a = s
for i in range(m + 1):
a = a - 9
if a < 0:
b = i
break
c = s - b * 9
for j in range(b):
ans1.append("9")
if c > 0:
ans1.append(str(c))
for k in range(m - b - 1):
ans1.append("0")
else:
for l in range(m - b):
ans1.append("0")
ans.append("".join(ans1))
d = ans[0][::-1]
for o in range(len(d)):
if int(d[o]) > 0:
e = o
break
print(
"%d %d"
% (int(d) + 10 ** (len(d) - 1) - int(10 ** (len(d) - 1 - o)), int(ans[0]))
) | 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 LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF 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 STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | st = input().split()
m = int(st[0])
s = int(st[1])
if m == 1 and s == 0:
print(0, 0)
elif s > 9 * m or s < 1:
print(-1, -1)
else:
n9 = s // 9
s1 = ""
for x in range(n9):
s1 = s1 + "9"
if len(s1) < m:
mo = s % 9
s1 = s1 + str(mo)
while len(s1) < m:
s1 = s1 + "0"
if s > 9 * (m - 1):
mo = s % 9
if mo == 0:
s2 = ""
else:
s2 = str(mo)
while len(s2) < m:
s2 = s2 + "9"
else:
mo = (s - 1) % 9
s2 = ""
n9 = (s - 1) // 9
for x in range(n9):
s2 = s2 + "9"
if mo != 0:
s2 = str(mo) + s2
while len(s2) < m - 1:
s2 = "0" + s2
s2 = "1" + s2
ans = s2 + " " + s1
print(ans) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR STRING VAR EXPR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
l = [str(s)]
p = int("".join(l))
minn = [0] * m
maxn = [0] * m
if m > 1 and s == 0:
print(-1, -1)
elif 9 * m < s:
print(-1, -1)
elif m == 1 and s == 0:
print(0, 0)
else:
for k in range(1, 10):
if 9 * (m - 1) >= s - k:
minn[0] = k
s = s - k
break
for i in range(1, m):
for j in range(10):
if 9 * (m - i - 1) >= s - j:
minn[i] = j
s = s - j
break
for t in range(m):
minn[t] = str(minn[t])
for q in range(9, 0, -1):
if q <= p:
maxn[0] = q
p = p - q
break
for r in range(1, m):
for y in range(9, -1, -1):
if y <= p:
maxn[r] = y
p = p - y
break
for z in range(m):
maxn[z] = str(maxn[z])
print("".join(minn), "".join(maxn)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(x) for x in input().split()]
beg, end = pow(10, m - 1), int(str(9) * m)
S = s
if s == 0 and m == 1:
print("0 0")
elif s > 9 * m or s == 0:
print("-1 -1")
else:
mn, mx = [0] * m, [0] * m
mn[0] = 1
s -= 1
i = m - 1
while s >= 10:
mn[i] = 9
s -= 9
i -= 1
mn[i] += s
s = S
i = 0
while s >= 10:
mx[i] = 9
s -= 9
i += 1
mx[i] += s
ansmn, ansmx = "", ""
for i in range(m):
ansmn += str(mn[i])
ansmx += str(mx[i])
print(ansmn, ansmx) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR STRING 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 | a = input().split()
m = int(a[0])
s = int(a[1])
if s == 0 and m != 1 or 9 * m < s:
max_ = "-1"
min_ = "-1"
elif s == 0 and m == 1:
max_ = "0"
min_ = "0"
elif s < m and s != 0:
if s <= 9:
max_ = a[1] + "0" * (m - 1)
else:
l = s // 9
k = s % 9
max_ = "9" * l + str(k) + "0" * (m - l - 1)
min_ = "1" + "0" * (m - s) + "1" * (s - 1)
l = (s - 1) // 9
k = (s - 1) % 9
min_ = "1" + "0" * (m - l - 2) + str(k) + "9" * l
elif 9 * (m - 1) < s and 9 * m > s:
l = str(s % 9)
max_ = "9" * (m - 1) + l
min_ = l + "9" * (m - 1)
elif 9 * m == s:
max_ = "9" * m
min_ = max_
else:
l = s // 9
k = s % 9
max_ = "9" * l + str(k) + "0" * (m - l - 1)
if k != 0:
min_ = "1" + "0" * (m - l - 2) + str(k - 1) + "9" * l
else:
min_ = "1" + "0" * (m - l - 1) + "8" + "9" * (l - 1)
print(min_ + " " + max_) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP STRING VAR IF BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER IF 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 ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def LenAndSum(m, s):
max = ""
min = ""
count = 0
s2 = s
if m == 1 and s == 0:
print("0 0")
return
if m > 0 and s == 0 or m * 9 < s:
print("-1 -1")
return
for i in range(m):
if s - 9 >= 0:
max = max + "9"
s -= 9
elif s > 0:
max = max + str(s)
s = 0
else:
max = max + "0"
count += 1
for i in range(m):
if s2 - 9 > 0:
min = min + "9"
s2 -= 9
elif s2 > 0 and i == m - 1:
min = str(s2) + min
s2 = 0
elif s2 > 1 and i != m:
min = str(s2 - 1) + min
s2 = 1
elif s2 == 1 and i < m - 1:
min = "0" + min
print(min, " ", max)
inp = input()
m = int(inp.split()[0])
s = int(inp.split()[1])
LenAndSum(m, s) | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING VAR EXPR FUNC_CALL VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL 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 = map(int, input().split())
if s > m * 9:
print(-1, -1)
elif s == 0:
if m == 1:
print(0, 0)
else:
print(-1, -1)
else:
k9 = (s - 1) // 9
kn9 = m - k9
a = [0] * (m - k9) + [9] * k9
if kn9 == 1:
a[0] = s - k9 * 9
else:
a[0] = 1
a[kn9 - 1] = s - k9 * 9 - 1
k9 = s // 9
b = [9] * k9 + [0] * (m - k9)
if k9 < m:
b[k9] = s % 9
print(*a, " ", *b, sep="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | line = input().split()
m = int(line[0])
sum = int(line[1])
if sum == 0:
if m != 1:
print(-1, -1)
else:
print(0, 0)
elif m * 9 < sum:
print(-1, -1)
else:
res = ""
k = sum
bit = 0
while k > 9:
res += "9"
k -= 9
bit += 1
res += str(k)
bit += 1
if not bit == m:
res += "0" * (m - bit)
temp = ""
if bit == m:
for i in range(m):
temp += res[m - i - 1]
print("%s %s" % (temp, res))
else:
temp += "1"
if m - bit >= 2:
temp += "0" * (m - bit - 1)
temp += str(int(res[bit - 1]) - 1)
num = bit - 2
while num >= 0:
temp += res[num]
num -= 1
print("%s %s" % (temp, res)) | 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 NUMBER NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP STRING BIN_OP VAR VAR ASSIGN VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR STRING IF BIN_OP VAR VAR NUMBER VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
maxx = ""
minn = []
s1 = s
s2 = s
for i in range(m):
if s > 9:
maxx += "9"
s -= 9
else:
maxx += str(s)
s = 0
if s1 > 9:
minn.insert(0, "9")
s1 -= 9
else:
minn.insert(0, str(s1))
s1 = 0
if minn[0] == "0":
for i in range(1, len(minn)):
if int(minn[i]) > 0:
minn[i] = str(int(minn[i]) - 1)
minn[0] = "1"
break
if s > m * 9 or s != 0:
maxx = -1
minn = ["-1"]
if maxx == "0" * m:
maxx = -1
if "".join(minn) == "0" * m:
minn = ["-1"]
if s2 == 0 and m == 1:
minn = ["0"]
maxx = 0
print("".join(minn), maxx) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER STRING IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING IF VAR BIN_OP STRING VAR ASSIGN VAR NUMBER IF FUNC_CALL STRING VAR BIN_OP STRING VAR ASSIGN VAR LIST STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n_m = input().split()
n, m = int(n_m[0]), int(n_m[1])
if m == 0:
if n == 1:
print("0", "0")
else:
print("-1", "-1")
elif n * 9 < m:
print("-1", "-1")
else:
if m < 10:
maximum = [m] + [0] * (n - 1)
if n == 1:
minimum = [m]
else:
minimum = [1] + [0] * (n - 2) + [m - 1]
else:
m1, m2 = m, m
maximum, minimum = [], []
for i in range(n - 1):
if m1 <= 9:
break
m1 -= 9
maximum += [9]
maximum += [m1] + (n - len(maximum) - 1) * [0]
if m > (n - 1) * 9:
for j in range(n):
if m2 <= 9:
break
m2 -= 9
minimum += [9]
minimum += [m2]
minimum.reverse()
else:
m2 -= 1
for j in range(n - 1):
if m2 <= 9:
break
m2 -= 9
minimum += [9]
minimum += [m2, 1]
minimum.reverse()
minimum[1:1] = [0] * (n - len(minimum))
for k in range(n):
maximum[k], minimum[k] = str(maximum[k]), str(minimum[k])
print("".join(minimum), "".join(maximum)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR STRING STRING IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING STRING IF VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR LIST NUMBER VAR BIN_OP LIST VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR LIST NUMBER VAR LIST VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR LIST NUMBER VAR LIST VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = input().split()
m = int(m)
s = int(s)
if m == 1 and s == 0:
print("0 0")
elif s > 9 * m or s < 1:
print("-1 -1")
else:
ma = "9" * m
ma = list(ma)
r = 9 * m - s
i = -1
while r != 0:
q = min(9, r)
ma[i] = str(9 - q)
r -= q
i -= 1
ma = "".join(ma)
mi = "1"
mi += "0" * (m - 1)
mi = list(mi)
r = s - 1
i = m - 1
while r != 0:
if i > 0:
q = min(9, r)
mi[i] = str(q)
r -= q
else:
mi[i] = str(r + 1)
r = 0
i -= 1
mi = "".join(mi)
print(mi, ma) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR 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 NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR STRING VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER 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 | def get_max(length, somme):
fs = []
for x in range(length):
temp = min(9, somme)
somme -= temp
fs.append(temp)
return fs
def get_min(length, somme):
mx = get_max(length, somme)
mx.sort()
if mx[0] == 0:
mx[0] = 1
x = 1
while mx[x] == 0:
x += 1
mx[x] -= 1
return mx
def main():
m, s = map(int, input().split())
if m == 1 and s == 0:
print(0, 0)
return
if m > 1 and s == 0 or s > m * 9:
print(-1, -1)
return
ml = get_max(m, s)
minl = get_min(m, s)
s1 = ""
s2 = ""
for item in minl:
s1 += str(item)
for item in ml:
s2 += str(item)
print(s1, s2)
main() | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF 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 RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR 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 | firstLine = [int(n) for n in input().split()]
length = firstLine[0]
total = firstLine[1]
def ones(a):
ret = 0
for i in range(0, a):
ret *= 10
ret += 1
return ret
def nines(a):
ret = 0
for i in range(0, a):
ret *= 10
ret += 9
return ret
def digitSum(a):
return sum(map(int, str(a)))
act = True
if total < 1 and length > 1 or total > 9 * length:
print(-1, -1)
act = False
if act:
low = 10 ** (length - 1)
index = 0
while digitSum(low) != total:
low += min(9, total - digitSum(low)) * 10**index
index += 1
high = nines(length)
index = 0
while digitSum(high) != total:
high -= min(9, digitSum(high) - total) * 10**index
index += 1
print(low, high) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER 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 = input().split()
m = int(m)
s = int(s)
if s == 0 and m != 1 or s > 9 * m:
nummin = -1
nummax = -1
print("-1", "-1")
else:
nummin = m * [0]
nummax = m * [0]
for i in range(m):
a = s - i * 9
if a > 9:
nummax[i] = 9
else:
nummax[i] = max(0, a)
b = s - 1 - i * 9
if b > 9:
nummin[m - i - 1] = 9
else:
nummin[m - i - 1] = max(0, b)
if not (s == 0 and m == 1):
nummin[0] += 1
print("".join(str(i) for i in nummin), "".join(str(i) for i in nummax)) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def func(m, s):
ans = ""
while m >= 1:
if s >= 10:
ans += "9"
s -= 9
else:
ans += str(s)
s = 0
m -= 1
return ans
def compute(m, s):
ans, c = "", 0
while m >= 1:
digit = 0
while 9 * (m - 1) < s - digit:
digit += 1
if digit == 0 and c == 0:
ans += "1"
s -= 1
else:
ans += str(digit)
s -= digit
c += 1
m -= 1
return ans
m, s = map(int, input().split())
if m == 1 and s == 0:
print("0 0")
elif m == 1 and s >= 10:
print("-1 -1")
elif m == 1 and s >= 0 and s < 10:
print(s, s)
elif m > 1 and s == 0:
print("-1 -1")
elif 9 * m < s:
print("-1 -1")
else:
v1 = compute(m, s)
if len(str(v1)) == m:
v2 = func(m, s)
if len(str(v2)) == m:
print(v1, v2)
else:
print("-1 -1")
else:
print("-1 -1") | FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER IF VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR STRING NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
if (m == 1) & (s == 0):
print(0, 0)
elif s == 0 or s > 9 * m:
print(-1, -1)
else:
max = ""
min = []
ms = s
while len(max) < m:
if ms > 9:
min.append("9")
max += "9"
ms -= 9
else:
min.append(str(ms))
max += str(ms)
ms = 0
min.reverse()
if min[0] == "0":
for i in range(m):
if min[i] != "0":
min[0] = "1"
min[i] = str(int(min[i]) - 1)
break
print("".join(min), max) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP 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 STRING ASSIGN VAR LIST ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required 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()))
minu = [(0) for i in range(m)]
s2 = s
beg = True
while s2 > 0:
found = False
if beg:
minu[0] += 1
beg = False
s2 -= 1
found = True
else:
j = m - 1
while j >= 0:
if minu[j] < 9:
minu[j] += 1
s2 -= 1
found = True
break
j -= 1
if found == False:
print(-1, -1)
exit(0)
maxu = [(0) for i in range(m)]
s2 = s
while s2 > 0:
found = False
j = 0
while j < m:
if maxu[j] < 9:
maxu[j] += 1
s2 -= 1
found = True
break
j += 1
if found == False:
print(-1, -1)
exit(0)
if sum(minu) != s:
print(-1, -1)
exit(0)
if sum(maxu) != s:
print(-1, -1)
exit(0)
minu_ans = int("".join([str(i) for i in minu]))
maxu_ans = int("".join([str(i) for i in maxu]))
if len(str(minu_ans)) != m:
print(-1, -1)
exit(0)
if len(str(maxu_ans)) != m:
print(-1, -1)
exit(0)
print(minu_ans, maxu_ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR 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 | n, s = map(int, input().split())
if n == 1 and s <= 9:
print(s, s)
elif s == 0 or s / n > 9:
print(-1, -1)
else:
a = ["0"] * n
a[0] = "1"
p = (s - 1) // 9
r = (s - 1) % 9
if p == 0:
a[len(a) - 1] = str(r)
else:
for i in range(len(a) - 1, len(a) - 1 - p, -1):
a[i] = "9"
a[i - 1] = str(int(a[i - 1]) + r)
aa = "".join(a)
b = ["0"] * n
pp = s // 9
rr = s % 9
if pp == 0:
b[0] = str(rr)
else:
for j in range(0, pp, 1):
b[j] = "9"
if rr > 0:
b[j + 1] = str(rr)
bb = "".join(b)
print(int(aa), int(bb)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
res = [] * m
mes = [] * m
summ = s
if summ == 1:
res.insert(0, "1")
if m != 1:
for i in range(1, m):
res.insert(i, "0")
maxe = mn = res
else:
maxe = mn = res
print("".join(maxe), "".join(mn))
elif summ == 0 and m != 1 or m * 9 < s:
print("-1 -1")
else:
for i in range(m):
if summ - 9 > 0:
res.insert(i, "9")
summ -= 9
else:
res.insert(i, "{}".format(summ))
summ = 0
maxe = res
summ = s
for i in range(m - 1, -1, -1):
if summ - 9 > 0:
mes.insert(0, "9")
summ -= 9
elif summ > 1:
if i != 0:
mes.insert(0, "{}".format(summ - 1))
summ = 1
else:
mes.insert(0, "{}".format(summ))
summ = 0
elif summ == 1:
if i != 0:
mes.insert(0, "0")
else:
mes.insert(0, "1")
elif summ == 0:
mes, res = "0", "0"
mn = mes
print("".join(mn), "".join(maxe)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR ASSIGN VAR BIN_OP LIST VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER STRING VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL STRING BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL STRING VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER STRING IF VAR NUMBER ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def maxi(m, s, q, r):
d = 0
big = ""
for i in range(q):
big += "9"
d += 9 * q
diff = s - d
dg = m - q
if dg < 0:
return -1
if dg == 0:
if d == s:
return big
else:
return -1
big += str(diff)
d += diff
dg -= 1
for i in range(dg):
big += "0"
return big
def mini(m, s, q, r):
d = 0
f = 0
small = ""
nines = ""
dg = m
if s > 9:
for i in range(q):
nines += "9"
d += 9 * q
dg = m - q
diff = s - d
j = 0
if diff == 0 and s != 0 and dg > 0:
good = nines
good = "8" + nines[1:]
nines = good
j = 1
elif dg == 0:
if d == s:
return nines
elif dg == 1:
small += str(diff)
d += diff
f = 1
else:
small += str(diff - 1)
d += diff - 1
f = 0
if j == 0:
dg -= 1
zeros = ""
if dg > 0:
for i in range(dg - 1):
zeros += "0"
if f == 0:
small = "1" + zeros + small + nines
else:
small = small + nines
if small[0] == "0" and s > 0:
new = small
small = small[1:]
lead = str(int(small[1]) - 1)
new = "1" + lead + small[1:]
return new
return small
l = [int(x) for x in input().split()]
m = l[0]
s = l[1]
q = s // 9
r = s % 9
big = maxi(m, s, q, r)
small = ""
if s == 0 and m > 1 or big == -1:
print(-1, -1)
else:
small = mini(m, s, q, r)
print(small, big) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR RETURN VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR NUMBER RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m == 1 and s == 0:
print(0, 0)
elif s < 1 or s > 9 * m:
print(-1, -1)
else:
maxi = s // 9 * "9" + str(s % 9) + (m - s // 9 - 1) * "0"
if len(maxi) > m:
maxi = maxi[:-1]
arr = [1] + [0] * (m - 1)
i = 1
j = m - 1
while i < s:
if arr[j] == 9:
j -= 1
arr[j] += 1
i += 1
mini = "".join(str(x) for x in arr)
print(mini, maxi) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, t = map(int, input().split(" "))
dec = [(9) for i in range(n)]
def min():
if n == 1 and t == 0:
return 0
m = dec.copy()
if t == 0:
return -1
if 9 * n < t:
return -1
else:
sub = 9 * n - t
if sub <= 8:
m[0] = 9 - sub
return "".join(list(map(str, m)))
else:
m[0] = 1
sub -= 8
ind = sub // 9
for i in range(1, ind + 1):
m[i] = 0
if ind + 1 < len(m):
m[ind + 1] = m[ind + 1] - sub + ind * 9
return "".join(list(map(str, m)))
def max():
if n == 1 and t == 0:
return 0
m = dec
if t == 0:
return -1
if 9 * n < t:
return -1
else:
sub = 9 * n - t
if sub <= 9:
m[0] = m[0] - sub
return "".join(list(map(str, m[::-1])))
m[0] = 0
sub -= 9
ind = sub // 9
for i in range(1, ind + 1):
m[i] = 0
if ind + 1 < len(m):
m[ind + 1] = m[ind + 1] - sub + ind * 9
return "".join(list(map(str, m[::-1])))
print(min(), max()) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | 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:
Z = "1" + "0" * (X - 1)
Z1 = list(Z)
Z2 = Z1[::-1]
index = 0
while sum(map(int, Z1)) != Y:
if Z1[index] == "9":
index += 1
t = Z1.pop(index)
t = str(int(t) + 1)
Z1.insert(index, t)
else:
Max = "".join(Z1)
index = 0
while sum(map(int, Z2)) != Y:
if Z2[index] == "9":
index += 1
t = Z2.pop(index)
t = str(int(t) + 1)
Z2.insert(index, t)
else:
Min = "".join(Z2)[::-1]
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 IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | length, su = map(int, input().split())
s = su
l = length
if s <= 0 and length != 1 or s > 9 * length:
print(-1, -1)
else:
lis = []
while length != 0:
if su <= 9:
if su == 1 and length == 1:
lis.append(1)
su = 0
elif su == 1:
lis.append(0)
elif length != 1:
lis.append(su - 1)
su = 1
else:
lis.append(su)
su = 0
else:
lis.append(9)
su -= 9
length -= 1
for i in range(len(lis)):
lis[i] = str(lis[i])
li = lis.copy()
li.reverse()
minans = "".join(li)
lis = []
while True:
if l == 0:
break
if s >= 9:
lis.append(str(9))
s -= 9
else:
lis.append(str(s))
s = 0
l -= 1
maxans = "".join(lis)
print(minans, maxans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR LIST WHILE NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = input().split()
m = int(m)
s = int(s)
sl = ""
ss = ""
if m == 1 and s == 0:
print("0 0")
elif m > 1 and s == 0:
print("-1 -1")
elif m * 9 < s:
print("-1 -1")
elif s <= 9:
if m != 1:
ss += str(s)
sl += str(1)
for i in range(1, m):
ss = ss + "0"
for i in range(1, m - 1):
sl = sl + "0"
sl += str(s - 1)
print(sl, ss)
if m == 1:
print(s, s)
else:
x = int(s / 9)
y = int(s % 9)
for i in range(x):
sl += "9"
if x < m:
sl += str(y)
for i in range(x + 1, m):
sl += "0"
if x == m:
for i in range(m):
ss = ss + "9"
elif x == m - 1:
if x * 9 != s:
ss += str(y)
for i in range(1, m):
ss = ss + "9"
else:
ss += "9"
for i in range(1, m - x + 1):
ss = ss + "0"
for i in range(m - x + 1, m):
ss = ss + "9"
else:
if x * 9 != s:
ss = ss + "1"
for i in range(1, m - x - 1):
ss = ss + "0"
ss += str(y - 1)
for i in range(m - x, m):
ss += "9"
if x * 9 == s:
ss = ss + "1"
for i in range(1, m - x):
ss = ss + "0"
if y != 0:
ss += str(y - 1)
if y == 0:
ss += str(8)
for i in range(m - x + 1, m):
ss += "9"
print(ss, sl) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR STRING IF VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR STRING VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR STRING IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if m is 1 and s is 0:
print(0, 0)
exit()
if s not in range(1, 9 * m + 1):
print(-1, -1)
exit()
digits = s // 9
rem = True if s % 9 else False
largest = ""
for i in range(m):
if i < digits:
largest += "9"
elif rem:
largest += str(s % 9)
rem = False
else:
largest += "0"
smallest = [0] * m
smallest[0] = 1
s -= 1
digits = s // 9
for i in range(digits):
smallest[m - i - 1] = 9
smallest[m - i - 2] += s % 9
smallest = [str(x) for x in smallest]
smallest = "".join(smallest)
print(smallest, largest) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 = 1000000007
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
m, s = f()
s1 = s
l1 = [0] * m
l2 = [0] * m
for i in range(m):
l1[i] = min(9, s)
s -= l1[i]
s1 -= 1
for i in range(m - 1, -1, -1):
l2[i] = min(9, s1)
s1 -= l2[i]
if l2[0] == 0:
l2[0] = 1
else:
l2[0] += 1
if m == 1 and s == 0:
print("".join(str(i) for i in l2), end=" ")
print("".join(str(i) for i in l1))
exit(0)
elif m == 1 and s != 0:
print(-1, -1)
exit(0)
if all(i <= 0 for i in l1) or s != 0:
print(-1, -1)
else:
print("".join(str(i) for i in l2), end=" ")
print("".join(str(i) for i in l1)) | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def get_max(num_digits, sum_digits):
if sum_digits > 9 * num_digits:
return -1, -1
max_num = [None for __ in range(num_digits)]
start_num = 9
current_sum = 0
current_digit = 0
while current_digit < num_digits:
while start_num > sum_digits - current_sum and start_num > 0:
start_num -= 1
if current_digit == 0 and start_num == 0 and num_digits > 1:
return -1, -1
if start_num < 0:
return -1, -1
max_num[current_digit] = start_num
current_sum += start_num
current_digit += 1
min_num = max_num[::-1]
if min_num[0] != 0:
max_num = "".join(map(str, max_num))
min_num = "".join(map(str, min_num))
return min_num, max_num
else:
for idx in range(len(min_num)):
if min_num[idx] != 0:
min_num[idx] -= 1
min_num[0] = 1
break
max_num = "".join(map(str, max_num))
min_num = "".join(map(str, min_num))
return min_num, max_num
m, s = list(map(int, input().split()))
minim, maxim = get_max(m, s)
print(minim, maxim) | FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL 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 | def can(m, s):
return s >= 0 and s <= 9 * m
m, s = map(int, input().split())
if s == 0 and m == 1:
print("0 0")
elif s == 0 or s > 9 * m:
print("-1 -1")
else:
mins = ""
maxs = ""
x = s
y = s
for i in range(m):
for j in range(10):
if i == 0 and j == 0:
continue
if can(m - i - 1, x - j):
x -= j
mins += str(j)
break
for j in range(9, -1, -1):
if can(m - i - 1, y - j):
y -= j
maxs += str(j)
break
print(mins, maxs) | FUNC_DEF RETURN VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if 9 * m >= s:
n = m
a = 0
x = 0
min_num = []
max_num = []
while x < m:
min_num.append(0)
max_num.append(0)
for i in range(10):
j = 9 - i
if j + 9 * (n - 1) + sum(min_num) - min_num[a] >= s:
if a == 0 and j == 0 and s != 0:
min_num[0] = 1
else:
min_num[a] = j
if j + 9 * (n - 1) + sum(max_num) - max_num[a] >= s:
if j == 0 and a == m - 1 and s != 0:
max_num[a] = 1
else:
max_num[a] = j
a = a + 1
n = n - 1
x = x + 1
small = 0
big = 0
if (min_num[0] == 0 or max_num[-1] == 0) and m > 1:
print("-1 -1")
elif sum(min_num) != s or sum(max_num) != s:
print("-1 -1")
else:
for i in range(m):
small = small + min_num[i] * 10 ** (m - i - 1)
big = big + max_num[i] * 10**i
print(small, big)
else:
print("-1 -1") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER 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 | a = input().split()
m = int(a[0])
s = int(a[1])
if m == 1 and s == 0:
print("0 0")
elif s < 1 or s > m * 9:
print("-1 -1")
else:
r = s % 9
rk = str(r)
l = s // 9
list1 = []
list2 = []
if m - l == 1:
list1.append(rk)
for i in range(l):
list1.append("9")
word1 = "".join(list1)
elif m - l == 0:
for i in range(l):
list1.append("9")
word1 = "".join(list1)
else:
if r > 0:
x = "1" + "0" * (m - l - 2)
list1.append(x)
rl = str(r - 1)
list1.append(rl)
for i in range(l):
list1.append("9")
if r == 0:
x = "1" + "0" * (m - l - 1)
list1.append(x)
list1.append("8")
for i in range(l - 1):
list1.append("9")
word1 = "".join(list1)
for i in range(l):
list2.append("9")
if m - l > 0:
list2.append(rk)
if m - l - 1 > 0:
for i in range(m - l - 1):
list2.append("0")
word2 = "".join(list2)
print(word1, word2) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL 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 | def minmax(m, n):
max = ""
while m:
while n:
if n < 10:
max += str(n)
n = 0
else:
max += "9"
n -= 9
m -= 1
if m:
max += "0"
m -= 1
return max
x = [int(i) for i in list(input().split())]
if x[0] == 1 and x[1] == 0:
print(0, 0)
elif x[1] > 9 * x[0] or x[1] == 0:
print(-1, -1)
else:
j = minmax(x[0], x[1])
h = j[::-1]
if h[0] == "0":
i = 1
while h[i] == "0":
i += 1
t = int(h[i]) - 1
h = "1" + h[1:i] + str(t) + h[i + 1 :]
print(h + " " + j) | FUNC_DEF ASSIGN VAR STRING WHILE VAR WHILE VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | ar = []
for x in input().split(" "):
ar.append(int(x))
ar2 = ar.copy()
res = []
if ar[1] == 0 and ar[0] == 1:
print(0, 0)
elif 9 * ar[0] < ar[1] or ar[1] == 0:
print(-1, -1)
else:
for k in range(ar[0]):
ch = 0
for i in reversed(range(0, 10)):
if k == ar[0] - 1:
res.append(ar[1])
ch = 1
break
if ar[1] - i <= 9 * (ar[0] - k - 1) and ar[1] - i >= 0:
if len(res) == 0 and i == 0:
break
res.append(i)
ar[1] = ar[1] - i
ch = 1
break
else:
continue
if len(res) != 0:
first = "".join([str(a) for a in res])
res = [0] * ar2[0]
res[0] = 1
curr = ar2[1] - 1
for k in range(ar2[0]):
if k == ar2[0] - 1:
res[0] = res[0] + curr
break
if curr <= 9:
res[ar2[0] - k - 1] = curr
break
else:
res[ar2[0] - k - 1] = 9
curr = curr - 9
print("".join([str(a) for a in res]), first) | ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = [int(i) for i in input().split()]
if m > 1 and s < 1 or s > m * 9:
print("-1 -1")
else:
a1 = 10 ** (m - 1)
q = (s - 1) // 9
p = (s - 1) % 9
a2 = (p + 1) * 10**q - 1
mi = a1 + a2
if s < 10:
ma = s * 10 ** (m - 1)
else:
w = s // 9
x = s % 9
if w == m:
ma = mi
else:
c = (10 - x) * 10 ** (m - w - 1)
ma = 10**m - c
print("%i %i" % (mi, ma)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, s = map(int, input().split())
a = [9] * n
b = [1] + [0] * (n - 1)
x = 9 * n - s
y = 1
if x >= 0 and s > 0:
for i in range(len(a) - 1, -1, -1):
if x >= 9:
a[i] = 0
x = x - 9
else:
a[i] = 9 - x
break
for j in range(len(b) - 1, -1, -1):
if s - 9 > y:
b[j] = 9
y = y + 9
else:
b[j] = b[j] + s - y
break
elif n == 1 and s == 0:
print("0 0")
exit(0)
else:
print("-1 -1")
exit(0)
resa = ""
resb = ""
for k in range(n):
resa = resa + str(a[k])
resb = resb + str(b[k])
print(resb + " " + resa) | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | import sys
def readInput():
for line in sys.stdin:
a = line.split(" ")
m = int(a[0])
s = int(a[1])
return [m, s]
def arrayToInt(x):
num = 0
l = len(x)
exp = 0
for i in range(l, 0, -1):
num += x[i - 1] * pow(10, exp)
exp += 1
return num
def findMin(m, s):
_min = []
k = s // 9
l = s % 9
if k == m:
for i in range(1, m + 1):
_min.append(9)
elif k == m - 1:
_min.append(l)
for i in range(1, m):
_min.append(9)
else:
k = (s - 1) // 9
l = (s - 1) % 9
_min.append(1)
for i in range(1, m - k - 1):
_min.append(0)
_min.append(l)
for i in range(1, k + 1):
_min.append(9)
return _min
def findMax(m, s):
_max = []
k = s // 9
l = s % 9
if k == m:
for i in range(1, m + 1):
_max.append(9)
elif k == m - 1:
for i in range(1, m):
_max.append(9)
_max.append(l)
else:
k = s // 9
l = s % 9
for i in range(1, k + 1):
_max.append(9)
_max.append(l)
for i in range(1, m - k):
_max.append(0)
return _max
def solve():
d = readInput()
m = d[0]
s = d[1]
if s == 0:
return [-1, -1] if m > 1 else [0, 0]
if 9 * m < s:
return [-1, -1]
_min = findMin(m, s)
_max = findMax(m, s)
return [arrayToInt(_min), arrayToInt(_max)]
data = solve()
print(str(data[0]) + " " + str(data[1])) | IMPORT FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN LIST VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER RETURN VAR NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER IF BIN_OP NUMBER VAR VAR RETURN LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
s1 = s
s2 = s
if m > 1 and s == 0 or s > 9 * m:
print("-1 -1")
else:
if s1 <= 1 + 9 * (m - 1):
min = 1 * 10 ** (m - 1)
s1 -= 1
min += 10 ** (s1 // 9) - 1 + s1 % 9 * 10 ** (s1 // 9)
else:
min = (s1 - 9 * (m - 1)) * 10 ** (m - 1) + 10 ** (m - 1) - 1
max = 0
while s2 != 0:
for p in range(m):
if s2 >= 9:
max += 9 * 10 ** (m - p - 1)
s2 -= 9
else:
max += s2 * 10 ** (m - p - 1)
s2 = 0
print("%d %d" % (min, max)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if s > 9 * m or s < 1 and m > 1:
print(-1, -1)
exit()
index = m - 1
min_s = s
while index >= 0:
pos = max(0, min_s - 9 * index)
if index == m - 1 and min_s > 0 and pos == 0:
pos = 1
print(pos, end="")
index -= 1
min_s -= pos
print(" ", end="")
index = m - 1
max_s = s
while index >= 0:
val = min(9, max_s)
print(val, end="")
max_s -= val
index -= 1 | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR VAR NUMBER |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a, b = map(int, input().split())
if b == 0 and a != 1 or b > a * 9:
print("-1 -1")
elif b == 0 and a == 1:
print("0 0")
else:
c = []
while b != 0:
if b >= 9:
c.append(9)
b -= 9
else:
c.append(b)
b = 0
while a - len(c) != 0:
c.append(0)
d = c[:]
d.reverse()
if a != 1 and b == 1:
for i in c:
print(i, end="")
elif d[0] != 0:
for i in d:
print(i, end="")
else:
for i in range(len(d)):
if d[i] != 0:
d[i] -= 1
d[0] = 1
break
for i in d:
print(i, end="")
print(end=" ")
for i in c:
print(i, end="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST WHILE VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | s1 = input().split()
leng = int(s1[0])
s = int(s1[1])
if leng * 9 < s or leng > 1 and s == 0:
print(-1, " ", -1)
raise SystemExit(0)
smax = ""
smin = ""
summax = s
summin = s
if s < 9:
smax += str(s)
smax += (leng - len(smax)) * "0"
if leng == 1:
print(s, " ", smax, sep="")
else:
print(1, (leng - 2) * "0", s - 1, " ", smax, sep="")
else:
while summax > 9:
smax += "9"
summax -= 9
smax += str(summax)
smax += (leng - len(smax)) * "0"
smin = "1" + (leng - 1) * "0"
summin -= 1
i = leng - 1
while summin > 9 and i >= 0:
shelp = str(int(smin[i]) + 9)
smin = smin[:i] + shelp + smin[i + 1 :]
summin -= 9
i -= 1
shelp = str(int(smin[i]) + summin)
smin = smin[:i] + shelp + smin[i + 1 :]
print(smin, " ", smax, sep="") | 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 NUMBER STRING NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER STRING VAR STRING WHILE VAR NUMBER VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP BIN_OP VAR NUMBER STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a, b = map(int, input().split(" "))
if [a, b] == [1, 0]:
print("0 0")
elif 1 <= b <= 9 * a:
haloe = []
max9 = b // 9
other = b % 9
if other != 0:
strx = "9" * max9 + str(other) + (a - max9 - 1) * "0"
else:
strx = "9" * max9 + (a - max9) * "0"
haloe.append(strx)
strx = strx[::-1]
if strx[0] != "0":
haloe.append(strx)
else:
bad = False
newstr = "1"
for i in range(1, len(strx)):
if strx[i] != "0" and not bad:
newstr += str(int(strx[i]) - 1)
bad = not bad
else:
newstr += strx[i]
haloe.append(newstr)
print(haloe[1] + " " + haloe[0])
else:
print(-1, -1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF LIST VAR VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING VAR 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 = map(int, input().split())
i = 0
strok = ""
s1 = s
while m != i and s > 9:
i += 1
s -= 9
else:
if s1 == 0 and m > 1 or m * 9 < s1:
print("-1 -1")
else:
strok += i * "9"
m -= i + 1
if m != 0:
k = 1
raz = 1
else:
k = ""
raz = 0
strok = "0" * m + str(s - raz) + strok
if k == 1:
strok = "1" + strok[1:]
strok2 = ""
strok2 += i * "9" + str(s) + "0" * m
if strok2[0] != "0":
print(strok, strok2, sep=" ")
else:
print(strok, strok, sep=" ") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING VAR BIN_OP VAR STRING VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP STRING VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR STRING 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())
u = ""
if s > 9 * m or s == 0 and m > 1:
print(-1, -1)
else:
i = m - 1
k = s
while i >= 0:
j = max(0, k - 9 * i)
if j == 0 and i == m - 1 and k:
j = 1
u += str(j)
k -= j
i -= 1
u += " "
k = s
for i in range(m):
u += str(min(9, s))
s -= min(9, s)
print(u) | 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER 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, s = [int(i) for i in input().split()]
mi = 0
ma = 0
if s == 0 and n != 1 or s > 9 * n:
print(-1, -1)
else:
e = s % 9
w = s // 9
for i in range(w):
mi += 9 * 10**i
if e == 0:
mi = mi + 10 ** (n - 1) - 10 ** (w - 1)
else:
mi = mi + 10 ** (n - 1) + (e - 1) * 10**w
for i in range(w):
ma += 9 * 10 ** (n - i - 1)
if n != w:
ma += e * 10 ** (n - w - 1)
print(int(mi), int(ma)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | x, y = map(int, input().split())
lol = [0] * x
i = 0
yo = [0] * x
y0 = y
if x == 1 and y < 10:
print(y, y)
exit()
while y > 0 and i < x:
if lol[i] == 9:
i += 1
else:
lol[i] += 1
y -= 1
if y0 > 0:
yo[0] = +1
y0 -= 1
else:
print(-1, -1)
exit()
i = x - 1
while y0 > 0 and i > -1:
if yo[i] == 9:
i -= 1
else:
yo[i] += 1
y0 -= 1
if lol[0] == 0 or yo[0] == 0 or y0 > 0 or y > 0:
print(-1, -1)
exit()
yo = list(map(str, yo))
lol = list(map(str, lol))
print("".join(yo), "".join(lol)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR WHILE VAR NUMBER VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL STRING VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | hello = list(map(int, input().split()))
m = hello[0]
s = hello[1]
a = ""
b = ""
new = "1"
done = False
if s == 0:
print("0 0" if m == 1 else "-1 -1")
done = True
if not done:
for i in range(m):
b += str(min(s, 9))
s -= min(s, 9)
if s > 0:
print("-1 -1")
done = True
if not done:
for i in range(m - 1, -1, -1):
a += b[i]
if a[0] == "0":
_ = 0
while a[_] == "0":
_ += 1
for i in range(1, len(a)):
if i == _:
new += str(int(a[i]) - 1)
else:
new += a[i]
else:
new = ""
new += a
print(new, b) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR STRING 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 | t = 1
for i in range(t):
m, s = [int(x) for x in input().split()]
nines = s // 9
if m == 1 and s == 0:
print(0, 0)
continue
if nines > m or s == 0 or m * 9 < s:
print("-1 -1")
continue
if s < 10:
if m == 1:
print(s, s)
else:
mn = "1" + "0" * (m - 2) + str(s - 1)
mx = str(s) + "0" * (m - 1)
print(mn, mx)
continue
if m * 9 == s:
print("9" * m, "9" * m)
continue
rem = s % 9
if nines + 1 == m and rem != 0:
mn = str(rem) + "9" * nines
elif rem == 0:
mn = "1" + "0" * (m - nines - 1) + "8" + "9" * (nines - 1)
else:
mn = "1" + "0" * (m - nines - 2) + str(rem - 1) + "9" * nines
mx = (nines * "9" + str(rem) + "0" * 101)[:m]
print(mn, mx) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR 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 IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR STRING FUNC_CALL VAR VAR BIN_OP STRING NUMBER VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = input().split(" ")
m = int(m)
s = int(s)
if s == 0 and m != 1 or s > m * 9:
print("-1 -1")
elif m == 1:
print(s, end=" ")
print(s)
elif s == m * 9:
A = [(9) for i in range(m)]
for i in range(0, m):
A[i] = str(A[i])
B = "".join(A)
c = int(B)
print(c, end=" ")
print(c)
else:
L = [(0) for i in range(m)]
a = s // 9
b = s % 9
c = 0
d = 0
for i in range(0, a):
L[i] = 9
L[a] = b
J = L[:]
for i in range(0, m):
L[i] = str(L[i])
H = "".join(L)
c = int(H)
J.reverse()
if J.count(0) != 0:
J[0] = 1
if J[m - a - 1] == 0:
J[m - a] = 8
else:
J[m - a - 1] = J[m - a - 1] - 1
for i in range(0, m):
J[i] = str(J[i])
I = "".join(J)
d = int(I)
print(d, end=" ")
print(c) | 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 VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | a, b = map(int, input().split())
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
lenth = 10
l2 = []
a1 = a
if a == 1 and b == 0:
numm = "0"
str1 = "0"
elif b <= 0 or 9 * a < b:
numm = -1
str1 = -1
else:
numm = ""
sum1 = 0
while a > 0:
lenth = 10
while lenth > 0:
if b - sum1 >= 9 and a > 1:
shuzi = "9"
numm += shuzi
lenth = 0
sum1 += int(shuzi)
elif sum1 == b:
shuzi = 0
numm += str(shuzi)
lenth = 0
elif b - sum1 - int(l[lenth - 1]) >= 0:
shuzi = str(l[lenth - 1])
numm += shuzi
lenth = 0
sum1 += int(shuzi)
lenth -= 1
a -= 1
pri = list(numm)
l3 = []
for i in pri:
if i != "0":
i = int(i)
l3.append(i)
str1 = ""
if len(l3) == int(a1):
l3.reverse()
for i in l3:
str1 += str(i)
else:
l3 = sorted(l3)
if l3[0] == "1":
pass
else:
shuzi = l3[0]
l3.pop(0)
shuzi = shuzi - 1
l3.append(shuzi)
l3 = sorted(l3)
lenth = len(l3)
n = 1
str1 = "1"
while a1 - len(l3) - 1 > 0:
str1 += "0"
a1 -= 1
for i in l3:
str1 += str(i)
print(str1, numm) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR STRING VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | n, m = map(int, input().split())
a = ["0"] * n
b = ["0"] * n
flag = 0
if m == 0 and n != 1:
flag = 1
for i in range(n - 1, -1, -1):
if m < 10 and i > 1 and m != 1 and m != 0:
a[i] = str(m - 1)
a[0] = "1"
m = 0
break
elif m >= 10:
a[i] = "9"
m = m - 9
elif m < 10 and i == 1 and m != 1 and m != 0:
a[i] = str(m - 1)
a[0] = "1"
m = 0
elif m == 1 and i > 1:
a[0] = "1"
m = 0
elif m < 10 and i == 0 and m != 0:
a[i] = str(m)
m = 0
if m != 0:
flag = 1
b = a
c = "".join(a)
b.sort(reverse=True)
for i in range(0, n - 1):
if int(b[i]) + int(b[i + 1]) <= 9:
b[i] = str(int(b[i]) + int(b[i + 1]))
b[i + 1] = "0"
if flag == 0:
print(c + " " + "".join(b))
else:
print("-1" + " " + "-1") | 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 IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING FUNC_CALL STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING STRING STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
if 9 * m < s:
print(-1, -1)
exit()
if s == 0 and m > 1:
print(-1, -1)
exit()
if m == 1:
print(s, s)
exit()
if m == s / 9:
print("9" * (s // 9), "9" * (s // 9))
exit()
st, nd = "", ""
if not s % 9:
n1 = s // 9
if m == n1 + 1:
st += "18" + "9" * (n1 - 1)
nd += "9" * n1 + "0"
else:
n3 = m - n1 - 1
st += "1" + "0" * n3 + "8" + "9" * (n1 - 1)
nd += "9" * n1 + "0" * (n3 + 1)
else:
n1 = s // 9
n2 = s % 9
if m == n1 + 1:
st += str(n2) + "9" * n1
nd += "9" * n1 + str(n2)
elif m == n1 + 2:
st += "1" + str(n2 - 1) + "9" * n1
nd += "9" * n1 + str(n2) + "0"
else:
n3 = m - n1 - 1
st += "1" + "0" * (n3 - 1) + str(n2 - 1) + "9" * n1
nd += "9" * n1 + str(n2) + "0" * n3
print(st + " " + nd) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING VAR STRING BIN_OP STRING BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING VAR VAR BIN_OP BIN_OP BIN_OP STRING VAR FUNC_CALL VAR VAR BIN_OP 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 | def ch(n, k):
return k >= 0 and k <= 9 * n
n, k = input().split(" ")
n = int(n)
k = int(k)
n1 = n
a = []
k1 = k
if k == 0 and n == 1:
print("0 0")
elif k == 0 or n * 9 < k:
print("-1 -1")
else:
for i in range(0, n):
for j in range(0, 10):
if (i > 0 or j > 0 or n == 1 and j == 0) and ch(n - i - 1, k - j):
a.append(str(j))
k -= j
break
print("".join(a), end=" ")
a.clear()
for i in range(0, n):
for j in range(0, 10):
x = 9 - j
if (i > 0 or x > 0 or n == 1 and x == 0) and ch(n - i - 1, k1 - x):
a.append(str(x))
k1 -= x
break
print("".join(a), end=" ") | FUNC_DEF RETURN VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL 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 = map(int, input().split())
if m == 1 and s == 0:
print("0 0")
elif s == 0 or s > 9 * m:
print("-1 -1")
else:
x = ""
y = ""
a = 9 * m - s
b = s
for i in range(m):
if i == 0:
t = min(min(9, a), 8)
x += str(9 - t)
a -= t
else:
t = max(min(9, a), 0)
x += str(9 - t)
a -= t
u = min(9, b)
y += str(u)
b -= u
print(int(x), int(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 STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR 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 = input().strip().split()
m = int(M)
s = int(S)
arr = [0] * m
arr[0] = s
e = m - 1
while e > 0:
if arr[0] == 1 or arr[0] == 0:
break
if arr[0] > 9:
arr[0] = arr[0] - 9
arr[e] = arr[e] + 9
e = e - 1
else:
arr[e] = arr[0] - 1
arr[0] = 1
e = e - 1
if s / m > 9 or s == 0 and m != 1:
print("-1 -1")
else:
for i in range(0, m):
print(arr[i], end="")
print(" ", end=" ")
maxar = [0] * m
e = 0
y = s
while e < m and s > 0:
x = min(9, s)
s = s - x
maxar[e] = x
e = e + 1
for i in maxar:
print(i, end="")
print() | ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def is_possible(count, sum):
return (sum != 0 or count <= 1) and 9 * count >= sum
def get_min(count, sum):
if 9 * count == sum:
return "{}".format("9" * count)
elif (sum - 1) % 9 == 0:
nine_count = (sum - 1) // 9
zero_count = count - 1 - nine_count
return "1{}{}".format("0" * zero_count, "9" * nine_count)
elif sum <= 9 * count - 8:
nine_count = (sum - 1) // 9
num = (sum - 1) % 9
zero_count = count - 2 - nine_count
return "1{}{}{}".format("0" * zero_count, num, "9" * nine_count)
else:
nine_count = count - 1
num = sum % 9
return "{}{}".format(num, "9" * nine_count)
def get_max(count, sum):
if 9 * count == sum:
return "{}".format("9" * count)
else:
nine_count = sum // 9
num = sum % 9
zero_count = count - 1 - nine_count
return "{}{}{}".format("9" * nine_count, num, "0" * zero_count)
def solve(count, sum):
if sum == 0 and count == 1:
print("0 0")
elif is_possible(count, sum):
print(get_min(count, sum), get_max(count, sum))
else:
print("-1 -1")
count, sum = map(int, input().split())
solve(count, sum) | FUNC_DEF RETURN VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN FUNC_CALL STRING BIN_OP STRING VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN FUNC_CALL STRING BIN_OP STRING VAR BIN_OP STRING VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN FUNC_CALL STRING BIN_OP STRING VAR VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL STRING VAR BIN_OP STRING VAR FUNC_DEF IF BIN_OP NUMBER VAR VAR RETURN FUNC_CALL STRING BIN_OP STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN FUNC_CALL STRING BIN_OP STRING VAR VAR BIN_OP STRING VAR FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = list(map(int, input().split()))
if s == 0 and m > 1 or 9 * m < s:
print("-1 -1")
elif s == 0 and m == 1:
print(0, 0)
else:
a1 = ""
s1 = s
while s1 - 9 >= 0:
a1 = a1 + "9"
s1 = s1 - 9
if s1 > 0:
a1 = a1 + str(s1)
a1 = a1 + "0" * (m - len(a1))
a2 = ""
s2 = s
c = m
while s2 > 9:
a2 = a2 + "9"
c = c - 1
s2 = s2 - 9
if s2 > 0:
if c == 1:
a2 = str(s2) + a2
else:
a2 = "1" + "0" * (c - 2) + str(s2 - 1) + a2
print(a2, a1) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL 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 NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP 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 | def dp_large(length, sum):
if length == 0:
if sum != 0:
raise IndexError
else:
return ""
if sum >= 9:
return "9" + dp_large(length - 1, sum - 9)
else:
return str(sum) + dp_large(length - 1, 0)
def dp_small(length, sum):
if length == 1:
if sum > 9:
raise IndexError
else:
return str(sum)
if sum > 9:
return dp_small(length - 1, sum - 9) + "9"
else:
return dp_small(length - 1, 1) + str(sum - 1)
return ""
def f(length, sum):
if sum == 0:
if length == 1:
print("0 0")
else:
print("-1 -1")
else:
try:
large = dp_large(length, sum)
except:
large = "-1"
try:
small = dp_small(length, sum)
except:
small = "-1"
print("{} {}".format(small, large))
f(*map(int, input().split())) | FUNC_DEF IF VAR NUMBER IF VAR NUMBER VAR RETURN STRING IF VAR NUMBER RETURN BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER IF VAR NUMBER VAR RETURN FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER RETURN STRING FUNC_DEF IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def solve(m, s):
smallest = [(0) for i in range(m)]
largest = [(0) for i in range(m)]
smallest[-1] = s
for i in range(1, m):
if smallest[-i] > 9:
smallest[-i - 1] = smallest[-i] - 9
smallest[-i] = 9
if smallest[0] == 0 and len(smallest) > 1:
try:
lastzero = m - 1 - smallest[::-1].index(0)
smallest[0] = 1
smallest[lastzero + 1] -= 1
except:
print("-1 -1")
return
largest[0] = s
for i in range(0, m - 1):
if largest[i] > 9:
largest[i + 1] = largest[i] - 9
largest[i] = 9
if smallest[0] > 9 or smallest[0] == 0 and len(smallest) > 1:
print("-1 -1")
return
if largest[-1] > 9 or largest[0] == 0 and len(smallest) > 1:
print("-1 -1")
return
smallest = "".join([str(c) for c in smallest])
largest = "".join([str(c) for c in largest])
print(smallest, largest)
m, s = [int(c) for c in input().split()]
solve(m, s) | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN 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 ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = map(int, input().split())
t = s
x = ["0"] * m
y = ["0"] * m
if s == 0 and m > 1:
print(-1, -1)
elif s / m > 9:
print(-1, -1)
else:
i = 0
while 1:
p = s - 9
if p >= 0:
x[i] = str(9)
i += 1
s -= 9
if i >= m:
break
else:
x[i] = str(p + 9)
break
x = "".join(x)
i = 1
d = 1
k = 0
s = t
while 1:
if d == m:
y[k] = str(s)
break
q = (s - i) / (m - d)
if q <= 9:
y[k] = str(i)
s = s - i
i = 0
d += 1
k += 1
if d == m:
y[k] = str(s)
break
else:
i += 1
y = "".join(y)
print(y, x) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST STRING VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | m, s = list(map(int, input().split()))
k = m
val = 0
pointer = min(9, s)
if m > 1 and s == 0 or s / m > 9:
print(-1, -1)
else:
while m:
val = val * 10 + pointer
m -= 1
s -= pointer
pointer = min(9, s)
if val == 0:
print(0, 0)
else:
val = str(val)
c = 0
f = 0
for i in range(k):
if val[k - i - 1] == "0":
f = 1
else:
c = k - i - 1
break
if f == 1:
v = int(val[c]) - 1
mval = val[:c] + str(v) + val[c + 1 : -1] + "1"
print(mval[::-1], val)
else:
print(val[::-1], val) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER 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 | a, b = map(int, input().split())
s = []
if b == 0 and a == 1:
print("0 0")
elif b == 0 or b / a > 9:
print("-1 -1")
else:
for i in range(a):
if b > 9:
s.append(9)
b -= 9
elif b > 0:
s.append(b)
b = 0
else:
s.append(0)
if 0 not in s:
s.sort()
for i in range(a):
print(s[i], end="")
else:
s.sort()
print("1", end="")
ff = 1
for i in range(1, a):
if ff == 1 and s[i] != 0:
print(s[i] - 1, end="")
ff = 0
else:
print(s[i], end="")
print(" ", end="")
s.sort(reverse=True)
for i in range(a):
print(s[i], end="") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | def min_d(a, b):
z = [1] + [0] * (a - 1)
dv = (b - 1) // 9
md = (b - 1) % 9
j = 0
for i in range(dv):
j -= 1
z[j] = 9
z[j - 1] += md
return z
def max_d(a, b):
y = [9] * a
dv = (9 * a - b) // 9
md = (9 * a - b) % 9
j = 0
for i in range(dv):
j -= 1
y[j] = 0
y[j - 1] -= md
return y
m, s = map(int, input().strip().split(" "))
if m == 1 and 0 <= s < 10:
print(s, s)
elif s < 1 or s > 9 * m:
print(-1, -1)
else:
x = min_d(m, s)
w = max_d(m, s)
print("".join([str(i) for i in x]), "".join([str(j) for j in w])) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
-----Input-----
The single line of the input contains a pair of integers m, s (1 β€ m β€ 100, 0 β€ s β€ 900) β the length and the sum of the digits of the required numbers.
-----Output-----
In the output print the pair of the required non-negative integer numbers β first the minimum possible number, then β the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
-----Examples-----
Input
2 15
Output
69 96
Input
3 0
Output
-1 -1 | l = input().split(" ")
m, s = int(l[0]), int(l[1])
ma = []
if m == 1 and s >= 10:
print(-1, -1)
elif m == 1 and s <= 9:
print(s, s)
elif m >= 2 and s == 0:
print(-1, -1)
elif m >= 2 and s > 9 * m:
print(-1, -1)
else:
for i in range(m):
n = 9
if n >= s:
n = s
s = 0
ma += [n]
else:
s = s - n
ma += [n]
mi = ma[::-1]
if mi[0] == 0:
mi[0] += 1
for i in range(m):
if not i == 0 and not mi[i] == 0:
mi[i] -= 1
break
for i in range(m):
ma[i] = str(ma[i])
mi[i] = str(mi[i])
print(int("".join(mi)), int("".join(ma))) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR LIST VAR ASSIGN VAR BIN_OP VAR VAR VAR LIST VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR FUNC_CALL STRING VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.