#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  int F[100][5][2];
  int P[100][11];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        std::cin >> F[i][j][k];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      std::cin >> P[i][j];
    }
  }
  int kaburi[100];
  int max;
  int eigyo[10];
  for (int a = 0; a < 2; a++) {
    for (int b = 0; b < 2; b++) {
      for (int c = 0; c < 2; c++) {
        for (int d = 0; d < 2; d++) {
          for (int e = 0; e < 2; e++) {
            for (int f = 0; f < 2; f++) {
              for (int g = 0; g < 2; g++) {
                for (int h = 0; h < 2; h++) {
                  for (int i = 0; i < 2; i++) {
                    for (int j = 0; j < 2; j++) {
                      for (int N = 0; N < n; N++) {
                        eigyo[0] = a;
                        eigyo[1] = b;
                        eigyo[2] = c;
                        eigyo[3] = d;
                        eigyo[4] = e;
                        eigyo[5] = f;
                        eigyo[6] = g;
                        eigyo[7] = h;
                        eigyo[8] = i;
                        eigyo[9] = j;
                        std::cout << "check1\n";
                        kaburi[N] = 0;
                        for (int z = 0; z < 10; z++) {
                          for (int x = 0; x < 5; x++) {
                            for (int y = 0; y < 2; y++) {
                              if (eigyo[z] == 1 && F[n][x][y] == 1) {
                                kaburi[N]++;
                              }
                            }
                          }
                        }
                        std::cout << "check2\n";
                        int rieki = 0;
                        for (int i = 0; i < n; i++) {
                          int K = kaburi[n];
                          rieki += P[n][K];
                        }
                        std::cout << "check3\n";
                        if (i == 0) {
                          max = rieki;
                        }
                        if (max > rieki) {
                          max = rieki;
                        }
                        std::cout << "check3\n";
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  std::cout << max << std::endl;
}
