#include <bits/stdc++.h>
using namespace std;
int arr[105][10];
int arr2[105][11];
int kk[105];
int main() {
  int n;
  while (cin >> n) {
    long long int max2[105];
    memset(max2, -10000000, sizeof(max2));
    memset(kk, 0, sizeof(kk));
    long long int max3 = -100000000;
    long long int result = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        cin >> arr[i][j];
        if (arr[i][j]) kk[i]++;
      }
    }
    for (int i = 0; i < n; i++) {
      long long int max1 = -100000000;
      for (int j = 0; j < 11; j++) cin >> arr2[i][j];
      for (int j = 0; j <= kk[i]; j++) {
        if (arr2[i][j] > max1) {
          max1 = arr2[i][j];
          if (j != 0) flag = true;
        }
      }
      for (int j = 1; j <= kk[i]; j++)
        if (max2[i] < arr2[i][j]) max2[i] = arr2[i][j];
      result = result + max1;
    }
    if (flag) {
      cout << result << endl;
    } else {
      for (int i = 0; i < n; i++) {
        if (max3 < (result - arr2[i][0] + max2[i])) {
          max3 = result - arr2[i][0] + max2[i];
        }
      }
      cout << max3 << endl;
    }
  }
  return 0;
}
