Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
alist = list(map(int,input().split()))
anslist = list(alist[i]^alist[j] for i in range(n) for j in range(i+1,n))
s = sum(anslist)
if s < 10**9+7:
  print(s)
else:
  print(s%(10**9+7))
    


### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

a.sort(reverse = True)

#l = len(bin(a[0])[2:])

ans  = 0
for b in range(60+1):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    count_1 %= mod
    count_0 %= mod
    ans += (count_1 * count_0 * pow(2,b,mod))%mod


print(ans%mod)
### BUGGY CODE ###

import numpy as np
import heapq

INF=10**12
def daik(s,g,d,adj):
    used=np.array([])
    heap=[]
    table=np.array([INF for i in range(N)])
    table[s]=0
    heapq.heappush(heap,(table[s],s))
    used=np.append(used,s)
                
    while heap and not(g in used):
        q=heapq.heappop(heap)
        a=q[1]
        used=np.append(used,a)
        for i in adj[a]:
            if not(i in used):
                table[i]=min(table[i],table[a]+d[a,i])
                heapq.heappush(heap,(table[i],i))
    return table[g]

N,M=map(int,input().split())
LRC=[]
for i in range(M):
    L,R,C=map(int,input().split())
    LRC.append([L-1,R-1,C])
LRC=np.array(LRC)
LRC=LRC[np.argsort(LRC[:,2])][::-1]

d=np.array([[INF for j in range(N)] for i in range(N)])
adj=[[] for i in range(N)]
for i in range(N-1):
    d[i+1,i]=0
    adj[i+1].append(i)
    adj[i].append(i+1)
for i in range(M):
    C=LRC[i,2]
    d[LRC[i,0],LRC[i,1]]=C
    d[LRC[i,1],LRC[i,0]]=C
    adj[LRC[i,0]].append(LRC[i,1])
    adj[LRC[i,1]].append(LRC[i,0])

ans=daik(0,N-1,d,adj)
if ans==INF:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import numpy as np
import heapq

INF=10**15
N,M=map(int,input().split())
adj=[[] for i in range(N)]
for i in range(M):
    L,R,C=map(int,input().split())
    L-=1
    R-=1
    adj[L].append((R,C))
    adj[R].append((L,C))
for i in range(N-1):
    adj[i+1].append((i,0))
    
s=0
g=N-1
heap=[]
table=np.array([INF for i in range(N)])
table[s]=0
heapq.heappush(heap,(table[s],s))
                
while heap:
    q=heapq.heappop(heap)
    a=q[1]
    if q[0]>table[a]: continue
    for ne in adj[a]:
        p=ne[0]
        co=ne[1]
        if table[p]>table[a]+co:
            table[p]=table[a]+co
            heapq.heappush(heap,(table[p],p))
ans=table[g]
if ans==INF:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

N = int(input())

lis = [i for i in range(N)]

ans = 0

for i in range(1, N):
    ans += i

print(ans)

### FIXED CODE ###

N = int(input())

ans = N * (N - 1) // 2

print(ans)
### BUGGY CODE ###

def AppendQue(now, depth, que, past_visit, maze):
    Next = ((now[0] - 1, now[1]), (now[0], now[1] - 1),
            (now[0] + 1, now[1]), (now[0], now[1] + 1))
    for h, w in Next:
        if min(h, w) < 0:
            continue
        elif h >= H or w >= W:
            continue
        elif (h, w) in past_visit:
            continue
        elif maze[h][w] == "#":
            continue

        que.append(((h, w), depth + 1))


H, W = map(int, input().split())

maze = []
black = 0
for i in range(H):
    maze.append(input())
    black += maze[i].count("#")

if maze[0][0] == "#" or maze[H - 1][W - 1] == "#":
    print(-1)
    exit()

que = []
now = (0, 0)
depth = 1
que.append((now, depth))
past_visit = set()
while True:
    if len(que) == 0:
        print(-1)
        exit()
    (now, depth), que = que[0], que[1:]
    if now == (H - 1, W - 1):
        break
    past_visit.add(now)
    AppendQue(now, depth, que, past_visit, maze)

print(H * W - black - depth)

### FIXED CODE ###

