#include <bits/stdc++.h>
int main() {
  int F[100][5][2], N, P[100][5][2];
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 5; j++)
      for (int k = 0; k < 2; k++) scanf("%d", F[i][j] + k);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 5; j++)
      for (int k = 0; k < 2; k++) scanf("%d", P[i][j] + k);
  int sum = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 5; j++)
      for (int k = 0; k < 2; k++) {
        if (F[i][j][k] == 1) sum += P[i][j][k];
      }
  printf("%d", sum);
  return 0;
}
