You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.


-----Input-----

The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer n is positive and doesn't exceed 1 000 000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.


-----Output-----

The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise.

If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to n. Follow the format given in the samples.


-----Examples-----
Input
? + ? - ? + ? + ? = 42

Output
Possible
9 + 13 - 39 + 28 + 31 = 42

Input
? - ? = 1

Output
Impossible

Input
? = 1000000

Output
Possible
1000000 = 1000000

Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Mathematics

Constructive algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
from math import ceil

def writeList(l):
	for (i, item) in enumerate(l):
		if i == len(l) - 1:
			print(item)
		else:
			print(item, end='')

def solve(items, n, aux_s):
	(r, last) = (['' for i in range(len(aux_s))], '')
	(num_minus, num_plus, c1, c2) = (0, 1, 0, 0)
	(last_divisor1, last_divisor2) = (1, 1)
	for i in items:
		if i == '-':
			num_minus += 1
		elif i == '+':
			num_plus += 1
	if num_minus == 0:
		if num_plus > n:
			return ['Impossible']
		flag = False
		(k, res) = divmod(n, num_plus)
		while res + k > n:
			last_divisor1 = min(num_plus, res)
			res = res / min(num_plus, res)
			if res == 1 and res + k > n:
				flag = True
				break
		if flag:
			return ['Impossible']
		for i in range(len(aux_s)):
			if aux_s[i] == '?':
				if c1 <= last_divisor1:
					r[i] = k + res
					c1 += 1
				else:
					r[i] = k
			else:
				r[i] = aux_s[i]
		return ['Possible', r]
	flag = False
	(k, res) = divmod(num_minus + n, num_plus)
	if k > n:
		return ['Impossible']
	while res + k > n:
		last_divisor1 = min(num_plus, res)
		res = res / min(num_plus, res)
		if int(res) == 1 and res + k > n:
			flag = True
			break
	(k, res) = (int(k), int(res))
	(m, s) = (1, 0)
	if flag:
		s = res + k - n
		while m + s > n:
			last_divisor2 = min(num_minus, s)
			s = s / min(num_minus, s)
			if s == 1 and m + s > n:
				flag = True
				break
		if flag:
			return ['Impossible']
		for i in range(len(aux_s)):
			if i == 0:
				r[i] = k + res
				c1 += 1
			elif aux_s[i] == '+':
				r[i] = aux_s[i]
				last = '+'
			elif aux_s[i] == '-':
				r[i] = aux_s[i]
				last = '-'
			elif aux_s[i] == '?':
				if last == '+':
					if c1 < last_divisor1:
						r[i] = k + res
						c1 += 1
					else:
						r[i] = k
				if last == '-':
					if c2 < last_divisor2:
						r[i] = m + s
						c2 += 1
					else:
						r[i] = m
		return ['Possible', r]
	if k == 0:
		(k, res) = (1, 0)
		(m, s) = divmod(num_plus - n, num_minus)
		while m + s > n:
			last_divisor2 = min(num_minus, s)
			s = s / min(num_minus, s)
			if int(s) == 1 and m + s > n:
				flag = True
				break
		if flag:
			return ['Impossible']
		(m, s) = (int(m), int(s))
	for i in range(len(aux_s)):
		if aux_s[i] == '+':
			r[i] = aux_s[i]
			last = '+'
		elif aux_s[i] == '-':
			r[i] = aux_s[i]
			last = '-'
		elif aux_s[i] == '?':
			if i == 0:
				r[i] = k + res
				c1 += 1
			elif last == '+':
				if c1 < last_divisor1:
					r[i] = k + res
					c1 += 1
				else:
					r[i] = k
			elif last == '-':
				if c2 < last_divisor2:
					r[i] = m + s
					c2 += 1
				else:
					r[i] = m
		else:
			r[i] = aux_s[i]
	return ['Possible', r]
str_aux = input()
items = [i for i in str_aux.split()]
n = int(items[len(items) - 1])
for i in solve(items, n, str_aux):
	writeList(i)


import re
try:
	while True:
		s = input()
		n = int(s[s.rfind(' '):])
		pos = s.count('+') + 1
		neg = s.count('-')
		if n * pos - neg < n or pos - n * neg > n:
			print('Impossible')
		else:
			print('Possible')
			need = n - (pos - neg)
			prev = '+'
			first = True
			for m in re.finditer('[+-]', s):
				if first:
					first = False
				else:
					print(prev, end=' ')
				if prev == '+' and need > 0:
					x = min(need + 1, n)
					need -= x - 1
				elif prev == '-' and need < 0:
					x = min(-need + 1, n)
					need += x - 1
				else:
					x = 1
				print(x, end=' ')
				prev = m.group()
			if not first:
				print(prev, end=' ')
			if prev == '+' and need > 0:
				x = min(need + 1, n)
				need -= x - 1
			elif prev == '-' and need < 0:
				x = min(-need + 1, n)
				need += x - 1
			else:
				x = 1
			print(x, '=', n)
except EOFError:
	pass


(s, n) = input().split(' = ')
if s == '?':
	print('Possible\n' + n + ' = ' + n)
elif not '+' in s:
	print('Impossible')
else:
	n = int(n)
	s = ['+'] + list(s.replace(' ', ''))
	cp = s.count('+')
	cm = s.count('-')
	if cm >= cp:
		t = (n + cm) // cp
		m = (n + cm) % cp
		cc = 0
		for i in range(1, len(s), 2):
			if s[i - 1] == '+':
				s[i] = str(t + (cc < m))
				cc += 1
			else:
				s[i] = '1'
	else:
		t = (n + cm * n) // cp
		m = (n + cm * n) % cp
		cc = 0
		for i in range(1, len(s), 2):
			if s[i - 1] == '+':
				s[i] = str(t + (cc < m))
				cc += 1
			else:
				s[i] = str(n)
	if int(s[1]) > n or int(s[-1]) < 1:
		print('Impossible')
	else:
		print('Possible')
		print(' '.join(s[1:]) + ' =', n)


s = input().split()
nrpoz = 0
nrneg = 0
for i in s:
	if i == '+':
		nrpoz += 1
	if i == '-':
		nrneg += 1
if s[0] == '?':
	nrpoz += 1
n = int(s[-1])
if nrpoz * n - nrneg >= n >= nrpoz - nrneg * n:
	print('Possible')
else:
	print('Impossible')
	return
neg = []
poz = []
if nrpoz - nrneg > n:
	poz = [1] * nrpoz
	neg = [1] * nrneg
	sn = nrneg
	for i in range(len(neg)):
		if sn < nrpoz - n:
			neg[i] += min(nrpoz - n - sn, n - neg[i])
			sn += neg[i] - 1
else:
	neg = [1] * nrneg
	poz = [1] * nrpoz
	sp = nrpoz - nrneg
	for i in range(len(poz)):
		if sp < n:
			poz[i] += min(n - poz[i], n - sp)
			sp += poz[i] - 1
sgn = '+'
(ipoz, ineg) = (0, 0)
for i in s:
	if i == '?':
		if sgn == '+':
			print(poz[ipoz], end=' ')
			ipoz += 1
		else:
			print(neg[ineg], end=' ')
			ineg += 1
	else:
		sgn = i
		print(i, end=' ')


