n = gets.to_i
f = []
n.times {f << gets.split.map(&:to_i)}
pp = []
n.times {pp << gets.split.map(&:to_i)}

ans = -(10 ** 8)

1.upto(1023) do |i|
    s = i.to_s(2).reverse
    c = Array.new(n,0)
    q = 0

    s.length.times do |j|
        if s[j] == '1' then
            f.each_with_index {|e,index| c[index] += e[j]}
        end
    end

    n.times {|k| q += pp[k][c[k]]}
    ans = q if ans < q
end

puts ans