import Data.Char
import Data.List
import Data.Bits
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  n <- head.parseLine <$> BS.getLine
  as <- parseLine <$> BS.getLine
  print $ solve n as
  where
    parseLine = unfoldr (BS.readInt . BS.dropWhile isSpace)

divValue :: Int
divValue = 10^9 + 7

solve :: Int -> [Int] -> Int
solve n as = (`mod` divValue) . (calcResults n) . aggregateBits $ as

aggregateBits :: [Int] -> [Int]
aggregateBits as = map (countBits as) [0..(bitLength as-1)] 

bitLength :: [Int] -> Int
bitLength as = finiteBitSize (maximum as) - countLeadingZeros (maximum as)

countBits :: [Int] -> Int -> Int
countBits as d = length . filter (flip testBit d) $ as

calcResults :: Int -> [Int] -> Int
calcResults n = sum . zipWith calcDigitValue [0..] 
  where
    calcDigitValue d x = (2^d `mod` divValue) * x * (n-x)