#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long a, long long b) {
  long long ans = 1;
  for (long long i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}
long long int gcd(long long int m, long long int n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
long long int lcm(long long int number1, long long int number2) {
  return number1 * number2 / gcd(number1, number2);
}
int main() {
  long long N;
  cin >> N;
  vector<vector<long long>> F(N, vector<long long>(10));
  vector<vector<long long>> P(N, vector<long long>(11));
  vector<vector<long long>> p(N, vector<long long>(11));
  vector<vector<long long>> maxP(N, vector<long long>(11));
  vector<long long> open(N);
  for (long long i = 0; i < (long long)(N); i++) {
    for (long long j = 0; j < (long long)(10); j++) {
      cin >> F[i][j];
    }
  }
  for (long long i = 0; i < (long long)(N); i++) {
    for (long long j = 0; j < (long long)(11); j++) {
      cin >> P[i][j];
    }
  }
  for (long long i = 0; i < (long long)(N); i++) {
    long long max = -1e9 + 7;
    for (long long j = 0; j < (long long)(11); j++) {
      if (P[i][j] > max) {
        max = P[i][j];
        p[i][j] = max;
      } else {
        p[i][j] = max;
      }
    }
  }
  for (long long i = 0; i < (long long)(N); i++) {
    long long sum = 0;
    for (long long j = 0; j < (long long)(10); j++) {
      if (F[i][j] == 1) {
        sum++;
      }
    }
    open[i] = sum;
  }
  for (long long i = 0; i < (long long)(N); i++) {
    long long max2 = -1e9 + 7;
    for (long long j = 1; j < 11; j++) {
      if (max2 < P[i][j]) {
        max2 = P[i][j];
        maxP[i][j] = max2;
      } else {
        maxP[i][j] = max2;
      }
    }
  }
  long long count = 0;
  long long ans = 0;
  long long max3 = -10000000000;
  long long mem = 0;
  for (long long i = 0; i < (long long)(N); i++) {
    ans += p[i][open[i]];
    if (maxP[i][open[i]] > max3) {
      max3 = maxP[i][open[i]];
      mem = i;
    }
    if (maxP[i][open[i]] != p[i][open[i]]) {
      count++;
    }
    if (i == N - 1 && count == N) {
      ans += max3;
      ans -= P[i][0];
    }
  }
  cout << ans << endl;
}
