# -*- coding:utf-8 -*-
# AIZU ONLINE JUDGE
# Introduction to Algorithms and Data Structures
# ALDS1_5_B
# Recursion / Divide and Conquer - Merge Sort

# ?????????????????????????????±??????????????\??????????????¢?????´????????????
# ????????±??????(Divide and Conquer method)?????????????????§????§£?±???§???????????§????????????????°????????????????????????????????????¨???????§£?±????????????¨??§?????????????????????????????¨???????§£?±?????????¨?????????????§£?±???????????????¨???
# ?????????????????´??????????????????????????????????????????????????°????????´???????????????????????????????????????????????¨????????£?????´?????????

# Input
# A     : ??´??????????????????
# left  : ??????????????????????????????????????????????????????
# mid   : right??¨mid???????????????????¬?????????§???????????????
# right : ??????????????????????????????????????????????????????

cnt = 0
def marge(A, left, mid, right):
    global cnt
    # ??????????????????????????????????????????
    n1 = mid-left
    n2 = right-mid

    # L[0..n1],R[0..n2]?????????
    l = []
    r = []
    for i in xrange(n1):
        l.append(A[left+i])
    for i in xrange(n2):
        r.append(A[mid+i])
    l.append(float('inf'))
    r.append(float('inf'))
    i = 0
    j = 0
    for k in xrange(left,right):
        cnt += 1
        if l[i]<=r[j]:
            A[k] = l[i]
            i+=1
        else:
            A[k] = r[j]
            j+=1

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

def main():
    n = input()
    A = map(int,raw_input().split())
    marge_sort(A,0,len(A))
    print " ".join(map(str,A))
    print cnt

if __name__ == '__main__':
    main() cnt = 0 cnt 0 def marge(A, left, mid, right):
    global cnt
    # ??????????????????????????????????????????
    n1 = mid-left
    n2 = right-mid

    # L[0..n1],R[0..n2]?????????
    l = []
    r = []
    for i in xrange(n1):
        l.append(A[left+i])
    for i in xrange(n2):
        r.append(A[mid+i])
    l.append(float('inf'))
    r.append(float('inf'))
    i = 0
    j = 0
    for k in xrange(left,right):
        cnt += 1
        if l[i]<=r[j]:
            A[k] = l[i]
            i+=1
        else:
            A[k] = r[j]
            j+=1 marge global cnt n1 = mid-left n1 mid-left mid left n2 = right-mid n2 right-mid right mid l = [] l [] r = [] r [] for i in xrange(n1):
        l.append(A[left+i])
     i xrange(n1) xrange n1 l.append(A[left+i]) l.append l append A[left+i] A left+i left i for i in xrange(n2):
        r.append(A[mid+i])
     i xrange(n2) xrange n2 r.append(A[mid+i]) r.append r append A[mid+i] A mid+i mid 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' i = 0 i 0 j = 0 j 0 for k in xrange(left,right):
        cnt += 1
        if l[i]<=r[j]:
            A[k] = l[i]
            i+=1
        else:
            A[k] = r[j]
            j+=1 k xrange(left,right) xrange left right cnt += 1 cnt 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 A A left left mid mid right right def marge_sort(A,left,right):
    if left+1<right:
        mid = (right+left)/2
        marge_sort(A, left,mid)
        marge_sort(A, mid,right)
        marge(A,left,mid,right) marge_sort if left+1<right:
        mid = (right+left)/2
        marge_sort(A, left,mid)
        marge_sort(A, mid,right)
        marge(A,left,mid,right) left+1<right left+1 left 1 right mid = (right+left)/2 mid (right+left)/2 right+left right left 2 marge_sort(A, left,mid) marge_sort A left mid marge_sort(A, mid,right) marge_sort A mid right marge(A,left,mid,right) marge A left mid right A A left left right right def main():
    n = input()
    A = map(int,raw_input().split())
    marge_sort(A,0,len(A))
    print " ".join(map(str,A))
    print cnt main n = input() n input() input A = map(int,raw_input().split()) A map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split marge_sort(A,0,len(A)) marge_sort A 0 len(A) len A print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = input()
    A = map(int,raw_input().split())
    marge_sort(A,0,len(A))
    print " ".join(map(str,A))
    print cnt def main():
    n = input()
    A = map(int,raw_input().split())
    marge_sort(A,0,len(A))
    print " ".join(map(str,A))
    print cnt main def marge(A, left, mid, right):
    global cnt
    # ??????????????????????????????????????????
    n1 = mid-left
    n2 = right-mid

    # L[0..n1],R[0..n2]?????????
    l = []
    r = []
    for i in xrange(n1):
        l.append(A[left+i])
    for i in xrange(n2):
        r.append(A[mid+i])
    l.append(float('inf'))
    r.append(float('inf'))
    i = 0
    j = 0
    for k in xrange(left,right):
        cnt += 1
        if l[i]<=r[j]:
            A[k] = l[i]
            i+=1
        else:
            A[k] = r[j]
            j+=1 def marge(A, left, mid, right):
    global cnt
    # ??????????????????????????????????????????
    n1 = mid-left
    n2 = right-mid

    # L[0..n1],R[0..n2]?????????
    l = []
    r = []
    for i in xrange(n1):
        l.append(A[left+i])
    for i in xrange(n2):
        r.append(A[mid+i])
    l.append(float('inf'))
    r.append(float('inf'))
    i = 0
    j = 0
    for k in xrange(left,right):
        cnt += 1
        if l[i]<=r[j]:
            A[k] = l[i]
            i+=1
        else:
            A[k] = r[j]
            j+=1 marge def marge_sort(A,left,right):
    if left+1<right:
        mid = (right+left)/2
        marge_sort(A, left,mid)
        marge_sort(A, mid,right)
        marge(A,left,mid,right) def marge_sort(A,left,right):
    if left+1<right:
        mid = (right+left)/2
        marge_sort(A, left,mid)
        marge_sort(A, mid,right)
        marge(A,left,mid,right) marge_sort cnt = 0 0 cnt
