import Data.List
main = do
  n <- getLine
  list <- getLine
  putStrLn $ solve list

solve :: String -> String
solve = unwords . map show . (\ws -> [head ws, last ws, sum ws]) . sort . map (read :: String -> Int) . words