/******************************************************************/
/* ACM ICPC 2012-2013                                             */
/* Northeastern European Regional Contest                         */
/* St Petersburg - Barnaul - Tashkent - Tbilisi, December 2, 2012 */
/******************************************************************/
/* Problem I. Identification of Protein                           */
/*                                                                */
/* Original idea         Mikhail Dvorkin                          */
/* Problem statement     Mikhail Dvorkin                          */
/* Test set              Mikhail Dvorkin                          */
/******************************************************************/
/* Checker                                                        */
/*                                                                */
/* Author                Mikhail Dvorkin                          */
/******************************************************************/

import java.util.*;

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

public class Check implements Checker {
	static final long T = 100000;
	static final long P = 9705276;
	static final long Q = 12805858;
	
	@Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
		long[] peaks = new long[inf.nextInt()];
		for (int i = 0; i < peaks.length; i++) {
			peaks[i] = Math.round(inf.nextDouble() * T);
		}
		Arrays.sort(peaks);
		int oufExplained = explained(ouf, peaks);
		int ansExplained = explained(ans, peaks);
		if (oufExplained > ansExplained) {
			return new Outcome(Outcome.Type.FAIL, "Explained more peaks than jury: " + oufExplained + " > " + ansExplained);
		}
		if (oufExplained < ansExplained) {
			return new Outcome(Outcome.Type.WA, "Explained less peaks than jury: " + oufExplained + " < " + ansExplained);
		}
		return new Outcome(Outcome.Type.OK, "Explained " + oufExplained + " peaks");
	}

	private static int explained(InStream ans, long[] peaks) {
		String protein = ans.nextToken();
        if (!ans.seekEoF())
            throw new Outcome(Outcome.Type.PE, "Extra data in output file");
		int len = protein.length();
		long[] cumulative = new long[len + 1];
		for (int i = 0; i < len; i++) {
			switch (protein.charAt(i)) {
			case 'P':
				cumulative[i + 1] = cumulative[i] + P;
				break;
			case 'Q':
				cumulative[i + 1] = cumulative[i] + Q;
				break;
			default:
				throw new Outcome(Outcome.Type.PE, "Invalid amino acid: \"" + protein.charAt(i) + "\"");
			}
		}
		if (cumulative[len] != peaks[peaks.length - 1]) {
			throw new Outcome(Outcome.Type.WA, "Mass of protein " + cumulative[len] + " != largest peak " + peaks[peaks.length - 1]);
		}
		Set<Long> explained = new TreeSet<Long>();
		for (int i = 1; i <= len; i++) {
			for (long theory : new long[]{cumulative[i], cumulative[len] - cumulative[len - i]}) {
				if (Arrays.binarySearch(peaks, theory) >= 0) {
					explained.add(theory);
				}
			}
		}
		return explained.size();
	}
}

