import std.stdio, std.string, std.conv, std.range, std.algorithm, std.functional;

void main() {
    auto N = readln.chomp.to!long;
    bool[][] shop;
    foreach (i; 0..N) {
        shop ~= readln.split.map!(s => s == "1").array;
    }
    long[][] P;
    foreach (i; 0..N) {
        P ~= readln.split.to!(long[]);
    }

    long func(bool[] b) {
        if (b.length < 10) return max(func(b ~ true), func(b ~ false));
        if (b.all!(a => !a)) {
            return long.min;
        }
        auto po = sum(iota(N).map!(i =>
            P[i][iota(10).count!(j => b[j] && shop[i][j])]));
        return po;
    }

    writeln(func([]));
}
