def main(): from sys import stdin, setrecursionlimit # setrecursionlimit(1000000) input = stdin.readline def iinput(): return int(input()) def sinput(): return input().rstrip() def i0input(): return int(input()) - 1 def linput(): return list(input().split()) def liinput(): return list(map(int, input().split())) def miinput(): return map(int, input().split()) def li0input(): return list(map(lambda x: int(x) - 1, input().split())) def mi0input(): return map(lambda x: int(x) - 1, input().split()) INF = 1000000000000000000 MOD = 1000000007 N = iinput() A = liinput() def rle(s): tmp, count, ans1, ans2 = s[0], 1, [], [] for i in range(1,len(s)): if tmp == s[i]: count += 1 else: ans1.append(tmp) ans2.append(count) tmp = s[i] count = 1 ans1.append(tmp) ans2.append(count) return ans1, ans2 ans = 0 for b in range(28): bis = [] for a in A: bis.append((a >> b) & 1) res = N * (N + 1) // 2 B, C = rle(bis) for bb, cc in zip(B, C): if bb == 0: res -= cc * (cc + 1) // 2 ans += (1 << b) * res print(ans) main()