n = int(raw_input())
A = map(int, raw_input().split(" "))
count = 0

def merge(left, right):
    global count
    
    sorted_list = list()
    left_index = 0
    right_index = 0

    while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
        count += 1

    if left:
        sorted_list.extend(left[left_index:])
        count += len(left[left_index:])
    if right:
        sorted_list.extend(right[right_index:])
        count += len(right[right_index:])
        

    return sorted_list


    
def mergeSort(A):
    if len(A) <= 1:
        return A

    mid = len(A) // 2
    left = A[:mid]
    right = A[mid:]

    left = mergeSort(left)
    right = mergeSort(right)

    return list(merge(left, right))

print " ".join(map(str, mergeSort(A)))
print count n = int(raw_input()) n int(raw_input()) int raw_input() raw_input A = map(int, raw_input().split(" ")) A map(int, raw_input().split(" ")) map int raw_input().split(" ") ().split () raw_input split " " count = 0 count 0 def merge(left, right):
    global count
    
    sorted_list = list()
    left_index = 0
    right_index = 0

    while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
        count += 1

    if left:
        sorted_list.extend(left[left_index:])
        count += len(left[left_index:])
    if right:
        sorted_list.extend(right[right_index:])
        count += len(right[right_index:])
        

    return sorted_list


     merge global count sorted_list = list() sorted_list list() list left_index = 0 left_index 0 right_index = 0 right_index 0 while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
        count += 1

     left_index < len(left) and right_index < len(right) left_index < len(left) left_index len(left) len left right_index < len(right) right_index len(right) len right if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
         left[left_index] <= right[right_index] left[left_index] left left_index right[right_index] right right_index sorted_list.append(left[left_index]) sorted_list.append sorted_list append left[left_index] left left_index left_index += 1 left_index 1 sorted_list.append(right[right_index]) sorted_list.append sorted_list append right[right_index] right right_index right_index += 1 right_index 1 count += 1 count 1 if left:
        sorted_list.extend(left[left_index:])
        count += len(left[left_index:])
     left sorted_list.extend(left[left_index:]) sorted_list.extend sorted_list extend left[left_index:] left left_index: left_index count += len(left[left_index:]) count len(left[left_index:]) len left[left_index:] left left_index: left_index if right:
        sorted_list.extend(right[right_index:])
        count += len(right[right_index:])
        

     right sorted_list.extend(right[right_index:]) sorted_list.extend sorted_list extend right[right_index:] right right_index: right_index count += len(right[right_index:]) count len(right[right_index:]) len right[right_index:] right right_index: right_index return sorted_list sorted_list left left right right def mergeSort(A):
    if len(A) <= 1:
        return A

    mid = len(A) // 2
    left = A[:mid]
    right = A[mid:]

    left = mergeSort(left)
    right = mergeSort(right)

    return list(merge(left, right)) mergeSort if len(A) <= 1:
        return A

     len(A) <= 1 len(A) len A 1 return A A mid = len(A) // 2 mid len(A) // 2 len(A) len A 2 left = A[:mid] left A[:mid] A :mid mid right = A[mid:] right A[mid:] A mid: mid left = mergeSort(left) left mergeSort(left) mergeSort left right = mergeSort(right) right mergeSort(right) mergeSort right return list(merge(left, right)) list(merge(left, right)) list merge(left, right) merge left right A A print " ".join(map(str, mergeSort(A))) " ".join " " join map(str, mergeSort(A)) map str mergeSort(A) mergeSort A print A = map(int, raw_input().split(" ")) map(int, raw_input().split(" ")) A def mergeSort(A):
    if len(A) <= 1:
        return A

    mid = len(A) // 2
    left = A[:mid]
    right = A[mid:]

    left = mergeSort(left)
    right = mergeSort(right)

    return list(merge(left, right)) def mergeSort(A):
    if len(A) <= 1:
        return A

    mid = len(A) // 2
    left = A[:mid]
    right = A[mid:]

    left = mergeSort(left)
    right = mergeSort(right)

    return list(merge(left, right)) mergeSort def merge(left, right):
    global count
    
    sorted_list = list()
    left_index = 0
    right_index = 0

    while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
        count += 1

    if left:
        sorted_list.extend(left[left_index:])
        count += len(left[left_index:])
    if right:
        sorted_list.extend(right[right_index:])
        count += len(right[right_index:])
        

    return sorted_list


     def merge(left, right):
    global count
    
    sorted_list = list()
    left_index = 0
    right_index = 0

    while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
        count += 1

    if left:
        sorted_list.extend(left[left_index:])
        count += len(left[left_index:])
    if right:
        sorted_list.extend(right[right_index:])
        count += len(right[right_index:])
        

    return sorted_list


     merge count = 0 0 count n = int(raw_input()) int(raw_input()) n
n = int(raw_input())
A = map(int, raw_input().split(" "))
count = 0

def merge(left, right):
    global count
    
    sorted_list = list()
    left_index = 0
    right_index = 0

    while left_index < len(left) and right_index < len(right):
        if left[left_index] <= right[right_index]:
            sorted_list.append(left[left_index])
            left_index += 1

        else:
            sorted_list.append(right[right_index])
            right_index += 1
            
        count += 1

    if left:
        sorted_list.extend(left[left_index:])
        count += len(left[left_index:])
    if right:
        sorted_list.extend(right[right_index:])
        count += len(right[right_index:])
        

    return sorted_list


    
def mergeSort(A):
    if len(A) <= 1:
        return A

    mid = len(A) // 2
    left = A[:mid]
    right = A[mid:]

    left = mergeSort(left)
    right = mergeSort(right)

    return list(merge(left, right))

print " ".join(map(str, mergeSort(A)))
print count