#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vs = vector<string>;
using P = pair<ll, ll>;
template <class T>
using heap = priority_queue<T>;
template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename T>
void assign2d(A &arr, ll H, ll W, T t) {
  arr.resize(H);
  for (int i = (int)(0); i < (int)(H); i++) arr[i].assign(W, t);
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  for (int i = (int)(0); i < (int)(n); i++)
    os << v[i] << (i == n - 1 ? "\n" : " ");
  return os;
}
template <class T = int>
inline T in() {
  T x;
  cin >> x;
  return x;
}
template <class T>
inline void print(const T &x) {
  cout << x << '\n';
}
struct pre_ {
  pre_() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
  }
} pre__;
int main() {
  ll N;
  vvll F;
  vvll P;
  cin >> N;
  vll Pm(N);
  assign2d(F, N, 10, 0);
  assign2d(P, N, 11, 0);
  for (int i = (int)(0); i < (int)(N); i++) {
    for (int n = (int)(0); n < (int)(10); n++) {
      F[i][n] = in();
    }
  }
  for (int i = (int)(0); i < (int)(N); i++) {
    for (int n = (int)(0); n < (int)(11); n++) {
      P[i][n] = in();
    }
  }
  for (int i = (int)(0); i < (int)(N); i++) {
    ll im = accumulate((F[i]).begin(), (F[i]).end(), 0);
    ll max = *max_element(P[i].begin() + 1, P[i].begin() + 1 + im);
    Pm[i] = max;
  }
  ll x = accumulate((Pm).begin(), (Pm).end(), 0);
  if (x > 0) {
    print(x);
  } else {
    print(*max_element((Pm).begin(), (Pm).end()));
  }
  return 0;
}
