#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int open[N] = {};
    rep(j, N){
        rep(i, 10) {
            int tmp;
            cin >> tmp;
            open[j] += tmp;
        }
    }
    int sum[N+1] = {};
    int sum2[N] = {};
    rep(i, N) {
        sum2[i] = -INF;
    } 
    rep(j, N) {
        rep(i, 11){
            int tmp;
            cin >> tmp;
            if (i <= open[j]) {
                sum[j] = max(sum[j], tmp);
                if (i != 0) {
                    sum2[j] = max(sum2[j], tmp);
                }
            }
        }
    }
    sort(sum, sum+N);
    //dump(sum[N-1]);
    //dump(sum2[N-1]);
    sort(sum2, sum2+N);
    if (sum2[N-1] < 0) {
        cout << sum2[N-1] << endl;
    } else {
        int tmp = 0;
        int i = N;
        while(sum[i] >= 0 && i >= 0) {
            tmp += sum[i];
            //dump(tmp);
            i--;
        }
        cout << tmp << endl;
    }


    return 0;
}
