count = 0

def marge(A,left,mid,right):
    global count
    n1 = mid -left
    n2 = right -mid
    L = []
    R = []
    for i in range(left,n1+left):
        L.append(A[i])
    for i in range(mid,n2+mid):
        R.append(A[i])

    L.append(float("inf"))
    R.append(float("inf"))

    r_id,l_id = 0,0
    for k in range(left,right):
        count += 1
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1

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


n = int(raw_input())
s = raw_input()
A = []
A = map(int,s.split())

margeSort(A,0,n)

A_str = map(str,A)
print(" ".join(list(A_str)))
print count count = 0 count 0 def marge(A,left,mid,right):
    global count
    n1 = mid -left
    n2 = right -mid
    L = []
    R = []
    for i in range(left,n1+left):
        L.append(A[i])
    for i in range(mid,n2+mid):
        R.append(A[i])

    L.append(float("inf"))
    R.append(float("inf"))

    r_id,l_id = 0,0
    for k in range(left,right):
        count += 1
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1 marge global count n1 = mid -left n1 mid -left mid left n2 = right -mid n2 right -mid right mid L = [] L [] R = [] R [] for i in range(left,n1+left):
        L.append(A[i])
     i range(left,n1+left) range left n1+left n1 left L.append(A[i]) L.append L append A[i] A i for i in range(mid,n2+mid):
        R.append(A[i])

     i range(mid,n2+mid) range mid n2+mid n2 mid R.append(A[i]) R.append R append A[i] A i L.append(float("inf")) L.append L append float("inf") float "inf" R.append(float("inf")) R.append R append float("inf") float "inf" r_id,l_id = 0,0 r_id 0 l_id 0 for k in range(left,right):
        count += 1
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1 k range(left,right) range left right count += 1 count 1 if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1 L[l_id] <= R[r_id] L[l_id] L l_id R[r_id] R r_id A[k] = L[l_id] A[k] A k L[l_id] L l_id l_id += 1 l_id 1 A[k] = R[r_id] A[k] A k R[r_id] R r_id r_id += 1 r_id 1 A A left left mid mid right right def margeSort(A,left,right):
    if left+1 < right:
        mid = int((left+right)/2)
        margeSort(A,left,mid)
        margeSort(A,mid,right)
        marge(A,left,mid,right) margeSort if left+1 < right:
        mid = int((left+right)/2)
        margeSort(A,left,mid)
        margeSort(A,mid,right)
        marge(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 margeSort(A,left,mid) margeSort A left mid margeSort(A,mid,right) margeSort A mid right marge(A,left,mid,right) marge A left mid right A A left left right right n = int(raw_input()) n int(raw_input()) int raw_input() raw_input s = raw_input() s raw_input() raw_input A = [] A [] A = map(int,s.split()) A map(int,s.split()) map int s.split() s.split s split margeSort(A,0,n) margeSort A 0 n A_str = map(str,A) A_str map(str,A) map str A print(" ".join(list(A_str))) print " ".join(list(A_str)) " ".join " " join list(A_str) list A_str print count = 0 0 count def margeSort(A,left,right):
    if left+1 < right:
        mid = int((left+right)/2)
        margeSort(A,left,mid)
        margeSort(A,mid,right)
        marge(A,left,mid,right) def margeSort(A,left,right):
    if left+1 < right:
        mid = int((left+right)/2)
        margeSort(A,left,mid)
        margeSort(A,mid,right)
        marge(A,left,mid,right) margeSort A = [] [] A s = raw_input() raw_input() s def marge(A,left,mid,right):
    global count
    n1 = mid -left
    n2 = right -mid
    L = []
    R = []
    for i in range(left,n1+left):
        L.append(A[i])
    for i in range(mid,n2+mid):
        R.append(A[i])

    L.append(float("inf"))
    R.append(float("inf"))

    r_id,l_id = 0,0
    for k in range(left,right):
        count += 1
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1 def marge(A,left,mid,right):
    global count
    n1 = mid -left
    n2 = right -mid
    L = []
    R = []
    for i in range(left,n1+left):
        L.append(A[i])
    for i in range(mid,n2+mid):
        R.append(A[i])

    L.append(float("inf"))
    R.append(float("inf"))

    r_id,l_id = 0,0
    for k in range(left,right):
        count += 1
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1 marge A = map(int,s.split()) map(int,s.split()) A A_str = map(str,A) map(str,A) A_str n = int(raw_input()) int(raw_input()) n
count = 0

def marge(A,left,mid,right):
    global count
    n1 = mid -left
    n2 = right -mid
    L = []
    R = []
    for i in range(left,n1+left):
        L.append(A[i])
    for i in range(mid,n2+mid):
        R.append(A[i])

    L.append(float("inf"))
    R.append(float("inf"))

    r_id,l_id = 0,0
    for k in range(left,right):
        count += 1
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1

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


n = int(raw_input())
s = raw_input()
A = []
A = map(int,s.split())

margeSort(A,0,n)

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