def AppendQue(now, depth, que, past_visit, maze):
    Next = ((now[0] - 1, now[1]), (now[0], now[1] - 1),
            (now[0] + 1, now[1]), (now[0], now[1] + 1))
    for h, w in Next:
        if h < 0 or w < 0 or h >= H or w >= W:
            continue
        elif (h, w) in past_visit:
            continue
        elif maze[h][w] == "#":
            continue
        elif (h, w) in que:
            continue

        que.append((h, w))
        depth[(h, w)] = depth[now] + 1


H, W = map(int, input().split())

maze = []
black = 0
for i in range(H):
    maze.append(input())
    black += maze[i].count("#")

if maze[0][0] == "#" or maze[H - 1][W - 1] == "#":
    print(-1)
    exit()

que = []
now = (0, 0)
depth = {}
depth[now] = 1
que.append(now)
past_visit = set()
while True:
    if len(que) == 0:
        print(-1)
        exit()
    now, que = que[0], que[1:]
    if now == (H - 1, W - 1):
        break
    past_visit.add(now)
    AppendQue(now, depth, que, past_visit, maze)

print(H * W - black - depth[(H - 1, W - 1)])
### BUGGY CODE ###

n,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(1,n):
    for k in range(1,K+1):
        if i-k>=0:
            dp[i] = min(dp[i],dp[i-k] + abs(h[i-k] - h[i]))
print(dp[n-1])

### FIXED CODE ###

n,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(1,n):
    for k in range(1,K+1):
        if i-k>=0:
            dp[i] = min(dp[i],dp[i-k] + abs(h[i-k] - h[i]))
print(dp[n-1])
### BUGGY CODE ###

a = int(input())
li = list(map(int,input().split()))

count = 0

for i in range(a):
    if a-1 == i:
        continue
    for j in li[i+1:]:
        if li[i] == j:
            count += 1
        else:
            pass

if count > 0:
    print('NO')
else:
    print("YES")

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split(' ')))

is_break = False
seen = set()
for a in A:
    if a not in seen:
        seen.add(a)
    else:
        is_break=True
        break

if is_break:
    print('NO')
else:
    print('YES')
### BUGGY CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))
list.sort(H, reverse=True)
for i in range(K):
    if len(H) != 0:
        H.pop(0)
    else:
        print("0")
        exit()
print(sum(H))

### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))
list.sort(H, reverse=True)
print(sum(H[K:]))
### BUGGY CODE ###

s=[str(x) for x in input()]

sum=0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        t=''.join(s[i:j+1])
        if int(t)%2019==0:
            sum+=1
print(sum)

### FIXED CODE ###

from collections import deque
s=input()[::-1]
l=[0]*2019
ten=1
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*ten
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
    ten = ten *10 %2019
print(cnt)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
from bisect import bisect_left

Ans = 0
pans = 0
low,high = -(10**5),10**9
for i in range(300):
    anslow,anshigh = 0,0
    for i in range(N):
        anslow += abs(A[i]-(i+low))
        anshigh += abs(A[i]-(i+high))
    if anshigh > anslow:
        high=(high+low)//2
    else:
        low=(high+low)//2
    Ans = min(anshigh,anslow)

print(Ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))

for i in range(N):
    A[i] -= i

A.sort()

Ans = 0
mi = len(A)//2 # 中央値のindex
for i in range(N):
    Ans += abs(A[i]-A[mi])

print(Ans)
### BUGGY CODE ###

import sys
#input = sys.stdin.buffer.readline
 
def main():
    H,W,K = map(int,input().split())
    a = [list(input()) for _ in range(H)]
    
    for i in range(H):
        for j in range(W):
            a[i][j] = int(a[i][j])
    
    ans = 10**6
    for i in range(1<<H-1):
        cut,count = [-1],0
        for j in range(H-1):
            if (i>>j)&1 != 0:
                count += 1
                cut.append(j)
        cut.append(H-1)
        l = len(cut)-1
        use = [[0 for _ in range(W)] for _ in range(l)]
        for x in range(l):
            up,down = cut[x],cut[x+1]
            for y in range(up+1,down+1):
                for z in range(W):
                    use[x][z] += a[y][z]

        bl,yorn = [0 for _ in range(l)],True
        for right in range(W):
            st = [0 for _ in range(l)]
            for x in range(l):
                st[x] += use[x][right]
            if max(st) > K:
                yorn = False
                break
            else:
                for x in range(l):
                    bl[x] += st[x]
                if max(bl) > K:
                    count += 1
                    bl = st
        if yorn:
            ans = min(ans,count)
    
    print(ans)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
