#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<vector<vector<int> > > vvvi;
typedef vector<long long> vl;
typedef vector<vector<long long> > vvl;
typedef vector<vector<vector<long long> > > vvvl;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

long long gcd(long long a, long long b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

bool isOpenAtLeastOneSlot(const vvi& openHours) {
    for (int j = 0; j < 5; ++j) {
        for (int k = 0; k < 2; ++k) {
            if (openHours[j][k] == 1) {
                return true;
            }
        }
    }
    return false;
}

long long computeProfit(const vvi& openHours, const vvvi& rivalOpenHours, const vvl& profits) {
    long long total = 0;
    for (int i = 0; i < rivalOpenHours.size(); ++i) {
        vvi rivalOpenHour = rivalOpenHours[i];
        int matched = 0;
        for (int j = 0; j < 5; ++j) {
            for (int k = 0; k < 2; ++k) {
                if (openHours[j][k] == 1 && rivalOpenHour[j][k] == 1) {
                    matched += 1;
                }
            }
        }
        total += profits[i][matched];
    }

    return total;
}

int main(){
    int numRivals;
    cin >> numRivals;

    vvvi rivalOpenHours(numRivals, vvi(5, vi(2, 0)));
    repeat (i, numRivals) {
        repeat (j, 5) {
            repeat (k, 2) {
                cin >> rivalOpenHours[i][j][k];
            }
        }
    }

    vvl profits(numRivals, vl(11, 0));
    repeat (i, numRivals) {
        repeat (j, 11) {
            cin >> profits[i][j];
        }
    }

    vvi openHours(5, vi(2, 0));

    long long maximum = -10000000000000;
    repeat (i, 4) {
        openHours[0][0] = i / 2 + i % 2;
        openHours[0][1] = i % 2;
        repeat (j, 4) {
            openHours[1][0] = j / 2 + j % 2;
            openHours[1][1] = j % 2;
            repeat (k, 4) {
                openHours[2][0] = k / 2 + k % 2;
                openHours[2][1] = k % 2;
                repeat (l, 4) {
                    openHours[3][0] = l / 2 + l % 2;
                    openHours[3][1] = l % 2;
                    repeat (m, 4) {
                        openHours[4][0] = m / 2 + m % 2;
                        openHours[4][1] = m % 2;
                        if (!isOpenAtLeastOneSlot(openHours)) {
                            continue;
                        }
                        long long candidate = computeProfit(openHours, rivalOpenHours, profits);
                        if (maximum < candidate) {
                            maximum = candidate;
                        }
                    }
                }
            }
        }
    }

    cout << maximum << endl;
    return 0;
}


Measured memory_bytes: 256