import ru.ifmo.testlib.Checker;
import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;

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

/**
 * Checker for NEERC'2013 Problem C: Cactus Automorphisms
 *
 * @author Roman Elizarov
 */
public class Check implements Checker {
	private static final int MAX_PRIMES = 10000;

	static class Answer {
		int k;
		int[] p;
		int[] q;

		Answer(InStream in, Outcome.Type type) {
			k = in.nextInt();
			if (k < 0 || k > MAX_PRIMES)
				throw new Outcome(type, String.format("k=%d exceeds limits", k));
			p = new int[k];
			q = new int[k];
			for (int i = 0; i < k; i++) {
				p[i] = in.nextInt();
				q[i] = in.nextInt();
			}
			if (!in.seekEoF())
				throw new Outcome(type, "Extra data in file");
		}
	}


	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		Answer ja = new Answer(ans, FAIL);
		Answer pa = new Answer(ouf, PE);

		if (ja.k != pa.k)
			return new Outcome(WA, String.format("Expected %d primes, found %d", ja.k, pa.k));
		for (int i = 0; i < ja.k; i++) {
			if (ja.p[i] != pa.p[i])
				return new Outcome(WA, String.format("Expected prime %d, found %d", ja.p[i], pa.p[i]));
			if (ja.q[i] != pa.q[i])
				return new Outcome(WA, String.format("Expected power %d, found %d for prime %d", ja.q[i], pa.q[i], ja.p[i]));
		}
		return new Outcome(OK, String.format("%d factors", ja.k));
	}
}
