# frozen_string_literal: true def solve A.map .with_index .select { |a, _| a.zero? } .map { |_, i| i } .tap { _1.unshift(-1) } .each_cons(2) .map { |prev, now| (now - prev) * (N - now) } .sum end N = gets.to_i A = gets.split.map { _1.to_i } puts solve