• + 1 comment

    f# solution

    open System
    
    let rec find res left right =
        match (left, right) with
        | ([], rs) -> [ List.rev res; []; rs ]
        | (ls, []) -> [ List.rev res; ls; [] ]
        | (l :: ls, r :: rs) when l = r -> find (l :: res) ls rs
        | (l :: _, r :: _) when l <> r ->
            [ List.rev res; left; right ]
    
    [<EntryPoint>]
    let main _ =
        let left = Console.ReadLine() |> Seq.map string |> List.ofSeq
        let righ = Console.ReadLine() |> Seq.map string |> List.ofSeq
    
        find [] left righ
        |> List.map (fun results ->
            (results |> List.length |> string)
            + " "
            + (results |> String.concat ""))
        |> List.map Console.WriteLine
    
        0