n = gets.to_i s = gets.split.map &:to_i t = gets.split.map &:to_i a = Array.new(n) {[nil] * n} sum = 0 row1 = [false] * n col1 = [false] * n row0 = n s.each_with_index do |x, i| if x == 0 n.times { |j| a[i][j] = 0 } elsif x == 2 sum += n row0 -= 1 row1[i] = true n.times do |j| col1[j] = true a[i][j] = 1 end end end t.each_with_index do |x, j| if x == 0 n.times { |i| a[i][j] = 0 } elsif x == 2 sum += row0 col1[j] = true n.times do |i| row1[i] = true a[i][j] = 1 end end end n.times do |i| n.times do |j| if !a[i][j] if !row1[i] or !col1[j] row1[i] = col1[j] = true a[i][j] = 1 sum += 1 end end end end p sum