import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    ps <- getIntList
    qs <- getIntList
    let as = sort $ permutations [1..n]
    let p = fromJust $ elemIndex ps as
    let q = fromJust $ elemIndex qs as
    putStr . show $ p + 1
    putStr " "
    putStrLn . show $ q + 1