let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.to_list @@ Array.init n @@ fun _ ->
    Scanf.scanf "%d\n" @@ fun a -> a in
  let bs = Array.to_list @@ Array.init n @@ fun _ ->
    Scanf.scanf "%d\n" @@ fun b -> b in
  List.map (fun a -> (true, a)) as_ @ List.map (fun b -> (false, b)) bs
  |> List.sort (fun (_, a) (_, b) -> compare a b)
  |> List.map fst
  |> List.fold_left (fun (acc, s) b ->
      match s with
      | None -> (acc, Some (b, 1))
      | Some (b', n) ->
          if b = b' then (acc, Some (b', n + 1))
          else (acc * n mod 1000000007, if n = 1 then None else Some (b', n - 1))) (1, None)
  |> fst
  |> Printf.printf "%d\n"
