import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bool (bool)
import Data.List (unfoldr, transpose)
import Data.Bits

main :: IO ()
main = do
  n <- unsafeSignedDecimal <$> T.getLine :: IO Int
  as <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print . h . take 60 . map (uncurry (*) . g) . transpose . map f $ as
  where
    h :: [Int] -> Int
    h = foldr step 0
      where
        step k l = (k + 2 * l) `mod` modulus
    
    g :: [Bool] -> (Int, Int)
    g = foldl step (0, 0)
      where
        step (cf, ct) = bool (succ cf, ct) (cf, succ ct)
    
    f :: Int -> [Bool]
    f = unfoldr next
      where
        next k = Just (testBit k 0, shiftR k 1)
    
    modulus :: Int
    modulus = 10 ^ 9 + 7
    
    unsafeSignedDecimal :: T.Text -> Int
    unsafeSignedDecimal s = case T.signed T.decimal s of
      Right (n, _) -> n
