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

public class Check implements Checker {

    final static int[] DX = {0, 1, 0, -1};
    final static int[] DY = {1, 0, -1, 0};

    static boolean[][] used;
    static int[][] a;
    static int n, m;

    static boolean inBounds(int x, int y) {
        return 0 <= x && x < n && 0 <= y && y < m;
    }

    int dfs(int x, int y, int c1, int c2) {
        if (used[x][y])
            return 0;
        used[x][y] = true;
        int res = 1;
        for (int dir = 0; dir < 4; dir++) {
            int x2 = x + DX[dir];
            int y2 = y + DY[dir];
            if (inBounds(x2, y2) && (a[x2][y2] == c1 || a[x2][y2] == c2)) {
                res += dfs(x2, y2, c1, c2);
            }
        }
        return res;
    }

    int count(int c1, int c2) {
        n = a.length;
        m = a[0].length;
        int res = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!used[i][j] && (a[i][j] == c1 || a[i][j] == c2)) {
                    int now = dfs(i, j, c1, c2);
                    res = Math.max(now, res);
                }
            }
        }
        return res;
    }

    @Override
	public Outcome test(InStream inf, InStream ouf, InStream ans) {
        n = inf.nextInt();
        m = inf.nextInt();
        a = new int[n][m];
        used = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = inf.nextInt();
            }
        }
        int jAns = ans.nextInt();
        int pAns = ouf.nextInt();
        int c1 = ouf.nextInt();
        int c2 = ouf.nextInt();
        int pRes = count(c1, c2);
        if (pRes != pAns) {
            return new Outcome(Outcome.Type.WA, "No region of colors " + c1 + " and" + c2 + " with size " + pAns + ", exists: " + pRes);
        }
        if (pAns > jAns) {
            return new Outcome(Outcome.Type.FAIL, "Achtung! Better solution was found: " + pAns + " > " + jAns);
        } else if (pAns < jAns) {
            return new Outcome(Outcome.Type.WA, "Jury has better solution: " + pAns + " < " + jAns);
        } else {
            return new Outcome(Outcome.Type.OK, "" + jAns);
        }
	}

}