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