#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++)
#define repbit(n) for(ll bit=0,bit<(1<<n),bit++)
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<int> bits(n);
    vector<vector<ll>> f(n,vector<ll>(10)),p(n,vector<ll>(10));
    ll ans=-100000000;
    rep(i,0,n){
        rep(j,0,10){
            cin>>f[i][j];
        }
    }
    rep(i,0,n){
        rep(j,0,10){
            cin>>p[i][j];
        }
    }
    rep(i,0,n) rep(j,0,10) bits[i] |= (f[i][j]<<(9-j));
    rep(bit,0,(1<<n)){
        rep(i,0,n){
            int k=bit;
            k&=bits[i];
            ans=max(ans,p[i][ __builtin_popcount(k) ]);
        }
    }
    cout<<ans
}