#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int op[n][10];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++) cin >> op[i][j];
  pair<int, int> arr[n][11];
  pair<int, int> mx[n][11];
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= 10; j++) {
      cin >> arr[i][j].first;
      arr[i][j].second = j;
      mx[i][j] = arr[i][j];
    }
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= 10; j++) {
      if (mx[i][j - 1].first > mx[i][j].first) mx[i][j] = mx[i][j - 1];
    }
  int sum = 0;
  bool val = false;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < 10; j++) {
      if (op[i][j]) cnt++;
    }
    sum += mx[i][cnt].first;
    if (mx[i][cnt].second != 0) val = true;
  }
  if (val)
    cout << sum << "\n";
  else {
    int mx = -1e9 - 5;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (op[i][j]) cnt++;
      }
      for (int j = 1; j <= cnt; j++) {
        mx = max(mx, sum - arr[i][0].first + arr[i][j].first);
      }
    }
    cout << mx << "\n";
  }
  return 0;
}
