#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  os << "[";
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << ",";
  }
  os << "]";
  return os;
}
template <typename T>
T input() {
  T t;
  cin >> t;
  return t;
}
template <typename T>
vector<T> input(const int N) {
  vector<T> v(N);
  for (int i = 0; i < static_cast<int>(N); i++) cin >> v[i];
  return v;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
bool isOpenAtLeastOneSlot(const vector<vector<int> >& openHours) {
  for (int j = 0; j < 5; ++j) {
    for (int k = 0; k < 2; ++k) {
      if (openHours[j][k] == 1) {
        return true;
      }
    }
  }
  return false;
}
long computeProfit(const vector<vector<int> >& openHours,
                   const vector<vector<vector<int> > >& rivalOpenHours,
                   const vector<vector<long> >& profits) {
  long total = 0;
  for (int i = 0; i < rivalOpenHours.size(); ++i) {
    vector<vector<int> > rivalOpenHour = rivalOpenHours[i];
    int matched = 0;
    for (int j = 0; j < 5; ++j) {
      for (int k = 0; k < 2; ++k) {
        if (openHours[j][k] == 1 && rivalOpenHour[j][k] == 1) {
          matched += 1;
        }
      }
    }
    total += profits[i][matched];
  }
  return total;
}
int main() {
  int numRivals;
  cin >> numRivals;
  vector<vector<vector<int> > > rivalOpenHours(
      numRivals, vector<vector<int> >(5, vector<int>(2, 0)));
  for (int i = 0; i < static_cast<int>(numRivals); i++) {
    for (int j = 0; j < static_cast<int>(5); j++) {
      for (int k = 0; k < static_cast<int>(2); k++) {
        cin >> rivalOpenHours[i][j][k];
      }
    }
  }
  vector<vector<long> > profits(numRivals, vector<long>(11, -10000000000000));
  for (int i = 0; i < static_cast<int>(numRivals); i++) {
    for (int j = 0; j < static_cast<int>(11); j++) {
      cin >> profits[i][j];
    }
  }
  vector<vector<int> > openHours(5, vector<int>(2, 0));
  long maximum = -10000000000000;
  for (int i = 0; i < static_cast<int>(4); i++) {
    openHours[0][i / 2] = i % 2;
    for (int j = 0; j < static_cast<int>(4); j++) {
      openHours[1][j / 2] = j % 2;
      for (int k = 0; k < static_cast<int>(4); k++) {
        openHours[2][k / 2] = k % 2;
        for (int l = 0; l < static_cast<int>(4); l++) {
          openHours[3][l / 2] = l % 2;
          for (int m = 0; m < static_cast<int>(4); m++) {
            openHours[4][m / 2] = m % 2;
            if (!isOpenAtLeastOneSlot(openHours)) {
              continue;
            }
            maximum =
                max(maximum, computeProfit(openHours, rivalOpenHours, profits));
          }
        }
      }
    }
  }
  cout << maximum << endl;
  return 0;
}
