count = 0 

def merge(data, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid 
    L = data[left : mid]
    R = data[mid : right]
    L.append(float('inf'))
    R.append(float('inf'))
    i = 0 
    j = 0 
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1

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

def main():
    num = raw_input()
    num_list = raw_input().split()
    num_list = map(int, num_list)
    merge_sort(num_list, 0, len(num_list))
    num_list =  map(str, num_list)
    print " ".join(num_list)
    print count

if __name__ == '__main__':
    main() count = 0 count 0 def merge(data, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid 
    L = data[left : mid]
    R = data[mid : right]
    L.append(float('inf'))
    R.append(float('inf'))
    i = 0 
    j = 0 
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1 merge global count n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = data[left : mid] L data[left : mid] data left : mid left mid R = data[mid : right] R data[mid : right] data mid : right mid right 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 range(left, right):
        count += 1
        if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1 k range(left, right) range left right count += 1 count 1 if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1 L[i] <= R[j] L[i] L i R[j] R j data[k] = L[i] data[k] data k L[i] L i i += 1 i 1 data[k] = R[j] data[k] data k R[j] R j j += 1 j 1 data data left left mid mid right right def merge_sort(data, left, right):
    if left + 1 < right:
        mid = (left + right) / 2 
        merge_sort(data, left, mid)
        merge_sort(data, mid, right)
        merge(data, left, mid, right) merge_sort if left + 1 < right:
        mid = (left + right) / 2 
        merge_sort(data, left, mid)
        merge_sort(data, mid, right)
        merge(data, left, mid, right) left + 1 < right left + 1 left 1 right mid = (left + right) / 2 mid (left + right) / 2 left + right left right 2 merge_sort(data, left, mid) merge_sort data left mid merge_sort(data, mid, right) merge_sort data mid right merge(data, left, mid, right) merge data left mid right data data left left right right def main():
    num = raw_input()
    num_list = raw_input().split()
    num_list = map(int, num_list)
    merge_sort(num_list, 0, len(num_list))
    num_list =  map(str, num_list)
    print " ".join(num_list)
    print count main num = raw_input() num raw_input() raw_input num_list = raw_input().split() num_list raw_input().split() ().split () raw_input split num_list = map(int, num_list) num_list map(int, num_list) map int num_list merge_sort(num_list, 0, len(num_list)) merge_sort num_list 0 len(num_list) len num_list num_list =  map(str, num_list) num_list map(str, num_list) map str num_list print " ".join(num_list) " ".join " " join num_list print if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def merge(data, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid 
    L = data[left : mid]
    R = data[mid : right]
    L.append(float('inf'))
    R.append(float('inf'))
    i = 0 
    j = 0 
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1 def merge(data, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid 
    L = data[left : mid]
    R = data[mid : right]
    L.append(float('inf'))
    R.append(float('inf'))
    i = 0 
    j = 0 
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1 merge def merge_sort(data, left, right):
    if left + 1 < right:
        mid = (left + right) / 2 
        merge_sort(data, left, mid)
        merge_sort(data, mid, right)
        merge(data, left, mid, right) def merge_sort(data, left, right):
    if left + 1 < right:
        mid = (left + right) / 2 
        merge_sort(data, left, mid)
        merge_sort(data, mid, right)
        merge(data, left, mid, right) merge_sort def main():
    num = raw_input()
    num_list = raw_input().split()
    num_list = map(int, num_list)
    merge_sort(num_list, 0, len(num_list))
    num_list =  map(str, num_list)
    print " ".join(num_list)
    print count def main():
    num = raw_input()
    num_list = raw_input().split()
    num_list = map(int, num_list)
    merge_sort(num_list, 0, len(num_list))
    num_list =  map(str, num_list)
    print " ".join(num_list)
    print count main count = 0 0 count
count = 0 

def merge(data, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid 
    L = data[left : mid]
    R = data[mid : right]
    L.append(float('inf'))
    R.append(float('inf'))
    i = 0 
    j = 0 
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            data[k] = L[i]
            i += 1
        else:
            data[k] = R[j]
            j += 1

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

def main():
    num = raw_input()
    num_list = raw_input().split()
    num_list = map(int, num_list)
    merge_sort(num_list, 0, len(num_list))
    num_list =  map(str, num_list)
    print " ".join(num_list)
    print count

if __name__ == '__main__':
    main()