a = ['+'] + input().split()
(n, m, s0, s1) = (int(a[-1]), len(a) // 2 - 1, 0, 0)
for i in range(m):
	if a[2 * i] == '+':
		(a[2 * i + 1], s0, s1) = (1, s0 + 1, s1 + n)
	else:
		(a[2 * i + 1], s0, s1) = (n, s0 - n, s1 - 1)
if n not in range(s0, s1 + 1):
	print('Impossible')
else:
	for i in range(m):
		d = n - max(1, s0)
		if a[2 * i] == '+':
			a[2 * i + 1] += d
		else:
			a[2 * i + 1] -= d
		s0 += d
	print('Possible')
	print(' '.join(map(str, a[1:])))


s = list(map(str, input().split()))
count1 = 1
count2 = 0
n = 0
for i in range(1, len(s)):
	if s[i] == '+':
		count1 += 1
	elif s[i] == '-':
		count2 += 1
	elif s[i] == '?':
		pass
	elif s[i] == '=':
		pass
	else:
		n = s[i]
		n = int(n)
max1 = count1 * n
min1 = count1
max2 = count2 * n
min2 = count2

def ans(a1, a2, count1, count2, s):
	b1 = a1 % count1
	if count2 != 0:
		b2 = a2 % count2
	for i in range(0, len(s)):
		if i == 0:
			s[i] = int(a1 / count1)
			if b1 > 0:
				b1 -= 1
				s[i] += 1
		elif s[i] == '-':
			s[i + 1] = int(a2 / count2)
			if b2 > 0:
				b2 -= 1
				s[i + 1] += 1
		elif s[i] == '+':
			s[i + 1] = int(a1 / count1)
			if b1 > 0:
				b1 -= 1
				s[i + 1] += 1
	for i in range(0, len(s)):
		if i == len(s) - 1:
			print(s[i], end='')
		else:
			print(s[i], end=' ')
	print('')
if max1 - min2 >= n and n >= min1 - max2:
	print('Possible')
	x = max1 - n
	if min2 <= x and x <= max2:
		ans(max1, x, count1, count2, s)
	else:
		t = x - max2
		ans(max1 - t, x - t, count1, count2, s)
else:
	print('Impossible')


from collections import Counter

def main():
	(a, n) = ('+' + input()).replace(' ', '').replace('?', '').split('=')
	n = int(n)
	cnt = Counter(a)
	(x, y) = (cnt['+'], cnt['-'])
	if (n + y + x - 1) // x <= n and (n + y) // x > 0:
		print('Possible')
		d = (n + y + x - 1) // x
		c = n + x + y - d * x
		var = [str(d)] * c + [str(d - 1)] * (x - c)
		ans = []
		for _ in a:
			ans.append(_)
			if _ == '+':
				ans.append(var.pop())
			else:
				ans.append('1')
		ans.extend(['=', str(n)])
		print(' '.join(ans)[2:])
		return
	if y > 0 and x - n >= y and ((x - n + y - 1) // y <= n):
		d = (x - n + y - 1) // y
		c = x + y - n - d * y
		var = [str(d)] * c + [str(d - 1)] * (y - c)
		ans = []
		for _ in a:
			ans.append(_)
			if _ == '+':
				ans.append('1')
			else:
				ans.append(var.pop())
		ans.extend(['=', str(n)])
		print('Possible')
		print(' '.join(ans)[2:])
		return
	print('Impossible')
main()


s = input().split()
n = int(s[-1])
val = 0
sign = 1
ls = []
for c in s[:-2]:
	if c == '+':
		sign = 1
	elif c == '-':
		sign = -1
	elif c == '?':
		ls.append(sign)
		val += sign
	else:
		print(c)
for i in range(len(ls)):
	if val > n:
		if ls[i] > 0:
			continue
		ls[i] -= min(n - 1, val - n)
		val -= min(n - 1, val - n)
	elif val < n:
		if ls[i] < 0:
			continue
		ls[i] += min(n - 1, n - val)
		val += min(n - 1, n - val)
if val != n:
	print('Impossible')
else:
	print('Possible')
	print(''.join([(' + ' if v > 0 else ' - ') + str(abs(v)) for v in ls])[3:] + ' = ' + str(n))


def main():
	(expr, val) = input().split(' = ')
	n = int(val)
	p = 1
	m = 0
	signs = [1]
	for ch in expr:
		if ch == '+':
			signs.append(1)
			p += 1
		elif ch == '-':
			signs.append(-1)
			m += 1
	if p - m * n > n or p * n - m < n:
		print('Impossible')
		return
	else:
		print('Possible')
		ans = [1 for i in range(len(signs))]
		if p - m < n:
			sum = abs(n - (p - m))
			for i in range(len(signs)):
				while sum > 0 and signs[i] == 1 and (ans[i] < n):
					ans[i] += 1
					sum -= 1
		elif p - m > n:
			sum = abs(n - (p - m))
			for i in range(len(signs)):
				while sum > 0 and signs[i] == -1 and (ans[i] < n):
					ans[i] += 1
					sum -= 1
	answer = str(ans[0])
	for i in range(p + m - 1):
		answer += ' + ' if signs[i + 1] > 0 else ' - '
		answer += str(ans[i + 1])
	print(answer + ' = ' + val)
main()


(s, n) = input().split(' = ')
n = int(n)
a = s.count('+') + 1
b = s.count('-')
if a - b * n <= n <= a * n - b:
	s = s.replace('- ?', '- !')
	if a - b < n:
		k = 1
		while k * a - b < n:
			k += 1
		s = s.replace('?', str(k)).replace(str(k), str(k - 1), k * a - b - n).replace('!', '1')
	else:
		k = 1
		while a - k * b > n:
			k += 1
		s = s.replace('!', str(k)).replace(str(k), str(k - 1), k * b + n - a).replace('?', '1')
	print('Possible\n' + s + ' = ' + str(n))
else:
	print('Impossible')


import sys
input = sys.stdin.readline
s = input().rstrip()
l = list(s.split(' '))
p = 1
m = 0
for ss in l:
	if ss == '+':
		p += 1
	if ss == '-':
		m += 1
n = int(l[-1])
if n * p - m < n or p - m * n > n:
	print('Impossible')
	exit()
arr_p = [1] * p
arr_m = [1] * m
r = p - m
for i in range(p):
	xx = min(n - 1, max(n - r, 0))
	arr_p[i] += xx
	r += xx
for i in range(m):
	xx = min(n - 1, max(r - n, 0))
	arr_m[i] += xx
	r -= xx
ans = []
pre = 1
for i in range(len(l)):
	if l[i] == '?':
		if pre:
			ans.append(str(arr_p.pop()))
		else:
			ans.append(str(arr_m.pop()))
	elif l[i] == '+':
		pre = 1
		ans.append(l[i])
	elif l[i] == '-':
		pre = 0
		ans.append(l[i])
	else:
		ans.append(str(l[i]))
print('Possible')
print(' '.join(ans))


import sys
r = input()
(r, n) = r.split('=')
z = ''
for i in r:
	z = z + i * (i in ['+', '-'])
r = z
n = int(n)
(p, v) = (r.count('+') + 1, r.count('-'))
if not p - n * v <= n <= p * n - v:
	print('Impossible')
	sys.exit()
print('Possible')
s = 0
ans = ''
for i in range(len(r)):
	zn = 1
	if i > 0 and r[i - 1] == '-':
		zn = -1
	if zn == 1:
		p -= 1
	else:
		v -= 1
	for x in range(1, n + 1):
		if s + x * zn + p - n * v <= n <= s + x * zn + p * n - v:
			s += x * zn
			zn = '+' if zn == 1 else '-'
			ans = ans + str(x) + ' ' + str(r[i]) + ' '
			break
ans = ans + str(abs(n - s)) + ' '
print(ans + '= ' + str(n))


import sys
input = sys.stdin.readline()
possible = False
input = '+ ' + input.strip()
inparse = input.split(' ')
n = int(inparse[-1])
items = inparse[0:-2]
nums = []
for i in range(0, int(len(items) / 2)):
	if items[i * 2] == '+':
		nums.append(1)
	else:
		nums.append(-1)
sumnum = sum(nums)
while sumnum != n:
	found = False
	deficit = abs(sumnum - n)
	if sumnum < n:
		for i in range(0, len(nums)):
			if nums[i] < n and nums[i] >= 1:
				nums[i] = min(nums[i] + deficit, n)
				found = True
				break
	elif sumnum > n:
		for i in range(0, len(nums)):
			if nums[i] > -1 * n and nums[i] <= -1:
				nums[i] = max(nums[i] - deficit, -1 * n)
				found = True
				break
	sumnum = sum(nums)
	if not found:
		break
if sumnum == n:
	possible = True
if possible:
	print('Possible')
	outstr = ''
	for i in nums:
		if i > 0:
			outstr = outstr + ' + ' + str(abs(i))
		else:
			outstr = outstr + ' - ' + str(abs(i))
	outstr = outstr + ' = ' + str(n)
	print(outstr.strip()[2:])
else:
	print('Impossible')


expr = input()
q_cnt = expr.count('?')
plus_cnt = expr.count('+')
minus_cnt = expr.count('-')
n = int(expr[expr.find('= ') + 2:])
if plus_cnt + 1 > n * (minus_cnt + 1) or n * (plus_cnt + 1) < n + minus_cnt:
	print('Impossible')
else:
	tokens = expr.split()
	before = 's'
	output = [t for t in tokens]
	if plus_cnt == minus_cnt:
		for (i, t) in enumerate(tokens):
			if t == '?':
				if before == 's':
					output[i] = str(n)
				else:
					output[i] = str(1)
			else:
				before = t
	elif plus_cnt > minus_cnt:
		yobun = plus_cnt - minus_cnt
		for (i, t) in enumerate(tokens):
			if t == '?':
				if before == 's':
					output[i] = str(max(1, n - yobun))
					yobun -= n - int(output[i])
				elif before == '+':
					output[i] = str(1)
				else:
					output[i] = str(min(n, yobun + 1))
					yobun -= int(output[i]) - 1
			elif t == '+' or t == '-':
				before = t
	else:
		yobun = minus_cnt - plus_cnt
		for (i, t) in enumerate(tokens):
			if t == '?':
				if before == 's':
					output[i] = str(n)
				elif before == '+':
					output[i] = str(min(n, yobun + 1))
					yobun -= int(output[i]) - 1
				else:
					output[i] = str(1)
			elif t == '+' or t == '-':
				before = t
	print('Possible')
	print(' '.join(output))


def binp(a, b):
	st = a[0]
	fin = a[1]
	b = [-b[1], -b[0]]
	while True:
		s = (st + fin) // 2
		if s >= b[0]:
			if s <= b[1]:
				return s
			else:
				fin = s - 1
		else:
			st = s + 1
s = input()
for i in range(len(s)):
	if s[i] == '=':
		y = i
		break
y += 1
n = int(s[y:])
now = '+'
max_ = 0
min_ = 0
ctr = 0
pls = 0
minus = 0
g = [[0, 0]]
for i in s:
	ctr += 1
	if i == '?':
		if now == '+':
			max_ += n
			min_ += 1
			pls += 1
		else:
			max_ -= 1
			min_ -= n
			minus += 1
		g.append([min_, max_])
	elif i == '-' or i == '+':
		now = i
	elif i == '=':
		break
v = n
if v < min_ or v > max_:
	print('Impossible')
else:
	print('Possible')
	a = [pls * 1, pls * v]
	b = [minus * -v - n, minus * -1 - n]
	ctr = 0
	ctr = binp(a, b)
	fir = ctr
	j = [0] * pls
	if pls != 0:
		j = [fir // pls] * pls
		for u in range(fir % pls):
			j[u] += 1
	sec = n - ctr
	k = [0] * minus
	if minus != 0:
		k = [-sec // minus] * minus
		for u in range(-sec % minus):
			k[u] += 1
	p = 0
	m = 0
	now = '+'
	for i in s:
		if i == '?':
			if now == '+':
				print(j[p], end='')
				p += 1
			else:
				print(k[m], end='')
				m += 1
		elif i == '-' or i == '+':
			now = i
			print(i, end='')
		else:
			print(i, end='')


def mp():
	return map(int, input().split())

def lt():
	return list(map(int, input().split()))

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)

def listring(l):
	return ' '.join([str(x) for x in l])

def printlist(l):
	print(' '.join([str(x) for x in l]))
a = input().split()
n = int(a[-1])
if n * (a.count('+') + 1) - a.count('-') < n:
	print('Impossible')
else:
	b = [x for x in a if x == '+' or x == '-']
	b.insert(0, '+')
	c = [n if b[i] == '+' else 1 for i in range(len(b))]
	x = n * (a.count('+') + 1) - a.count('-') - n
	j = 0
	while x > 0 and j < len(c):
		if x >= n - 1:
			if c[j] == n:
				c[j] -= n - 1
			else:
				c[j] += n - 1
			x -= n - 1
		else:
			if c[j] == n:
				c[j] -= x
			else:
				c[j] += x
			x = 0
		j += 1
	if x != 0:
		print('Impossible')
		exit()
	print('Possible')
	result = ''
	b.pop(0)
	for i in range(len(b)):
		result += str(c[i])
		result += ' '
		result += b[i]
		result += ' '
	result += '%d ' % c[-1]
	result += '= %d ' % n
	print(result)


s = ('+ ' + input()).strip().split()
plus = 0
minus = 0
for c in s:
	if c == '+':
		plus += 1
	elif c == '-':
		minus += 1
n = int(s[-1])
maxn = plus * n - minus
minn = plus - minus * n
if not maxn >= n >= minn:
	print('Impossible')
	exit()
ans = []
for i in range(1, len(s)):
	need = min(maxn - n, n - 1)
	if s[i - 1] == '+':
		ans.append(str(n - need))
		maxn -= need
	elif s[i - 1] == '-':
		ans.append(str(1 + need))
		maxn -= need
	else:
		ans.append(s[i])
print('Possible')
print(' '.join(ans))


from sys import stdin
s = stdin.readline().strip().split()

def smas(x, mas):
	for i in range(len(s)):
		if s[i] == 1 and (i == 0 or s[i - 1] == '+'):
			if x > 0:
				y = min(n - 1, x)
				s[i] += y
				x -= y

def smen(x, men):
	for i in range(len(s)):
		if s[i] == 1 and i > 0 and (s[i - 1] == '-'):
			if x > 0:
				y = min(n - 1, x)
				s[i] += y
				x -= y
n = int(s[-1])
ans = 0
y = 0
if s[0] == '-':
	y = 1
ind = -1
men = 0
mas = 0
for i in range(y, len(s) - 1, 2):
	if i != 0 and s[i - 1] == '-':
		ans -= 1
		men += 1
	else:
		mas += 1
		if ind == -1:
			ind = i
		else:
			ans += 1
	s[i] = 1
l = [-(n * men), -men]
t = True
for i in range(mas, n * mas + 1):
	if i >= n:
		x = n - i
	else:
		continue
	if x >= l[0] and x <= l[1]:
		t = False
		smas(i - mas, mas)
		smen(-x - men, men)
		break
if t:
	print('Impossible')
else:
	print('Possible')
	print(*s)


from sys import stdin

def genp(num, cnt):
	global N
	rem = num - cnt * 1
	(cnt2, rem2) = (int(rem / (N - 1)), rem % (N - 1))
	for i in range(cnt2):
		yield N
	yield (1 + rem2)
	for i in range(cnt - cnt2 - 1):
		yield 1

def print_answer(plus, minus, nplus, nminus, line):
	gplus = genp(nplus, plus) if N != 1 else (1 for x in range(plus))
	gminus = genp(nminus, minus) if N != 1 else (1 for x in range(minus))
	print('%d' % next(gplus), end='')
	for i in range(1, len(line), 2):
		if line[i] == '+':
			print(' + %d' % next(gplus), end='')
		elif line[i] == '-':
			print(' - %d' % next(gminus), end='')
		elif line[i] == '=':
			print(' = %s' % line[i + 1])
			break

def parse():
	global TERM, N
	line = stdin.readline().split()
	N = int(line[-1])
	(plus, minus) = (1, 0)
	for i in range(1, len(line), 2):
		if line[i] == '+':
			plus += 1
		elif line[i] == '-':
			minus += 1
	TERM = plus + minus
	if plus * 1 - minus * N > N:
		print('Impossible')
	elif plus * N - minus * 1 < N:
		print('Impossible')
	else:
		print('Possible')
		nplus = N * plus
		nminus = minus
		if nplus - nminus != N:
			d = nplus - nminus - N
			if d <= (N - 1) * plus:
				nplus -= d
			else:
				nplus -= (N - 1) * plus
				d = nplus - nminus - N
				nminus += d
		print_answer(plus, minus, nplus, nminus, line)
parse()


(ar, ans) = input().split('=')
ans = int(ans)
pl = ar.count('+') + 1
mn = ar.count('-')
if pl * ans - mn * 1 < ans or pl * 1 - mn * ans > ans:
	print('Impossible')
	exit(0)
print('Possible')
mat = [1] * (pl + mn)
sig = ('+' + ar).replace(' ', '').split('?')
del sig[-1]
while True:
	i = 0
	s = ''
	for ch in ar:
		if ch == '?':
			s += str(mat[i])
			i += 1
		else:
			s += ch
	t = eval(s)
	if t == ans:
		print('{0}= {1}'.format(s, ans))
		exit(0)
	d = ans - t
	for i in range(len(mat)):
		if sig[i] == '+' and d > 0:
			mat[i] = min(1 + d, ans)
			d -= mat[i] - 1
		elif sig[i] == '-' and d < 0:
			mat[i] = min(1 + abs(d), ans)
			d += mat[i] - 1


expr = input().split()
target_number = int(expr[-1])
result_expr = None

def spread(number_sum, quantity):
	spreaded = []
	acc = number_sum
	remaining = quantity - 1
	for i in range(quantity):
		next_number = min(target_number, acc - remaining)
		spreaded.append(next_number)
		acc -= next_number
		remaining -= 1
	return spreaded
plus_count = 1 + expr.count('+')
minus_count = expr.count('-')
if minus_count == 0:
	if plus_count <= target_number <= plus_count * target_number:
		spreaded = spread(target_number, plus_count)
		result_expr = '{0} = {1}'.format(' + '.join(map(str, spreaded)), target_number)
else:
	negatives = range(minus_count, minus_count * target_number + 1)
	for negative in negatives:
		positive = negative + target_number
		if plus_count <= positive <= plus_count * target_number:
			spreaded_positive = spread(positive, plus_count)
			spreaded_negative = spread(negative, minus_count)
			result_expr = '{0} '.format(spreaded_positive.pop())
			for i in range(1, len(expr) - 2):
				if expr[i] == '+':
					result_expr += '+ {0} '.format(spreaded_positive.pop())
				elif expr[i] == '-':
					result_expr += '- {0} '.format(spreaded_negative.pop())
			result_expr += '= {0}'.format(target_number)
			break
		if positive > plus_count * target_number:
			break
if result_expr:
	print('Possible')
	print(result_expr)
else:
	print('Impossible')


l = [i for i in input().split(' ')]
(n, make) = (int(l[-1]), int(l[-1]))
positives = 1
negatives = 0
for i in l:
	if i == '-':
		make += 1
		negatives += 1
	elif i == '+':
		positives += 1
if make > n * positives or (make < positives and negatives == 0):
	print('Impossible')
	exit(0)
ans = []
for i in range(n, 0, -1):
	while make >= i:
		ans.append(i)
		make -= i
	if make == 0:
		break
idx = 0
while len(ans) > 0 and len(ans) < positives:
	if ans[idx] == 1:
		idx += 1
	if idx > len(ans) or ans[idx] == 1:
		break
	ans[idx] -= 1
	ans.append(1)
idx = 0
negs = [0] * negatives
while len(ans) < positives:
	ans.append(1)
	negs[idx] += 1
	if negs[idx] == n:
		print('Impossible')
		exit(0)
	idx = (idx + 1) % negatives
print('Possible')
print(ans[0], end=' ')
(j, k) = (0, 1)
for i in l:
	if i == '-':
		print(i, 1 + negs[j], end=' ')
		j += 1
	elif i == '+':
		print(i, ans[k], end=' ')
		k += 1
	elif i != '?':
		print(i, end=' ')
print()


l = str(input()).split(' ')
pos = 1
n = 0
neg = 0
dum = []
for x in range(1, len(l)):
	if l[x] == '=':
		n = int(l[x + 1])
		break
	elif l[x] == '+':
		pos += 1
		dum.append('+')
	elif l[x] == '-':
		neg += 1
		dum.append('-')
if neg == 0:
	if n % pos != 0:
		print('Impossible')
		exit(0)
	print('Possible')
	res = ''
	for i in range(pos):
		res += str(n // pos) + ' '
		if i != pos - 1:
			res += '+ '
	res += '= ' + str(n)
	print(res)
	exit(0)
tot = pos + neg
ps = -1
ys = -1
mds = 0
(a1, a2) = ([], [])
for y in range(1, n + 1):
	z = n + y * neg
	if (z + pos - 1) // pos <= n and z // pos >= 1:
		ys = y
		ps = z // pos
		mds = z % pos
		break
if ys == -1:
	for x in range(1, n + 1):
		if x * pos - n <= 0:
			continue
		z = x * pos - n
		if (z + neg - 1) // neg <= n and z // neg >= 1:
			ys = z // neg
			mds = z % neg
			ps = x
			break
	if ys == -1:
		print('Impossible')
		exit(0)
	for i in range(mds):
		a2.append(ys + 1)
	for i in range(neg - mds):
		a2.append(ys)
	for i in range(pos):
		a1.append(ps)
for i in range(mds):
	a1.append(ps + 1)
for i in range(pos - mds):
	a1.append(ps)
for i in range(neg):
	a2.append(ys)
res = str(a1[0]) + ' '
(u1, u2) = (1, 0)
for i in range(1, len(l)):
	if l[i] == '+':
		res += '+ ' + str(a1[u1]) + ' '
		u1 += 1
	elif l[i] == '-':
		res += '- ' + str(a2[u2]) + ' '
		u2 += 1
	elif l[i] == '=':
		break
res += '= ' + str(n)
print('Possible')
print(res)


mass = input().split()
length = mass.count('?')
tmp_mass = [1]
flag = False
for i in range(1, (length - 1) * 2, 2):
	if mass[i] == '+':
		tmp_mass.append(1)
	else:
		tmp_mass.append(-1)
tmp_sum = sum(tmp_mass)
summ = int(mass[len(mass) - 1])
for i in range(length):
	if tmp_mass[i] > 0:
		tmp_mass[i] = summ - sum(tmp_mass) + tmp_mass[i]
		if tmp_mass[i] >= summ:
			tmp_mass[i] = summ
		elif tmp_mass[i] <= 1:
			tmp_mass[i] = 1
		else:
			flag = True
			break
	else:
		tmp_mass[i] = summ - sum(tmp_mass) + tmp_mass[i]
		if tmp_mass[i] >= -1:
			tmp_mass[i] = -1
		elif abs(tmp_mass[i]) >= summ:
			tmp_mass[i] = -summ
		else:
			flag = True
			break
if sum(tmp_mass) == summ:
	flag = True
else:
	flag = False
for i in range(len(mass)):
	if mass[i] == '?':
		mass[i] = abs(tmp_mass.pop(0))
if flag:
	print('Possible')
	print(' '.join(list(map(str, mass))))
else:
	print('Impossible')


import math

def solve():
	eq = input()
	num_plus = eq.count('+') + 1
	num_minus = eq.count('-')
	qmark = eq.count('?')
	qmark -= num_minus
	divid = [i for i in eq.split()]
	n = int(divid[-1])
	t = n + num_minus - num_plus
	if t != 0 and n == 1:
		print('Impossible')
		return
	fill_to_n = math.ceil(abs(t) / (n - 1)) if n > 1 else 0
	if t > 0 and fill_to_n > num_plus or (t < 0 and fill_to_n > num_minus):
		print('Impossible')
		return
	if t > 0:
		if fill_to_n > 0:
			divid[0] = t % (n - 1) + 1 if t % (n - 1) != 0 else n
			fill_to_n -= 1
		else:
			divid[0] = 1
	else:
		divid[0] = 1
	for i in range(1, len(divid)):
		if divid[i] == '?':
			divid[i] = 1
		if t > 0:
			if divid[i - 1] == '+':
				if fill_to_n > 0:
					divid[i] = n
					fill_to_n -= 1
		elif t < 0:
			if divid[i - 1] == '-':
				if fill_to_n > 0:
					divid[i] = n
					fill_to_n -= 1
	if t < 0 and abs(t) % (n - 1) != 0:
		for i in range(len(divid)):
			if divid[i - 1] == '-':
				divid[i] = abs(t) % (n - 1) + 1
				break
	print('Possible')
	print(*divid, sep=' ')
solve()


s = input().split()
n = int(s[-1])
summands = [1]
for sign in s[1::2]:
	if sign == '+':
		summands.append(1)
	elif sign == '-':
		summands.append(-n)
m = len(summands)
cur = sum(summands)
if cur > n:
	print('Impossible')
else:
	for i in range(m):
		summands[i] = n if summands[i] == 1 else -1
		cur += n - 1
		if cur >= n:
			summands[i] -= cur - n
			print('Possible')
			print(summands[0], end='')
			for summand in summands[1:]:
				if summand < 0:
					print(' - {0}'.format(-summand), end='')
				else:
					print(' + {0}'.format(summand), end='')
			print(' = {0}'.format(n), end='')
			break
	else:
		print('Impossible')


s = input().split('=')
signs = s[0].split('?')[0:-1]
n = int(s[1])
plus = [i for i in range(len(signs)) if signs[i] != ' - ']
minus = [i for i in range(len(signs)) if signs[i] == ' - ']
delta = len(plus) - len(minus)
if len(plus) * n - len(minus) < n or len(plus) - len(minus) * n > n:
	print('Impossible')
else:
	res = ''
	cur = delta
	for i in range(len(signs)):
		if signs[i] == ' - ':
			if cur <= n:
				res += ' - 1'
			elif cur > n + n - 1:
				cur -= n - 1
				res += ' - ' + str(n)
			else:
				res += ' - ' + str(cur + 1 - n)
				cur = n
		elif cur >= n:
			res += signs[i] + '1'
		elif cur <= 1:
			cur += n - 1
			res += signs[i] + str(n)
		else:
			res += signs[i] + str(n - cur + 1)
			cur = n
	print('Possible')
	print(res + ' = ' + str(n))


import sys
X = sys.stdin.read()
a = X.split()
(plus, minus) = (1, 0)
for i in a:
	if i == '+':
		plus += 1
	if i == '-':
		minus += 1
N = int(a[-1])

def calcmaxv(p, m, calc):
	return p * N - m + calc

def calcminv(p, m, calc):
	return p - m * N + calc
now = 0
if calcminv(plus, minus, now) > N:
	print('Impossible')
	quit()
if calcmaxv(plus, minus, now) < N:
	print('Impossible')
	quit()
sign = +1
for j in range(len(a)):
	i = a[j]
	if i == '+':
		sign = +1
		continue
	if i == '-':
		sign = -1
		continue
	if i != '?':
		continue
	maxv = calcmaxv(plus, minus, now)
	if sign > 0:
		a[j] = str(max(2 * N - maxv, 1))
		now += max(2 * N - maxv, 1)
	else:
		a[j] = str(min(N, 1 + maxv - N))
		now -= min(N, 1 + maxv - N)
	if sign > 0:
		plus -= 1
	else:
		minus -= 1
print('Possible')
print(' '.join(a))


s = input().split(' = ')
n = int(s[1])
t = s[0]
m = len(t) // 4 + 1
val = ['+' for _ in range(m)]
nb = [-1 for _ in range(m)]
for i in range(1, m):
	val[i] = t[4 * i - 2]
mini = 0
maxi = 0
for i in range(m):
	if val[i] == '+':
		mini += 1
		maxi += n
	else:
		mini -= n
		maxi -= 1
if not mini <= n <= maxi:
	print('Impossible')
else:
	v = 0
	for i in range(m):
		if val[i] == '+':
			v += 1
		else:
			v -= 1
		nb[i] = 1
	while v < n:
		for i in range(m):
			if val[i] == '+' and nb[i] == 1:
				nb[i] += min(n - 1, n - v)
				v += nb[i] - 1
	while v > n:
		for i in range(m):
			if val[i] == '-' and nb[i] == 1:
				nb[i] += min(n - 1, v - n)
				v -= nb[i] - 1
	print('Possible')
	s = str(nb[0])
	for i in range(1, m):
		s += ' ' + str(val[i]) + ' ' + str(nb[i])
	s += ' = ' + str(n)
	print(s)


import unittest
import sys
import re

class Rebus:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		self.str = uinput()
		self.n = 0
		m = re.search('(\\d+)', self.str)
		if m:
			self.n = int(m.group(1))
		self.signs = ['+'] + re.findall('\\? ([+-])', self.str)

	def summ(self, nums, signs):
		result = 0
		for i in range(len(self.signs)):
			if self.signs[i] == '+':
				result += nums[i]
			else:
				result -= nums[i]
		return result

	def calculate(self):
		nums = [0] * len(self.signs)
		for i in range(len(self.signs)):
			nums[i] = 1
		sum = self.summ(nums, self.signs)
		for i in range(len(self.signs)):
			if sum != self.n:
				if self.signs[i] == '+' and sum < self.n:
					nums[i] = min(self.n - sum + 1, self.n)
					sum -= 1
					sum += nums[i]
				if self.signs[i] == '-' and sum > self.n:
					nums[i] = min(sum + 1 - self.n, self.n)
					sum += 1
					sum -= nums[i]
		if sum == self.n:
			result = 'Possible\n'
			for i in range(len(self.signs)):
				if i != 0:
					result += self.signs[i] + ' '
				result += str(nums[i]) + ' '
			result += '= ' + str(self.n)
		else:
			result = 'Impossible'
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '? + ? - ? + ? + ? = 42'
		d = Rebus(test)
		self.assertEqual(d.str, '? + ? - ? + ? + ? = 42')
		self.assertEqual(d.n, 42)
		self.assertEqual(d.signs, ['+', '+', '-', '+', '+'])
		self.assertEqual(Rebus(test).calculate(), 'Possible\n40 + 1 - 1 + 1 + 1 = 42')
		test = '? - ? = 1'
		self.assertEqual(Rebus(test).calculate(), 'Impossible')
		test = '? = 1000000'
		self.assertEqual(Rebus(test).calculate(), 'Possible\n1000000 = 1000000')
		test = '? + ? + ? + ? - ? = 2'
		self.assertEqual(Rebus(test).calculate(), 'Possible\n1 + 1 + 1 + 1 - 2 = 2')
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Rebus(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Rebus().calculate())


s = input().split()
n = int(s[len(s) - 1])
size = (len(s) - 1) // 2
masP = [0]
masM = []
(P, M) = (1, 0)
for i in range(1, len(s) - 2, 2):
	if s[i] == '+':
		P += 1
		masP.append(i + 1)
	else:
		M += 1
		masM.append(i + 1)
sum1 = n + M * n
sum2 = n + M
if n + M > n * P or n + M * n < P:
	print('Impossible')
else:
	print('Possible')
	while M != 0:
		for u in range(1, n + 1):
			if sum2 + u - 1 <= n * P and sum1 + u - n >= P:
				s[masM.pop()] = u
				M = M - 1
				sum2 = sum2 + u - 1
				sum1 = sum1 + u - n
				break
	while P != 0:
		a = sum2 // P
		s[masP.pop()] = a
		P = P - 1
		sum2 = sum2 - a
	print(' '.join((str(x) for x in s)))


s = input()
a = s.split()
n = int(a[-1])
pos = 1
neg = 0
for item in a:
	if item == '+':
		pos += 1
	if item == '-':
		neg += 1
if n < pos - neg * n or n > pos * n - neg:
	print('Impossible')
else:
	print('Possible')
	parr = []
	narr = []
	if pos > neg:
		for i in range(neg):
			narr.append(n)
		x = int(n * (neg + 1) // pos)
		for i in range(pos):
			if i < n * (neg + 1) % pos:
				parr.append(x + 1)
			else:
				parr.append(x)
	else:
		for i in range(pos):
			parr.append(n)
		x = int(n * (pos - 1) // neg)
		for i in range(neg):
			if i < n * (pos - 1) % neg:
				narr.append(x + 1)
			else:
				narr.append(x)
	sgn = 1
	for c in s:
		if c == '?':
			if sgn == 1:
				print(parr[0], end='')
				del parr[0]
			else:
				print(narr[0], end='')
				del narr[0]
			continue
		elif c == '+':
			sgn = 1
		elif c == '-':
			sgn = -1
		print(c, end='')


raw = input()
s = raw.replace('?', '')
n = int(s.split()[-1])
m = s.count('-')
p = s.count('+')
c = p - m
if (p + 1) * n - m < n or p + 1 - m * n > n:
	print('Impossible')
else:
	print('Possible')
	rez = n - c
	s = raw[1:]
	while rez > n or rez < 1:
		if rez > n:
			s = s.replace('+ ?', '+ ' + str(n), 1)
			rez -= n - 1
		else:
			s = s.replace('- ?', '- ' + str(n), 1)
			rez += n - 1
	print(str(rez) + s.replace('?', '1'))


def max(a, b):
	if a >= b:
		return a
	else:
		return b
s = input().split()
length = len(s)
n = int(s[length - 1])
plus = 1
minus = 0
for i in s:
	if i == '+':
		plus += 1
	if i == '-':
		minus += 1
if plus * n - minus < n or plus - n * minus > n:
	print('Impossible')
	return
else:
	print('Possible')
for i in range(0, length - 1, 2):
	s[i] = '1'
res = n - plus + minus
for i in range(0, length - 1, 2):
	if (i == 0 or s[i - 1] == '+') and res > 0:
		val = int(s[i])
		if res > n - val:
			res -= n - val
			s[i] = repr(n)
		else:
			val += res
			s[i] = repr(val)
			res = 0
	elif s[i - 1] == '-' and res < 0:
		val = int(s[i])
		if res < val - n:
			res += n - val
			s[i] = repr(n)
		else:
			val -= res
			s[i] = repr(val)
			res = 0
print(' '.join(s))


a = input()
while a:
	(expr, n) = a.split('=')
	n = int(n.strip())
	pos = 1
	neg = 0
	sg = [1]
	for c in expr:
		if c == '+':
			pos += 1
			sg.append(1)
		elif c == '-':
			neg += 1
			sg.append(0)
	csum = pos - neg
	rez = []
	for i in sg:
		if csum < n:
			if i > 0:
				v = min(n - csum, n - 1)
				csum += v
				rez.append(1 + v)
			else:
				rez.append(-1)
		elif i > 0:
			rez.append(1)
		else:
			v = min(csum - n, n - 1)
			csum -= v
			rez.append(-1 - v)
	if csum == n:
		print('Possible')
		ans = str(rez[0])
		for j in rez[1:]:
			ans += ' ' + ('+' if j > 0 else '-') + ' '
			ans += str(abs(j))
		ans += ' = ' + str(n)
		print(ans)
	else:
		print('Impossible')
	break
	a = input()


s = input().split('=')
v = int(s[1])
qs = s[0].split()
pos = 0
neg = 0
if len(qs) > 0:
	pos += 1
signs = []
for i in qs:
	if i == '+':
		pos += 1
		signs.append(1)
	elif i == '-':
		neg += 1
		signs.append(0)
if pos == 0 and neg == 0 and (v == 0):
	print('Possible\n= 0')
elif pos == 0 and neg == 0 or pos * v - neg < v or pos - neg * v > v:
	print('Impossible')
else:
	print('Possible')
	t = pos - neg
	print(1 + max(0, min(v - 1, v - t)), end=' ')
	t += max(0, min(v - 1, v - t))
	for i in signs:
		if i == 0:
			print('-', end=' ')
			print(1 + max(0, min(v - 1, t - v)), end=' ')
			t -= max(0, min(v - 1, t - v))
		if i == 1:
			print('+', end=' ')
			print(1 + max(0, min(v - 1, v - t)), end=' ')
			t += max(0, min(v - 1, v - t))
	print('= ' + str(v))


from collections import Counter

def solve():
	s = input()
	s = '+ ' + s
	ls = s.split()
	n = int(ls[-1])
	ops = [ls[i * 2] for i in range(len(ls) // 2 - 1)]
	nop = len(ops)
	c = Counter(ops)
	p = c['+']
	m = c['-']
	ma = n * p - 1 * m
	mi = 1 * p - n * m
	if not mi <= n <= ma:
		print('Impossible')
		return
	x = (ma - n) // (p + m)
	mae = [n - x if o == '+' else 1 + x for o in ops]
	ma -= x * (p + m)
	i = 0
	while ma > n:
		if ops[i % nop] == '+':
			mae[i % nop] -= 1
		else:
			mae[i % nop] += 1
		i += 1
		ma -= 1
	ans = []
	for i in range(nop):
		ans.append(ops[i])
		ans.append(str(mae[i]))
	ans.append('=')
	ans.append(str(n))
	print('Possible')
	print(' '.join(ans[1:]))
solve()


class CodeforcesTask664BSolution:

	def __init__(self):
		self.result = ''
		self.equation = ''

	def read_input(self):
		self.equation = input()

	def process_task(self):
		n = int(self.equation.split('=')[1].strip())
		left_eq = self.equation.split('=')[0]
		plus = 1 + left_eq.count('+')
		minus = left_eq.count('-')
		if plus - minus * n <= n <= plus * n - minus:
			val = n * plus - minus
			values = [n] * plus + [-1] * minus
			changing = 0
			while val != n:
				if changing < plus:
					if val - n >= n - 1:
						values[changing] = 1
						val -= n - 1
					else:
						values[changing] -= val - n
						val = n
				elif val - n >= n - 1:
					values[changing] = -n
					val -= n - 1
				else:
					values[changing] += -val + n
					val = n
				changing += 1
			sign_str = ('+' + self.equation.split('=')[0]).replace(' ', '').replace('+?', '+|').replace('-?', '-|')[:-1]
			plus_values = values[:plus]
			minus_values = values[plus:]
			eq_string = ''
			for sign in sign_str.split('|'):
				vl = plus_values.pop(0) if sign == '+' else minus_values.pop(0)
				eq_string += sign + ' ' + str(abs(vl)) + ' '
			eq_string += '= ' + str(n)
			eq_string = eq_string[2:]
			self.result = 'Possible\n' + eq_string
		else:
			self.result = 'Impossible'

	def get_result(self):
		return self.result
Solution = CodeforcesTask664BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


__author__ = 'Utena'
s = input().split()
n = int(s[-1])
add = 0
minus = 0
for a in s:
	if a == '+':
		add += 1
	if a == '-':
		minus += 1
if minus > n * add or add - n * minus > n:
	print('Impossible')
else:
	print('Possible')
	ans = []
	if minus < add:
		q = add - minus
		q1 = max(n - q, 1)
		q -= n - q1
		ans.append(str(q1))
		for a in s:
			if a == '+':
				ans.append('+')
				ans.append('1')
			if a == '-':
				ans.append('-')
				q2 = min(1 + q, n)
				q -= q2 - 1
				ans.append(str(q2))
			if a == '=':
				ans.append('=')
				ans.append(str(n))
	else:
		ans.append(str(n))
		q = minus - add
		for a in s:
			if a == '+':
				ans.append('+')
				q3 = min(n, 1 + q)
				q -= q3 - 1
				ans.append(str(q3))
			if a == '-':
				ans.append('-')
				ans.append('1')
			if a == '=':
				ans.append('=')
				ans.append(str(n))
	print(' '.join(ans))


def set_numbers(S, k):
	ans = []
	for i in range(k):
		ans.append(S // k)
	for i in range(S - k * (S // k)):
		ans[i] += 1
	return ans
s = input().split()
i = s.count('+') + 1
j = s.count('-')
n = int(s[-1])
if i - j * n <= n <= i * n - j:
	print('Possible')
	S1 = max(i, j + n)
	l1 = [] if i == 0 else set_numbers(S1, i)
	S2 = S1 - n
	l2 = [] if j == 0 else set_numbers(S2, j)
	p = 0
	q = 0
	for k in range(len(s)):
		if k == 0:
			s[k] = str(l1[p])
			p += 1
		elif s[k] == '?':
			if s[k - 1] == '+':
				s[k] = str(l1[p])
				p += 1
			else:
				s[k] = str(l2[q])
				q += 1
	print(' '.join(s))
else:
	print('Impossible')


def main():
	s = input().split()
	n = int(s[-1])
	xs = [1] + [int(x + '1') for x in s[1:-2:2]]
	d = sum(xs) - n
	if d > 0:
		for (i, x) in enumerate(xs):
			if d == 0:
				break
			if x < 0:
				xs[i] = -min(n, d + 1)
				d += xs[i] + 1
	elif d < 0:
		for (i, x) in enumerate(xs):
			if d == 0:
				break
			if x > 0:
				xs[i] = min(n, -d + 1)
				d += xs[i] - 1
	if sum(xs) == n:
		print('Possible')
		print('{} = {}'.format(' '.join((('+ ' if x > 0 else '- ') + str(abs(x)) for x in xs))[2:], n))
	else:
		print('Impossible')
main()


a = list(input().split())
n = int(a[-1])
R = int(a[-1])
(one, two) = (0, 0)
for i in range(1, len(a), 2):
	if a[i] == '=':
		break
	if a[i] == '+':
		R -= 1
		one += 1
	else:
		R += 1
		two += 1
R -= 1
one += 1
if R >= 0:
	if one * (n - 1) >= R:
		print('Possible')
		for i in range(0, len(a), 2):
			if i > 0 and a[i - 1] == '=':
				print(a[i])
			elif i == 0 or a[i - 1] == '+':
				print(min(n - 1, R) + 1, a[i + 1], end=' ')
				R -= min(n - 1, R)
			else:
				print(1, a[i + 1], end=' ')
	else:
		print('Impossible')
elif two * (1 - n) <= R:
	print('Possible')
	for i in range(0, len(a), 2):
		if i > 0 and a[i - 1] == '=':
			print(a[i])
		elif i > 0 and a[i - 1] == '-':
			print(-(max(1 - n, R) - 1), a[i + 1], end=' ')
			R -= max(1 - n, R)
		else:
			print(1, a[i + 1], end=' ')
else:
	print('Impossible')


(sgn, a, b) = (1, 0, 0)
sol = ''
ok = 0
for ch in input().split():
	if ch == '?':
		if sgn == 1:
			a += 1
			ch = 'P'
		else:
			b += 1
			ch = 'M'
	elif ch == '+':
		sgn = 1
	elif ch == '-':
		sgn = -1
	elif ch != '=':
		n = int(ch)
		ok = 1
	if not ok:
		sol += ch
(pl, mn) = ([n] * a, [1] * b)
s = n * a - b
(i, j) = (0, 0)
while s > n and (i < a or j < b):
	if i < a:
		amt = min(s - n, n - 1)
		pl[i] -= amt
		s -= amt
		i += 1
	else:
		amt = min(s - n, n - 1)
		mn[j] += amt
		s -= amt
		j += 1
if s != n:
	print('Impossible')
else:
	print('Possible')
	for ch in sol:
		if ch != 'P' and ch != 'M':
			print(ch, end=' ')
		elif ch == 'P':
			print(pl[-1], end=' ')
			pl.pop()
		else:
			print(mn[-1], end=' ')
			mn.pop()
	print(n)


from math import ceil

def main():
	p = 1
	m = 0
	n = 0
	exp = str(input()).split(' ')
	for i in range(len(exp)):
		if exp[i] == '+':
			p += 1
		elif exp[i] == '-':
			m += 1
		elif exp[i] == '=':
			n = int(exp[i + 1])
	if p > n + m * n:
		print('Impossible')
		return
	result = n + m
	if p <= result:
		required = ceil(result / n)
		if p >= required:
			print('Possible')
		else:
			print('Impossible')
			return
		pVal = result // p
		pRem = result % p
		isMinus = False
		s_out = ''
		for i in range(len(exp)):
			if exp[i] == '?':
				if not isMinus:
					val = pVal
					if pRem > 0:
						val += 1
						pRem -= 1
					s_out += str(val) + ' '
				else:
					s_out += '1 '
			else:
				if exp[i] == '-':
					isMinus = True
				elif exp[i] == '+':
					isMinus = False
				else:
					s_out += exp[i] + ' ' + exp[i + 1]
					break
				s_out += exp[i] + ' '
		print(s_out)
	else:
		print('Possible')
		comp = p - n
		mVal = comp // m
		mRem = comp % m
		isMinus = False
		s_out = ''
		for i in range(len(exp)):
			if exp[i] == '?':
				if isMinus:
					val = mVal
					if mRem > 0:
						val += 1
						mRem -= 1
					s_out += str(val) + ' '
				else:
					s_out += '1 '
			else:
				if exp[i] == '-':
					isMinus = True
				elif exp[i] == '+':
					isMinus = False
				else:
					s_out += exp[i] + ' ' + exp[i + 1]
					break
				s_out += exp[i] + ' '
		print(s_out)
main()


import sys
s = input()
n = int(s[s.index('=') + 1:])
plus = s.count('+') + 1
minus = s.count('-')
diff = increse_pos = count = neg = a = b = 0
if plus - minus < n:
	diff = n + minus
	a = diff // plus
	b = diff % plus
	if b != 0 and a + 1 > n or a > n:
		neg = 1
	else:
		increse_pos = 1
elif plus - minus > n:
	diff = plus - n
	if minus > 0:
		a = diff // minus
		b = diff % minus
	else:
		neg = 1
	if neg == 0 and b != 0 and (a + 1 > n) or (neg == 0 and a > n):
		neg = 1
	else:
		increse_pos = 0
else:
	diff = 0
	a = 1
sign = 1
res = ''
if neg == 0:
	for ch in s:
		if ch == '?' and sign == 1:
			if increse_pos == 1:
				if b > 0:
					res += str(a + 1)
					count += a + 1
					b -= 1
				else:
					res += str(a)
					count += a
			else:
				res += str(1)
				count += 1
			sign = 0
		elif ch == '?' and sign == 0:
			if increse_pos == 0:
				if b > 0:
					res += str(a + 1)
					count -= a + 1
					b -= 1
				else:
					res += str(a)
					count -= a
			else:
				res += str(1)
				count -= 1
		elif ch == '+':
			sign = 1
			res += ch
		elif ch == '-':
			sign = 0
			res += ch
		else:
			res += ch
	print('Possible')
	print(res)
else:
	print('Impossible')


data = input()
data = data.split()
data.reverse()
n = int(data[0])
data.reverse()
pos = 1
neg = 0
for x in data:
	if x == '-':
		neg += 1
	if x == '+':
		pos += 1
ans = pos - neg
if ans <= n:
	tmp = n - ans
	if tmp > pos * (n - 1):
		print('Impossible')
		exit(0)
	else:
		print('Possible')
		fin = ''
		for x in range(len(data)):
			if data[x] != '?':
				fin += data[x] + ' '
				continue
			if x == 0 or data[x - 1] == '+':
				t = min(n - 1, tmp)
				tmp -= t
				fin += str(1 + t) + ' '
			else:
				fin += '1 '
		print(fin)
else:
	tmp = ans - n
	if tmp > neg * (n - 1):
		print('Impossible')
		exit(0)
	else:
		print('Possible')
		fin = ''
		for x in range(len(data)):
			if data[x] != '?':
				fin += data[x] + ' '
				continue
			if x != 0 and data[x - 1] == '-':
				t = min(n - 1, tmp)
				tmp -= t
				fin += str(1 + t) + ' '
			else:
				fin += '1 '
		print(fin)


s = input()
n = int(s.split(' = ')[1])
a = s.count('+')
b = s.count('-')
mx = (a + 1) * n - b
mn = a + 1 - b * n
if mn <= n <= mx:
	print('Possible')
	need = n - (a - b)
	ans = s[1:]
	while need < 1 or need > n:
		if need > n:
			ans = ans.replace('+ ?', '+ ' + str(n), 1)
			need -= n - 1
		else:
			ans = ans.replace('- ?', '- ' + str(n), 1)
			need += n - 1
	print(str(need) + ans.replace('?', '1'))
else:
	print('Impossible')


s = input().split()
t = s[:]
req = int(s[-1])
lim = req
S = 0
for i in range(len(s)):
	if s[i] == '?':
		s[i] = '1'
		S += 1 if i == 0 or s[i - 1] == '+' else -1
if S < req:
	for i in range(len(s)):
		if t[i] == '?':
			sign = 1 if i == 0 or s[i - 1] == '+' else -1
			if sign == 1:
				d = min(req - S, lim - 1)
				s[i] = str(d + 1)
				S += d
else:
	for i in range(len(s)):
		if t[i] == '?':
			sign = 1 if i == 0 or s[i - 1] == '+' else -1
			if sign == -1:
				d = min(S - req, lim - 1)
				s[i] = str(d + 1)
				S -= d
if S == req:
	print('Possible')
	print(' '.join(s))
else:
	print('Impossible')


def main():
	(s, n) = input().rsplit(sep='= ', maxsplit=2)
	n = int(n)
	m = s.count('-')
	p = s.count('+') + 1
	if p * n - m < n or p - m * n > n:
		print('Impossible')
		return
	x = (n + m) // p
	if x:
		src = ([x + 1] * ((n + m) % p) + [x] * (p - (n + m) % p), [1] * m)
	else:
		x = (p - n) // m
		src = ([1] * p, [x + 1] * ((p - n) % m) + [x] * (m - (p - n) % m))
	res = [str(src[0].pop())]
	for c in s[2:len(s):4]:
		res.append(c)
		res.append(str(src[c == '-'].pop()))
	res.append('=')
	res.append(str(n))
	print('Possible')
	print(' '.join(res))
main()


s = input().split()
plus = 1
minus = 0
for c in s:
	if c == '+':
		plus += 1
	if c == '-':
		minus += 1
n = int(s[len(s) - 1])
mx = plus * n - minus
mn = plus - n * minus
now = n - (plus - minus)
if n > mx or n < mn:
	print('Impossible')
	exit()
pre = '+'
print('Possible')
for c in s:
	if c == '?':
		if pre == '+':
			val = 1
			if now > 0:
				val = min(n - 1, now) + 1
			now -= val - 1
			print(val, end=' ')
		if pre == '-':
			val = 1
			if now < 0:
				val = min(abs(n) - 1, abs(now)) + 1
			now += val - 1
			print(val, end=' ')
	else:
		print(c, end=' ')
	pre = c


s = input().split()
plus = 1
minus = 0
for ch in s:
	if ch == '+':
		plus += 1
	if ch == '-':
		minus += 1
n = int(s[len(s) - 1])
maxx = plus * n - 1 * minus
minn = plus - n * minus
now = n - (plus - minus)
if n > maxx or n < minn:
	print('Impossible')
else:
	pre = '+'
	print('Possible')
	for ch in s:
		if ch == '?':
			if pre == '+':
				val = 1
				if now > 0:
					val = min(n - 1, now) + 1
				now -= val - 1
				print(val, end=' ')
			if pre == '-':
				val = 1
				if now < 0:
					val = min(abs(n) - 1, abs(now)) + 1
				now += val - 1
				print(val, end=' ')
		else:
			print(ch, end=' ')
		pre = ch


s = input().split()
n = 0
arr = []
op = []
for i in s:
	if i == '=':
		break
	if i == '+':
		op.append(1)
	elif i == '-':
		op.append(-1)
	else:
		arr.append(1)
n = int(s[-1])
val = arr[0]
for i in range(len(op)):
	val += op[i] * arr[i + 1]
if val < n:
	rem = n - val
	for i in range(len(arr)):
		if i != 0 and op[i - 1] == -1:
			continue
		up = min(rem, n - arr[i])
		arr[i] += up
		rem -= up
		if rem == 0:
			break
	if rem != 0:
		print('Impossible')
		exit(0)
elif val > n:
	rem = val - n
	for i in range(len(arr)):
		if i == 0 or op[i - 1] == 1:
			continue
		up = min(rem, n - arr[i])
		arr[i] += up
		rem -= up
		if rem == 0:
			break
	if rem != 0:
		print('Impossible')
		exit(0)
print('Possible')
tos = str(arr[0]) + ' '
for i in range(len(op)):
	if op[i] == -1:
		tos += '- '
	else:
		tos += '+ '
	tos += str(arr[i + 1]) + ' '
tos += '= ' + str(n)
print(tos)


a = list(input().split())
(b, c) = (1, 0)
for i in a:
	if i == '-':
		c = c + 1
	elif i == '+':
		b = b + 1
	elif i != '?' and i != '=':
		n = int(i)
if b - c * n <= n and n <= b * n - c:
	print('Possible')
	b0 = []
	for i in range(b):
		b0.append(1)
	c0 = []
	for i in range(c):
		c0.append(1)
	x = b - c - n
	if x < 0:
		i = 0
		while x + n - 1 < 0:
			b0[i] = n
			x = x + n - 1
			i = i + 1
		if x != 0:
			b0[i] = -x + 1
	else:
		i = 0
		while x - n + 1 > 0:
			c0[i] = n
			x = x - n + 1
			i = i + 1
		if x != 0:
			c0[i] = x + 1
	s = str(b0[0])
	b = 1
	c = 0
	for i in a:
		if i == '-':
			s = s + ' - ' + str(c0[c])
			c = c + 1
		elif i == '+':
			s = s + ' + ' + str(b0[b])
			b = b + 1
		elif i == '=':
			print(s + ' = ' + str(n))
else:
	print('Impossible')


s = input()
a = s.split()
tot = 0
b = [1 if x == '?' else x for x in a]
for (i, x) in enumerate(b):
	if x == 1:
		if i == 0 or b[i - 1] == '+':
			tot += 1
		elif b[i - 1] == '-':
			tot -= 1
goal = int(b[-1])
if tot < goal:
	for (i, x) in enumerate(b):
		if x == 1 and i == 0 or (b[i - 1] == '+' and tot < goal):
			a = min(goal - 1, goal - tot)
			tot += a
			b[i] += a
elif tot > goal:
	for (i, x) in enumerate(b):
		if x == 1 and b[i - 1] == '-' and (tot > goal):
			a = min(goal - 1, tot - goal)
			tot -= a
			b[i] += a
if tot != goal:
	print('Impossible')
else:
	print('Possible')
	print(' '.join([str(x) for x in b]))


def main():
	eqn = input().split()
	pos_inds = [0]
	neg_inds = []
	n = int(eqn[-1])
	for (i, x) in enumerate(eqn):
		if x == '+':
			pos_inds.append(i + 1)
		elif x == '-':
			neg_inds.append(i + 1)
	pos = len(pos_inds)
	neg = len(neg_inds)
	val = pos - n * neg
	pos_vals = [1] * pos
	neg_vals = [n] * neg
	ptr = 0
	while ptr < len(pos_vals) and val < n:
		while ptr < len(pos_vals) and pos_vals[ptr] == n:
			ptr += 1
		if ptr == len(pos_vals):
			break
		pos_vals[ptr] += 1
		val += 1
	ptr = 0
	while ptr < len(neg_vals) and val < n:
		while ptr < len(neg_vals) and neg_vals[ptr] == 1:
			ptr += 1
		if ptr == len(neg_vals):
			break
		neg_vals[ptr] -= 1
		val += 1
	if val != n:
		print('Impossible')
	else:
		print('Possible')
		for (i, x) in enumerate(pos_inds):
			eqn[x] = str(pos_vals[i])
		for (i, x) in enumerate(neg_inds):
			eqn[x] = str(neg_vals[i])
		print(' '.join(eqn))
main()