import           Control.Monad
import           Data.List

-- main :: IO ()
-- main = do
--   n <- readLn :: IO Integer
--   s <- map read . words <$> getLine :: IO [Integer]
--   print $ sol s

-- sol (x:xs) = go x xs 0
--   where go _ [] n = n
--         go m (x:xs) n =
--           let newMax = min m x in
--             go newMin xs (n + m)

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  xs <- sort . map read . words <$> getLine :: IO [Integer]
  print $ (maximum $ map product $ foo xs k) `mod` (10^9 + 7)

foo xs k = map (take k) $ go xs
  where go :: [Integer] -> [[Integer]]
        go []       = [xs]
        go a@(_:ys) = (a ++ xs) : go ys

