N = gets.to_i
f = []
p = []
N.times {|i| f[i] = gets.split.join.to_i(2) }
N.times {|i| p[i] = gets.split.map(&:to_i) }

max_profit = - 10 ** 7

1.upto(2 ** 10 - 1) do |i|
  tmp_profit = 0

  f.each_with_index do |j, index|
    tmp_profit += p[index][(i & j).to_s(2).split('').count {|e| e == '1' }]
  end

  max_profit = tmp_profit if max_profit < tmp_profit
end

puts max_profit