import Control.Applicative

main :: IO ()
main = do
    getLine
    (x:xs) <- map read . words <$> getLine
    mapM_ putStrLn $ solve xs [x]

solve :: [Int] -> [Int] -> [String]
solve [] ls = [unwords $ map show ls]
solve xs'@(x:xs) ls = stringify:(solve xs ls')
    where
        stringify = unwords $ map show $ ls ++ xs'
        ls' = [ a | a <- ls, a <= x ] ++ [x] ++ [ a | a <- ls, a > x ]