#include <bits/stdc++.h>
using namespace std;
const int MAX = 110;
const int INF = 0x3fffffff;
int a[MAX][MAX][MAX];
int c[MAX][MAX];
int b[MAX];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    memset(a, 0, sizeof(a));
    memset(c, 0, sizeof(c));
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 5; j++) {
        for (int k = 1; k <= 2; k++) {
          scanf("%d", &a[i][j][k]);
        }
      }
    }
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= 10; j++) {
        scanf("%d", &c[i][j]);
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 5; j++) {
        for (int k = 1; k <= 2; k++) {
          if (a[i][j][k] == 1) {
            b[i]++;
          }
        }
      }
    }
    int Max = -INF;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= b[i]; j++) {
        if (c[i][j] > Max) {
          Max = c[i][j];
        }
      }
      sum += Max;
      Max = -INF;
    }
    cout << sum << endl;
  }
  return 0;
}
