main = do
  _ <- getLine
  ps <- fmap (map read . words) getLine
  putStrLn . unwords . map show $ analyze ps

analyze :: [Int] -> [Int]
analyze [] = []
analyze us = let (ts,(u,v)) = minimum [ (analyze s, t) | (s,t) <- cuts us] in ts++[u,v]

cuts :: [a] -> [([a],(a,a))]
cuts [x,y] = [([],(x,y))]
cuts (x:y:zs) = (zs,(x,y)) : map f (cuts (y:zs))
 where f (arr,u) = (x:arr,u) 