#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f[100][10], p[100][10];
  vector<int> m;
  cin >> n;
  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 < 11; j++) cin >> p[i][j];
  int ans = 0;
  bool open = false;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < 10; j++)
      if (f[i][j] == 1) cnt++;
    int max = p[i][0];
    for (int j = 1; j <= cnt; j++)
      if (max < p[i][j]) max = p[i][j], open = true;
    ans += max;
    m.push_back(p[i][1]);
  }
  if (!open) {
    sort(m.begin(), m.end());
    ans = m[m.size() - 1];
  }
  cout << ans << endl;
  return 0;
}
