#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const* argv[]) {
  int n;
  cin >> n;
  int f[n][10];
  int p[n][11];
  int count[n], maxp[n];
  for (int i = 0; i < n; i++) {
    count[i] = 0;
    maxp[i] = -1000000000;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      count[i] += f[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < count[i] + 1; j++) {
      if (p[i][j] > maxp[i]) maxp[i] = p[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    ans += maxp[i];
  }
  cout << ans << endl;
  return 0;
}
