#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Outln(const string &sep, const T &val) {
  cout << val << '\n';
}
template <typename T, typename... Args>
void Outln(const string &sep, const T &val, Args... args) {
  cout << val << sep;
  Outln(sep, std::forward<Args>(args)...);
}
template <typename T>
inline void OutN(T x) {
  size_t i, len = x.size() - 1;
  for (i = 0; i < len; i++) cout << x[i] << " ";
  cout << x[len] << '\n';
}
template <typename T>
inline void OutaN(T x) {
  size_t i, len = sizeof(x) / sizeof(__typeof(x[0])) - 1;
  for (i = 0; i < len; i++) cout << x[i] << " ";
  cout << x[len] << '\n';
}
template <typename T>
inline void Outit(T x) {
  auto end = x.end();
  end--;
  for (auto it = x.begin(); it != end; it++) cout << *it << " ";
  cout << *end << '\n';
}
template <typename T>
void Debug(const T &val) {
  cerr << val << '\n';
}
template <typename T, typename... Args>
void Debug(const T &val, Args... args) {
  cerr << val << ' ';
  Debug(std::forward<Args>(args)...);
}
template <typename T>
inline bool Max(T &x, const T &y) {
  return x < y ? x = y, 1 : 0;
}
template <typename T>
inline bool Min(T &x, const T &y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T> >;
inline bool isSame(const string &first, const string &second) {
  return first.compare(second) == 0;
}
inline bool isLess(const string &first, const string &second) {
  return first.compare(second) < 0;
}
inline bool isGreater(const string &first, const string &second) {
  return first.compare(second) > 0;
}
inline string Str(const char &ch, const int &n) { return string(n, ch); }
inline string Str(const int &n, const char &ch) { return string(n, ch); }
vector<string> getStrLine() {
  vector<string> v;
  string str;
  getline(cin, str);
  istringstream iss(str);
  for (string word; iss >> word;) v.push_back(word);
  return v;
}
static const long long MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
inline double rad2deg(const double &rad) { return rad * (180.0 / PI); }
inline double deg2rad(const double &deg) { return deg * (PI / 180.0); }
void rec(const VV<V<int> > &shops, const VV<long long> &table, const int &n,
         const int &day, const int &time, VV<int> plan, long long &ans) {
  if (5 <= day && 1 <= time) {
    long long cost = 0;
    int num;
    int i, j, k;
    for ((i) = 0; (i) < (n); (i)++) {
      num = 0;
      for ((j) = 0; (j) < (5); (j)++) {
        for ((k) = 0; (k) < (2); (k)++) {
          if (plan[j][k] == 1 && shops[i][j][k] == 1) num++;
        }
      }
      cost += table[i][num];
    }
    Max(ans, cost);
    return;
  }
  if (0 < time) {
    rec(shops, table, n, day + 1, 0, plan, ans);
    plan[day][time] = 1;
    rec(shops, table, n, day + 1, 0, plan, ans);
  } else {
    rec(shops, table, n, day, time + 1, plan, ans);
    plan[day][time] = 1;
    rec(shops, table, n, day, time + 1, plan, ans);
  }
}
void solve(const VV<V<int> > &shops, const VV<long long> &table, const int &n) {
  long long ans = LLONG_MIN;
  VV<int> plan(5);
  int i;
  for ((i) = 0; (i) < (5); (i)++) plan[i] = V<int>(2, 0);
  rec(shops, table, n, 0, 1, plan, ans);
  plan[0][0] = 1;
  rec(shops, table, n, 0, 1, plan, ans);
  cout << (ans) << '\n';
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VV<V<int> > shops(n);
  VV<long long> table(n);
  int morning, afternoon;
  int i, j, len = 11;
  for ((i) = 0; (i) < (n); (i)++) {
    shops[i] = VV<int>(5);
    for ((j) = 0; (j) < (5); (j)++) {
      cin >> morning >> afternoon;
      shops[i][j] = V<int>(2);
      shops[i][j][0] = morning;
      shops[i][j][1] = afternoon;
    }
  }
  for ((i) = 0; (i) < (n); (i)++) {
    table[i] = V<long long>(len);
    for ((j) = 0; (j) < (len); (j)++) cin >> table[i][j];
  }
  solve(shops, table, n);
  return 0;
}
