def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    cnt += n1+n2
    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergesort(A,left,right):
    if left +1 < right:
        mid = int((left+right)/2)
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right)

n = int(input())
A = list(map(int,input().split()))
cnt = 0
mergesort(A,0,n)
print(" ".join(map(str,A)))
print(cnt) def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    cnt += n1+n2
    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 merge global cnt n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid cnt += n1+n2 cnt n1+n2 n1 n2 A[left+i] for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) A[left+i] A left+i left i L = [A[left+i] for i in range(n1)] L [A[left+i] for i in range(n1)] A[mid+i] for i in range(n2) for i in range(n2) i range(n2) range n2 for i in range(n2) A[mid+i] A mid+i mid i R = [A[mid+i] for i in range(n2)] R [A[mid+i] for i in range(n2)] L.append(float("inf")) L.append L append float("inf") float "inf" R.append(float("inf")) R.append R append float("inf") float "inf" i = 0 i 0 j = 0 j 0 for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 k range(left,right) range left right if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 L[i] <= R[j] L[i] L i R[j] R j A[k] = L[i] A[k] A k L[i] L i i += 1 i 1 A[k] = R[j] A[k] A k R[j] R j j += 1 j 1 A A left left mid mid right right def mergesort(A,left,right):
    if left +1 < right:
        mid = int((left+right)/2)
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) mergesort if left +1 < right:
        mid = int((left+right)/2)
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) left +1 < right left +1 left 1 right mid = int((left+right)/2) mid int((left+right)/2) int (left+right)/2 left+right left right 2 mergesort(A,left,mid) mergesort A left mid mergesort(A,mid,right) mergesort A mid right merge(A,left,mid,right) merge A left mid right A A left left right right n = int(input()) n int(input()) int input() input A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split cnt = 0 cnt 0 mergesort(A,0,n) mergesort A 0 n print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print(cnt) print cnt cnt = 0 0 cnt n = int(input()) int(input()) n def mergesort(A,left,right):
    if left +1 < right:
        mid = int((left+right)/2)
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) def mergesort(A,left,right):
    if left +1 < right:
        mid = int((left+right)/2)
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right) mergesort def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    cnt += n1+n2
    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    cnt += n1+n2
    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1 merge A = list(map(int,input().split())) list(map(int,input().split())) A
def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    cnt += n1+n2
    L = [A[left+i] for i in range(n1)]
    R = [A[mid+i] for i in range(n2)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def mergesort(A,left,right):
    if left +1 < right:
        mid = int((left+right)/2)
        mergesort(A,left,mid)
        mergesort(A,mid,right)
        merge(A,left,mid,right)

n = int(input())
A = list(map(int,input().split()))
cnt = 0
mergesort(A,0,n)
print(" ".join(map(str,A)))
print(cnt)