#input = sys.stdin.buffer.readline
 
def main():
    H,W,K = map(int,input().split())
    a = S = [list(map(int, list(input()))) for _ in range(H)]
    
    ans = 10**6
    for i in range(1<<H-1):
        cut,count = [-1],0
        for j in range(H-1):
            if (i>>j)&1 != 0:
                count += 1
                cut.append(j)
        cut.append(H-1)
        l = len(cut)-1
        use = [[0 for _ in range(W)] for _ in range(l)]
        for x in range(l):
            up,down = cut[x],cut[x+1]
            for y in range(up+1,down+1):
                for z in range(W):
                    use[x][z] += a[y][z]

        bl,yorn = [0 for _ in range(l)],True
        for right in range(W):
            st = [0 for _ in range(l)]
            for x in range(l):
                st[x] += use[x][right]
            if max(st) > K:
                yorn = False
                break
            else:
                for x in range(l):
                    bl[x] += st[x]
                if max(bl) > K:
                    count += 1
                    bl = st
        if yorn:
            ans = min(ans,count)
    
    print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

s = input()
q = int(input())

rev_s = False
for i in range(q):
   tmp = list(input().split())
   if len(tmp) == 1:
      if rev_s == True:
         rev_s = False
      else:
         rev_s = True
   else:
      f, c = int(tmp[1]), tmp[2]
      if (rev_s == False and f == 1) or (rev_s == True and f == 2):
         s = c + s
      else:
         s = s + c

if rev_s == True:
   print(s[::-1])
else:
   print(s)


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)
### BUGGY CODE ###

def main():
        N = int(input())
        A = list(map(int, input().split()))

        l = []

        for i in range(N-1):
                l.append(A.count(i+1))
                print(l[i])
        l.append(0)
        print(l[N-1])

if __name__=="__main__":
        main()

### FIXED CODE ###

def main():
        N = int(input())
        A = list(map(int, input().split()))

        l = [0]*N

        for a in A:
                l[a-1] += 1

        ans = "\n".join([str(x) for x in l])
        print(ans)

if __name__=="__main__":
        main()
### BUGGY CODE ###

import numpy as np
import collections as col
from collections import defaultdict as dd

d=dd(list)

N,M=map(int, input().split())
p=np.array([-1]*N)
p[0]=1

for _ in range(M):
    i,j=map(int, input().split())
    if i>j:
        i,j=j,i
    d[i].append(j)

for i in d:
    for j in d[i]:
        if p[i-1]==-1:
            if p[j-1]==-1:
                if i<j:
                    p[i-1]=i
                    p[j-1]=i
                else:
                    p[i-1]=j
                    p[j-1]=j
            else:
                p[i-1]=p[j-1]
        else:
            if p[j-1]==-1:
                p[j-1]=p[i-1]
            else:
                if p[i-1]<p[j-1]:
                    temp1=p[j-1]
                    temp2=p[i-1]
                else:
                    temp1=p[j-1]
                    temp2=p[i-1]
                p=[temp2 if k==temp1 else k for k in p]

ans=col.Counter(p)

if ans.most_common()[0][0]==-1:
    print(ans.most_common()[1][1])
else:
    print(ans.most_common()[0][1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def union(a,b):
    a=find(a)
    b=find(b)
    if a==b:
        return
    
    if rank[a]<rank[b]:
        par[a]=b
        rank[b]+=rank[a]
        rank[a]=rank[b]
    else:
        par[b]=a
        rank[a]+=rank[b]
        rank[b]=rank[a]

    return

def chk(a,b):
    if par[a]==par[b]:
        print('Yes')
    else:
        print('No')

    return

N,M=map(int, input().split())

par=(list(range(N+1)))
rank=[1]*(N+1)

for _ in range(M):
    A,B=map(int, input().split())
    union(A,B)

print(max(rank))
### BUGGY CODE ###

from functools import reduce
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
ans = 0
for i in range(N):
  if i < N-1:
    a = A[i]
    A[i] = A[i+1]
  else:
    A[i] = A[0]
  ans = max(ans, reduce(gcd,A))
  A[i] = a
print(ans)

### FIXED CODE ###

import fractions
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i + 1] = (fractions.gcd(left[i],a[i]))
    right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))
