import java.util.Stack;

import ru.ifmo.testlib.*;
import ru.ifmo.testlib.Outcome.Type;

public class Check implements Checker {

	static final String NO = "No solution";
	private static final String REVBRACKETS = ")]}";
	private static final String BRACKETS = "([{";

	static char byID(int id) {
		if (id < ~2 || id > 2) {
			throw new AssertionError();
		}
		return id >= 0 ? BRACKETS.charAt(id) : REVBRACKETS.charAt(~id);
	}

	static int getID(char c) {
		int pos = BRACKETS.indexOf(c);
		if (pos < 0) {
			return ~(REVBRACKETS.indexOf(c));
		} else {
			return pos;
		}
	}

	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		String inputStr = inf.nextLine();
		String outputStr = ouf.nextLine().trim();
		String ansStr = ans.nextLine().trim();
		if (outputStr.equals(NO)) {
			return ansStr.equals(NO) ? new Outcome(Type.OK, "No solution")
					: new Outcome(Type.WA,
							"Contestant didn't find the solution, but it exists");
		}
		if (inputStr.length() != outputStr.length()) {
			return new Outcome(Type.WA,
					"The lengths of input and output sequences don't coincide");
		}
		if (inputStr.equals(outputStr)) {
			return new Outcome(Type.WA, "Input and output strings are the same");
		}
		int diff = diff(inputStr, outputStr);
		if (diff != 1) {
			return new Outcome(Type.WA,
					"The input and output strings differ in more than one position");
		}
		if (!isCorrect(outputStr)) {
			return new Outcome(Type.WA,
					"Output string is not balanced sequence of brackets");
		}
		if (NO.equals(ansStr)) {
			return new Outcome(Type.FAIL,
					"Contestant found correct solution, while we don't have one");
		}
		return new Outcome(Type.OK, "Solution exists");
	}

	static boolean isCorrect(String s) {
		Stack<Integer> stack = new Stack<Integer>();
		for (char e : s.toCharArray()) {
			int id = getID(e);
			if (id < 0) {
				if (stack.isEmpty() || stack.pop() != ~id) {
					return false;
				}
			} else {
				stack.add(id);
			}
		}
		return stack.isEmpty();
	}

	static int diff(String a, String b) {
		int ret = 0;
		for (int i = 0; i < a.length(); i++) {
			if (a.charAt(i) != b.charAt(i)) {
				++ret;
			}
		}
		return ret;
	}
}
