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 = [int(i) for i in input().split()]
a,b = [n*i+1 for i in range(n)],[0 for i in range(n)]
for i in range(n-1): print(a[i],end=" ")
print(a[-1])
for i in range(n): b[p[i]-1] = i-a[p[i]-1]
x = abs(b[-1])+1
for i in range(n-1): print(b[i]+x,end=" ")
print(1)

Solution (Python):
N = int(input())
P = 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)]

AB = []
for p in P:
    add = A[p-1] + B[p-1]
    AB.append([p, add])
    
for i in range(N-1):
    if AB[i][1] >= AB[i+1][1]:
        diff = AB[i][1] - AB[i+1][1]
        AB[i+1][1] += diff+1
        A[AB[i+1][0]-1] += diff+1

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

Solution (Python):
def generate(p):
    n = len(p)
    a = [n*i+1 for i in xrange(n)]
    b = a[::-1]
    for i in xrange(n):
        a[p[i]-1] += i
    return a, b

def main():
    n = int(raw_input().strip())
    p = [int(x) for x in raw_input().strip().split()]
    a, b = generate(p)
    print ' '.join([str(x) for x in a])
    print ' '.join([str(x) for x in b])

if __name__ == '__main__':
    main()

Solution (Python):

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

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

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

asc = [N*(n+1) for n in range(N)]
desc = [N*(n+1) for n in reversed(range(N))]

for i,a in enumerate(src):
    desc[a-1] += i

print(' '.join(list(map(str,asc))))
print(' '.join(list(map(str,desc))))

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N = int(input())
    p_list = list(map(int, input().split()))
    a_list = [i * N for i in range(1, N + 1)]
    b_list = a_list[::-1]

    for i, p in enumerate(p_list):
        a_list[p - 1] += i

    print(*a_list)
    print(*b_list)


if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
ps = list(map(int,input().split()))
imos = [None] * n
for i, p in enumerate(ps):
    imos[p-1] = i
a = [ 0 ]
b = [ 0 ]
for i in range(n):
    a += [ a[-1] + 1 + imos[i]     ]
    b += [ b[-1] + 1 + imos[n-i-1] ]
print(*a[1:])
print(*reversed(b[1:]))

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

a = [i * (N) for i in range(1, N+1)]
b = [(N-(i-1)) * (N) for i in range(1, N+1)]
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()))
Pi = [0] * n
for i, p in enumerate(P):
    Pi[p-1] = i

A = [30000*(i+1) for i in range(n)]
B = [30000*(n-i)+pi for i, pi in enumerate(Pi)]

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

Solution (Python):
n = int(raw_input())
p = [int(x) for x in raw_input().split(" ")]

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

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

print " ".join([str(n) for n in a])
print " ".join([str(n) for n in b])

Solution (Python):
n=int(input())
pprr = list(map(int,input().split()))
prr=[0]*n
for ix,p in enumerate(pprr):
    prr[p-1]=ix+1

arr=[]
brr=[]
cumsum=0
for p in prr:
    cumsum+=p
    arr.append(cumsum)
cumsum=0
print(" ".join(map(str,arr)))
for p in reversed(prr):
    cumsum+=p
    brr.append(cumsum)
print(" ".join(map(str,reversed(brr))))

Solution (Python):
n = int(input())
list = input().split()
for i in range(0,n):
   if int(list[i]) == n:
      p = i
      break

list1 = []
list2 = []
for k in range(0,n):
   list1.append(n* int ( list[k] ) - n + 1)
for k in range(0,n):
   list2.append( max ( int(list1[p] ) + 1 - p + k - int( list1[k] ), n - int ( list[k] ) +1))

a = ""
b = ""

list2.sort(reverse = True)
list1.sort()
for l in range (0,n):
   a += str(list1[l])
   a += " "
   b += str(list2[l])
   b += " "

print(a)
print(b)

Solution (Python):

n = int(input())
ps = list(map(int,input().split()))
imos = [None] * n
for i, p in enumerate(ps):
    imos[p-1] = i
a = [ 0 ]
b = [ 0 ]
for i in range(n):
    a += [ a[-1] + 1 + imos[i]     ]
    b += [ b[-1] + 1 + imos[n-i-1] ]
print(*a[1:])
print(*reversed(b[1:]))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    n = int(input())
    a = list(map(int, input().split()))
    ra = []
    for i in range(n):
        ra.append((i+1)*30000)
    rb = []
    c = 1
    for i in range(n):
        rb.append((n-i)*30000)
    for i in a:
        rb[i-1] += c
        c += 1
    print(' '.join(map(str,ra)))
    print(' '.join(map(str,rb)))


f()

Solution (Python):
N = input()
l = input().split()

N=int(N)
a=range(1,N+1)
b=range(1,N+1)
a=[i*N for i in a]
b=[i*N for i in b]
b.reverse()

