Scanf.scanf "%d" (fun n ->
    let a = Array.make (n + 1) 0 in
    let b = Array.make (n + 1) 0 in
    let module S = Set.Make (struct type t = int * int let compare = compare end) in
    for i = 1 to n do Scanf.scanf " %d" (fun j -> a.(j) <- a.(j) + 1) done;
    for i = 1 to n do Scanf.scanf " %d" (fun j -> b.(j) <- b.(j) + 1) done;

    let rec loop arr i acc =
        if i > n then acc else
            let acc = if arr.(i) = 0 then acc else S.add (arr.(i), i) acc in
            loop arr (i + 1) acc
    in
    let src = loop a 1 S.empty in
    let dst = loop b 1 S.empty in

    let result = Array.make (n + 1) [] in
    let rec loop src dst rest =
        if rest = 0 then true else (
            let ((count, v) as m) = S.max_elt src in
            let src = S.remove m src in

            let ((cdst, vd) as m) = S.max_elt dst in
            let dst2 = S.remove m dst in

            if v <> vd then (
                let k = min count cdst in
                result.(v) <- (vd, k) :: result.(v);
                let src = if k = count then src  else S.add (count - k,  v) src in
                let dst = if k = cdst  then dst2 else S.add (cdst  - k, vd) dst2 in
                loop src dst (rest - k)
            ) else (
                if S.is_empty dst2 then false else (
                    let ((cdst, vd) as m) = S.max_elt dst2 in
                    let dst = S.remove m dst in
                    let k = min count cdst in
                    result.(v) <- (vd, k) :: result.(v);
                    let src = if k = count then src else S.add (count - k,  v) src in
                    let dst = if k = cdst  then dst else S.add (cdst  - k, vd) dst in
                    loop src dst (rest - k)
                )
            )
        )
    in
    if loop src dst n then (
        print_endline "Yes";
        for i = 1 to n do
            List.iter (fun (v, count) ->
                for j = 1 to count do Printf.printf "%d " v done) result.(i)
        done;
        print_newline ()
    ) else print_endline "No"
)