#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, j, k;
    cin >> n;
    vll c(n, 0);
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < 10; j++)
            cin >> k, c[i] += k;
    }
    ll ans = 0, flag = 0;
    ll p[n][11];
    for(i = 0; i < n; i++)
    {
        ll op = LLONG_MIN, ind = -1;
        for(j = 0; j <= 10; j++)
        {
            cin >> p[i][j];
            k = p[i][j];
            if(k >= op && j <= c[i])
                op = k, ind = j;
        }
        // cout << op << endl;
        if(ind > 0)
            flag = 1;
        ans += op;
    }
    if(flag)
        cout << ans << endl;
    else
    {
        // cout << ans << endl;
        ll x = LLONG_MIN;
        for(i = 0; i < n; i++)
            for(j = 1; j <= c[i]; j++)
                x = max(x, ans - p[i][0] + p[i][j]);
        cout << x << endl;
    }
    return 0;
}