import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) res = N * (N + 1) // 2 r = 0 for l in range(N): if a[l] == 0: continue if r < l: r = l while r < N and a[r]: r += 1 res -= r - l print(res)