n = int(input()) a = list(map(int, input().split())) ans = 0 for d in range(28): l = None st = [] for i in range(n): if l is None: if (a[i] >> d) & 1 == 0: l = i else: if (a[i] >> d) & 1 != 0: st.append((l, i - 1)) l = None if not l is None: st.append((l, n - 1)) cnt = n * (n + 1) // 2 for l, r in st: cnt -= (r - l + 1) * (r - l + 2) // 2 ans += (1 << d) * cnt print(ans)