# require "template" lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end n = read_line.to_i a = read_line.split.map(&.to_i) one = a.chunk { |i| i }.select { |b| b[0] == 1 }.map(&.[1].size).to_a puts n.to_i64 * -~n // 2 - one.sum { |m| m.to_i64 * -~m // 2 }