#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    auto F = make_vec<int>(N, 10);
    auto P = make_vec<int>(N, 11);
    vector<int> C(N);
    REP(i, N) {
        REP(j, 10) {
            cin >> F[i][j];
            C[i] += F[i][j];
        }
    }
    REP(i, N) {
        REP(j, 11) { cin >> P[i][j]; }
    }

    int ans = 0;
    bool flag = false;
    int s = -INF;
    REP(i, N) {
        int tmp = -INF;
        REP(j, C[i] + 1) {
            if (tmp <= P[i][j]) {
                if (j != 0) flag = true;
                tmp = P[i][j];
            }
            if (j != 0) {
                chmax(s, P[i][j]);
            }
        }
        if (tmp >= 0) {
            ans += tmp;
        }
    }

    if (flag) {
        cout << ans << endl;
    } else {
        cout << s << endl;
    }
    return 0;
}
