INF = 10000000000


def merge(A, left, mid, right):
    global num
    leftA = A[left:mid]
    rightA = A[mid:right]
    leftA.append(INF)
    rightA.append(INF)
    l = 0
    r = 0
    for i in range(left, right):
        num += 1
        if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1


def mergeSort(A, left, right):
    if right - left < 2:
        return
    mid = left + (right - left) // 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)


if __name__ == "__main__":
    n = int(input())
    S = list(map(int, input().split()))
    num = 0
    mergeSort(S, 0, len(S))
    print(" ".join(map(str, S)))
    print(num) INF = 10000000000 INF 10000000000 def merge(A, left, mid, right):
    global num
    leftA = A[left:mid]
    rightA = A[mid:right]
    leftA.append(INF)
    rightA.append(INF)
    l = 0
    r = 0
    for i in range(left, right):
        num += 1
        if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1 merge global num leftA = A[left:mid] leftA A[left:mid] A left:mid left mid rightA = A[mid:right] rightA A[mid:right] A mid:right mid right leftA.append(INF) leftA.append leftA append INF rightA.append(INF) rightA.append rightA append INF l = 0 l 0 r = 0 r 0 for i in range(left, right):
        num += 1
        if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1 i range(left, right) range left right num += 1 num 1 if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1 leftA[l] <= rightA[r] leftA[l] leftA l rightA[r] rightA r A[i] = leftA[l] A[i] A i leftA[l] leftA l l += 1 l 1 A[i] = rightA[r] A[i] A i rightA[r] rightA r r += 1 r 1 A A left left mid mid right right def mergeSort(A, left, right):
    if right - left < 2:
        return
    mid = left + (right - left) // 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right) mergeSort if right - left < 2:
        return
     right - left < 2 right - left right left 2 return mid = left + (right - left) // 2 mid left + (right - left) // 2 left (right - left) // 2 right - left right left 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 if __name__ == "__main__":
    n = int(input())
    S = list(map(int, input().split()))
    num = 0
    mergeSort(S, 0, len(S))
    print(" ".join(map(str, S)))
    print(num) __name__ == "__main__" __name__ "__main__" 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 num = 0 num 0 mergeSort(S, 0, len(S)) mergeSort S 0 len(S) len S print(" ".join(map(str, S))) print " ".join(map(str, S)) " ".join " " join map(str, S) map str S print(num) print num n = int(input()) int(input()) n def mergeSort(A, left, right):
    if right - left < 2:
        return
    mid = left + (right - left) // 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right) def mergeSort(A, left, right):
    if right - left < 2:
        return
    mid = left + (right - left) // 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right) mergeSort INF = 10000000000 10000000000 INF num = 0 0 num def merge(A, left, mid, right):
    global num
    leftA = A[left:mid]
    rightA = A[mid:right]
    leftA.append(INF)
    rightA.append(INF)
    l = 0
    r = 0
    for i in range(left, right):
        num += 1
        if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1 def merge(A, left, mid, right):
    global num
    leftA = A[left:mid]
    rightA = A[mid:right]
    leftA.append(INF)
    rightA.append(INF)
    l = 0
    r = 0
    for i in range(left, right):
        num += 1
        if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1 merge S = list(map(int, input().split())) list(map(int, input().split())) S
INF = 10000000000


def merge(A, left, mid, right):
    global num
    leftA = A[left:mid]
    rightA = A[mid:right]
    leftA.append(INF)
    rightA.append(INF)
    l = 0
    r = 0
    for i in range(left, right):
        num += 1
        if leftA[l] <= rightA[r]:
            A[i] = leftA[l]
            l += 1
        else:
            A[i] = rightA[r]
            r += 1


def mergeSort(A, left, right):
    if right - left < 2:
        return
    mid = left + (right - left) // 2
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)


if __name__ == "__main__":
    n = int(input())
    S = list(map(int, input().split()))
    num = 0
    mergeSort(S, 0, len(S))
    print(" ".join(map(str, S)))
    print(num)