import Control.Applicative ((<$>), (<*>)) import Control.Monad (replicateM) import Data.List (foldl', intercalate) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List (unfoldr) import Data.Char (isSpace) main :: IO () main = do [n, k, x] <- f solve n <$> replicateM (x-1) f <*> (getLine >> replicateM (k-x) f) <*> f >>= putStrLn where f = readil B.readInt <$> B.getLine solve :: Int -> [[Int]] -> [[Int]] -> [Int] -> String solve n hs ts cs = intercalate " " . map show . foldr g [] $ zip3 [1..n] nhs nts where swp ls ss = foldl' f ls ss where f ls [i, j] = let (us, (v:vs)) = splitAt (i-1) ls (vs', (w:ws)) = splitAt (j-i-1) vs in us ++ (w:vs') ++ (v:ws) nhs = swp [1..n] hs nts = swp cs (reverse ts) g (i, x, y) ls | x == y = ls | otherwise = i:ls readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')