n = int(input()) A = list(map(int, input().split())) ans = n * (n - 1) // 2 + n cnt = 0 for i in range(n): if A[i] == 1: cnt += 1 if i == n - 1: ans -= cnt * (cnt - 1) // 2 + cnt else: ans -= cnt * (cnt - 1) // 2 + cnt cnt = 0 print(ans)