/*--------------------------------------------------------------*/
/* ACM ICPC 2011-2012, NEERC                                    */
/* Northern Subregional Contest                                 */
/* St Petersburg, October 29, 2011                              */
/*--------------------------------------------------------------*/
/* Problem D. Dice                                              */
/*                                                              */
/* Original idea         Georgiy Korneev                        */
/* Problem statement     Dmitry Shtukenberg                     */
/* Testset               Anton Akhi                             */
/*--------------------------------------------------------------*/
/* Solution                                                     */
/*                                                              */
/* Author                Anton Akhi                             */
/*--------------------------------------------------------------*/
 
import ru.ifmo.testlib.Checker;
import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;
import ru.ifmo.testlib.Outcome.Type;

import java.util.*;

/**
 * Checker for Northern QF'2011 Problem D: Dice
 * 
 * @author Anton Akhi
 */
public class Check implements Checker {

	final double eps = 2.1e-5;

	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		int n = inf.nextInt();
		int[] a = new int[n];
		int m = 0;
		for (int i = 0; i < a.length; i++) {
			a[i] = inf.nextInt();
			m += a[i];
		}

		double pAns = ouf.nextDouble();
		double pRealAns = 0;
		boolean[] u = new boolean[m + 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < a[i]; j++) {
				int x = ouf.nextInt();
				if (x < 1 || m < x) {
					return new Outcome(Type.PE, "Unexpected number on dice #"
							+ (i + 1) + ": " + x);
				}
				if (u[x]) {
					return new Outcome(Type.WA, "Number " + x
							+ " has been used more than once");
				}
				u[x] = true;
				pRealAns += (x + 0.0) / a[i];
			}
		}
		if (Math.abs(pAns - pRealAns) > eps) {
			return new Outcome(Type.WA,
					"Real expectance does not match with one in the output: output = "
							+ pAns + "; real = " + pRealAns);
		}
		double jAns = ans.nextDouble();
		if (Math.abs(jAns - pAns) <= eps) {
			return new Outcome(Type.OK, "ans = " + pAns + "; n = " + n + "; m = "
				+ m);
		}
		if (jAns < pAns) {
			return new Outcome(Type.FAIL,
					"Participant has better answer: ja = " + jAns + "; pa = "
							+ pAns);
		}
		return new Outcome(Type.WA, "Jury has better answer: ja = " + jAns
					+ "; pa = " + pAns);
	}
}
