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