;; D - Xor Sum 4

(defparameter *modulus* (+ (expt 10 9) 7))

(defun main ()
  (let* ((N (read))
         (A (loop repeat N collect (read))))
    (print (solve N A))
    (fresh-line)))

(defun solve (N A)
  (reduce #'(lambda (l h) (mod (+ l (ash h 1)) *modulus*))
    ; 2進各桁のXORの総和 (= 1の個数 * 0の個数)
    (mapcar #'(lambda (m) (* m (- N m)))
      ; ベクトル和 (2進各桁の1の個数)
      (reduce #'(lambda (l1 l2) (mapcar-longer #'+ l1 l2))
        ; 各数を2進各桁のリスト (最下位が前) に変換
        (mapcar #'to-binary-list A)))
    :from-end t))

(defun mapcar-longer (f l1 l2)
  "(mapcar f l1 l2)と同様だが, 一方が短ければ長い方の要素をそのまま残す"
  (cond ((null l1) l2)
        ((null l2) l1)
        (t (cons (funcall f (car l1) (car l2))
                 (mapcar-longer f (cdr l1) (cdr l2))))))

(defun to-binary-list (n)
  "整数nを2進各桁のリスト (最下位が前) に変換"
  (when (> n 0)
    (cons (mod n 2) (to-binary-list (ash n -1)))))

(main)
