#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

bool isPrime(ll num) {

	bool flag = true;
	for (int i = 2; i <= sqrt(num); i++) {
		if (num%i == 0) {
			flag = false;
			break;
		}
	}

	return flag;
}

vector<vector<vector<bool>>> others;
vector<vector<ll>> profit;

vector<vector<bool>> open(5, vector<bool>(2));
vector<vector<bool>> best(5, vector<bool>(2));
ll N;

vector<ll> ans(0);

void sale(int day, int time) {

	if (day == 5) {
		//評価

		bool flag = false;
		rep(i, 5) rep(j,2) {
			if (open[i][j] == true) flag = true;
		}
		if (flag == false) return;

		ll sum = 0;

		rep(i, N) {

			ll cnt = 0;
			rep(j, 5) rep(k, 2) {
				if (open[j][k] && others[i][j][k]) cnt++;
			}

			sum += profit[i][cnt];

		}

		if (ans.size() == 0) {
			ans.emplace_back(sum);
			debug(sum);
			debug(open);
		}
		else if (ans[0] < sum){
			ans[0] = sum;
			debug(sum);
			debug(open);
		}

		return;
	}

	open[day][time] = false;

	if (time == 0) sale(day, 1);
	else sale(day + 1, 0);

	open[day][time] = true;

	if (time == 0) sale(day, 1);
	else sale(day + 1, 0);

}

void solve() {

	cin >> N;
	others.resize(N, vector<vector<bool>>(5, vector<bool>(2)));

	rep(i, N) rep(j, 5) rep(k, 2) {
		int tmp;
		cin >> tmp;
		others[i][j][k] = (tmp == 1);
	}

	profit.resize(N, vector<ll>(11));

	rep(i, N) rep(j, 11) cin >> profit[i][j];

	//open = vector<vector<bool>>(5,vector<bool>(2,true));

	sale(0, 0);

	cout << ans[0] << endl;
	debug(others);
	debug(profit);

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}
