{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

solve :: Int -> VU.Vector Int -> (VU.Vector Int, VU.Vector Int)
solve !n !pn = accursedUnutterablePerformIO $ do
  an <- VU.thaw $ VU.fromList [1 .. n]
  bn <- VU.thaw $ VU.reverse $ VU.fromList [1 .. n]

  _  <- VU.foldM'
    (\(!pj) (!pi) -> case () of
      () | pj == -1 -> return pi
      () | pj < pi  -> do
        d <- liftM3 (\x y z -> x - y + z)
                    (VUM.read bn pj)
                    (VUM.read bn pi)
                    (VUM.read an pj)
        VUM.write an pi (d + 1)

        return pi
      () | pj > pi -> do
        d <- liftM3 (\x y z -> x - y + z)
                    (VUM.read an pj)
                    (VUM.read an pi)
                    (VUM.read bn pj)
        VUM.write bn pi (d + 1)

        return pi
    )
    (-1)
    (VU.map (\n -> n - 1) pn)

  (,) <$> VU.freeze an <*> VU.freeze bn

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  pn <- VU.unfoldrN n readInt <$> B.getLine
  let (an, bn) = solve n pn
  VU.forM_ an $ \i -> do
    putStr $ show i
    putStr " "
  putStrLn ""

  VU.forM_ bn $ \i -> do
    putStr $ show i
    putStr " "
  putStrLn ""
