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):
N = int(input())
P = list(map(int, input().split()))

A = [1 for i in range(N)]
B = [1 for i in range(N)]

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

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

print(*A)
print(*B)

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

A = [1 for i in range(N)]
B = [1 for i in range(N)]

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

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

print(*A)
print(*B)

Solution (Python):
class BIT:
    def __init__(self, size):
        self.bit = [0] * (size + 1)
        self.size = size

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

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

N = int(input())
p = list(map(lambda x: int(x)-1, input().split()))
a = BIT(N)
b = BIT(N)
a.add(0, 1)
b.add(0, N)
for i in range(1, N):
    a.add(i, 1)
    b.add(i, -1)
for i, j in enumerate(p):
    a.add(j, i)
    b.add(0, i)
    b.add(j+1, -i)
print(*[a.sum(i) for i in range(N)])
print(*[b.sum(i) for i in range(N)])

Solution (Python):
N = int(input())
P = [int(x) for x in input().split()]

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

for i in range(N) :
    a[P[i]-1] += i

print(*a)
print(*b)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
 
def main():
    N = int(input())
    p = list(map(int,input().split()))
    
    a = [N*i+1 for i in range(N)]
    b = [N*(N-i-1)+1 for i in range(N)]

    for i,num in enumerate(p):
        a[num-1] += i
        
    print(*a)
    print(*b)
    
if __name__ == "__main__":
    main()

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

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

num = 0
for e in p:
    e -= 1
    b[e] += num
    num += 1

print(*a)
print(*b)

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

a = [30000*i for i in range(n)]
b = [30000*(n-i) for i in range(n)]

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

print(*a)
print(*b)

Solution (Python):
def main():
    N = int(input())
    P = [int(i) for i in input().split()]
    A = [30000*(i+1) for i in range(1, N+1)]
    B = [30000*(N-i+1) for i in range(1, N+1)]
    for i, p in enumerate(P):
        B[p-1] += i
    print(*A)
    print(*B)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
P = [p-1 for p in P]

A=  list(range(1, n+1))
B = list(reversed(range(1, n+1)))

C = [0]*(n+1)
D = [0]*(n+1)
for i in range(n):
    p = P[i]
    C[p] += i+1
    C[n] -= i+1
    D[0] += i+1
    D[p+1] -= i+1
from itertools import accumulate
C = list(accumulate(C))
D = list(accumulate(D))

A_ = [0]*n
B_ = [0]*n
for i in range(n):
    A_[i] = A[i] + C[i]
    B_[i] = B[i] + D[i]

print(*A_)
print(*B_)

Solution (Python):
n = int(input())
P = list(map(int, input().split()))
P = [p-1 for p in P]

A=  list(range(1, n+1))
B = list(reversed(range(1, n+1)))

C = [0]*(n+1)
D = [0]*(n+1)
for i in range(n):
    p = P[i]
    C[p] += i+1
    C[n] -= i+1
    D[0] += i+1
    D[p+1] -= i+1
from itertools import accumulate
C = list(accumulate(C))
D = list(accumulate(D))

A_ = [0]*n
B_ = [0]*n
for i in range(n):
    A_[i] = A[i] + C[i]
    B_[i] = B[i] + D[i]

print(*A_)
print(*B_)

Solution (Python):
N = int(input())
P = [int(p) for p in input().split()]
A = [(N + 1) * (i + 1) for i in range(N)]
B = [(N + 1) * (N - i) for i in range(N)]
for i in range(N): B[P[i] - 1] += i + 1
print(" ".join(map(str, A)))
print(" ".join(map(str, B)))

Solution (Python):
N = int(input())
P = [int(p) for p in input().split()]

A = [30000 * i for i in range(1, N+1)]
R = [0 for i in range(N)]
for i in range(N):
    R[P[i]-1] = i+1
B = [30000 * (N-i) + R[i-1] for i in range(1, N+1)]

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

Solution (Python):
N = int(input())
P = list(map(lambda a: int(a) - 1, input().split()))

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

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

print(*A)
print(*B)

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


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

p = P[0]
B[p - 1] = N * (N - p + 1)

for x, y in zip(P[:-1], P[1:]):
    x -= 1
    y -= 1
    Xsum = A[x] + B[x]
    Ysum = Xsum + 1
    B[y] = Ysum - A[y]

