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

import java.util.Arrays;

public class Check implements Checker {
    @Override
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int n = inf.nextInt();
        int k = inf.nextInt();
        int[][] a = new int[n][3];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = inf.nextInt();
            }
        }
        int[] jSet = new int[k];
        for (int i = 0; i < k; i++) {
            jSet[i] = ans.nextInt() - 1;
        }
        int jDiff = getDiff(jSet, a);
        int[] pSet = new int[k];
        for (int i = 0; i < k; i++) {
            pSet[i] = ouf.nextInt() - 1;
        }
        Arrays.sort(pSet);
        for (int i = 0; i < k; i++) {
            if (pSet[i] < 0 || pSet[i] >= n) {
                return new Outcome(Outcome.Type.WA, "There's no such element having index equal to " + (pSet[i] + 1));
            }
            if (i > 0 && pSet[i] == pSet[i - 1]) {
                return new Outcome(Outcome.Type.WA, "Duplicate indices in output, " + (pSet[i] + 1) + " occur at least twice");
            }
        }
        int pDiff = getDiff(pSet, a);
        if (pDiff > jDiff) {
            return new Outcome(Outcome.Type.WA, "Not optimal answer, jury has " + jDiff + ", participant got only " + pDiff);
        }
        if (jDiff > pDiff) {
            return new Outcome(Outcome.Type.FAIL, "Jury didn't get optimal solution");
        }
        return new Outcome(Outcome.Type.OK, "answer = " + pDiff + ", " + k + " numbers in output");
    }

    private int getDiff(int[] set, int[][] a) {
        int[] min = new int[3];
        int[] max = new int[3];
        Arrays.fill(min, Integer.MAX_VALUE);
        Arrays.fill(max, Integer.MIN_VALUE);
        for (int i : set) {
            for (int j = 0; j < 3; j++) {
                min[j] = Math.min(min[j], a[i][j]);
                max[j] = Math.max(max[j], a[i][j]);
            }
        }
        int ans = Integer.MIN_VALUE;
        for (int i = 0; i < 3; i++) {
            ans = Math.max(ans, max[i] - min[i]);
        }
        return ans;
    }
}
