#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n;
  int isopen[110][2][5];
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (2); ++j) {
      for (int k = 0; k < (5); ++k) {
        cin >> isopen[i][j][k];
      }
    }
  }
  int profit[110][12];
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (11); ++j) {
      cin >> profit[i][j];
    }
  }
  int answer = -1000000010;
  for (int a = 0; a < (2); ++a) {
    for (int b = 0; b < (2); ++b) {
      for (int c = 0; c < (2); ++c) {
        for (int d = 0; d < (2); ++d) {
          for (int e = 0; e < (2); ++e) {
            for (int v = 0; v < (2); ++v) {
              for (int w = 0; w < (2); ++w) {
                for (int x = 0; x < (2); ++x) {
                  for (int y = 0; y < (2); ++y) {
                    for (int z = 0; z < (2); ++z) {
                      int pro = 0;
                      for (int i = 0; i < (n); ++i) {
                        int cnt = 0;
                        if (a && isopen[i][0][0]) cnt++;
                        if (b && isopen[i][0][1]) cnt++;
                        if (c && isopen[i][0][2]) cnt++;
                        if (d && isopen[i][0][3]) cnt++;
                        if (e && isopen[i][0][4]) cnt++;
                        if (v && isopen[i][1][0]) cnt++;
                        if (w && isopen[i][1][1]) cnt++;
                        if (x && isopen[i][1][2]) cnt++;
                        if (y && isopen[i][1][3]) cnt++;
                        if (z && isopen[i][1][4]) cnt++;
                        pro += profit[i][cnt];
                      }
                      answer = max(answer, pro);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << answer << endl;
}
