import itertools N = int(input()) A = list(map(int,input().split())) ans = (2**28-1)*(N)*(N+1)//2 for i in range(28): temp = 0 B = [] for a in A: B.append(a&2**i>0) GB = itertools.groupby(B) for k,l in GB: if k==0: le = len(list(l)) ans-=2**i*(le)*(le+1)//2 print(ans)