Problem:
 Score : 400 points    Problem Statement  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 (Python):
import sys
input = sys.stdin.readline

N = int(input())
P = list(map(int,input().split()))
P = [p-1 for p in P]

class SegmentTree:
  def __init__(self, n, e):
    self.n = n
    self.e = e
    self.size = 2 ** ((n - 1).bit_length())
    self.node = [self.e] * (2 * self.size)
 
  def build(self, array):
    for i in range(self.n):
      self.node[self.size + i] = array[i]
 
  def get(self, i):
    i += self.size
    ret = self.node[i]
    while i > 1:
      i >>= 1
      ret += self.node[i]
    return ret
 
  def add(self, l, r, val):
    l, r = l + self.size, r + self.size
    while l < r:
      if l & 1:
        self.node[l] += val
        l += 1
      if r & 1:
        r -= 1
        self.node[r] += val
      l, r = l >> 1, r >> 1
      
STA = SegmentTree(N,0)
STB = SegmentTree(N,0)

STA.build(list(range(N)))
STB.build(list(range(N)[::-1]))

prev = P[0]
for p in P[1:]:
  toadd = (STA.get(prev)+STB.get(prev)) - (STA.get(p)+STB.get(p)) + 1
  toadd = max(0,toadd)
  if p>prev:
    STA.add(p,N,toadd)
    if p+1 <= N-1:
      STB.add(p+1,N,-toadd)
  else:
    STB.add(0,p+1,toadd)
    if p >= 1:
      STA.add(0,p,-toadd)
  prev = p
  
ansa = [STA.get(i) for i in range(N)]
ansb = [STB.get(i) for i in range(N)]

mina = min(ansa)
minb = min(ansb)

ansa = [i-mina+1 for i in ansa]
ansb = [i-minb+1 for i in ansb]

print(*ansa)
print(*ansb)

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
P = list(map(int,input().split()))

class SegmentTree:
  def __init__(self, n, e):
    self.n = n
    self.e = e
    self.size = 2 ** ((n - 1).bit_length())
    self.node = [self.e] * (2 * self.size)
 
  def build(self, array):
    for i in range(self.n):
      self.node[self.size + i] = array[i]
 
  def get(self, i):
    i += self.size
    ret = self.node[i]
    while i > 1:
      i >>= 1
      ret += self.node[i]
    return ret
 
  def add(self, l, r, val):
    l, r = l + self.size, r + self.size
    while l < r:
      if l & 1:
        self.node[l] += val
        l += 1
      if r & 1:
        r -= 1
        self.node[r] += val
      l, r = l >> 1, r >> 1
      
STA = SegmentTree(N,0)
STB = SegmentTree(N,0)

STA.build(list(range(N)))
STB.build(list(range(N)[::-1]))

prev = P[0]-1
for p in P[1:]:
  p -= 1
  toadd = (STA.get(prev)+STB.get(prev)) - (STA.get(p)+STB.get(p)) + 1
  toadd = max(0,toadd)
  if p>prev:
    STA.add(p,N,toadd)
    if p+1 <= N-1:
      STB.add(p+1,N,-toadd)
  else:
    STB.add(0,p+1,toadd)
    if p >= 1:
      STA.add(0,p,-toadd)
  prev = p
  
ansa = [STA.get(i) for i in range(N)]
ansb = [STB.get(i) for i in range(N)]

mina = min(ansa)
minb = min(ansb)

ansa = [i-mina+1 for i in ansa]
ansb = [i-minb+1 for i in ansb]

print(*ansa)
print(*ansb)

Solution (Python):






import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]



def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
P = IL()

P = [p-1 for p in P]

class SegmentTree:
  def __init__(self, n, e):
    self.n = n
    self.e = e
    self.size = 2 ** ((n - 1).bit_length())
    self.node = [self.e] * (2 * self.size)
 
  def build(self, array):
    for i in range(self.n):
      self.node[self.size + i] = array[i]
 
  def get(self, i):
    i += self.size
    ret = self.node[i]
    while i > 1:
      i >>= 1
      ret += self.node[i]
    return ret
 
  def add(self, l, r, val):
    l, r = l + self.size, r + self.size
    while l < r:
      if l & 1:
        self.node[l] += val
        l += 1
      if r & 1:
        r -= 1
        self.node[r] += val
      l, r = l >> 1, r >> 1
      
