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