import sys from collections import Counter def main(): N = int(input()) A = list(map(int,input().split())) MAX = 2*pow(10,5) + 1000 S = [0] for i in range(1,MAX): temp = S[-1] + i S.append(temp) ans = S[N] cnt = 0 for i in range(N): if A[i] == 0: ans -= S[cnt] cnt = 0 else: cnt += 1 ans -= S[cnt] print(ans) if __name__ == '__main__': main()