import Data.List main = interact $ unlines . solve . words solve :: [String] -> [String] solve (x:xs) = (show m) : xxs where n = (read :: String -> Int) x ys = intersect (take n xs) (drop n xs) zs = union (take n xs) (drop n xs) xxs = zs \\ ys m = find' (xxs !! 0) xs find' :: String -> [String] -> Int find' s [x] = 1 find' s (x:xs) = if s == x then 1 else 1 + (find' s xs)