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

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

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

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

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

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

if __name__ == '__main__':
    main()