#include <bits/stdc++.h>
int main() {
  int N;
  scanf("%d", &N);
  int i;
  int a[105][11] = {0};
  for (i = 1; i <= N; i++) {
    int j;
    for (j = 1; j <= 10; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int p[105][11];
  for (i = 1; i <= N; i++) {
    int j;
    for (j = 0; j <= 10; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  int count_hour[105] = {0};
  for (i = 1; i <= N; i++) {
    int j;
    for (j = 1; j <= 10; j++) {
      if (a[i][j] == 1) {
        count_hour[i]++;
      }
    }
  }
  int sum_max = 0;
  int max = -10000001;
  int time[11];
  int gg = 0;
  for (i = 1; i <= N; i++) {
    max = -10000001;
    int j;
    for (j = 0; j <= count_hour[i]; j++) {
      if (max < p[i][j]) {
        max = p[i][j];
      }
    }
    if (max != p[i][0]) {
      gg = 1;
    }
    sum_max += max;
  }
  max = -10000001;
  if (gg == 0) {
    for (i = 1; i <= N; i++) {
      int j;
      for (j = 1; j <= count_hour[i]; j++) {
        if (max < p[i][j]) {
          max = p[i][j];
        }
      }
    }
  }
  printf("%d", sum_max);
  return 0;
}