STA = SegmentTree(N,0)
STB = SegmentTree(N,0)

STA.build(list(range(N)))
STB.build(list(range(N)[::-1]))

prev = P[0]
for p in P[1:]:
  toadd = (STA.get(prev)+STB.get(prev)) - (STA.get(p)+STB.get(p)) + 1
  toadd = max(0,toadd)
  if p>prev:
    STA.add(p,N,toadd)
    if p+1 <= N-1:
      STB.add(p+1,N,-toadd)
  else:
    STB.add(0,p+1,toadd)
    if p >= 1:
      STA.add(0,p,-toadd)
  prev = p
  
ansa = [STA.get(i) for i in range(N)]
ansb = [STB.get(i) for i in range(N)]

mina = min(ansa)
minb = min(ansb)

ansa = [i-mina+1 for i in ansa]
ansb = [i-minb+1 for i in ansb]

print(*ansa)
print(*ansb)
"""
wa = [ansa[i]+ansb[i] for i in range(N)]
wasort = [wa[P[i]] for i in range(N)]
for i in range(N-1):
  if ansa[i] > ansa[i+1]:
    exit()
  if ansb[i] < ansb[i+1]:
    exit()
  if wasort[i] > wasort[i+1]:
    exit()

print(*wasort)
"""

Solution (Python):
import sys
input = sys.stdin.buffer.readline

MOD = int(1e9 + 7)  
INF = int(8e18)

in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]


def main():

    N = in_n()
    p = list(in_nn())
    p = [x - 1 for x in p]

    A = [i * 20000 + 1 for i in range(N)]
    B = [-1] * N

    B[p[0]] = 1
    now = A[p[0]] + B[p[0]]

    for i in range(1, N):
        ind = p[i]
        B[ind] = now + 1 - A[ind]
        now += 1

    if min(B) <= 0:
        p = abs(min(B)) + 1
        for i in range(N):
            B[i] += p

    print(*A)
    print(*B)


if __name__ == '__main__':
    main()

Solution (Python):





n = int(input())
indices = list(map(int, input().split()))

a_diff = [1] * n 
b_diff = [-1] * n

for plus, idx in enumerate(indices):
    idx -= 1
    a_diff[idx] += plus
    

    b_diff[0] += plus
    if idx +1 < n:
        b_diff[idx+1] -= plus

a = []
now = 1
for i in range(n):
    now += a_diff[i]
    a.append(now)

b = []
now = n+1
for i in range(n):
    now += b_diff[i]
    b.append(now)

print(' '.join(map(str, a)))
print(' '.join(map(str, b)))

Solution (Python):
N = int(input())
p = list(map(int, input().split()))

