import Control.Applicative
import Control.Monad
import Data.Functor
import Data.List

insertList :: (Ord a) => [a] -> a -> [a]
insertList [] a = [a]
insertList xxs@(x:xs) a
  | a < x = a : xxs
  | otherwise = x : insertList xs a


f xs = tail $ zipWith (++) (scanl insertList [] xs) (scanr (:) [] xs)

main = getLine >> map (read :: String -> Int) . words <$> getLine >>= putStr . unlines . map (unwords . map show) . f
