from collections import deque from typing import Iterator, Deque, Callable, Tuple from sys import stdin import itertools class Scanner: _tokens: Deque[str] def __init__(self): self._tokens = deque() def read(self) -> str: if len(self._tokens) == 0: self._tokens.extend(stdin.readline().split()) return self._tokens.popleft() def read_int(self) -> int: return int(self.read()) def read_ints(self, n: int) -> Iterator[int]: return [self.read_int() for _ in range(n)] @staticmethod def readline(func: Callable = str): return map(func, stdin.readline().split()) cin = Scanner() def main(): n = cin.read_int() a = [*map(lambda x: bool(x), cin.read_ints(n))] ans_all = n * (n + 1) // 2 a_start = -1 for i in range(n): if a[i]: if a_start == -1: a_start = i else: if a_start != -1: tmp = i - a_start ans_all -= tmp * (tmp + 1) // 2 a_start = -1 if a_start != -1: tmp = n - a_start ans_all -= tmp * (tmp + 1) // 2 print(ans_all) if __name__ == '__main__': main()