N = int(raw_input())
count = 0

A_str = raw_input().split()
A = map(int, A_str)

def merge(left, right):
    global count
    sorted_list = []
    l_index = 0
    r_index = 0

    while l_index < len(left) and r_index < len(right):
        count += 1
        if left[l_index] <= right[r_index]:
            sorted_list.append(left[l_index])
            l_index += 1
        else:
            sorted_list.append(right[r_index])
            r_index += 1

    if len(left) != l_index:
        sorted_list.extend(left[l_index:])
        count += len(left[l_index:])
    if len(right) != r_index:
        sorted_list.extend(right[r_index:])
        count += len(right[r_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 count = 0 count 0 A_str = raw_input().split() A_str raw_input().split() ().split () raw_input split A = map(int, A_str) A map(int, A_str) map int A_str def merge(left, right):
    global count
    sorted_list = []
    l_index = 0
    r_index = 0

    while l_index < len(left) and r_index < len(right):
        count += 1
        if left[l_index] <= right[r_index]:
            sorted_list.append(left[l_index])
            l_index += 1
        else:
            sorted_list.append(right[r_index])
            r_index += 1

    if len(left) != l_index:
        sorted_list.extend(left[l_index:])
        count += len(left[l_index:])
    if len(right) != r_index:
        sorted_list.extend(right[r_index:])
        count += len(right[r_index:])

    return sorted_list  merge global count sorted_list = [] sorted_list [] l_index = 0 l_index 0 r_index = 0 r_index 0 while l_index < len(left) and r_index < len(right):
        count += 1
        if left[l_index] <= right[r_index]:
            sorted_list.append(left[l_index])
            l_index += 1
        else:
            sorted_list.append(right[r_index])
            r_index += 1

     l_index < len(left) and r_index < len(right) l_index < len(left) l_index len(left) len left r_index < len(right) r_index len(right) len right count += 1 count 1 if left[l_index] <= right[r_index]:
            sorted_list.append(left[l_index])
            l_index += 1
        else:
            sorted_list.append(right[r_index])
            r_index += 1

     left[l_index] <= right[r_index] left[l_index] left l_index right[r_index] right r_index sorted_list.append(left[l_index]) sorted_list.append sorted_list append left[l_index] left l_index l_index += 1 l_index 1 sorted_list.append(right[r_index]) sorted_list.append sorted_list append right[r_index] right r_index r_index += 1 r_index 1 if len(left) != l_index:
        sorted_list.extend(left[l_index:])
        count += len(left[l_index:])
     len(left) != l_index len(left) len left l_index sorted_list.extend(left[l_index:]) sorted_list.extend sorted_list extend left[l_index:] left l_index: l_index count += len(left[l_index:]) count len(left[l_index:]) len left[l_index:] left l_index: l_index if len(right) != r_index:
        sorted_list.extend(right[r_index:])
        count += len(right[r_index:])

     len(right) != r_index len(right) len right r_index sorted_list.extend(right[r_index:]) sorted_list.extend sorted_list extend right[r_index:] right r_index: r_index count += len(right[r_index:]) count len(right[r_index:]) len right[r_index:] right r_index: r_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_str = raw_input().split() raw_input().split() A_str 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 count = 0 0 count A = map(int, A_str) map(int, A_str) A N = int(raw_input()) int(raw_input()) N def merge(left, right):
    global count
    sorted_list = []
    l_index = 0
    r_index = 0

    while l_index < len(left) and r_index < len(right):
        count += 1
        if left[l_index] <= right[r_index]:
            sorted_list.append(left[l_index])
            l_index += 1
        else:
            sorted_list.append(right[r_index])
            r_index += 1

    if len(left) != l_index:
        sorted_list.extend(left[l_index:])
        count += len(left[l_index:])
    if len(right) != r_index:
        sorted_list.extend(right[r_index:])
        count += len(right[r_index:])

    return sorted_list  def merge(left, right):
    global count
    sorted_list = []
    l_index = 0
    r_index = 0

    while l_index < len(left) and r_index < len(right):
        count += 1
        if left[l_index] <= right[r_index]:
            sorted_list.append(left[l_index])
            l_index += 1
        else:
            sorted_list.append(right[r_index])
            r_index += 1

    if len(left) != l_index:
        sorted_list.extend(left[l_index:])
        count += len(left[l_index:])
    if len(right) != r_index:
        sorted_list.extend(right[r_index:])
        count += len(right[r_index:])

    return sorted_list  merge
N = int(raw_input())
count = 0

A_str = raw_input().split()
A = map(int, A_str)

def merge(left, right):
    global count
    sorted_list = []
    l_index = 0
    r_index = 0

    while l_index < len(left) and r_index < len(right):
        count += 1
        if left[l_index] <= right[r_index]:
            sorted_list.append(left[l_index])
            l_index += 1
        else:
            sorted_list.append(right[r_index])
            r_index += 1

    if len(left) != l_index:
        sorted_list.extend(left[l_index:])
        count += len(left[l_index:])
    if len(right) != r_index:
        sorted_list.extend(right[r_index:])
        count += len(right[r_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