n = gets.chomp.to_i
f = Array.new(n, 0)
n.times do |i|
    f[i] = gets.chomp.count("1")
end
ans = 0
no_open_flag = true
most_masi_arr = []
n.times do |i|
    values = gets.chomp.split(" ").map(&:to_i)
    max_val = values[0]
    max_index = 0
    (f[i]+1).times do |i|
        if values[i] > max_val then
            max_val = values[i]
            max_index = i
        end
    end
    if no_open_flag
        if max_index == 0 then
            most_masi_arr << values[1..f[i]].max
        else
            no_open_flag = false
        end
    end
    ans += max_val
end

if no_open_flag then
    ans += most_masi_arr.max
end

puts ans