let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let ps = Array.init n (fun _ -> Scanf.scanf "%d " (fun p -> p - 1)) in
  let das = Array.init n (fun _ -> 1) in
  let dbs = Array.init n (fun _ -> -1) in
  Array.iteri (fun i p ->
    das.(p) <- das.(p) + i + 1;
    dbs.(p) <- dbs.(p) - i - 1) ps;
  let (a :: as_) =
    Array.fold_left (fun (a, as_) da -> (da + a, da + a :: as_)) (1, []) das
      |> snd
      |> List.rev in
  Printf.printf "%d" a;
  List.iter (Printf.printf " %d") as_;
  print_newline ();
  let (b :: bs) =
    Array.fold_left (fun (b, bs) db -> (db + b, b :: bs)) (1000000000, []) dbs
      |> snd
      |> List.rev in
  Printf.printf "%d" b;
  List.iter (Printf.printf " %d") bs;
  print_newline ()