ans = 0
for i in range(n):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)
### BUGGY CODE ###

import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
for i in range(m):
    b, c = [int(i) for i in input().split()]
    idx = bisect.bisect_left(a, c)
    
    if idx <= b:
        a[:idx] = [c]*idx
    else:
        a[:b] = [c]*b
        a[:idx] = a[b:idx] + a[:b]

print(sum(a))


### FIXED CODE ###

import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
d = []
cnt = 1
for i in range(n-1):
    if a[i+1] == a[i]:
        cnt += 1
    else:
        d.append([a[i], cnt])
        cnt = 1
d.append([a[n-1], cnt])


for i in range(m):
    b, c = [int(i) for i in input().split()]
    d.append([c, b])
d.sort(reverse=True)
ans = 0
j = 0
for i in range(n):
    if d[j][1] > 0:
        ans += d[j][0]
        d[j][1] -= 1
    if d[j][1] == 0:
        j += 1
print(ans)
### BUGGY CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a.sort()
lmx = len(bin(a[-1])) - 2
cnt = [[0,0] for _ in range(lmx)]
for i in range(n):
    tmp = bin(a[i])[::-1]
    ln = len(tmp)-2
    for j in range(lmx):
        tt = 0
        if j < ln:
            tt = int(tmp[j])
        cnt[j][tt] += 1
# print(cnt)
res = 0
for i,bit in enumerate(cnt):
    x,y = bit
    res += x*y*pow(2,i)
    res %= mod
print(res)

### FIXED CODE ###

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
ln = len(bin(a[-1])) - 2
bit = [defaultdict(int) for i in range(ln)]
res = 0
for i in a:
    tmp = bin(i)
    for _,j in enumerate(tmp[:1:-1]):
        # print(_,j)
        bit[_][j] += 1
# pprint.pprint(bit)
for i,j in enumerate(bit):
    x = j['0']
    y = j['1']
    if x+y < n:
        x = n - y
    # print(i,x,y)
    c = pow(2,i)
    res += x * y * c
    res %= mod
print(res)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())

seg_el=1<<((N+1).bit_length()) # Segment treeの台の要素数

SEG=[N-2]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
SEG2=[N-2]*(2*seg_el)

def getvalue(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG[i],ANS)
        i>>=1

    return ANS

