#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

ll N;
int  shop[100][10];
ll profit[100][11];
int open[10];
ll nums[100];
ll ans = -1000000000;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    for(int i = 0; i < N; i++){
        for(int  j = 0; j < 10; j++){
            cin >> shop[i][j];
        }
    }

    for(int i = 0; i < N; i++){
        for(int  j = 0; j < 11; j++){
            cin >> profit[i][j];
        }
    }

    for(int a = 0; a < 2; a++){
        for(int b = 0; b < 2; b++){
            for(int c = 0; c < 2; c++){
                for(int d = 0; d < 2; d++){
                    for(int e = 0; e < 2; e++){
                        for(int f = 0; f < 2; f++){
                            for(int g = 0; g < 2; g++){
                                for(int h = 0; h < 2; h++){
                                    for(int i = 0; i < 2; i++){
                                        for(int j = 0; j < 2; j++){
                                            open[0] = a;
                                            open[1] = b;
                                            open[2] = c;
                                            open[3] = d;
                                            open[4] = e;
                                            open[5] = f;
                                            open[6] = g;
                                            open[7] = h;
                                            open[8] = i;
                                            open[9] = j;

                                            for(int s = 0; s < N; s++){
                                                nums[s] = 0;
                                            }


                                            bool check = false;
                                            for(int s = 0; s < 10; s++){
                                                if(open[s] == 1){
                                                    check = true;
                                                }
                                            }

                                            if(check == false){
                                                continue;
                                            }


                                            ll ansNow = 0;



                                            for(int s = 0; s < 10; s++){
                                                for(int t = 0; t < N; t++){
                                                    if(open[s]==1 && shop[t][s]==1){
                                                        nums[t]++;
                                                    }
                                                }
                                            }

//                                            for (int i=0; i<N; i++) {
//                                                cout << "nums["<<i<<"]="<<nums[i]<<endl;
//                                            }

                                            for(int s = 0; s < N; s++){
                                                ansNow += profit[s][nums[s]];
                                            }

//                                            cout << ansNow << " " << a << b<< c<< d<< e<< f<<g<<h<<i<<j<<endl;

                                            if(ansNow > ans){
                                                ans = ansNow;
                                            }

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

            }
        }

    }


    cout << ans << endl;
}

Measured memory_bytes: 256