N = gets.to_i A = gets.split.map(&:to_i) a = A.tally c0 = a[1] || 0 c1 = a[2] || 0 puts 2 * c0 * (c0 - 1) / 2 + 3 * c0 * c1