
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
sum = 0
b = a

while(len(a) > 1):
    a = np.delete(a, -1)
    b = np.delete(b, 0)
    sum += np.sum(a^b)

print(int(sum % (1E9 + 7)))
