n = int(input()) A = list(map(int, input().split())) ans = 0 for i in range(30): tot = 0 row = 0 for a in A: if a >> i & 1: tot += row * (row + 1) // 2 row = 0 else: row += 1 tot += row * (row + 1) // 2 ans += (n * (n + 1) // 2 - tot) * (1 << i) print(ans)