#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T x, T y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
template <typename T>
T lcm(T x, T y) {
  if (x == 0 || y == 0) return 0;
  return x / gcd(x, y) * y;
}
int main() {
  int N;
  cin >> N;
  vector<int> F(N);
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    for (int j = 0; j < 10; j++) {
      cin >> tmp;
      F[i] += tmp;
    }
  }
  vector<vector<int>> P(N, vector<int>(11, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  long cnt = 0;
  bool check = true;
  for (int i = 0; i < N; i++) {
    int tmp = P[i][0];
    for (int j = 1; j <= F[i]; j++) {
      if (tmp <= P[i][j]) {
        check = false;
        tmp = P[i][j];
      }
    }
    cnt += tmp;
  }
  if (check) {
    int tmp = INT32_MIN;
    for (int i = 0; i < N; i++) {
      for (int j = 1; j <= F[i]; j++) {
        tmp = max(tmp, P[i][j]);
      }
    }
    cnt += tmp;
  }
  cout << cnt << endl;
}
