N = gets.chomp.to_i
Fs = [] 
N.times{
    tmp = gets.chomp.split.map(&:to_i)
    Fs << tmp
}
Ps = []
N.times{
    tmp = gets.chomp.split.map(&:to_i)
    Ps << tmp
}

mux = -1000000000000
(1..1024).each{ |x|
    business_times = x.to_s(2).split("").map(&:to_i)

    butting_nums = []
    Fs.each { |f|
        butting_num = 0
        10.times { |i|
            butting_num = butting_num + 1 if f[i] == 1 && business_times[i] == 1
        }
        butting_nums << butting_num
    }

    # p butting_nums
    tmp = 0
    Ps.each{ |p|
        tmp += p[butting_nums.shift]
    }
    mux = tmp if tmp > mux
}

puts mux
