Problem:
Score : 400 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

You are given a permutation p of the set {1, 2, ..., N}. Please construct two sequences of positive integers a_1, a_2, ..., a_N and b_1, b_2, ..., b_N satisfying the following conditions:

1 \leq a_i, b_i \leq 10^9 for all i

a_1 < a_2 < ... < a_N

b_1 > b_2 > ... > b_N

a_{p_1}+b_{p_1} < a_{p_2}+b_{p_2} < ... < a_{p_N}+b_{p_N}

Constraints

2 \leq N \leq 20,000

p is a permutation of the set {1, 2, ..., N}

Input

The input is given from Standard Input in the following format:

N
p_1 p_2 ... p_N

Output

The output consists of two lines. The first line contains a_1, a_2, ..., a_N seperated by a space. The second line contains b_1, b_2, ..., b_N seperated by a space.

It can be shown that there always exists a solution for any input satisfying the constraints.

Sample Input 1

2
1 2

Sample Output 1

1 4
5 4

a_1 + b_1 = 6 and a_2 + b_2 = 8. So this output satisfies all conditions.

Sample Input 2

3
3 2 1

Sample Output 2

1 2 3
5 3 1

Sample Input 3

3
2 3 1

Sample Output 3

5 10 100
100 10 1

Solution in Ruby (2.3.3) (judge verdict: Wrong Answer)


n = gets.chomp.to_i

p = gets.chomp.split(" ").map(&:to_i).map{|t| t-1}

a = [*1..n]
b = a.reverse
#c = Array.new(n, 0)
d = Array.new(n, 0)
=begin
crt = 0
p.each_with_index do |k,i|
  #p a[k]+b[k]
  if crt >= a[k] + b[k]
    c[k] = crt + 1 - (a[k] + b[k])
    crt += 1
  else
  crt = a[k]+b[k]
  end 
end
=end
sep = n#(c.size+1)/2
#c[0]
d[p[0]] = 1
a[p[0]] = sep
b[p[0]] = sep
#p p

crt = sep*2
p[1..-1].each_with_index do |k, i|
  if k != 0 && d[k-1]==1# > sep
  a[k] = a[k-1]+2# + i
  b[k] = b[k-1]-1
  d[k] = 1
  akmin = crt + 1 - (b[k]) 
  a[k] = akmin if a[k] < akmin
  #elsif k==sep
  else
  a[k] = a[k+1]-1
  b[k] = b[k+1]+2 #+ i
  #b[k] += i+1
  d[k] = 1
  akmin = crt + 1 - (a[k]) 
  b[k] = akmin if b[k] < akmin
  end
  crt = a[k]+b[k]
end

=begin
k=Array.new(c.size)
k[0]=c[0]
for i in 1..c.size-1
  k[i] = k[i-1]+c[i]
end
p k

carry = 0

c[sep+1..-1].each_with_index do |k, i|
  if k > 0
  carry = carry + k#[carry, k].max
  a[sep+1+i] += carry
  else
  a[sep+1+i] += carry
  end
end
carry = 0

c[0..sep].reverse.each_with_index do |k, i|
  #puts [k,i]

#c.reverse.each_with_index do |k, i|
  if k > 0
  carry = [carry, k].max
  b[sep-i] += carry
  else
  b[sep-i] += carry
  end
end
=begin
p.each_cons(2).with_index do |t,i|
p t
if t[0]<t[1]
  a[t[1]] += k[t[1]]#] += 
else
  b[t[1]] += k[t[1]]#] #-=i
end
end
#a[-1] += c[-1]
=end
puts a.join(" ")
puts b.join(" ")