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.

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.

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.

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// Do I need to modify the -? or the +?s
var diff = 0;
var a = 0; // a --> change a number of ?'s to n
var b = 1; // b --> change another -? to b
var counter = 0; // used to count how many ?'s are replaced with n (count a)

// Modify 'minus' ?
if (count.plus - count.minus > n) {
	// modify 'minus'
	// minus_sum is what the sum of all -? needs to be
	var minus_sum = count.plus - n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (minus_sum >= count.minus && minus_sum <= count.minus * n) {

		diff = minus_sum - count.minus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		rebus[0] = 1;

		counter = 0;
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == '-') {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == '-') {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}

} else {
	//modify 'plus'
	// plus_sum is what the sum of all +? needs to be
	var plus_sum = count.minus + n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (plus_sum >= count.plus && plus_sum <= count.plus * n) {

		diff = plus_sum - count.plus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		if (diff === 0) {
			rebus[0] = 1;
		} else if (a === 0) {
			rebus[0] = b;
		} else if (a >= 1) {
			rebus[0] = n;
			counter = 1;
			for (var i = 1; i < rebus.length; i++)  {
				// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1
				if (counter == a) {
					if (rebus[i] == '+') {
						rebus[i + 1] = b;
						break;
					}
				} else {
					if (rebus[i] == '+') {
						rebus[i + 1] = n;
						counter += 1;
					}
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus (add +1 to 'plus' because of the very first '?' is + by default)

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// used for look_for parameter
var plus = '+';
var minus = '-';

// if possible get rebus with this function
var getRebus = function(increase, ones, look_for) {
	var sum = 0;
	if (increase == count.plus) {
		sum = ones + n;
	} else {
		sum = ones - n;
	}

	var diff = sum - increase;
	var a = Math.floor(diff / (n - 1)); // a --> change a number of ?'s to n
	var b = diff % (n - 1) + 1; // b --> change another ? to b
	var counter = 0; // used to count how many ?'s are replaced with n (count a)

	// if diff is 0, I want every ? to be 1
	if (diff === 0) {
		rebus[0] = 1;
	// if I want 'n' to appear 0 times, the first ? must be b (ONLY do this when increasing +?'s)
	} else if (a === 0 && increase == count.plus) {
		rebus[0] = b;
	} else {
		// ONLY when increasing +?'s
		if (increase == count.plus) {
			rebus[0] = n;
			counter = 1;
		// ONLY when increasing -?'s
		} else {
			rebus[0] = 1;
		}
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace ? with n a times, the next replacement should be b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == look_for) {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == look_for) {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}
	}

	// replacing all other ?'s with 1's
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}

	rebus = rebus.join(' ');

	return rebus;
};

// Increase 'minus' ?'s
if (count.plus - count.minus > n) {
	var sum = count.plus - n;
	if (sum >= count.minus && sum <= count.minus * n) {
		print('Possible');
		print(getRebus(count.minus, count.plus, minus));
	} else {
		print('Impossible');
	}
// Increase 'plus' ?'s
} else {
	var sum = count.minus + n;
	if (sum >= count.plus && sum <= count.plus * n) {
		print('Possible');
		print(getRebus(count.plus, count.minus, plus));
	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else if (first_q > n && n > 1 && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = first_q - n + 1;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

/* x is what we need to add in the rebus instead of a 1
it must be less than n though.... so if it's bigger than n
then we need to divide it into a bunch of n's plus a remaineder
a is the number of n's
b is the remainder */
var x = (first_q - n + 1);

var a = 1;
var b = 0;

// to find 2 unknowns (a and b) we need a double loop..
if (x < n) {
	b = x;
} else {
	for (a = Math.floor(x / n); a < Math.floor(x / n + 2); a++) {
		for (b = 0; b < n; b++) {
			if (a * n + b == x + a) {
				break;
			}
		}
		if (a * n + b == x + a) {
		    break;
		}
	}
}

// we just need to replace all ?'s with 1s
if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && x < n && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = x;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			if (rebus[i] == '+') {
				rebus[i + 1] = b;
				break;
			}
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')
} else if (first_q > n && n > 1 && b == 0 && count.plus >= a){
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			break;
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

} else {
	print('Impossible');
}

/* checking stuff
print(JSON.stringify(count));
print(first_q);

print(n);
print(a);
print(b);
print(x);
*/

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

/* x is what we need to add in the rebus instead of a 1
it must be less than n though.... so if it's bigger than n
then we need to divide it into a bunch of n's plus a remaineder
a is the number of n's
b is the remainder */
var x = (count.minus - count.plus+ 1);

var a = 1;
var b = 0;

// to find 2 unknowns (a and b) we need a double loop..
if (x < n) {
	b = x;
} else {
	for (a = Math.floor(x / n); a <= x; a++) {
		for (b = 0; b < n; b++) {
			if (a * n + b == x + a) {
				break;
			}
		}
		if (a * n + b == x + a) {
		    break;
		}
	}
}

// we just need to replace all ?'s with 1s
if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && x < n && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = x;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			if (rebus[i] == '+') {
				rebus[i + 1] = b;
				break;
			}
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')
} else if (first_q > n && n > 1 && b == 0 && count.plus >= a){
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			break;
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

} else {
	print('Impossible');
}

/* checking stuff
print(JSON.stringify(count));
print(first_q);

print(n);
print(a);
print(b);
print(x);
*/

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// Do I need to modify the -? or the +?s
var diff = 0;
var a = 0; // a --> change a number of ?'s to n
var b = 1; // b --> change another -? to b
var counter = 0; // used to count how many ?'s are replaced with n (count a)

// Modify 'minus' ?
if (count.plus - count.minus > n) {
	// modify 'minus'
	// minus_sum is what the sum of all -? needs to be
	var minus_sum = count.plus - n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (minus_sum >= count.minus && minus_sum <= count.minus * n) {
		print('Possible');

		diff = minus_sum - count.minus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		rebus[0] = 1;

		counter = 0;
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == '-') {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == '-') {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}

} else {
	//modify 'plus'
	// plus_sum is what the sum of all +? needs to be
	var plus_sum = count.minus + n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (plus_sum >= count.plus && plus_sum <= count.plus * n) {

		diff = plus_sum - count.plus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		if (a === 0) {
			rebus[0] = b;
		} else if (a >= 1) {
			rebus[0] = n;
			counter = 1;
			for (var i = 1; i < rebus.length; i++)  {
				// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1
				if (counter == a) {
					if (rebus[i] == '+') {
						rebus[i + 1] = b;
						break;
					}
				} else {
					if (rebus[i] == '+') {
						rebus[i + 1] = n;
						counter += 1;
					}
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus (add +1 to 'plus' because of the very first '?' is + by default)

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// used for look_for parameter
var plus = '+';
var minus = '-';

// if possible get rebus with this function
var getRebus = function(increase, ones, look_for) {
	var sum = 0;
	if (increase == count.plus) {
		sum = ones + n;
	} else {
		sum = ones - n;
	}

	var diff = sum - increase;
	var a = Math.floor(diff / (n - 1)); // a --> change a number of ?'s to n
	var b = diff % (n - 1) + 1; // b --> change another ? to b
	var counter = 0; // used to count how many ?'s are replaced with n (count a)

	// if diff is 0, I want every ? to be 1
	if (diff === 0) {
		rebus[0] = 1;
	// if I want 'n' to appear 0 times, the first ? must be b (ONLY do this when increasing +?'s)
	} else if (a === 0 && increase == count.plus) {
		rebus[0] = b;
	} else if (a >= 1) {
		// ONLY when increasing +?'s
		if (increase == count.plus) {
			rebus[0] = n;
			counter = 1;
		// ONLY when increasing -?'s
		} else {
			rebus[0] = 1;
		}
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace ? with n a times, the next replacement should be b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == look_for) {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == look_for) {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}
	}

	// replacing all other ?'s with 1's
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}

	rebus = rebus.join(' ');

	return rebus;
};

// Increase 'minus' ?'s
if (count.plus - count.minus > n) {
	var sum = count.plus - n;
	if (sum >= count.minus && sum <= count.minus * n) {
		print('Possible');
		print(getRebus(count.minus, count.plus, minus));
	} else {
		print('Impossible');
	}
// Increase 'plus' ?'s
} else {
	var sum = count.minus + n;
	if (sum >= count.plus && sum <= count.plus * n) {
		print('Possible');
		print(getRebus(count.plus, count.minus, plus));
	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

/* x is what we need to add in the rebus instead of a 1
it must be less than n though.... so if it's bigger than n
then we need to divide it into a bunch of n's plus a remaineder
a is the number of n's
b is the remainder */
var x = (first_q - n + 1);

var a = 1;
var b = 0;

// to find 2 unknowns (a and b) we need a double loop..
if (x < n) {
	b = x;
} else {
	for (a = Math.floor(x / n); a < Math.floor(x / n + 2); a++) {
		for (b = 0; b < n; b++) {
			if (a * n + b == x + a) {
				break;
			}
		}
		if (a * n + b == x + a) {
		    break;
		}
	}
}

// we just need to replace all ?'s with 1s
if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && x < n && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = x;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			if (rebus[i] == '+') {
				rebus[i + 1] = b;
				break;
			}
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')
} else if (first_q > n && n > 1 && count.plus >= a){
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			break;
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

} else {
	print('Impossible');
}

/* checking stuff
print(JSON.stringify(count));
print(first_q);

print(n);
print(a);
print(b);
print(x);
*/

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// Do I need to modify the -? or the +?s
var diff = 0;
var a = 0; // a --> change a number of ?'s to n
var b = 1; // b --> change another -? to b
var counter = 0; // used to count how many ?'s are replaced with n (count a)

// Modify 'minus' ?
if (count.plus - count.minus > n) {
	// modify 'minus'
	// minus_sum is what the sum of all -? needs to be
	var minus_sum = count.plus - n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (minus_sum >= count.minus && minus_sum <= count.minus * n) {

		diff = minus_sum - count.minus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		rebus[0] = 1;

		counter = 0;
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == '-') {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == '-') {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}

} else {
	//modify 'plus'
	// plus_sum is what the sum of all +? needs to be
	var plus_sum = count.minus + n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (plus_sum >= count.plus && plus_sum <= count.plus * n) {

		diff = plus_sum - count.plus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		if (a === 0) {
			rebus[0] = b;
		} else if (a >= 1) {
			rebus[0] = n;
			counter = 1;
			for (var i = 1; i < rebus.length; i++)  {
				// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1
				if (counter == a) {
					if (rebus[i] == '+') {
						rebus[i + 1] = b;
						break;
					}
				} else {
					if (rebus[i] == '+') {
						rebus[i + 1] = n;
						counter += 1;
					}
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else if (first_q - 1 == n && n > 1) {
	rebus[0] = first_q - 1;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = 2;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else if (first_q > n && n > 1) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = first_q - n + 1;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}


Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be $$$n$$$ participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.Suppose in the first round participant A took $$$x$$$-th place and in the second round — $$$y$$$-th place. Then the total score of the participant A is sum $$$x + y$$$. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every $$$i$$$ from $$$1$$$ to $$$n$$$ exactly one participant took $$$i$$$-th place in first round and exactly one participant took $$$i$$$-th place in second round.Right after the end of the Olympiad, Nikolay was informed that he got $$$x$$$-th place in first round and $$$y$$$-th place in the second round. Nikolay doesn't know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases to solve. Each of the following $$$t$$$ lines contains integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \leq n \leq 10^9$$$, $$$1 \le x, y \le n$$$) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Print two integers — the minimum and maximum possible overall place Nikolay could take.

NoteExplanation for the first example:Suppose there were 5 participants A-E. Let's denote Nikolay as A. The the most favorable results for Nikolay could look as follows:  However, the results of the Olympiad could also look like this:  In the first case Nikolay would have taken first place, and in the second — third place.

function findMax(p, x, y) {
    var sum = x + y;

    return sum > p ? p : sum - 1;
}

function findMin(p, x, y) {
    var sum = x + y;

    return sum <= p ? 1 : (sum - p + 1 > p ? p : sum - p + 1);
}

function processItem() {
    var items = readline().split(' ').map(function(i) { return +i; });
    var p = items[0];
    var x = items[1];
    var y = items[2];

    print(findMin(p, x, y) + ' ' + findMax(p, x, y));
}

function processItems() {
  var itemsCount = +readline();
  var items = [];

  for (var i = 0; i < itemsCount; ++i) {
    processItem();
  }

  return items;
}

processItems();

function findMax(p, x, y) {
    var sum = x + y;

    return sum > p ? p : sum - 1;
}

function findMin(p, x, y) {
    var sum = x + y;

    return sum <= p ? 1 : sum - p;
}

function processItem() {
    var items = readline().split(' ').map(function(i) { return +i; });
    var p = items[0];
    var x = items[1];
    var y = items[2];

    print(findMin(p, x, y) + ' ' + findMax(p, x, y));
}

function processItems() {
  var itemsCount = +readline();
  var items = [];

  for (var i = 0; i < itemsCount; ++i) {
    processItem();
  }

  return items;
}

processItems();


Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, b2, ..., bn] of length n each which he uses to ask people some quite peculiar questions.To test you on how good are you at spotting inequality in life, he wants you to find an "unfair" subset of the original sequence. To be more precise, he wants you to select k numbers P = [p1, p2, ..., pk] such that 1 ≤ pi ≤ n for 1 ≤ i ≤ k and elements in P are distinct. Sequence P will represent indices of elements that you'll select from both sequences. He calls such a subset P "unfair" if and only if the following conditions are satisfied: 2·(ap1 + ... + apk) is greater than the sum of all elements from sequence A, and 2·(bp1 + ... + bpk) is greater than the sum of all elements from the sequence B. Also, k should be smaller or equal to  because it will be to easy to find sequence P if he allowed you to select too many elements!Mike guarantees you that a solution will always exist given the conditions described above, so please help him satisfy his curiosity!

The first line contains integer n (1 ≤ n ≤ 105) — the number of elements in the sequences.  On the second line there are n space-separated integers a1, ..., an (1 ≤ ai ≤ 109) — elements of sequence A. On the third line there are also n space-separated integers b1, ..., bn (1 ≤ bi ≤ 109) — elements of sequence B.

On the first line output an integer k which represents the size of the found subset. k should be less or equal to . On the next line print k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the elements of sequence P. You can print the numbers in any order you want. Elements in sequence P should be distinct.

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));
  var b = readline().split(' ').map(x => parseInt(x));

  var idx = Array(n).fill(0).map((x, i) => i);

  idx.sort((x, y) => a[y] - a[x]);

  k = Math.floor(n / 2) + 1;

  var res = [idx[0]];

  for(var i = 1; i < n; i += 2) {
    if(i + 1 < n && b[idx[i + 1]] > b[idx[i]]) {
      res.push(idx[i + 1]);
    } else {
      res.push(idx[i]);
    }
  }
  print(k);
  print(res.slice(0, k).map(x => x + 1).join(' '));

 var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));
  var b = readline().split(' ').map(x => parseInt(x));

  var idx = Array(n).fill(0).map((x, i) => i);

  idx.sort((x, y) => a[x] * b[x] / (a[x] + b[x]) - a[y] * b[y] / (a[y] + b[y]));

  k = Math.floor(n / 2) + 1;
  print(k);
  print(idx.slice(0, k).join(' '));

  var n = parseInt(readline());
  var a = readline().split(' ').map(x => parseInt(x));
  var b = readline().split(' ').map(x => parseInt(x));

  var idx = Array(n).fill(0).map((x, i) => i);

  idx.sort((x, y) => a[x] * b[x] / (a[x] + b[x]) - a[y] * b[y] / (a[y] + b[y]));

  k = Math.floor(n / 2) + 1;
  print(k);
  print(idx.slice(0, k).map(x => x + 1).join(' '));


Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.  English alphabet You are given a string s. Check if the string is "s-palindrome".

The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.

Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.

var x = readline();

var a = "pq"+"bd"+"AHIMOoTUVvWwXxY";
var b = "qp"+"db"+"AHIMOoTUVvWwXxY";

var ok = true;
for (var i=0, j=x.length-1 ; ok && i<=j ; i++, j--)
{
    var m = a.indexOf(x[i]), n = b.indexOf(x[j]);
    ok = ok && m>=0 && m==n;
}

print(ok ? "TAK" : "NIE");

var left = "bd" + "pq" + "AHIMOoTUVvWwXxY";
var right = "db" + "qp" + "AHIMOoTUVvWwXxY";

var x = readline();

var ok = true;

for (var i = 0, j = x.length - 1; i < x.length / 2 && ok; i++, j--) {
  var leftPosition = left.indexOf(x[i]);
  var rightPosition = right.indexOf(x[j]);

  ok = leftPosition >= 0 && leftPosition == rightPosition;
}

print(ok ? "TAK" : "NIE");

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    const symmetric = "AHIMOoTUVvWwXxY";

    if(str.length % 2){
        let char = str[Math.floor(str.length / 2)];
        if(!symmetric.includes(char))
            return "NIE";
    }

    for(let i = 0; i < Math.floor(str.length) / 2; i++){
        if(str[i] === "p" && str[str.length - i - 1] === "q")
            continue;
        if(str[i] === "q" && str[str.length - i - 1] === "p")
            continue;
        if(str[i] === "b" && str[str.length - i - 1] === "d")
            continue;
        if(str[i] === "d" && str[str.length - i - 1] === "b")
            continue;

        if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){
            if(str[i] === str[str.length - i - 1])
                continue;
        }

        return "NIE";
    }

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

const readline = require('readline')
const rl = readline.createInterface(process.stdin, process.stdout)

const input = []

rl.on('line', line => input.push(line.toString()))

rl.on('close', () => {
  solve()
})

const solve = () => {
  const mirrorAlphabetPairs = [
    'xx',
    'XX',
    'oo',
    'OO',
    'vv',
    'VV',
    'ww',
    'WW',
    'II',
    'TT',
    'HH',
    'MM',
    'YY',
    'UU',
    'AA',
    'pq',
    'qp',
    'bd',
    'db',
  ]

  const isSPalindrome = s => {
    for (let i = 0; i < s.length / 2; i++) {
      const j = s.length - 1 - i
      const pair = s[i] + s[j]

      if (!mirrorAlphabetPairs.includes(pair)) {
        return false
      }
    }

    return true
  }

  const [s] = input
  const output = isSPalindrome(s) ? 'TAK' : 'NIE'

  console.log(output)
}

var x = readline();

var a = "pq"+"bd"+"AHIMOoTUVvWwXxYy";
var b = "qp"+"db"+"AHIMOoTUVvWwXxYy";

var ok = true;
for (var i=0, j=x.length-1 ; ok && i<=j ; i++, j--)
{
    var m = a.indexOf(x[i]), n = b.indexOf(x[j]);
    ok = ok && (m>=0 && m == n);
}

print(ok?"TAK":"NIE");

var x = readline();

var a="pqbd";
var b="qpdb";

var ok = true;
for (var i=0, j=x.length-1 ; ok && i<j ; i++, j--)
{
    ok = ok && (
        (x[i]==x[j] && "AHIMOoTUVvWwXxYy".includes(x[i]))
        || a.indexOf(x[i])==b.indexOf(x[j])
    );
}

print(ok?"TAK":"NIE");

var left = "bd" + "pq" + "AHIMOoTUVWwXxY";
var right = "db" + "qp" + "AHIMOoTUVWwXxY";

var x = readline();

var ok = true;

for (var i = 0, j = x.length - 1; i < x.length / 2 && ok; i++, j--) {
  var leftPosition = left.indexOf(x[i]);
  var rightPosition = right.indexOf(x[j]);

  ok = ok && leftPosition >= 0 && leftPosition == rightPosition;
}

print(ok ? "TAK" : "NIE");

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    const symmetric = "AHIMOoTUVvWwXxY";

    if( str.length % 2){
        let char = str[Math.floor(str.length) / 2];
        if(!symmetric.includes(char))
            return "NIE";
    }

    for(let i = 0; i < Math.floor(str.length) / 2; i++){
        if(str[i] === "p" && str[str.length - i - 1] === "q")
            continue;
        if(str[i] === "q" && str[str.length - i - 1] === "p")
            continue;
        if(str[i] === "b" && str[str.length - i - 1] === "d")
            continue;
        if(str[i] === "d" && str[str.length - i - 1] === "b")
            continue;

        if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){
            if(str[i] === str[str.length - i - 1])
                continue;
        }

        return "NIE";
    }

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    if( str.length % 2 !== 1)
        return "NIE";

    for(let i = 0; i < Math.floor(str.length) / 2; i++)
        if(str[i] !== str[str.length - i - 1])
            return "NIE";

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    const symmetric = "AHIMOoTUVvWwXxY";

    if( str.length % 2 !== 1){
        let char = str[Math.floor(str.length) / 2];
        if(!symmetric.includes(char))
            return "NIE";
    }

    for(let i = 0; i < Math.floor(str.length) / 2; i++){
        if(str[i] === "p" && str[str.length - i - 1] === "q")
            continue;
        if(str[i] === "q" && str[str.length - i - 1] === "p")
            continue;
        if(str[i] === "b" && str[str.length - i - 1] === "d")
            continue;
        if(str[i] === "d" && str[str.length - i - 1] === "b")
            continue;

        if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){
            if(str[i] === str[str.length - i - 1])
                continue;
        }

        return "NIE";
    }

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

const readline = require('readline')
const rl = readline.createInterface(process.stdin, process.stdout)

const input = []

rl.on('line', line => input.push(line.toString()))

rl.on('close', () => {
  solve()
})

const solve = () => {
  const mirrorAlphabetPairs = [
    'll',
    'xx',
    'XX',
    'ii',
    'II',
    'oo',
    'OO',
    'vv',
    'VV',
    'ww',
    'WW',
    'TT',
    'HH',
    'MM',
    'YY',
    'UU',
    'AA',
    'pq',
    'qp',
    'bd',
    'db',
  ]

  const isSPalindrome = s => {
    for (let i = 0; i < s.length / 2; i++) {
      const j = s.length - 1 - i
      const pair = s[i] + s[j]

      if (!mirrorAlphabetPairs.includes(pair)) {
        return false
      }
    }

    return true
  }

  const [s] = input
  const output = isSPalindrome(s) ? 'TAK' : 'NIE'

  console.log(output)
}

const readline = require('readline')
const rl = readline.createInterface(process.stdin, process.stdout)

const input = []

rl.on('line', line => input.push(line.toString()))

rl.on('close', () => {
  solve()
})

const solve = () => {
  const mirrorAlphabetPairs = [
    'xx',
    'bd',
    'db',
    'ii',
    'll',
    'oo',
    'vv',
    'ww',
    'pq',
    'qp',
    'XX',
    'II',
    'OO',
    'VV',
    'WW',
    'TT',
    'HH',
    'MM',
    'YY',
    'UU',
    'AA',
  ]

  const isSPalindrome = s => {
    const upperLimit = Math.floor(s.length / 2)

    for (let i = 0; i < upperLimit; i++) {
      const j = s.length - 1 - i
      const pair = s[i] + s[j]

      if (!mirrorAlphabetPairs.includes(pair)) {
        return false
      }
    }

    return true
  }

  const [s] = input
  const output = isSPalindrome(s) ? 'TAK' : 'NIE'

  console.log(output)
}


When Masha came to math classes today, she saw two integer sequences of length $$$n - 1$$$ on the blackboard. Let's denote the elements of the first sequence as $$$a_i$$$ ($$$0 \le a_i \le 3$$$), and the elements of the second sequence as $$$b_i$$$ ($$$0 \le b_i \le 3$$$).Masha became interested if or not there is an integer sequence of length $$$n$$$, which elements we will denote as $$$t_i$$$ ($$$0 \le t_i \le 3$$$), so that for every $$$i$$$ ($$$1 \le i \le n - 1$$$) the following is true:   $$$a_i = t_i | t_{i + 1}$$$ (where $$$|$$$ denotes the bitwise OR operation) and  $$$b_i = t_i \& t_{i + 1}$$$ (where $$$\&$$$ denotes the bitwise AND operation). The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence $$$t_i$$$ of length $$$n$$$ exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the length of the sequence $$$t_i$$$.  The second line contains $$$n - 1$$$ integers $$$a_1, a_2, \ldots, a_{n-1}$$$ ($$$0 \le a_i \le 3$$$) — the first sequence on the blackboard. The third line contains $$$n - 1$$$ integers $$$b_1, b_2, \ldots, b_{n-1}$$$ ($$$0 \le b_i \le 3$$$) — the second sequence on the blackboard.

In the first line print "YES" (without quotes), if there is a sequence $$$t_i$$$ that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence. If there is such a sequence, on the second line print $$$n$$$ integers $$$t_1, t_2, \ldots, t_n$$$ ($$$0 \le t_i \le 3$$$) — the sequence that satisfies the statements conditions. If there are multiple answers, print any of them.

var n = +readline();
var a = readline().split(' ').map(v=>+v);
var b = readline().split(' ').map(v=>+v);

var map = {};
for(var i = 0; i < 4; i++) {
    for(var j = i; j < 4; j++) {
        var aValue = i | j;
        var bValue = i & j;
        var ind = aValue * 10 + bValue;
        if(!map[ind]) map[ind] = [];
        map[ind].push([i, j]);
    }
}

var options = [];

var res = true, i = 0, t = [], couplesArr;
for(; i < a.length || !res; i++) {

    if(!res) {
        if(!options.length) break;
        res = true;
        option = options.pop();

        couplesArr = [option.couple];
        i = option.ind;
    } else {
        couplesArr = map[a[i] * 10 + b[i]];
        if(!couplesArr) {
            res = false;
            continue;
        } else if(i === 0) {
            couplesArr = couplesArr.concat(couplesArr.map(v => [v[1], v[0]]));
        }
    }

    var couple = couplesArr[0];
    for(var j = 1; j < couplesArr.length; j++) {
        options.push({ind: i, couple: couplesArr[j]});
    }

    if(!i) {
        t = [couple[0], couple[1]];
    } else if(couple[0] !== t[i] && couple[1] !== t[i]) {
        res = false;
    } else {
        t[i+1] = couple[0] !== t[i] ? couple[0] : couple[1];
    }
}

print(res ? 'YES' : 'NO');
if(res) {
    print(t.join(' '));
}

var n = +readline();
var a = readline().split(' ').map(v=>+v);
var b = readline().split(' ').map(v=>+v);

var map = {};
for(var i = 0; i < 4; i++) {
    for(var j = i; j < 4; j++) {
        var aValue = i | j;
        var bValue = i & j;
        var ind = aValue * 10 + bValue;
        if(!map[ind]) map[ind] = [];
        map[ind].push([i, j]);
    }
}

var t;
var check = function(i) {
   if(i === a.length) return true;
   var couplesArr = map[a[i] * 10 + b[i]];
   if(!couplesArr) return false;

   var res = false;
   for(var j = 0; j < couplesArr.length; j++) {
      var couple = couplesArr[j];
      if(!i) {
         t = [couple[0], couple[1]];
         res = check(i + 1);
      } else if(couple[0] !== t[i] && couple[1] !== t[i]){
         res = false;
      } else {
         t[i+1] = couple[0] !== t[i] ? couple[0] : couple[1];
         res = check(i + 1, t);
      }
      if(res) break;
   }

   return res;
}

var final = check(0);

print(final ? 'YES' : 'NO');
if(final) {
    print(t.join(' '));
}

var n = +readline();
var a = readline().split(' ').map(v=>+v);
var b = readline().split(' ').map(v=>+v);

var map = {};
for(var i = 0; i < 4; i++) {
    for(var j = i; j < 4; j++) {
        var aValue = i | j;
        var bValue = i & j;
        var ind = aValue * 10 + bValue;
        if(!map[ind]) map[ind] = [];
        map[ind].push([i, j]);
    }
}

var t;
var check = function(i) {
   if(i === a.length) return true;
   var couplesArr = map[a[i] * 10 + b[i]];
   if(!couplesArr) return false;

   var res = false;
   for(var j = 0; j < couplesArr.length; j++) {
      var couple = couplesArr[j];
      if(!i) {
         t = [couple[0], couple[1]];
         res = check(i + 1);
      } else if(couple[0] !== t[i] && couple[1] !== t[i]){
         res = false;
      } else {
         t[i+1] = couple[0] !== t[i] ? couple[0] : couple[1];
         res = check(i + 1);
      }
      if(res) break;
   }

   return res;
}

var final = check(0);

print(final ? 'YES' : 'NO');
if(final) {
    print(t.join(' '));
}

var n = +readline();
var a = readline().split(' ').map(v=>+v);
var b = readline().split(' ').map(v=>+v);

var t = [];
var res = true;

var map = {};
for(var i = 0; i < 4; i++) {
    for(var j = i; j < 4; j++) {
        var aValue = i | j;
        var bValue = i & j;
        map[aValue * 10 + bValue] = [i, j];
    }
}

var start = map[a[0] * 10 + b[0]];
if(!start) res = false;
else t = start.map(v=>v);
for(var i = 1; i < a.length && res; i++) {
    var tCouple = map[a[i] * 10 + b[i]];
    if(!tCouple || (tCouple[0] !== t[i] && tCouple[1] !== t[i])) {
        res = false;
    } else {
        t[i+1] = tCouple[0] !== t[i] ? tCouple[0] : tCouple[1];
    }
}

print(res ? 'YES' : 'NO');
if(res) {
    print(t.join(' '));
}

var n = +readline();
var a = readline().split(' ').map(v=>+v);
var b = readline().split(' ').map(v=>+v);

var map = {};
for(var i = 0; i < 4; i++) {
    for(var j = i; j < 4; j++) {
        var aValue = i | j;
        var bValue = i & j;
        var ind = aValue * 10 + bValue;
        if(!map[ind]) map[ind] = [];
        map[ind].push([i, j]);
    }
}

var t;
var check = function(i) {
   if(i === a.length) return true;
   var couplesArr = map[a[i] * 10 + b[i]];
   if(!couplesArr) return false;

   var res = false;
   for(var j = 0; j < couplesArr.length; j++) {
      var couple = couplesArr[j];
      if(!i) {
         t = [couple[0], couple[1]];
         res = check(i + 1);
      } else if(couple[0] !== t[i] && couple[1] !== t[i]){
         res = false;
      } else {
         t[i+1] = couple[0] !== t[i] ? couple[0] : couple[1];
         res = check(i + 1, t);
      }
      if(res) break;
   }

   return res;
}

var final = check(0);
var v = 10;

print(final ? 'YES' : 'NO');
if(final) {
    print(t.join(' '));
}