def merge(targ,first,mid,last):
    left = targ[first:mid] + [10 ** 9 + 1]
    right = targ[mid:last] + [10 ** 9 + 1]

    leftcnt = rightcnt = 0
    global ans
    for i in range(first,last):
        ans += 1
        #print(left,right,left[leftcnt],right[rightcnt],targ,ans)
        if left[leftcnt] <= right[rightcnt]:
            targ[i] = left[leftcnt]
            leftcnt += 1
        else:
            targ[i] = right[rightcnt]
            rightcnt += 1

def mergesort(targ,first,last):

    if first +1 >= last:
        pass
    else:
        mid = (first + last) // 2
        mergesort(targ,first,mid)
        mergesort(targ,mid,last)
        merge(targ,first,mid,last)


ans = 0
num = int(input())
targ = [int(n) for n in input().split(' ')]
mergesort(targ,0,num)
print(" ".join([str(n) for n in targ]))
print(ans) def merge(targ,first,mid,last):
    left = targ[first:mid] + [10 ** 9 + 1]
    right = targ[mid:last] + [10 ** 9 + 1]

    leftcnt = rightcnt = 0
    global ans
    for i in range(first,last):
        ans += 1
        #print(left,right,left[leftcnt],right[rightcnt],targ,ans)
        if left[leftcnt] <= right[rightcnt]:
            targ[i] = left[leftcnt]
            leftcnt += 1
        else:
            targ[i] = right[rightcnt]
            rightcnt += 1 merge left = targ[first:mid] + [10 ** 9 + 1] left targ[first:mid] + [10 ** 9 + 1] targ[first:mid] targ first:mid first mid [10 ** 9 + 1] 10 ** 9 + 1 10 ** 9 10 9 1 right = targ[mid:last] + [10 ** 9 + 1] right targ[mid:last] + [10 ** 9 + 1] targ[mid:last] targ mid:last mid last [10 ** 9 + 1] 10 ** 9 + 1 10 ** 9 10 9 1 leftcnt = rightcnt = 0 leftcnt 0 = rightcnt = 0 rightcnt 0 global ans for i in range(first,last):
        ans += 1
        #print(left,right,left[leftcnt],right[rightcnt],targ,ans)
        if left[leftcnt] <= right[rightcnt]:
            targ[i] = left[leftcnt]
            leftcnt += 1
        else:
            targ[i] = right[rightcnt]
            rightcnt += 1 i range(first,last) range first last ans += 1 ans 1 if left[leftcnt] <= right[rightcnt]:
            targ[i] = left[leftcnt]
            leftcnt += 1
        else:
            targ[i] = right[rightcnt]
            rightcnt += 1 left[leftcnt] <= right[rightcnt] left[leftcnt] left leftcnt right[rightcnt] right rightcnt targ[i] = left[leftcnt] targ[i] targ i left[leftcnt] left leftcnt leftcnt += 1 leftcnt 1 targ[i] = right[rightcnt] targ[i] targ i right[rightcnt] right rightcnt rightcnt += 1 rightcnt 1 targ targ first first mid mid last last def mergesort(targ,first,last):

    if first +1 >= last:
        pass
    else:
        mid = (first + last) // 2
        mergesort(targ,first,mid)
        mergesort(targ,mid,last)
        merge(targ,first,mid,last) mergesort if first +1 >= last:
        pass
    else:
        mid = (first + last) // 2
        mergesort(targ,first,mid)
        mergesort(targ,mid,last)
        merge(targ,first,mid,last) first +1 >= last first +1 first 1 last mid = (first + last) // 2 mid (first + last) // 2 first + last first last 2 mergesort(targ,first,mid) mergesort targ first mid mergesort(targ,mid,last) mergesort targ mid last merge(targ,first,mid,last) merge targ first mid last targ targ first first last last ans = 0 ans 0 num = int(input()) num int(input()) int input() input int(n) for n in input().split(' ') for n in input().split(' ') n input().split(' ') ().split () input split ' ' for n in input().split(' ') int(n) int n targ = [int(n) for n in input().split(' ')] targ [int(n) for n in input().split(' ')] mergesort(targ,0,num) mergesort targ 0 num str(n) for n in targ for n in targ n targ for n in targ str(n) str n print(" ".join([str(n) for n in targ])) print " ".join([str(n) for n in targ]) " ".join " " join [str(n) for n in targ] print(ans) print ans def mergesort(targ,first,last):

    if first +1 >= last:
        pass
    else:
        mid = (first + last) // 2
        mergesort(targ,first,mid)
        mergesort(targ,mid,last)
        merge(targ,first,mid,last) def mergesort(targ,first,last):

    if first +1 >= last:
        pass
    else:
        mid = (first + last) // 2
        mergesort(targ,first,mid)
        mergesort(targ,mid,last)
        merge(targ,first,mid,last) mergesort targ = [int(n) for n in input().split(' ')] [int(n) for n in input().split(' ')] targ ans = 0 0 ans def merge(targ,first,mid,last):
    left = targ[first:mid] + [10 ** 9 + 1]
    right = targ[mid:last] + [10 ** 9 + 1]

    leftcnt = rightcnt = 0
    global ans
    for i in range(first,last):
        ans += 1
        #print(left,right,left[leftcnt],right[rightcnt],targ,ans)
        if left[leftcnt] <= right[rightcnt]:
            targ[i] = left[leftcnt]
            leftcnt += 1
        else:
            targ[i] = right[rightcnt]
            rightcnt += 1 def merge(targ,first,mid,last):
    left = targ[first:mid] + [10 ** 9 + 1]
    right = targ[mid:last] + [10 ** 9 + 1]

    leftcnt = rightcnt = 0
    global ans
    for i in range(first,last):
        ans += 1
        #print(left,right,left[leftcnt],right[rightcnt],targ,ans)
        if left[leftcnt] <= right[rightcnt]:
            targ[i] = left[leftcnt]
            leftcnt += 1
        else:
            targ[i] = right[rightcnt]
            rightcnt += 1 merge num = int(input()) int(input()) num
def merge(targ,first,mid,last):
    left = targ[first:mid] + [10 ** 9 + 1]
    right = targ[mid:last] + [10 ** 9 + 1]

    leftcnt = rightcnt = 0
    global ans
    for i in range(first,last):
        ans += 1
        #print(left,right,left[leftcnt],right[rightcnt],targ,ans)
        if left[leftcnt] <= right[rightcnt]:
            targ[i] = left[leftcnt]
            leftcnt += 1
        else:
            targ[i] = right[rightcnt]
            rightcnt += 1

def mergesort(targ,first,last):

    if first +1 >= last:
        pass
    else:
        mid = (first + last) // 2
        mergesort(targ,first,mid)
        mergesort(targ,mid,last)
        merge(targ,first,mid,last)


ans = 0
num = int(input())
targ = [int(n) for n in input().split(' ')]
mergesort(targ,0,num)
print(" ".join([str(n) for n in targ]))
print(ans)