#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int f[n][5][2];
  int f2[n][10];
  long long p[n][11];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      f2[i][j] = -1;
    }
  }
  bool flag = false;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> f[i][j][k];
        f2[i][cnt] = f[i][j][k];
        cnt++;
        if (cnt == 10) cnt = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
    }
  }
  long long res = 0, tmp = 0;
  long long m[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      if (f2[i][j] == 1) tmp++;
    }
    m[i] = tmp;
    tmp = 0;
  }
  tmp = -10000001;
  int check, c_cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m[i]; j++) {
      if (tmp < p[i][j]) {
        tmp = p[i][j];
        check = j;
      }
    }
    res += tmp;
    tmp = -10000001;
    if (check == 0) c_cnt++;
  }
  if (c_cnt == n) {
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= m[i]; j++) {
        if (tmp < p[i][j]) {
          tmp = p[i][j];
          check = i;
        }
      }
    }
    res += tmp;
    res -= p[check][0];
  }
  cout << res << endl;
}
