def merge(A,left,mid,right):
    INF = 10**9
    n1 = mid - left
    n2 = right - mid
    #L[0…n1], R[0…n2]を生成
    L = A[left:left+n1]
    R = A[mid:mid+n2]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    c = 0
    for k in range(left,right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return c

def mergeSort(A,left,right):
    if left+1 < right:
        mid = (left+right)//2
        cL = mergeSort(A,left,mid)
        cR = mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cL+cR
    return 0

N = int(input())
S = list(map(int,input().split()))
c = mergeSort(S,0,N)
print(' '.join(map(str,S)))
print(c)
 def merge(A,left,mid,right):
    INF = 10**9
    n1 = mid - left
    n2 = right - mid
    #L[0…n1], R[0…n2]を生成
    L = A[left:left+n1]
    R = A[mid:mid+n2]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    c = 0
    for k in range(left,right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return c merge INF = 10**9 INF 10**9 10 9 n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = A[left:left+n1] L A[left:left+n1] A left:left+n1 left left+n1 left n1 R = A[mid:mid+n2] R A[mid:mid+n2] A mid:mid+n2 mid mid+n2 mid n2 L.append(INF) L.append L append INF R.append(INF) R.append R append INF i = 0 i 0 j = 0 j 0 c = 0 c 0 for k in range(left,right):
        c += 1
        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 c += 1 c 1 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 return c c A A left left mid mid right right def mergeSort(A,left,right):
    if left+1 < right:
        mid = (left+right)//2
        cL = mergeSort(A,left,mid)
        cR = mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cL+cR
    return 0 mergeSort if left+1 < right:
        mid = (left+right)//2
        cL = mergeSort(A,left,mid)
        cR = mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cL+cR
     left+1 < right left+1 left 1 right mid = (left+right)//2 mid (left+right)//2 left+right left right 2 cL = mergeSort(A,left,mid) cL mergeSort(A,left,mid) mergeSort A left mid cR = mergeSort(A,mid,right) cR mergeSort(A,mid,right) mergeSort A mid right return merge(A,left,mid,right)+cL+cR merge(A,left,mid,right)+cL+cR merge(A,left,mid,right)+cL merge(A,left,mid,right) merge A left mid right cL cR return 0 0 A A left left right right N = int(input()) N int(input()) int input() input S = list(map(int,input().split())) S list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split c = mergeSort(S,0,N) c mergeSort(S,0,N) mergeSort S 0 N print(' '.join(map(str,S))) print ' '.join(map(str,S)) ' '.join ' ' join map(str,S) map str S print(c) print c c = mergeSort(S,0,N) mergeSort(S,0,N) c S = list(map(int,input().split())) list(map(int,input().split())) S def mergeSort(A,left,right):
    if left+1 < right:
        mid = (left+right)//2
        cL = mergeSort(A,left,mid)
        cR = mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cL+cR
    return 0 def mergeSort(A,left,right):
    if left+1 < right:
        mid = (left+right)//2
        cL = mergeSort(A,left,mid)
        cR = mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cL+cR
    return 0 mergeSort N = int(input()) int(input()) N def merge(A,left,mid,right):
    INF = 10**9
    n1 = mid - left
    n2 = right - mid
    #L[0…n1], R[0…n2]を生成
    L = A[left:left+n1]
    R = A[mid:mid+n2]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    c = 0
    for k in range(left,right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return c def merge(A,left,mid,right):
    INF = 10**9
    n1 = mid - left
    n2 = right - mid
    #L[0…n1], R[0…n2]を生成
    L = A[left:left+n1]
    R = A[mid:mid+n2]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    c = 0
    for k in range(left,right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return c merge
def merge(A,left,mid,right):
    INF = 10**9
    n1 = mid - left
    n2 = right - mid
    #L[0…n1], R[0…n2]を生成
    L = A[left:left+n1]
    R = A[mid:mid+n2]
    L.append(INF)
    R.append(INF)
    i = 0
    j = 0
    c = 0
    for k in range(left,right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    return c

def mergeSort(A,left,right):
    if left+1 < right:
        mid = (left+right)//2
        cL = mergeSort(A,left,mid)
        cR = mergeSort(A,mid,right)
        return merge(A,left,mid,right)+cL+cR
    return 0

N = int(input())
S = list(map(int,input().split()))
c = mergeSort(S,0,N)
print(' '.join(map(str,S)))
print(c)

