import Control.Applicative ((<$>), (<*>)) import Control.Monad (replicateM) import Data.List (foldl', intercalate) main :: IO () main = do [n, k, x] <- f solve n <$> replicateM (x-1) f <*> (getLine >> replicateM (k-x) f) <*> f >>= putStrLn where f = map read <$> words <$> 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