#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int kosu[100] = {};
  int flag = 0;
  int f[100][10] = {};
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (10); ++j) {
      cin >> f[i][j];
      if (f[i][j]) kosu[i]++;
    }
  int p[100][11] = {};
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (11); ++j) {
      cin >> p[i][j];
    }
  int sum = 0;
  int m_max = -1000000000;
  for (int i = 0; i < (n); ++i) {
    int max_p = -1000000000;
    for (int j = 0; j < (kosu[i] + 1); ++j) {
      if (j) m_max = max(m_max, p[i][j]);
      if (max_p < p[i][j]) {
        max_p = p[i][j];
        if (!j)
          flag = 1;
        else
          flag = 0;
      }
    }
    sum += max_p;
  }
  if (flag)
    cout << m_max << endl;
  else
    cout << sum << endl;
  return 0;
}