def getvalue2(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG2[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG2[i],ANS)
        i>>=1

    return ANS

def updates(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG[L]=min(x,SEG[L])
            L+=1

        if R & 1:
            R-=1
            SEG[R]=min(x,SEG[R])
        L>>=1
        R>>=1

def updates2(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG2[L]=min(x,SEG2[L])
            L+=1

        if R & 1:
            R-=1
            SEG2[R]=min(x,SEG2[R])
        L>>=1
        R>>=1

ANS=(N-2)*(N-2)

MINX=N
MINY=N

for queries in range(Q):
    t,x=map(int,input().split())

    if t==1:
        v=getvalue(x,seg_el)
        ANS-=v
        updates2(1,MINY,x-2)
        MINX=min(MINX,x)

    else:
        v=getvalue2(x,seg_el)
        ANS-=v
        updates(1,MINX,x-2)
        MINY=min(MINY,x)

print(ANS)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())

seg_el=1<<((N+1).bit_length()) # Segment treeの台の要素数

SEG=[N-2]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
SEG2=[N-2]*(2*seg_el)

def getvalue(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG[i],ANS)
        i>>=1

    return ANS

def getvalue2(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=N-2
    
    ANS=min(SEG2[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG2[i],ANS)
        i>>=1

    return ANS

def updates(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG[L]=min(x,SEG[L])
            L+=1

        if R & 1:
            R-=1
            SEG[R]=min(x,SEG[R])
        L>>=1
        R>>=1

def updates2(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG2[L]=min(x,SEG2[L])
            L+=1

        if R & 1:
            R-=1
            SEG2[R]=min(x,SEG2[R])
        L>>=1
        R>>=1

ANS=(N-2)*(N-2)

MINX=N
MINY=N

for queries in range(Q):
    t,x=map(int,input().split())

    if t==1:
        v=getvalue(x,seg_el)
        ANS-=v
        updates2(1,MINY,x-2)
        MINX=min(MINX,x)

    else:
        v=getvalue2(x,seg_el)
        ANS-=v
        updates(1,MINX,x-2)
        MINY=min(MINY,x)

print(ANS)
### BUGGY CODE ###

from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math


#N,K=map(int,input().split())
N=int(input())
S=input()
Q=int(input())
Query=[input().split() for i in range(Q)]


def segfunc(x,y):
    return (x.union(y))

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,b):
    k += num-1
    if seg[k]==set([b]):
        return ()
    seg[k] = set([b])
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele =set()

#num:n以上の最小の2のべき乗
n=N
num =2**(n-1).bit_length()
seg=[set() for i in range(2*num)]

for i in range(N):
    update(i,S[i])

for type,i,c in Query:

    if type=="1":
        update(int(i)-1,c)
    else:
        print(len(query(int(i)-1,int(c))))
    #print(seg)


### FIXED CODE ###

from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math


#N,K=map(int,input().split())
N=int(input())
S=input()
Q=int(input())
Query=[input().split() for i in range(Q)]

def segfunc(x,y):
    return (x|y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=seg[2*i+1]|seg[2*i+2]

def update(k,b):
    k += num-1
    if seg[k]=={b}:
        return ()
    seg[k] = {b}
    while k:
        k = (k-1)>>1
        seg[k] = seg[k*2+1]|seg[k*2+2]

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=set()
    while q-p>1:
        if p&1 == 0:
            res = res|seg[p]
        if q&1 == 1:
            res = res|seg[q]
            q -= 1
        p = p>>1
        q = (q-1)>>1
    if p == q:
        res = res|seg[p]
    else:
        res = res|seg[p]|seg[q]
    return res

#num:n以上の最小の2のべき乗
n=N
num =2**(n-1).bit_length()
seg=[set()] * (2*num)

for i in range(N):
    seg[i+num-1]={ord(S[i])}
for k in range(num-2,-1,-1):
    seg[k] = seg[k*2+1]|seg[k*2+2]
for type, i, c in Query:
    if type=="1":
        update(int(i)-1,ord(c))
    else:
        print(len(query(int(i)-1,int(c))))
    #print(seg)
### BUGGY CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10**9+7

    A_bin_cnt = [0] * 60
    for i in range(N):
        a = A[i]
        for j in range(60):
            if a >> j & 1:
                A_bin_cnt[j] += 1
    ans = 0
    for i in range(N):
        a = A[i]
        for j in range(60):
            if not a >> j & 1:
                ans = (ans + (pow(2, j, mod) * A_bin_cnt[j]) % mod) % mod
            else:
                ans = (ans + (pow(2, j, mod) * (N - A_bin_cnt[j])) % mod) % mod
    inv2 = pow(2, mod-2, mod)
    print((ans*inv2)%mod)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = list(map(int, input().split()))
    mod = 10**9+7

    A_bin_cnt = [0] * 60
    for i in range(N):
        a = A[i]
        for j in range(60):
            if a >> j & 1:
                A_bin_cnt[j] += 1

    ans = 0
    for i in range(60):
        ans = (ans + (pow(2, i, mod) * (A_bin_cnt[i] * (N - A_bin_cnt[i])))%mod) % mod
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

R,G,B,N=map(int,input().split())
 
ans=0
for r in range(N//R+1):
  for g in range(N//G+1):
    if R*r+G*g>N: continue
    if (N-R*r-G*g)%B!=0: continue
    ans+=1
print(ans)

### FIXED CODE ###

def input_list():
  return list(map(int, input().split()))

def main():
  r, g, b, n = input_list()
  ans = 0
  for x in range(n//r+1):
    for y in range(n//g+1):
      rr = r*x
      gg = g*y
      if rr + gg > n:
        continue
      bb = (n - rr - gg)
      if bb % b != 0:
        continue
      ans += 1
  print(ans)

main()
### BUGGY CODE ###

n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(a[i][0],w+1):
		z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])


### FIXED CODE ###

n,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(n)]
z=[[0]*(w+1)]
for i in xrange(n):
    z.append(z[-1][:])
    for j in xrange(w+1):
        if a[i][0]<=j:
            z[i+1][j]=max(z[i+1][j],z[i][j-a[i][0]]+a[i][1])
print max(z[-1])