#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  int n;
  int a[110][15], p[110][15];
  while (cin >> n) {
    int ma = -99999999;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= 10; j++) cin >> a[i][j];
    for (int i = 1; i <= n; i++)
      for (int j = 0; j <= 10; j++) cin >> p[i][j];
    int i1, i2, i3, i4, i5, i6, i7, i8, i9, i0;
    for (i1 = 0; i1 < 2; i1++)
      for (i2 = 0; i2 < 2; i2++)
        for (i3 = 0; i3 < 2; i3++)
          for (i4 = 0; i4 < 2; i4++)
            for (i5 = 0; i5 < 2; i5++)
              for (i6 = 0; i6 < 2; i6++)
                for (i7 = 0; i7 < 2; i7++)
                  for (i8 = 0; i8 < 2; i8++)
                    for (i9 = 0; i9 < 2; i9++)
                      for (i0 = 0; i0 < 2; i0++) {
                        int h = i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i0;
                        if (h >= 1) {
                          for (int i = 1; i <= n; i++)
                            ans += p[i][i1 * a[i][1] + i2 * a[i][2] +
                                        i3 * a[i][3] + i4 * a[i][4] +
                                        i5 * a[i][5] + i6 * a[i][6] +
                                        i7 * a[i][7] + i8 * a[i][8] +
                                        i9 * a[i][9] + i0 * a[i][10]];
                          if (ans > ma) ma = ans;
                        }
                        ans = 0;
                      }
    cout << ma << endl;
  }
  return 0;
}
