import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main() {
  auto n = readln.chomp.to!int;
  int[][][] f = new int[][][](n, 5, 2);
  int[][] p = new int[][](n, 11);

  for (int i = 0; i < n; ++i) {
    auto l = readln.chomp.split.map!(to!int).array;
    for (int j = 0; j < 10; j += 2) {
      f[i][j / 2][0] = l[j];
      f[i][j / 2][1] = l[j + 1];
    }
  }

  for (int i = 0; i < n; ++i) {
    auto l = readln.chomp.split.map!(to!int).array;
    for (int j = 0; j < 11; ++j) {
      p[i][j] = l[j];
    }
  }

  int maxBenefit = -1000000007;

  for (int i = 1; i < (2 << 9); ++i) {
    int sum;
    int[] c = new int[](n);
    for (int j = 0; j < 10; ++j) {
      //writeln(j, " = ", (i >> j) & 1);
      if (((i >> j) & 1) == 1) {
        for (int k = 0; k < n; ++k) {
          //writeln(k, " ", j / 2, " " , j % 2, " = ", f[k][j / 2][j % 2]);
          if (f[k][j / 2][j % 2] == 1) {
            c[k]++;
          }
        }
      }
    }

    for (int j = 0; j < n; ++j) {
      sum += p[j][c[j]];
    }

    if (maxBenefit < sum) {
      maxBenefit = sum;
    }
  }

  maxBenefit.writeln;
}