c=0
for i in l:
    i=int(i)
    b[i-1]+=c
    c+=1

for i in a:
    print(i,end=" ")
print("")
for i in b:
    print(i,end=" ")

Solution (Python):
import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def fix(a):
    mn = min(a) - 1
    return [x - mn for x in a]

def main():
    N = rl(int)
    p = srl(int)
    a = range(N)
    b = list(reversed(a))
    inc = [0] * (N+1)
    for i, v in enumerate(p[1:], 1):
        a[v-1] += i
        inc[v] += i
    s = 0
    for i in xrange(N):
        s += inc[i]
        a[i] += s
        b[i] -= s
    print " ".join(map(str, fix(a)))
    print " ".join(map(str, fix(b)))

if __name__ == '__main__':
    main()

Solution (Python):

import numpy as np

n = int(input())
p = enumerate(map(int, input().split()))
next(p)
a = np.arange(1, n + 1)
b = np.arange(n, 0, -1)
for c, i in p:
    i -= 1
    a[i:] += c
    b[:i + 1] += c
print(*a)
print(*b)

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

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

for i in range(n):
    c[i] = a[i] + b[i]

for i in range(n-1):
    if(p[i] > p[i+1]):
        b[p[i+1]-1] +=  c[p[i]-1] - c[p[i+1]-1] + 1
        c[p[i+1]-1] +=  c[p[i]-1] - c[p[i+1]-1] + 1
    else:
        a[p[i+1]-1] += c[p[i]-1] - c[p[i+1]-1] + 1
        c[p[i+1]-1] += c[p[i]-1] - c[p[i+1]-1] + 1

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

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

import numpy as np
a = np.arange(1, N + 1)
b = np.arange(N, 0, -1)

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

for i in range(N):
    print(a[i], end=" ")

print()  

for i in range(N):
    print(b[i], end=" ")

print()

Solution (Python):
N = int(input())
p = list(map(int, input().split()))
a = [0]*N
b = [0]*N

for i in range(N):
    c = 49999
    a[p[i]-1] = c*p[i]
    b[p[i]-1] = i + 1 - c*p[i]

m = min(b)
b = map(lambda x: x-m+1,b)
print(" ".join(map(str,a)))
print(" ".join(map(str,b)))

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

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



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

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


def check():
    tmp =0
    for i in P:
        i-=1
        if not (tmp<a[i]+b[i]):
            raise
        tmp=a[i]+b[i]
    return True

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


MAX = int(1e8) * 5
MIN = 1

sums = [MAX + MIN for i in range(N)]
for i, p in enumerate(P):
    sums[p - 1] += i


A = [0 for i in range(N)]
B = [0 for i in range(N)]
A[0] = MIN
B[0] = sums[0] - A[0]
prev_A = A[0]
prev_B = B[0]

for i, p in enumerate(P):
    if i == 0:
        
        continue
    next_A = prev_A + 1
    next_B = sums[i] - next_A
    if next_B >= prev_B:
        next_B = prev_B - 1
        next_A = sums[i] - next_B
    
    A[i] = next_A
    B[i] = next_B
    prev_A = A[i]
    prev_B = B[i]
print(" ".join(map(str, A)))
print(" ".join(map(str, B)))

Solution (Python):
n = int(input())
p = [int(i) for i in raw_input().split()]
a = [0 for i in range(n)]
b = [0 for i in range(n)]
p.reverse()
for i in range(n):
	k = p.pop()
	a[k-1] = i + 1
	b[k-1] = i + 1
for i in range(1,n):
	d = min(a[i] - a[i-1],b[i-1] - b[i])
	if d <= 0:
		a[i] -= d - 1
		b[i] += d - 1
ma = min(a)
mb = min(b)
a = [str(i+1-ma) for i in a] 
b = [str(i+1-mb) for i in b]
print(" ".join(a))
print(" ".join(b))

Solution (Python):
import sys
N = int(sys.stdin.readline())
ps = map(int, sys.stdin.readline().strip().split())
M = N + 5

A = []
B = []
for i in range(N):
    A.append(M * (i+1))
    B.insert(0, M * (i+1))

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

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

Solution (Python):


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

def solve(Ps):
    n = len(Ps)
    As = [x * 30000 + 1 for x in range(n)]
    Bs = list(reversed(As[:]))
    for i, p in enumerate(Ps):
        Bs[p-1] += i
    return As, Bs

As, Bs = solve(Ps)
print(*As)
print(*Bs)

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

b = [None] * (n + 1)
b[P[0]] = 1
bs = {1}

for p, pprev in zip(P[1:], P):
    bp = b[pprev] + (pprev - p) * 20000 + 1
    while bp in bs:
        bp += 1
    b[p] = bp
    bs.add(bp)

