#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  int shopflag[101] = {0};
  int buff = 0;
  int profit[101][11];
  int count;
  const int cc = -10000000;
  int zerocnt = 0;
  int ans = 0;
  int mincount = -10000000;
  bool minimin = false;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> buff;
      if (buff == 1) {
        shopflag[i]++;
      }
    }
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < 11; ++i) {
      cin >> profit[k][i];
    }
  }
  for (int l = 0; l < n; ++l) {
    count = cc;
    zerocnt = 0;
    for (int i = 0; i < shopflag[l] + 1; ++i) {
      if (count < profit[l][i]) {
        count = profit[l][i];
        zerocnt = i;
      }
    }
    if (zerocnt == 0) {
      for (int i = 1; i < shopflag[l] + 1; ++i) {
        if (mincount < profit[l][i]) {
          mincount = profit[l][i];
          minimin = true;
        }
      }
    }
    ans += count;
  }
  if (minimin == false) {
    cout << ans;
  } else {
    cout << mincount;
  }
  return 0;
}