# -*- coding:utf-8 -*-
# AIZU ONLINE JUDGE
# Introduction to Algorithms and Data Structures
# ALDS1_5_B
# Recursion / Divide and Conquer - Merge Sort

# ?????????????????????????????±??????????????\??????????????¢?????´????????????
# ????????±??????(Divide and Conquer method)?????????????????§????§£?±???§???????????§????????????????°????????????????????????????????????¨???????§£?±????????????¨??§?????????????????????????????¨???????§£?±?????????¨?????????????§£?±???????????????¨???
# ?????????????????´??????????????????????????????????????????????????°????????´???????????????????????????????????????????????¨????????£?????´?????????

# Input
# A     : ??´??????????????????
# left  : ??????????????????????????????????????????????????????
# mid   : right??¨mid???????????????????¬?????????§???????????????
# right : ??????????????????????????????????????????????????????

cnt = 0
def marge(A, left, mid, right):
    global cnt
    # ??????????????????????????????????????????
    n1 = mid-left
    n2 = right-mid

    # L[0..n1],R[0..n2]?????????
    l = []
    r = []
    for i in xrange(n1):
        l.append(A[left+i])
    for i in xrange(n2):
        r.append(A[mid+i])
    l.append(float('inf'))
    r.append(float('inf'))
    i = 0
    j = 0
    for k in xrange(left,right):
        cnt += 1
        if l[i]<=r[j]:
            A[k] = l[i]
            i+=1
        else:
            A[k] = r[j]
            j+=1

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

def main():
    n = input()
    A = map(int,raw_input().split())
    marge_sort(A,0,len(A))
    print " ".join(map(str,A))
    print cnt

if __name__ == '__main__':
    main()