offset = 1 - min(b[1:])
b = [i + offset for i in b[1:]]

print(' '.join([str(20000 * i) for i in range(1, n + 1)]))
print(' '.join([str(i) for i in b]))

Solution (Python):
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

N = read()
p = reads()

q = [0] * N
for i in range(N):
  q[p[i]-1] = i+1

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

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

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

print(" ".join(str(x) for x in a))
print(" ".join(str(x) for x in b))

Solution (Python):
n = input()
P = map(int, raw_input().split())
C = [0]*n
for i in xrange(n):
    C[P[i]-1] = i+1
A = [0]*n
B = [0]*n
su = 0
for i in xrange(n):
    su += C[i]
    A[i] = su
su = 0
for i in xrange(n-1, -1, -1):
    su += C[i]
    B[i] = su
print ' '.join(map(str, A))
print ' '.join(map(str, 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):
import numpy as np
N = int(raw_input())
p = np.array(map(int, raw_input().split()))

q = np.zeros(N, dtype='int')
for i in range(N):
    q[p[i]-1] = i
a = np.zeros(N, dtype='int')
b = np.zeros(N, dtype='int')

ai = 0
bi = 0
for i in range(N):
    if ai + bi < q[i]:
        ai = q[i] - bi
    elif ai + bi > q[i]:
        bi = q[i] - ai
    else:
        pass
    a[i] = ai
    b[i] = bi
a += np.arange(1, N+1, dtype='int')
b -= np.arange(1, N+1, dtype='int')
b -= b.min()
b += 1

a_list = [str(x) for x in a]
b_list = [str(x) for x in b]
print ' '.join(a_list)
print ' '.join(b_list)

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

MAX = 10**9
A = [MAX/(N-1)*i for i in xrange(N)]
A[0] += 1
B = A[::-1]

t = 0
for p in P:
    if A[p] + B[p] > t:
        t = A[p] + B[p]
    elif p == N-1:
        B[p] += t+1-A[p]-B[p]
        t += 1
    else:
        A[p] += t+1-A[p]-B[p]
        t += 1
print ' '.join(map(str, A))
print ' '.join(map(str, B))

Solution (Python):
n = int(raw_input())
p = map(int, raw_input().split())
a = [0] * n
b = [0] * n
for i, x in enumerate(p):
    x -= 1
    a[x] = x * 30000 + i + 1
    b[x] = n * 30000 - x * 30000
for x in a:
    print x,
print
for x in b:
    print x,
print

Solution (Python):
n = int(input())
p = [int(_) for _ in input().split()]
a = []
b = []
for i in range(1, n + 1):
    a.append(i * 2 * n)
    b.append((n + 1 - i) * 2 * n)
d = 1
for i in p:
    if d % 2 == 0:
        a[i - 1] += d // 2
        b[i - 1] += d // 2
    else:
        a[i - 1] += d // 2
        b[i - 1] += d // 2
        if a[i - 1] >= b[i - 1]:
            b[i - 1] += 1
        else:
            a[i - 1] += 1
    d += 1
for i in a:
    print(i, end=' ')
print()
for i in b:
    print(i, end=' ')

Solution (Python):
N = input()
p = [int(t)-1 for t in raw_input().split()]

ad = [1]*N
bd = [1]*N

for i in range(len(p)):
    ad[p[i]] += i
    bd[p[i]] += i

a = [0]*N
for i in range(N):
    a[i] = (0 if i==0 else a[i-1]) + ad[i]
b = [0]*N
for i in range(N)[::-1]:
    b[i] = (0 if i==N-1 else b[i+1]) + bd[i]

for t in a:
    print t,
print
for t in b:
    print t,
print

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

Solution (Python):
N = input()
l = input().split()

N=int(N)
a=range(1,N+1)
b=range(1,N+1)
a=[i*N for i in a]
b=[i*N for i in b]
b.reverse()

c=0
for i in l:
	i=int(i)
	b[i-1]+=c 
	c+=1

for i in a:
	print(i,end=" ")
print("")
for i in b:
	print(i,end=" ")

Solution (Python):



def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

N =        int( stdin.readline().strip() )
ps = map(int, stdin.readline().strip().split())

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

aa = [1 + 21000*i for i in range(N)]
bb = [heights[i] - aa[i] for i in range(N)]
base = min(bb)
bb = [b + abs(base)+1 for b in bb]

print ' '.join(map(str, aa))
print ' '.join(map(str, bb))

Solution (Python):
N=int(raw_input())
P=map(int,raw_input().split())
PA=[0]*N
for i in xrange(N):
    PA[P[i]-1]=i
A=[]
B=[]
for i in xrange(N):
    A.append(30000*(i+1)+PA[i])
    B.append(30000*(N-i))
print " ".join(map(str,A))
print " ".join(map(str,B))