#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n, f[100][10], p[100][11], t[100] = {0};
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j += 2) {
      scanf("%d%d", &f[i][j], &f[i][j + 1]);
    }
  }
  for (int i = 0; i < n; i++) {
    int tmp = 0;
    for (int j = 0; j < 11; j++) {
      if (f[i][j] != 0) tmp++;
    }
    t[i] = tmp;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      scanf("%d", &p[i][j]);
    }
    int tmax = 0;
    for (int j = 1; j <= t[i]; j++) {
      tmax = max(tmax, p[i][j]);
    }
    ans += tmax;
  }
  printf("%d\n", ans);
  return 0;
}
