1.


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 10344 23 out of 5
* Link:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1285
*
* @author Kratzer Kevin
* @version 1.0, 10/14/2009
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 1.180
*/

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Main10344 {

protected final BufferedReader input;
public static final int opAdd = 0;
public static final int opSub = 1;
public static final int opMul = 2;
public static final int opAmount = 3;

public Main10344() {
input = new BufferedReader(new InputStreamReader(System.in));
}

void process() throws IOException {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
while (true) {
String line = input.readLine();
int[] inputNr = new int[5];
String[] split = line.split(" ");
boolean end = true;
for (int i = 0; i < 5; i++) {
inputNr[i] = Integer.parseInt(split[i]);
end = end && (inputNr[i] == 0);
}
if (end) {
out.flush();
return;
}
boolean possible = false;
for (int i = 0; i < 120 && !possible; i++) {
int[] numbers = permuateOne(i, inputNr);
for (int w = 0; w < opAmount && !possible; w++) {
int resFirstOp = calc(numbers[0], numbers[1], w);
for (int x = 0; x < opAmount && !possible; x++) {
int resSecondOp = calc(resFirstOp, numbers[2], x);
for (int y = 0; y < opAmount && !possible; y++) {
int resThirdOp = calc(resSecondOp, numbers[3], y);
for (int z = 0; z < opAmount && !possible; z++) {
if (calc(resThirdOp, numbers[4], z) == 23) {
possible = true;
}

}
}
}
}
}
if (possible) {
out.append("Possible");
} else {
out.append("Impossible");
}
}
}

int calc(int nrOne, int nrTwo, int opNr) {
if (opNr == opAdd) {
return nrOne + nrTwo;
}
if (opNr == opSub) {
return nrOne - nrTwo;
}
if (opNr == opMul) {
return nrOne * nrTwo;
}
throw new IllegalArgumentException("Calc with undefined opcode!");
}

int[] permuateOne(int i, int[] input) {
int[] result = new int[5];
int k = i;
result[0] = input[0];
result[1] = input[1];
result[2] = input[2];
result[3] = input[3];
result[4] = input[4];
for (int j = 2; j < 6; j++) {
int toSwap = result[k % j];
result[k % j] = result[j - 1];
result[j - 1] = toSwap;
k = k / (j -1);
}
return result;
}

public static void main(String... args) throws Exception {
new Main10344().process();
}
}

2.

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS09
* Problem: 10344 23 out of 5
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=15&page=show_problem&problem=1285
*
* @author Christoph Hausmann
* @version 0.1, 10/14/2009
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 2.120
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class TwentyThreeOutOf5_10344 {

private static enum op {
ADD, SUB, MUL;
}

public static void main(String... args) throws IOException {
final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

while(true) {
final String curLine = br.readLine();

if(curLine == null)
break;

final int[] numbers = parseNums(curLine);

if(allNull(numbers))
break;

if(isPossible(numbers))
System.out.println("Possible");
else
System.out.println("Impossible");
System.out.flush();

}
}

private static boolean isPossible(final int[] getNumbers) {

int[] numbers = Arrays.copyOf(getNumbers, getNumbers.length);

for(int k = 0; k < 120; k++) {
for(op op0 : op.values()) {
for(op op1 : op.values()) {
for(op op2 : op.values()) {
for(op op3 : op.values()) {
if(calc(calc(calc(calc(numbers[0],numbers[1],op0),numbers[2],op1),numbers[3],op2),numbers[4],op3) == 23) {
return true;
}

}
}
}
}

numbers = permutate(Arrays.copyOf(getNumbers, getNumbers.length), k);
}

return false;
}

private static int calc(int num1, int num2, op op) {
if(op == op.ADD)
return num1+num2;
else if(op == op.SUB)
return num1-num2;
else if(op == op.MUL)
return num1*num2;

return 0;
}

private static boolean allNull(int[] numbers) {
for(int i = 0; i < numbers.length; i++) {
if(numbers[1] != 0)
return false;
}

return true;
}

private static int[] parseNums(String readLine) {
final String[] split = readLine.split(" ");
final int[] nums = new int[split.length];

for(int i = 0; i < split.length; i++) {
nums[i] = Integer.parseInt(split[i]);
}

return nums;
}

private static int[] permutate(int[] s, int k) {

for(int j = 1; j <= s.length; j++) {
int temp = s[(k%j)];
s[(k%j)] = s[j-1];
s[j-1] = temp;
k = k / j;
}

return s;
}

}