print(*A)
print(*B)

Solution (Python):
N = int(input())
P = [int(i) - 1 for i in input().split()]

a = [0] * N
b = [0] * N
rank = 1
for p in P:
    a[p] = rank
    b[p] = rank
    rank += 1

b.reverse()

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

b.reverse()

print(*a)
print(*b)

Solution (Python):
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys


import copy
"""
N=int(input())
P=list(map(int,input().split()))
for i in range(N):
    P[i]-=1
A=[30000*i for i in range(1,N+1)]
B=list(reversed(A))
ruiA=[]
ruiB=[]



count=1
for i in range(0,N)[::-1]:
    B[P[i]]-=count
    """for m in lst:
        B[m]-=1
    lst.add(P[i])"""
    count+=1

print(" ".join([str(i) for i in A]))
print(" ".join([str(i) for i in B]))

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

Solution (Python):
N, *P = map(int, open(0).read().split())
b = list(range(N*N, N-1, -N))
a = [0]*N
for i,p in enumerate(P):
  a[p-1] = N*p+i
print(*a)
print(*b)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

N, *p = map(int, read().split())

p = np.array(p, np.int64) - 1
a = np.arange(30000, 30000 * N + 1, 30000)
b = a[::-1]
idx = np.arange(1, N + 1)
a = a + idx[np.argsort(p)]
print(' '.join(map(str, a.tolist())))
print(' '.join(map(str, b.tolist())))

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

Solution (Python):
def main():
    N = int(input())
    P = list(map(int, input().split()))
    delta = [0] * N
    for i, p in enumerate(P):
        delta[p-1] = i
    A = [0] * N
    B = [0] * N
    A[0] = a = delta[0] + 1
    B[0] = b = int(1e9)

    for i in range(1, N):
        a += 1
        b -= 1
        tmp = delta[i] - delta[i-1]
        if tmp > 0:
            a += tmp
        else:
            b += tmp
        A[i] = a
        B[i] = b
    print(*A)
    print(*B)


if __name__ == "__main__":
    main()

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

a = list(range(30000, 30000*(1+n), 30000))
b = a[::-1]

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

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

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

import bisect

a = list(range(1,n*20000+1,20000))
b = a[::-1]


def init(n, init_num=0):
    num = len(str(bin(n-1))) -2
    seg = [init_num] * (2**(num+1))
    seg_num = 2**num
    return seg, seg_num

def calc_sum(head, tail):
    head += seg_num
    tail += seg_num
    l = []
    while(head <= tail):
        if(head == tail):
            l.append(head)
            break

        if(head % 2 == 1):
            l.append(head)
            head += 1
        head = head //2

        if(tail % 2 == 0):
            l.append(tail)
            tail -= 1
        tail = tail //2

    ans = 0
    for i in l:
        ans += seg[i]
    return(ans)

def update(i,x):
    i += seg_num
    seg[i] = x
    while(i > 1):
        i = i//2
        seg[i] = seg[2*i] + seg[2*i+1]

seg,seg_num = init(n)

for i in p:
    i -= 1
    a[i] += calc_sum(0,i-1)
    b[i] += calc_sum(i+1,n-1)
    update(i,1)

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

Solution (Python):
N = int(input())
P = [int(p) for p in input().split()]

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

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

for i in range(N):
    A[i] = str(A[i])
    B[i] = str(B[i])
print(" ".join(A))
print(" ".join(B))

Solution (Python):
N=int(input())
P=list(map(int, input().split()))
Q=[0]*(N+1)
for i,p in enumerate(P):
    Q[p]=i
A=[i*N+Q[i] for i in range(1,N+1)]
B=[i*N for i in range(N,0,-1)]
print(*A)
print(*B)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
p = inl()
c = 20001
a = [c*i for i in range(1,n+1)]
b = [c*(n+1-i) for i in range(1,n+1)]
for i in range(n):
    a[p[i]-1] += i
pad = ''
for i in range(n):
    printn(pad + str(a[i]))
    pad = ' '
print('')
pad = ''
for i in range(n):
    printn(pad + str(b[i]))
    pad = ' '
print('')

Solution (Python):
from operator import itemgetter
N = int(input())
P = list(map(int, input().split()))



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

for i, p in enumerate(P):
    p -= 1
    if i == 0:
        A[p] = (p + 1) * N
        AB = A[p] + B[p]
        continue
    A[p] = AB - B[p] + 1
    AB = A[p] + B[p]

print(*A)
print(*B)

Solution (Python):



n = int(input())
p = list(map(int, input().split( )))
for i in range(n):
    p[i]-=1

a = [5*10**8+i*20001 for i in range(n)]
b = [5*10**8-i*20001 for i in range(n)]



for i in range(n):
    a[p[i]] += i 
   
print(*a)
print(*b)
"""
for i in range(n-1):
    assert a[i]<a[i+1],(a[i],a[i+1])
    assert b[i]>b[i+1],(b[i],b[i+1])
    assert a[p[i]]+b[p[i]]<a[p[i+1]]+b[p[i+1]],(i,p[i],a[p[i]],b[p[i]],a[p[i+1]],b[p[i+1]])
