#include #include #include

using namespace std;

#define _l (long long int)

const int maxn = 503; const int hmod = 1111111121;

int n, m, a[maxn][maxn], b[maxn][maxn], rb[maxn][maxn], c[maxn], o[maxn]; int t, s;

inline bool cCmp(const int& a, const int& b) { return c[a] < c[b]; }

void pr() { for (int i = 0; i < t; ++ i, putchar(10)) for (int j = 0; j < m; ++ j) fprintf(stderr, “%5d”, b[i][j]); }

inline int modPow(int a, int x) { int s(1); for (; x; x »= 1, a = _l a * a % hmod) if (x & 1) s = _l s * a % hmod; return s; }

bool checkIns(int lo) { bool az(1); for (int i = 0; i < m; ++ i) { b[t][i] = a[lo][i]; if (b[t][i]) az = 0; } if (az) return 0; for (int i = 0, l = 0; i < t; ++ i) { while (l < m && !b[t][l] && !b[i][l]) ++ l; if (l == m) return 0; while (b[t][l]) { int rat(b[i][l] / b[t][l]); for (int j = l; j < m; ++ j) { b[i][j] -= _l b[t][j] * rat % hmod; if (b[i][j] < 0) b[i][j] += hmod; } if (b[t][l]) { for (int j = l; j < m; ++ j) swap(b[i][j], b[t][j]); } } } bool r(0); for (int i = t; i < m && !r; ++ i) if (b[t][i]) r = 1; return r; }

int main() { #ifdef LAEKOV_LOCAL freopen(".in", “r”, stdin); #endif

scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++ i)
	for (int j = 0; j < m; ++ j)
		scanf("%d", a[i] + j);
for (int i = 0; i < n; ++ i)
	scanf("%d", c + i), o[i] = i;
sort(o, o + n, cCmp);
t = s = 0;
for (int i = 0; i < n; ++ i) {
	memcpy(rb, b, sizeof(b));
	if (checkIns(o[i]))
		++ t, s += c[o[i]];
	else
		memcpy(b, rb, sizeof(b));
}
printf("%d %d\n", t, s);

}