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
  |> (fun (b :: bs) ->
      List.fold_left (fun (b', (acc, curr)) b ->
        b,
        if b = b'
        then (acc, curr + 1)
        else (curr :: acc, 1)) (b, ([], 1)) bs)
  |> (fun (_, (acc, curr)) -> curr :: acc)
  |> (fun (n :: ns) ->
      List.fold_left (fun (b, (b', curr, acc)) n ->
        not b,
        if b = b'
        then (b', curr + n, acc)
        else if curr < n
        then (b, n - curr, acc * curr mod 1000000007)
        else (b', curr - n, acc * n mod 1000000007)) (true, (false, n, 1)) ns)
  |> (fun (_, (_, _, acc)) -> acc)
  |> Printf.printf "%d\n"