A = [0] * N
B = [N * (N + 1) // 2] * N

for i in range(N):
  A[p[i] - 1] += i + 1

cnt = A[0]
A[0] = 1
for i in range(1, N):
  B[i] -= cnt
  cnt += A[i]
  A[i] += A[i - 1]

print(" ".join(list(map(str, A))))
print(" ".join(list(map(str, B))))

Solution (Python):
n = int(input())
p = list(map(int,input().split()))

a = [10**8+i*n for i in range(n)]
b = a[::-1]
for i in range(n):
    a[p[i]-1] += i
    b[p[i]-1] += i
print(*a)
print(*b)

Solution (Python):
N = int(input())
P = list(map(int, input().split()))
A, B = [], []
R = 2*10**4 + 1
for i in range(N):
    A.append(1+R*i)
    B.append(10**9-R*i)
for i, p in enumerate(P):
    p -= 1
    A[p] += i
print(*A)
print(*B)

Solution (Python):

def solve(P):
    N = len(P)
    s = N+1

    A = [s*i+1 for i in range(N)]
    B = [s*i+1 for i in reversed(range(N))]

    for i,p in enumerate(P):
        A[p-1] += i

    return A,B


if __name__ == '__main__':
    N = int(input())
    P = list(map(int,input().split()))

    a,b = solve(P)
    print(*a)
    print(*b)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    P = list(map(int, input().split()))
    MAX = 10 ** 9 - n
    A = list(range(1, MAX + 2, MAX // (n - 1)))
    T = list(range(1, n + 1))
    B = [0] * n
    for i in range(n):
        idx = P[i] - 1
        B[idx] = T[i] - A[idx]
    mi = min(B)
    if mi <= 0:
        d = mi * -1 + 1
        B = [b + d for b in B]
    print(*A)
    print(*B)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    p = list(map(int, input().split()))
    
    a = [(int(x)+1)*20000 for x in range(n)]
    b = [int(x)*20000 for x in range(n, 0, -1)]
    
    for i in range(n):
        v = p[i]-1
        a[v] += i+1
        b[v] += i+1
        
    print(*a)
    print(*b)
    
    
    
if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    p = list(map(int, input().split()))
    
    a = [(int(x)+1)*30000 for x in range(n)]
    b = [int(x)*30000 for x in range(n, 0, -1)]
    
    for i in range(n):
        v = p[i]-1
        a[v] += i+1
        b[v] += i+1
        
    print(*a)
    print(*b)
    
    
    
if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
P=list(map(int, input().split()))
A,B=[0]*N,[0]*N

for i in range(N):
  A[i]=20001*(i+2)
  B[i]=20001*(N-i)
for i in range(N):
  a=P[i]-1
  A[a]+=i
print(*A)
print(*B)

Solution (Python):
N = int(input())
ps = list(map(int, input().split()))

As = [45000 * (i+1) for i in range(N)]
Bs = list(reversed(As))

for i, p in enumerate(ps):
    As[p-1] += i
    Bs[p-1] += i

print(*As)
print(*Bs)

Solution (Python):
def main():
    N = int(input())
    P = list(map(lambda x: int(x) - 1, input().split()))
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    A, B = list(range(1, N + 1)), list(range(N, 0, -1))
    
    imos_a, imos_b = [0] * N, [0] * N
    for i, p in enumerate(P):
        d = N - i
        if p < N - 1:
            imos_a[p + 1] += d
        if p > 0:
            imos_b[p - 1] += d
    for i in range(1, N):
        imos_a[i] += imos_a[i - 1]
        j = N - i - 1
        imos_b[j] += imos_b[j + 1]
    for i in range(N):
        A[i] += imos_a[i]
        B[i] += imos_b[i]
    print(' '.join(map(str, A)))
    print(' '.join(map(str, B)))


if __name__ == '__main__':
    main()

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
p=list(map(int,input().split()))

alst=[]
blst=[]
for i in range(n):
    alst.append(30000*i+1)
    blst.append(30000*(n-i-1)+1)
for i in range(n):
    blst[p[i]-1]+=i
print(*alst)
print(*blst)

Solution (Python):
N = int(input())
P = list(map(int,input().split()))

A = [N*i for i in range(1,N+1)]
B = [N*i for i in reversed(range(1,N+1))]
for i,p in enumerate(P):
    A[p-1] += i

print(*A)
print(*B)

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
q=[0 for i in range(n)]
for i in range(n):
  q[p[i]-1]=i+1
a=[i*n+q[i] for i in range(n)]
b=[(n-i-1)*n+q[i] for i in range(n)]
sa=""
sb=""
for i in range(n):
  sa+=str(a[i])+" "
  sb+=str(b[i])+" "
print(sa)
print(sb)

Solution (Python):
def main():
    n = int(input())
    p = list(map(int, input().split()))
    a = [0]*n
    b = [0]*n
    for i, v in enumerate(p):
        x, y = i+1, v-1
        a[y] += x
        b[y] += x
    for i in range(n-1):
        a[i+1] += a[i]
    for i in reversed(range(1, n)):
        b[i-1] += b[i]
    for v in a:
        print(v, end=" ")
    print()
    for v in b:
        print(v, end=" ")

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
a = list(range(20000, (n + 1) * 20000, 20000))
b = a[::-1]
for i in range(len(p)):
	a[p[i] - 1] -= n - i - 1
print(*a)
print(*b)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
a = list(range(20000, (n + 1) * 20000, 20000))
b = a[::-1]
for i in range(len(p)):
	a[p[i] - 1] -= n - i - 1
for i in a:
	print(i, end=" ")
print()
for i in b:
	print(i, end=" ")
print()

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
a=[1]*(n+1)
b=[1]*(n+1)
a[0],b[n]=0,0
for i in range(n):
  a[p[i]]=i+1
  b[p[i]-1]=i+1
for i in range(n):
  a[i+1]+=a[i]
  b[n-1-i]+=b[n-i]
print(*a[1:])
print(*b[:n])

Solution (Python):
class BinaryIndexedTree:  
    """
    init(n):     要素数nを与えて0で初期化
    add(i, x):   i番目の値にxを追加 O(logN)
    sum(i):      区間[0,i)の和を返す O(logN)
    query(l, r): 区間[l,r)の和を返す O(logN)
    """

    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)  

    def add(self, i, x):  
        i += 1  
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):  
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def query(self, l, r):  
        return self.sum(r) - self.sum(l)



n = int(input())
P = list(int(x) - 1 for x in input().split())

bit_a = BinaryIndexedTree(n)
bit_b = BinaryIndexedTree(n)
for i in range(n):
    bit_a.add(i, 1)
    bit_b.add(i, 1)
for i in reversed(range(n)):
    bit_a.add(P[i], i)
    bit_b.add(n - P[i] - 1, i)

A = []
B = []
for i in range(n):
    A.append(bit_a.sum(i + 1))
    B.append(bit_b.sum(i + 1))

print(*A)
print(*reversed(B))

Solution (Python):
n=int(input())
p=list(map(int,input().split()))
d={x-1:i+1 for i,x in enumerate(p)}
a=[30000*i for i in range(1,n+1)]
b=[30000*(n-i)+d[i] for i in range(n)]
print(' '.join(map(str,a)))
print(' '.join(map(str,b)))

Solution (Python):
N=int(input())
p=list(map(int,input().split()))

ss=[1]*(N+1)
ss2=[-1]*(N+1)
ss[0]=0
ss2[0]=0
for i,x in enumerate(p[1:]):
  x-=1
  ss[x]+=i+1
  ss2[x+1]-=i+1

ac=[0]*(N+1)
ac2=[0]*(N+1)
ac[0]=1
ac2[0]=N**2
for i in range(N):
  ac[i+1]=ac[i]+ss[i]
  ac2[i+1]=ac2[i]+ss2[i]
print(*ac[1:])
print(*ac2[1:])

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
l = [0] * n
for i in range(n):
    l[p[i] - 1] = i
a = [3 * 10 ** 4 * (i + 1) for i in range(n)]
b = [3 * 10 ** 4 * (n - i) + l[i] for i in range(n)]
print(*a)
print(*b)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    p = list(map(int, readline().split()))
    a = [0] * n
    b = [0] * n

    for i, x in enumerate(p):
        y = p[i] - 1
        a[y] = (y + 1) * (4 * 10 ** 4) + i
        b[y] = (n - y) * (4 * 10 ** 4)

    print(*a)
    print(*b)


if __name__ == '__main__':
    main()

Solution (Python):
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()

Solution (Python):
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N = I()
    P = LI()
    O_ = [-1]*N
    start = P[0]-1
    for i in range(N):
        O_[P[i]-1] = i
    
    A = [1]*N
    B = [1]*N
    for i in range(start+1,N):
        cur = O_[i]-O_[i-1]
        if cur>0:
            A[i] = A[i-1] + (cur+1)
            B[i] = B[i-1] - 1
        else:
            A[i] = A[i-1] + 1
            B[i] = B[i-1] - (-cur+1)
    for i in range(start)[::-1]:
        cur = O_[i]-O_[i+1]
        if cur>0:
            B[i] = B[i+1] + (cur+1)
            A[i] = A[i+1] - 1
        else:
            B[i] = B[i+1] + 1
            A[i] = A[i+1] - (-cur+1)
    if A[0]<1:
        add = (1-A[0])
        for i in range(N):
            A[i] += add
    if B[-1]<1:
        add = (1-B[-1])
        for i in range(N):
            B[i] += add

    print(" ".join(map(str,A)))
    print(" ".join(map(str,B)))
    return

def examE():
    return

def examF():
    ans = 0
    print(ans)
    return


from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
9
7 3 9 1 8 4 5 6 2
"""

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
M = 3*10**4
A = [M*i for i in range(1, n+1)]
B = A[::-1]
for i, p in enumerate(P):
  B[p-1] += i
print(*A)
print(*B)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
P = np.array(read().split(), np.int32)

K = 40000
A = K * np.arange(N) + 10
x = np.argsort(P)
B = A[::-1] + x

print(' '.join(map(str, A.tolist())))
print(' '.join(map(str, B.tolist())))

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
p=list(map(int,input().split()))
ps=[]
for i in range(n):
    ps.append((p[i],i))
ps.sort()
s=1
for i in range(n):
    print(s+ps[i][1],end='')
    print(' ',end='')
    s=s+30000
print('')
s=1+30000*(n-1)
for i in range(n):
    print(s,end='')
    print(' ',end='')
    s=s-30000

Solution (Python):
n=int(input())
a=[25252*(i+1) for i in range(n)]
b=[25252*(n-i) for i in range(n)]
l=list(map(int,input().split()))
for i in range(n):
    b[l[i]-1]+=i+1
print(*a)
print(*b)

Solution (Python):
n = int(input())
p = [int(x) - 1 for x in input().split()]

x = 5 * (10 ** 4)
a = [1 + i * x for i in range(n)]
b = a[::-1]

for i in range(1, n):
    a[p[i]] += i

print(*a)
print(*b)

Solution (Python):

N = int(input())
p = list(map(int,input().split()))
a = [40000*i for i in range(1,N+1)]
b = [40000*i for i in range(N,0,-1)]
for i in range(N):
    b[p[i]-1] += i
print(' '.join(map(str,a)))
print(' '.join(map(str,b)))

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    P = tuple(map(int,input().split()))

    A = [2*N*(i + 1) for i in range(N)]
    B = A[::-1]
    cnt = 1
    for a,b in zip(P[:-1],P[1:]):
        if a < b:
            A[b - 1] += cnt
        else:
            B[b - 1] += cnt
        cnt += 1
    print(' '.join(map(str,A)))
    print(' '.join(map(str,B)))

if __name__ == '__main__':
    main()

Solution (Python):
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    n = NI()
    a = [0] * (n+1)
    b = [0] * (n+1)

    for i,p in enumerate(LI()):
        a[p-1] += i
        b[0] += i
        b[p] -= i

    ans_a = []
    ans_b = []
    cnt_a = 0
    cnt_b = 0
    for i in range(n):
        cnt_a += a[i]
        cnt_b += b[i]
        ans_a.append(cnt_a+i+1)
        ans_b.append(cnt_b+(n-i))
    print(*ans_a,sep=' ')
    print(*ans_b,sep=' ')






if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans1 = [(i+1)*n for i in range(n)]
ans2 = [(i+1)*n for i in range(n-1,-1,-1)]
for i in range(n):
  ans2[a[i]-1] += i
print(*ans1)
print(*ans2)

Solution (Python):
def main():

    N = int(input())
    p = list(map(int, input().split()))

    a = dict()
    b = dict()
    for i in range(N):
        v = N * N - N + 2 + i
        a[p[i]] = (p[i]-1) * N +1
        b[p[i]] = v - a[p[i]]

    
    print(" ".join(map(str, [a[i] for i in range(1, N+1)])))
    print(" ".join(map(str, [b[i] for i in range(1, N+1)])))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
P = list(map(int, input().split()))

A = [(N+1) * i for i in range(1, N+1)]
B = A[::-1].copy()
for i, p in enumerate(P):
  B[p-1] += i

print(*A)
print(*B)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

a = [i*40000+1 for i in range(n)]
b = a[:]
b.reverse()

for i in range(n):
    b[p[i]-1] += i+1
print(*a)
print(*b)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))






N = I()
p = LI()

a = [(i+1)*3*10**4 for i in range(N)]
b = a[::-1]

for i,p0 in enumerate(p):
    a[p0-1] += i

print(*a)
print(*b)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
print(' '.join(map(str, range(n, n ** 2 + n, n))))
b = list(range(n, n ** 2 + n, n))[::-1]
for i, x in enumerate(p):
    b[x - 1] += i
print(' '.join(map(str, b)))

Solution (Python):
import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
mod = 10 ** 9 + 7



def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: int(x) - 1, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v

    def __str__(self):
        return str(self.v)

    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)


def main():
    N = int(input())
    P = read_list()
    A = [N * k + 1 for k in range(N)]
    B = A[::-1]

    for i, p in enumerate(P):
        A[p - 1] += i

    print(" ".join(map(str, A)))
    print(" ".join(map(str, B)))


if __name__ == "__main__":
    main()

Solution (Python):


import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))



n = int(input())
ps = [item - 1 for item in map(int, input().split())]

aind = [0]*n
bind = [0]*n

for i,p in enumerate(ps):
    aind[p] = i
    bind[p] = i
    
for i in range(1,n):
    aind[i] += aind[i-1]
    bind[-i-1] += bind[-i]
    
for i in range(n):
    aind[i] += i+1
    bind[i] += n-i
    
print(" ".join(map(str, aind)))
print(" ".join(map(str, bind)))

Solution (Python):
n = int(input())
p = reversed(list(map(int, input().split())))
a = [i*20000 for i in range(1,n+1)]
b = [i*20000 for i in range(n,0,-1)]
for k,v in enumerate(p):
  b[v-1] -= k
print(*a)
print(*b)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
a=[(n+1)*(i+1) for i in range(n)]
b=a[::-1]
for i in range(n):
    a[l[i]-1]+=i
print(" ".join(map(str,a)))
print(" ".join(map(str,b)))

Solution (Python):
N=int(input())
p=list(map(int,input().split()))

a=[30000*(i+1) for i in range(N)]
b=[30000*(N-i) for i in range(N)]

for i in range(0,N):
    a[p[i]-1]+=i
    b[p[i]-1]+=i

print(*a)
print(*b)

Solution (Python):
n = int(input())
p = list(map(int, input().split()))
a = [3 * (i + 1) * pow(10, 4) for i in range(n)]
b = list(a)
b.reverse()
p.reverse()
for i in range(n):
    a[p[i] - 1] -= i
print(" ".join(map(str, a)))
print(" ".join(map(str, b)))

Solution (Python):
n = int(input())
l = list(map(int, input().split()))

a = [i*n for i in range(1,n+1)]
b = [i*n for i in range(1,n+1)][::-1]

for i,x in enumerate(l):
    b[x-1] += i
print(*a)
print(*b)

Solution (Python):
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
p = na()
a = [20000*i for i in range(1,n+1)]
b = list(reversed(a))

j = 1
for i in p:
    b[i-1] += j
    j += 1

print(' '.join([str(m) for m in a]))
print(' '.join([str(m) for m in b]))

Solution (Python):
N = int(input())
p = list(map(int, input().split()))

A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
X = [0 for _ in range(N)]
S = N
A[0] = 1
for i in range(N - 1):
  S += abs(p[i] - p[i-1])
for i in range(N):
  X[p[i]-1] = S + i
B[0] = X[0] - 1
for i in range(1, N):
  s = max(A[i-1] + 1, X[i] - B[i-1] + 1)
  A[i] = s
  B[i] = X[i] - s
if min(min(A), min(B)) <= 0:
  m = -min(min(A), min(B)) + 1
  for i in range(N):
    A[i] += m
    B[i] += m
for i in range(N):
  if i != N - 1:
    print(A[i], end = ' ')
  else:
    print(A[i])
for i in range(N):
  if i != N - 1:
    print(B[i], end = ' ')
  else:
    print(B[i])

Solution (Python):
n = int(input())
p = list(map(int, input().split()))

a=[1]
for num in range(1,n):
    a.append(num * 22000)
c=[0]*n

p=list(reversed(p))
new_p=[0]*n

for i in range(n):
    new_p[p[i]-1]=i

for i in range(n):
    c[i]=10**9 - new_p[i]

b=[0]*n
for i in range(n):
    b[i] = c[i]-a[i]

print(*a)
print(*b)