{-# LANGUAGE BangPatterns #-}
import Control.Arrow
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

unew :: VUM.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.new n

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

umodify :: VUM.Unbox a => Int -> (a -> a) -> VUM.IOVector a -> VUM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VUM.unsafeModify v f i >> return v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uset :: VUM.Unbox a => a -> VUM.IOVector a -> VUM.IOVector a
uset !a !v = accursedUnutterablePerformIO $ VUM.set v a >> return v

solve :: Int -> VU.Vector Int -> (VU.Vector Int, VU.Vector Int)
solve !n !pn = (\(x, y, _) -> (ufreeze x, ufreeze y)) $ VU.foldl'
  (\(!an, !bn, !pj) !pi -> case () of
    () | pj == 0 -> (an, bn, pi)
    () | pj < pi ->
      let !d   = uread pj bn - uread pi bn + uread pj an
          !an' = uwrite pi (d + 1) an
      in  (an', bn, pi)
    () | pj > pi ->
      let !d   = uread pj an - uread pi an + uread pj bn
          !bn' = uwrite pi (d + 1) bn
      in  (an, bn', pi)
  )
  (uthaw $ VU.replicate n 0, uthaw $ VU.replicate n 0, 0)
  (VU.map (\n -> n - 1) pn)

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 ""
