#include <bits/stdc++.h>
using namespace std;
int main() {
  bool f[100][100], flag;
  int n, p[100][10], count[100], tmp = -10000000, ans = 0, c = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    count[i] = 0;
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> f[j][k];
        if (f[j][k]) count[i]++;
      }
    }
  }
  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++) {
    flag = true;
    if (p[i][count[i]] > 0)
      ans += p[i][count[i]];
    else
      flag = false;
    if (!flag) c++;
    tmp = max(tmp, p[i][count[i]]);
  }
  if (c == n) ans = tmp;
  cout << ans << endl;
}
