global count
count = 0


def merge(num_list, left, mid, right):
    a = mid - left
    b = right - mid
    L = []
    R = []

    for i in range(a):
        L.append(num_list[left + i])
    for i in range(b):
        R.append(num_list[mid + i])

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

    i = 0
    j = 0
    global count

    for k in range(left, right):
        if L[i] <= R[j]:
            num_list[k] = L[i]
            i += 1
        else:
            num_list[k] = R[j]
            j += 1
        count += 1


def mergeSort(num_list, left, right):
    if left+1 < right:
        mid = (left + right) / 2
        mergeSort(num_list, left, mid)
        mergeSort(num_list, mid, right)
        merge(num_list, left, mid, right)

    return num_list


if __name__ == "__main__":
    num = raw_input()
    line = raw_input()

    num_list = line.strip().split()
    num_list = map(int, num_list)

    merge_list = mergeSort(num_list, 0, len(num_list))
    merge_list = map(str, merge_list)
    print " ".join(merge_list)
    print count global count count = 0 count 0 def merge(num_list, left, mid, right):
    a = mid - left
    b = right - mid
    L = []
    R = []

    for i in range(a):
        L.append(num_list[left + i])
    for i in range(b):
        R.append(num_list[mid + i])

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

    i = 0
    j = 0
    global count

    for k in range(left, right):
        if L[i] <= R[j]:
            num_list[k] = L[i]
            i += 1
        else:
            num_list[k] = R[j]
            j += 1
        count += 1 merge a = mid - left a mid - left mid left b = right - mid b right - mid right mid L = [] L [] R = [] R [] for i in range(a):
        L.append(num_list[left + i])
     i range(a) range a L.append(num_list[left + i]) L.append L append num_list[left + i] num_list left + i left i for i in range(b):
        R.append(num_list[mid + i])

     i range(b) range b R.append(num_list[mid + i]) R.append R append num_list[mid + i] num_list 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 global count for k in range(left, right):
        if L[i] <= R[j]:
            num_list[k] = L[i]
            i += 1
        else:
            num_list[k] = R[j]
            j += 1
        count += 1 k range(left, right) range left right if L[i] <= R[j]:
            num_list[k] = L[i]
            i += 1
        else:
            num_list[k] = R[j]
            j += 1
         L[i] <= R[j] L[i] L i R[j] R j num_list[k] = L[i] num_list[k] num_list k L[i] L i i += 1 i 1 num_list[k] = R[j] num_list[k] num_list k R[j] R j j += 1 j 1 count += 1 count 1 num_list num_list left left mid mid right right def mergeSort(num_list, left, right):
    if left+1 < right:
        mid = (left + right) / 2
        mergeSort(num_list, left, mid)
        mergeSort(num_list, mid, right)
        merge(num_list, left, mid, right)

    return num_list mergeSort if left+1 < right:
        mid = (left + right) / 2
        mergeSort(num_list, left, mid)
        mergeSort(num_list, mid, right)
        merge(num_list, left, mid, right)

     left+1 < right left+1 left 1 right mid = (left + right) / 2 mid (left + right) / 2 left + right left right 2 mergeSort(num_list, left, mid) mergeSort num_list left mid mergeSort(num_list, mid, right) mergeSort num_list mid right merge(num_list, left, mid, right) merge num_list left mid right return num_list num_list num_list num_list left left right right if __name__ == "__main__":
    num = raw_input()
    line = raw_input()

    num_list = line.strip().split()
    num_list = map(int, num_list)

    merge_list = mergeSort(num_list, 0, len(num_list))
    merge_list = map(str, merge_list)
    print " ".join(merge_list)
    print count __name__ == "__main__" __name__ "__main__" num = raw_input() num raw_input() raw_input line = raw_input() line raw_input() raw_input num_list = line.strip().split() num_list line.strip().split() line.strip().split line.strip() line.strip line strip split num_list = map(int, num_list) num_list map(int, num_list) map int num_list merge_list = mergeSort(num_list, 0, len(num_list)) merge_list mergeSort(num_list, 0, len(num_list)) mergeSort num_list 0 len(num_list) len num_list merge_list = map(str, merge_list) merge_list map(str, merge_list) map str merge_list print " ".join(merge_list) " ".join " " join merge_list print def mergeSort(num_list, left, right):
    if left+1 < right:
        mid = (left + right) / 2
        mergeSort(num_list, left, mid)
        mergeSort(num_list, mid, right)
        merge(num_list, left, mid, right)

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

    return num_list mergeSort num = raw_input() raw_input() num num_list = line.strip().split() line.strip().split() num_list line = raw_input() raw_input() line merge_list = map(str, merge_list) map(str, merge_list) merge_list merge_list = mergeSort(num_list, 0, len(num_list)) mergeSort(num_list, 0, len(num_list)) merge_list num_list = map(int, num_list) map(int, num_list) num_list global count count = 0 0 count def merge(num_list, left, mid, right):
    a = mid - left
    b = right - mid
    L = []
    R = []

    for i in range(a):
        L.append(num_list[left + i])
    for i in range(b):
        R.append(num_list[mid + i])

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

    i = 0
    j = 0
    global count

    for k in range(left, right):
        if L[i] <= R[j]:
            num_list[k] = L[i]
            i += 1
        else:
            num_list[k] = R[j]
            j += 1
        count += 1 def merge(num_list, left, mid, right):
    a = mid - left
    b = right - mid
    L = []
    R = []

    for i in range(a):
        L.append(num_list[left + i])
    for i in range(b):
        R.append(num_list[mid + i])

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

    i = 0
    j = 0
    global count

    for k in range(left, right):
        if L[i] <= R[j]:
            num_list[k] = L[i]
            i += 1
        else:
            num_list[k] = R[j]
            j += 1
        count += 1 merge
global count
count = 0


def merge(num_list, left, mid, right):
    a = mid - left
    b = right - mid
    L = []
    R = []

    for i in range(a):
        L.append(num_list[left + i])
    for i in range(b):
        R.append(num_list[mid + i])

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

    i = 0
    j = 0
    global count

    for k in range(left, right):
        if L[i] <= R[j]:
            num_list[k] = L[i]
            i += 1
        else:
            num_list[k] = R[j]
            j += 1
        count += 1


def mergeSort(num_list, left, right):
    if left+1 < right:
        mid = (left + right) / 2
        mergeSort(num_list, left, mid)
        mergeSort(num_list, mid, right)
        merge(num_list, left, mid, right)

    return num_list


if __name__ == "__main__":
    num = raw_input()
    line = raw_input()

    num_list = line.strip().split()
    num_list = map(int, num_list)

    merge_list = mergeSort(num_list, 0, len(num_list))
    merge_list = map(str, merge_list)
    print " ".join(merge_list)
    print count