N = int(input()) A = list(map(int,input().split())) k = 0 while 2**k0: tot += T1[x] x -= x&(-x) return tot update(A[0]) for i in range(1,N): x = A[i] cuml = cumsum(x) high = x low = -1 while high-low>1: mid = (high+low)//2 if cumsum(mid)>=cuml: high = mid else: low = mid left = high high = N+1 low = x while high-low>1: mid = (high+low)//2 if cumsum(mid)>cuml: high = mid else: low =mid right = high if left==0: T2[right][0] = x elif right==N+1: T2[left][1] = x else: if T2[left][1]==0: T2[left][1] = x else: T2[right][0] = x update(x) B = [0]*(N+1) C = [[0,0] for _ in range(N+1)] def dfs(x,p): global cnt B[x] = B[p]+1 C[x][0] = cnt cnt += 1 for y in T2[x]: if y==0:continue dfs(y,x) C[x][1] = cnt cnt += 1 cnt = 0 B[0] = -1 dfs(A[0],0) C = [(C[i][1]-C[i][0])//2 for i in range(N+1)] ans1 = [0]*N ans2 = [0]*N for i in range(N): ans1[i] = B[A[i]] ans2[i] = C[A[i]] print(*ans1) print(*ans2)