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