#include<iostream>
#include<array>
#include<vector>
using namespace std;

void main() {
	int N;
	cin >> N;
	int F[100][10];
	int P[100][11];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++)cin >> F[i][j];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 11; j++)cin >> P[i][j];
	}
	int count = 0;
	int ans = 0;
	int max = -(1 << 10);
	int m_p = 0;
	bool s = true;
	for (int i = 0; i < N; i++) {
		count = 0;
		for (int j = 0; j < 10; j++)count += (F[i][j] == 1 ? 1 : 0);
		count = (count == 0 ? 1 : count);
		max = -(1 << 10);
		m_p = 0;
		for (int j = 0; j <= count; j++) {
			if (max < P[i][j]) {
				max = P[i][j];
				m_p = j;
			}
		}
		if (m_p != 0)s = false;
		ans += max;
	}
	if (s) {
		max = -(1 << 10);
		int min = (1 << 10);
		for (int i = 0; i < N; i++) {
			count = 0;
			for (int j = 0; j < 10; j++)count += (F[i][j] == 1 ? 1 : 0);
			count = (count == 0 ? 1 : count);
			for (int j = 1; j < count; j++) {
				if (max < P[i][j])max = P[i][j];
			}
			if (min > P[i][0])min = P[i][0];
		}
		ans += max;
		ans -= min;
	}
	cout << ans << endl;
}

