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 Python (3.8.2) (judge verdict: Time Limit Exceeded)

import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


class LazySegTree:
    X_unit = 0
    A_unit = 0

    @classmethod
    def X_f(cls, x, y):
        return max(x, y)

    @classmethod
    def A_f(cls, x, y):
        return x + y

    @classmethod
    def operate(cls, x, a):
        return x + a

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)
        self.A = [self.A_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def _eval_at(self, i):
        return self.operate(self.X[i], self.A[i])

    def _propagate_at(self, i):
        self.X[i] = self._eval_at(i)
        self.A[i << 1] = self.A_f(self.A[i << 1], self.A[i])
        self.A[i << 1 | 1] = self.A_f(self.A[i << 1 | 1], self.A[i])
        self.A[i] = self.A_unit

    def _propagate_above(self, i):
        H = i.bit_length() - 1
        for h in range(H, 0, -1):
            self._propagate_at(i >> h)

    def _recalc_above(self, i):
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self._eval_at(i << 1), self._eval_at(i << 1 | 1))

    def set_val(self, i, x):
        i += self.N
        self._propagate_above(i)
        self.X[i] = x
        self.A[i] = self.A_unit
        self._recalc_above(i)

    def __getitem__(self, i):
        return self.fold(i, i + 1)

    def fold(self, L, R):
        L += self.N
        R += self.N
        self._propagate_above(L // (L & -L))
        self._propagate_above(R // (R & -R) - 1)
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self._eval_at(L))
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self._eval_at(R), vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)

    def operate_range(self, L, R, x):
        L += self.N
        R += self.N
        L0 = L // (L & -L)
        R0 = R // (R & -R) - 1
        self._propagate_above(L0)
        self._propagate_above(R0)
        while L < R:
            if L & 1:
                self.A[L] = self.A_f(self.A[L], x)
                L += 1
            if R & 1:
                R -= 1
                self.A[R] = self.A_f(self.A[R], x)
            L >>= 1
            R >>= 1
        self._recalc_above(L0)
        self._recalc_above(R0)


N = ini()
P = [x - 1 for x in inl()]
assert len(P) == N


def solve():
    A = LazySegTree(N)
    A.build(range(1, N + 1))
    B = LazySegTree(N)
    B.build(range(10 ** 9 - 1, 10 ** 9 - N - 1, -1))
    prev = 0
    for p in P:
        a = A[p]
        b = B[p]
        v = a + b
        if v <= prev:
            delta = prev - v + 1
            A.operate_range(p, N, delta)
            B.operate_range(p + 1, N, -delta)
            prev = v + delta
        else:
            prev = v
    print(*[A[i] for i in range(N)])
    print(*[B[i] for i in range(N)])


solve()