N = int(input()) A = list(map(int,input().split())) ans = 0 for i in range(28): tmp = 0 j = 0 while j < N: if A[j] >> i & 1 == 0: count = 1 j += 1 while j < N and A[j] >> i & 1 == 0: j += 1 count += 1 tmp += count * (count + 1) // 2 else: j += 1 ans += (N * (N + 1) // 2 - tmp) * (1 << i) print(ans)