#include "testlib.h"
#include <vector>
#include <map>
using namespace std;

int main(int argc, char* argv[]) {
	registerTestlibCmd(argc, argv);
	int N = inf.readInt();
	inf.readSpace();
	int M = inf.readInt();
	inf.readEoln();
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		v[i] = inf.readInt();
		if (i + 1 < N) inf.readSpace();
	}
	inf.readEoln();
	vector<vector<int>> h(N, vector<int>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			h[i][j] = inf.readInt();
			if (j + 1 < M) inf.readSpace();
		}
		inf.readEoln();
	}

	int userAnsH = ouf.readInt();
	int juryAnsH = ans.readInt();

	if (juryAnsH != userAnsH) {
		quitf(_wa, format("expected %d, got %d", juryAnsH, userAnsH).c_str());
	}

	ouf.readEoln();
	ans.readEoln();
	int userSum = 0, userMax = -1;
	int jurySum = 0, juryMax = -1;
	vector<int> userV = ouf.readIntegers(M, 0), juryV = ans.readIntegers(M, 0);
	for (int i = 0; i < M; i++) {
		if (userV[i] < 0) {
			quitf(_wa, format("negative %d salad value", i + 1).c_str());
		}
		userSum += userV[i];
		userMax = max(userMax, userV[i]);
	}
	for (int i = 0; i < M; i++) {
		jurySum += juryV[i];
		juryMax = max(juryMax, juryV[i]);
	}
	if (juryMax != userMax) {
		quitf(_wa, format("expected max salad value %d, got %d", juryMax, userMax).c_str());
	}
	if (jurySum != userSum) {
		quitf(_wa, format("expected summary salad value %d, got %d", jurySum, userSum).c_str());
	}
	int sumH = 0;
	vector<int> saladV(M);
	for (int i = 0; i < N; i++) {
		int sumEat = 0;
		vector<int> vals = ouf.readIntegers(M, 0);
		for (int j = 0; j < M; j++) {
			saladV[j] += vals[j];
			sumH += vals[j] * h[i][j];
			sumEat += vals[j];
		}
		if (sumEat > v[i]) {
			quitf(_wa, format("%d guest ate more than stomach value", i + 1).c_str());
		}
	}

	if (sumH != userAnsH) {
		quitf(_wa, format("summary happy value not equal right happy value").c_str());
	}

	for (int j = 0; j < M; j++) {
		if (saladV[j] != userV[j]) {
			quitf(_wa, format("summary eaten value of %d salad not equal cooked value", j + 1).c_str());
		}
	}

	quitf(_ok, "ok");
}