"""

Solution (Python):
N = int(input())
a = list(range(0, N*20000, 20000))
b = a[::-1]
P = list(map(int, input().split()))
for i in range(N):
    a[P[i]-1]+=i+1
    b[P[i]-1]+=1
print(*a)
print(*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(n):
    b[p[i]-1]+=i
for i in a:
    print(i,end =' ')
print()
for i in b:
    print(i,end=' ')
print()

Solution (Python):
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    N = I()
    P = LI()
    A = [N*(i+1) for i in range(N)]
    B = [N*(N-i) for i in range(N)]
    for i,p in enumerate(P):
        A[p-1] += i
    print(" ".join(map(str,A)))
    print(" ".join(map(str,B)))
    return

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

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

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

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

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,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
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
p = list(map(int, input().split()))
res = [0] * N
for i in range(N):
  res[p[i] - 1] = 10 ** 9 - N + i + 1

a = [1]
b = [res[0] - 1]
for i in range(1, N):
  if res[i] - a[-1] - 1 >= b[-1]:
    b.append(b[-1] - 1)
    a.append(res[i] - b[-1])
  else:
    a.append(a[-1] + 1)
    b.append(res[i] - a[-1])
print(*a)
print(*b)

Solution (Python):
N = int(input())
P = list(map(int,input().split()))
A = [1 for _ in range(N+1)]
B = [0 for _ in range(N+1)]
L = [0 for _ in range(N+1)]
for i in range(N):
    L[P[i]] = 2*i
B[1] = L[1]-A[1]
for i in range(2,N+1):
    if L[i]>L[i-1]:
        B[i] = B[i-1]-1
        A[i] = L[i]-B[i]
    else:
        A[i] = A[i-1]+1
        B[i] = L[i]-A[i]
b = abs(B[-1])+1
for i in range(1,N+1):
    B[i] += b
print(*A[1:])
print(*B[1:])

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
P = [p-1 for p in LIST()]

A = [0] * N
B = [0] * N
gap = 30000
for i in range(N):
    A[i] = gap * i + 1
    B[i] = gap * (N-i)

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

print(*A)
print(*B)

Solution (Python):
def gen_ordinary_lists(n):
    up_lis = list(range(1, n * 20001, 20001))
    return up_lis, up_lis[::-1]


def argsort(lis):
    tpls = [(l, i) for i, l in enumerate(lis)]
    return sorted(tpls)


def solve(N, lis):
    up_list, down_list = gen_ordinary_lists(N)
    arg_tpls = argsort(lis)
    for val, idx in arg_tpls:
        up_list[val - 1] += idx
    print(*up_list)
    print(*down_list)
    

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

solve(N, lis)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
B = [[0] * n for i in range(2)]

k = 10**4 * 3

for i in range(n):
    B[0][i] = k * (i+1)
    B[1][n-1-i] = k * (i+1)


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

for i in range(2):
    print(" ".join([str(j) for j in B[i]]))

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

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

x=[10**9]*n
for i in range(n):
  x[p[i]-1]-=n-i-1


a=[1]
b=[x[0]-a[0]]

for i in range(n-1):
  t=max(a[-1],10**9-b[-1])
  a.append(t+1)
  b.append(x[i+1]-t-1)
print(*a)
print(*b)

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N = ri()
P = rl()

A = np.array(list(range(1, N+1)))
B = np.array(list(range(N, 0, -1)))

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

print(*A)
print(*B)

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

Solution (Python):
def main():
    N = int( input())
    Q = list( map( int, input().split()))
    P = [0]*N
    for i in range(N):
        P[Q[i]-1] = i+1
    A = [1]
    B = [1]
    for i in range(N-1):
        if P[i] < P[i+1]:
            A.append(A[-1] + P[i+1] - P[i] + 1)
        else:
            A.append(A[-1] + 1)
    for i in range(N-2,-1,-1):
        if P[i] > P[i+1]:
            B.append(B[-1] + P[i] - P[i+1] + 1)
        else:
            B.append(B[-1]+1)
    print(" ".join( map(str, A)))
    print(" ".join( map(str, B[::-1])))
if __name__ == '__main__':
    main()

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

import numpy as np

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

X = 40000
A = np.arange(N) * X + 1
B = np.arange(N)[::-1] * X + 1

add = np.empty(N,np.int32)
add[P-1] = np.arange(N)
A += add

print(' '.join(A.astype(str)))
print(' '.join(B.astype(str)))

Solution (Python):
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time

def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 +10 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase


input=lambda: sys.stdin.readline().rstrip()

show_flg=False
show_flg=True

ans='Possible'
n=I()
p=LI_()
b=[30000*(n-i) for i in range(n)]
a=[30000*(i+1) for i in range(n)]
prev=b[p[0]]
l=[]
for i in range(n):
    b[p[i]]+=i
    l.append(a[p[i]]+b[p[i]])
    





show(*a)
show(*b)

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

Solution (Python):
N, *P = map(int, open(0).read().split())

R = [0] * N
for i, p in enumerate(P, 1):
    R[p - 1] = i

A = [30000 * i for i in range(1, N + 1)]
B = [30000 * (N - i) + r for i, r in enumerate(R, 1)]

print(*A)
print(*B)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    M=20000
    A=[M*i for i in range(1,n+1)]
    B=[M*(n-i+1) for i in range(1,n+1)]
    perm=list(map(lambda x:int(x)-1,input().split()))
    for i in range(n):
        A[perm[i]]+=i

    print(*A)
    print(*B)
resolve()

Solution (Python):

N = int(input())

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

a = [0] * N
b = [0] * N

for i in range(N):

    b[i] = (N-i) * N
    a[i] = (i + 1) * N

for i in range(N):
    b[p[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 = [0]*n
b = [0]*n
for i in range(n):
  a[p[i] - 1] += i
  a[i] += n * (i + 1)
  b[i] = n * (n - i)
print(' '.join(map(str,a)))
print(' '.join(map(str,b)))

Solution (Python):
N = int(input())
p = [int(i) for i in input().split()]

A = [0] * N
B = [0] * N

for i in range(1, N) :
    if p[i] > p[i-1] :
        A[p[i]-1] = A[p[i-1]-1] + N * (p[i] - p[i-1]) + 1
        B[p[i]-1] = B[p[i-1]-1] - N * (p[i] - p[i-1])
    else :
        A[p[i]-1] = A[p[i-1]-1] + N * (p[i] - p[i-1])
        B[p[i]-1] = B[p[i-1]-1] - N * (p[i] - p[i-1]) + 1

ma, mb = min(A), min(B)
for i in range(N) :
    A[i] = A[i] - ma + 1
    B[i] = B[i] - mb + 1
    
print(*A)
print(*B)

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

ls = [0 for _ in range(n)]
for i, p in enumerate(ps):
    ls[p-1] = i

cs = [ls[0]]
for i in range(1, n):
    cs.append(cs[-1] + ls[i])

xs = [c + 1 + i for i, c in enumerate(cs)]
ys = [cs[-1]+n+1] + [cs[-1] - c + 1 + n - i for i, c in zip(range(1, n), cs)]
print(" ".join(map(str, xs)))
print(" ".join(map(str, ys)))

Solution (Python):
def main():
	n, *p = map(int, open(0).read().split())
	c = 40000
	a = [c * i for i in range(n)]
	b = [c * (n - i) for i in range(n)]
	for i, x in enumerate(p, start=1):
		a[x - 1] += i
	print(*a)
	print(*b)


if __name__=="__main__":
	main()

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
p = LI()
a = [i * 30000 for i in range(1, n + 1)]
b = [i * 30000 for i in range(n, 0, -1)]
for i in range(n):
    a[p[i] - 1] += i


print(*a)
print(*b)

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

a = [0] * N
b = [0] * N
for i in range(N):
    a[p[i]-1] = p[i] * 22000 + 500000000
    b[p[i]-1] = -p[i] * 22000 + i + 500000000
print(*a)
print(*b)

Solution (Python):


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

a = [-1] * n
for x, ind in enumerate(p, 1):
    a[ind - 1] = x










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

abs_min = abs(min(b)) + 1
b = list(map(lambda x: x + abs_min, b))

print(*a)
print(*b)

Solution (Python):
def getlist():
	return list(map(int, input().split()))

def main():
	N = int(input())
	p = getlist()
	a = [N * i for i in range(1, N + 1)]
	b = [N * (N - i) for i in range(N)]
	for i in range(N):
		a[p[i] - 1] += i
	print(" ".join(list(map(str, a))))
	print(" ".join(list(map(str, b))))

if __name__ == '__main__':
	main()

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

M = 40000
A = []
B = []
for i in range(N):
  A.append(M*i)
  B.append(M*(N-i))
for i in range(N):
  A[P[i]-1] += i+1
print(*A)
print(*B)

Solution (Python):
n = int(input())
p = [i for i,j in sorted([[i,pp] for i,pp in enumerate(map(int, input().split()))], key=lambda t:t[1])]

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

Solution (Python):
n=int(input())
a=[i*30000+1 for i in range(n)]
b=[30000**2-i for i in a]
p=list(map(int,input().split()))
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()))
L = 2*N

for i in range(1, N+1):
    print(i*L, end=' ')
print()

B = [L*(N-i) for i in range(1, N+1)]
for i, p in enumerate(P):
    B[p-1] += i+1
print(' '.join([str(a) for a in B]))

Solution (Python):
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    N = I()
    P = LI()

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

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

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






if __name__ == "__main__":
    main()

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

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]

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

a=b[:]
b.reverse()

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

Solution (Python):
n=int(input())
line=input().split()
for i in range (n):
    line[i]=int(line[i])
 
b=[]
for i in range (n):
    b.append(22000*i+1)
a=b[:]
b.reverse()
 
for i in range (1,n):
    a[line[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 = []
B = []
for i in range(N):
    P[i]-=1
    A.append(40000*(i+1))
    B.append(40000*(N-i))
    
add = 0
C = []
for p in P:
    if len(C) == 0:
        C.append(A[p]+B[p])
    else:
        c = C[-1]
        if c < A[p]+B[p]+add:
            C.append(A[p]+B[p]+add)
        else:
            add+=c-(A[p]+B[p]+add)+1
            C.append(A[p]+B[p]+add)
    A[p]+=add
    
for a in A:
    print(a+add,end=" ")
print()
for b in B:
    print(b,end=" ")

Solution (Python):
N = int(input())
P = [int(x) - 1 for x in input().split()]
A = [0] * N
B = [0] * N
D = [0] * N
for i, p in enumerate(P):
  D[p] = i
for i in range(P[0] + 1, N):
  if D[i] > D[i - 1]:
    B[i] = B[i - 1] - 1
    A[i] = D[i] - B[i]
  else:
    A[i] = A[i - 1] + 1
    B[i] = D[i] - A[i]
for i in range(P[0] - 1, -1, -1):
  if D[i] > D[i + 1]:
    A[i] = A[i + 1] - 1
    B[i] = D[i] - A[i]
  else:
    B[i] = B[i + 1] + 1
    A[i] = D[i] - B[i]
_a = 1 - A[0]
_b = 1 - B[-1]
print(' '.join([str(a + _a) for a in A]))
print(' '.join([str(b + _b) for b in B]))

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
n = onem()

p = l()


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

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

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

a = list(map(lambda x : x * (N + 1), range(1, N + 1)))
b = list(map(lambda x : x * (N + 1), range(N, 0, -1)))

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

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

a = [40000 * (i + 1) for i in range(n)]
b = list(reversed(a))
for i in range(n):
    a[p[i]] += i

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