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

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

public class Check implements Checker {
    public Outcome outcome(Outcome.Type type, final String format, final Object... args) {
        return new Outcome(type, String.format(format, args));
    }

    public String checkCorrectness(int k, int[] answer) {
        int sum = 0;
        for (int i = 0; i < answer.length; i++) {
            if (answer[i] <= 0 || answer[i] > k) {
                return new String(String.format("k[%d] is not in [1, %d]", i + 1, k));
            }
            sum += answer[i];
        }
        if (sum != k) {
            return new String("Sum of k_i is not equal to K");
        }

        return null;
    }

    public long calcAnger(int[] cars, int[] answer) {
        long anger = 0;
        for (int i = 0; i < cars.length; i++) {
            int cnt = cars[i] / answer[i];
            anger -= cnt * 1L * cars[i] - answer[i] * 1L * cnt * (cnt + 1) / 2;
            anger -= cars[i] * 1L * answer[i] * cnt * (cnt + 1);
            anger += cnt * 1L * cars[i] * cars[i];
            anger += cnt * 1L * (cnt + 1) * (2 * cnt + 1) / 6 * answer[i] * answer[i];
        }
        return anger / 2;
    }

    @Override
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int n = inf.nextInt();
        int k = inf.nextInt();
        int[] cars = new int[n];
        for (int i = 0; i < n; i++) {
            cars[i] = inf.nextInt();
        }
        long mpAnger = ouf.nextLong();
        int[] participantAnswer = new int[n];
        for (int i = 0; i < n; i++) {
            participantAnswer[i] = ouf.nextInt();
        }
        long mjAnger = ans.nextLong();
        int[] juryAnswer = new int[n];
        for (int i = 0; i < n; i++) {
            juryAnswer[i] = ans.nextInt();  
        }

        String pResult = checkCorrectness(k, participantAnswer); 
        if (pResult != null) {
            return outcome(WA, pResult);
        }

        long jAnger = calcAnger(cars, juryAnswer);
        long pAnger = calcAnger(cars, participantAnswer);
        if (pAnger != mpAnger) {
            return outcome(WA, String.format("Anger in output is not equal to anger in certificate: expected %d, found %d", pAnger, mpAnger));
        }

        if (jAnger > pAnger) {
            return outcome(FAIL, String.format("Participant has better answer: expected anger %d, found %d", jAnger, pAnger)); 
        }
        if (jAnger < pAnger) {
            return outcome(WA, String.format("Jury has better answer: expected anger %d, found %d", jAnger, pAnger));
        }
        return outcome(OK, String.format("Corrent answer, anger=%d", jAnger));
    }
}
