#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, f[100][5][2], p[100][11], total[100], max = -10000001, ans, cnt = 0,
                                               num;
  cin >> n;
  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];
        total[i] += f[i][j][k];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
      if (total[i] >= j) {
        if (max < p[i][j]) {
          if (j != 0) {
            max = p[i][j];
            num = j;
          } else if (j == 0 && cnt == 0) {
            max = p[i][j];
            num = j;
          }
        }
      }
    }
    if (num == 0) {
      cnt++;
    }
    ans += max;
    max = -10000001;
  }
  cout << ans << endl;
  return 0;
}
