#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans*(b&1?a:1);
}
int main(){
    int n;
    cin>>n;
    vector<vector<ll>> f(n,vector<ll>(10)),p(n,vector<ll>(10));
    ll ans=0,cnt=0;
    vector<ll> sum(10);
    rep(i,0,n){
        rep(j,0,10){
            cin>>f[i][j];
        }
    }
    rep(i,0,n){
        rep(j,0,10){
            cin>>p[i][j];
            if(f[i][j]) sum[j]+=p[i][j];
        }
    }
    ll maxsum=-10000001;
    rep(j,0,10){
        if(maxsum<sum[j]) maxsum=sum[j];
    }
    rep(j,0,10){
        if(sum[j]>0) ans+=sum[j];
        cnt++;
    }
    if(!cnt) ans=maxsum;
    cout<<ans
}