#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<vector<int>> opendata(N,vector<int>(10));
  vector<vector<int>> valuedata(N,vector<int>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> opendata.at(i).at(j);
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> valuedata.at(i).at(j);
    }
  }
  vector<int> onoff{0,1};
  int ans = 0, counta, countb, countc, value;
  for(int a: onoff) {
    for(int b: onoff) {
      for(int c: onoff) {
        for(int d: onoff) {
          for(int e: onoff) {
            for(int f: onoff) {
              for(int g: onoff) {
                for(int h: onoff) {
                  for(int i: onoff) {
                    for(int j: onoff) {
                      value = 0,couta = 0, countb = 0, countc = 0;
                      vector<int> bin(10){a,b,c,d,e,f,g,h,i,j}
                      for(int k = 0; k < 10; i++) {
                        counta += opendata.at(0).at(k) * bin.at(k);
                        countb += opendata.at(1).at(k) * bin.at(k);
                        countc += opendata.at(2).at(k) * bin.at(k);
                      }
                      value = value.at(0).at(counta) + valuedata.at(0).at(countb) + valuedata.at(2).at(countc);
                      if (value > ans) ans = value
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}