import math

def InputData():
    
    sequence_len = int(input())
    sequence = list(map(int, input().split(" ")))

    return sequence_len, sequence

def merge(sequence, left, mid, right):
    global merge_cnt
    n1 = mid - left
    n2 = right - mid
    sequence_left = sequence[left:left + n1]
    sequence_right = sequence[mid:mid + n2]
    sequence_left.append(float('inf'))
    sequence_right.append(float('inf'))

    left_cnt = 0
    right_cnt = 0
    for i in range(left, right):
        merge_cnt += 1
        if sequence_left[left_cnt] <= sequence_right[right_cnt]:
            # print(sequence_left[left_cnt])
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            # print(sequence_right[right_cnt])
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1

def mergeSort(sequence, left, right):
    if left + 1 < right:
        # print(merge_cnt)
        mid = (left + right) // 2
        mergeSort(sequence, left, mid)
        mergeSort(sequence, mid, right)
        merge(sequence, left, mid, right)

def PrintOut(sequence, merge_cnt):
    print(' '.join( map(str, sequence)))
    print(merge_cnt)

def main():
    global merge_cnt
    [sequence_len, sequence] = InputData()
    merge_cnt = 0
    mergeSort(sequence, 0, sequence_len)
    PrintOut(sequence, merge_cnt)

if __name__=="__main__":
    main()

 import math math def InputData():
    
    sequence_len = int(input())
    sequence = list(map(int, input().split(" ")))

    return sequence_len, sequence InputData sequence_len = int(input()) sequence_len int(input()) int input() input sequence = list(map(int, input().split(" "))) sequence list(map(int, input().split(" "))) list map(int, input().split(" ")) map int input().split(" ") ().split () input split " " return sequence_len, sequence return sequence_len, sequence sequence_len sequence def merge(sequence, left, mid, right):
    global merge_cnt
    n1 = mid - left
    n2 = right - mid
    sequence_left = sequence[left:left + n1]
    sequence_right = sequence[mid:mid + n2]
    sequence_left.append(float('inf'))
    sequence_right.append(float('inf'))

    left_cnt = 0
    right_cnt = 0
    for i in range(left, right):
        merge_cnt += 1
        if sequence_left[left_cnt] <= sequence_right[right_cnt]:
            # print(sequence_left[left_cnt])
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            # print(sequence_right[right_cnt])
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1 merge global merge_cnt n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid sequence_left = sequence[left:left + n1] sequence_left sequence[left:left + n1] sequence left:left + n1 left left + n1 left n1 sequence_right = sequence[mid:mid + n2] sequence_right sequence[mid:mid + n2] sequence mid:mid + n2 mid mid + n2 mid n2 sequence_left.append(float('inf')) sequence_left.append sequence_left append float('inf') float 'inf' sequence_right.append(float('inf')) sequence_right.append sequence_right append float('inf') float 'inf' left_cnt = 0 left_cnt 0 right_cnt = 0 right_cnt 0 for i in range(left, right):
        merge_cnt += 1
        if sequence_left[left_cnt] <= sequence_right[right_cnt]:
            # print(sequence_left[left_cnt])
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            # print(sequence_right[right_cnt])
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1 i range(left, right) range left right merge_cnt += 1 merge_cnt 1 if sequence_left[left_cnt] <= sequence_right[right_cnt]:
            # print(sequence_left[left_cnt])
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            # print(sequence_right[right_cnt])
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1 sequence_left[left_cnt] <= sequence_right[right_cnt] sequence_left[left_cnt] sequence_left left_cnt sequence_right[right_cnt] sequence_right right_cnt sequence[i] = sequence_left[left_cnt] sequence[i] sequence i sequence_left[left_cnt] sequence_left left_cnt left_cnt += 1 left_cnt 1 sequence[i] = sequence_right[right_cnt] sequence[i] sequence i sequence_right[right_cnt] sequence_right right_cnt right_cnt += 1 right_cnt 1 sequence sequence left left mid mid right right def mergeSort(sequence, left, right):
    if left + 1 < right:
        # print(merge_cnt)
        mid = (left + right) // 2
        mergeSort(sequence, left, mid)
        mergeSort(sequence, mid, right)
        merge(sequence, left, mid, right) mergeSort if left + 1 < right:
        # print(merge_cnt)
        mid = (left + right) // 2
        mergeSort(sequence, left, mid)
        mergeSort(sequence, mid, right)
        merge(sequence, 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(sequence, left, mid) mergeSort sequence left mid mergeSort(sequence, mid, right) mergeSort sequence mid right merge(sequence, left, mid, right) merge sequence left mid right sequence sequence left left right right def PrintOut(sequence, merge_cnt):
    print(' '.join( map(str, sequence)))
    print(merge_cnt) PrintOut print(' '.join( map(str, sequence))) print ' '.join( map(str, sequence)) ' '.join ' ' join map(str, sequence) map str sequence print(merge_cnt) print merge_cnt sequence sequence merge_cnt merge_cnt def main():
    global merge_cnt
    [sequence_len, sequence] = InputData()
    merge_cnt = 0
    mergeSort(sequence, 0, sequence_len)
    PrintOut(sequence, merge_cnt) main global merge_cnt [sequence_len, sequence] = InputData() [sequence_len, sequence] sequence_len sequence InputData() InputData merge_cnt = 0 merge_cnt 0 mergeSort(sequence, 0, sequence_len) mergeSort sequence 0 sequence_len PrintOut(sequence, merge_cnt) PrintOut sequence merge_cnt if __name__=="__main__":
    main() __name__=="__main__" __name__ "__main__" main() main def PrintOut(sequence, merge_cnt):
    print(' '.join( map(str, sequence)))
    print(merge_cnt) def PrintOut(sequence, merge_cnt):
    print(' '.join( map(str, sequence)))
    print(merge_cnt) PrintOut def InputData():
    
    sequence_len = int(input())
    sequence = list(map(int, input().split(" ")))

    return sequence_len, sequence def InputData():
    
    sequence_len = int(input())
    sequence = list(map(int, input().split(" ")))

    return sequence_len, sequence InputData def merge(sequence, left, mid, right):
    global merge_cnt
    n1 = mid - left
    n2 = right - mid
    sequence_left = sequence[left:left + n1]
    sequence_right = sequence[mid:mid + n2]
    sequence_left.append(float('inf'))
    sequence_right.append(float('inf'))

    left_cnt = 0
    right_cnt = 0
    for i in range(left, right):
        merge_cnt += 1
        if sequence_left[left_cnt] <= sequence_right[right_cnt]:
            # print(sequence_left[left_cnt])
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            # print(sequence_right[right_cnt])
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1 def merge(sequence, left, mid, right):
    global merge_cnt
    n1 = mid - left
    n2 = right - mid
    sequence_left = sequence[left:left + n1]
    sequence_right = sequence[mid:mid + n2]
    sequence_left.append(float('inf'))
    sequence_right.append(float('inf'))

    left_cnt = 0
    right_cnt = 0
    for i in range(left, right):
        merge_cnt += 1
        if sequence_left[left_cnt] <= sequence_right[right_cnt]:
            # print(sequence_left[left_cnt])
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            # print(sequence_right[right_cnt])
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1 merge def mergeSort(sequence, left, right):
    if left + 1 < right:
        # print(merge_cnt)
        mid = (left + right) // 2
        mergeSort(sequence, left, mid)
        mergeSort(sequence, mid, right)
        merge(sequence, left, mid, right) def mergeSort(sequence, left, right):
    if left + 1 < right:
        # print(merge_cnt)
        mid = (left + right) // 2
        mergeSort(sequence, left, mid)
        mergeSort(sequence, mid, right)
        merge(sequence, left, mid, right) mergeSort def main():
    global merge_cnt
    [sequence_len, sequence] = InputData()
    merge_cnt = 0
    mergeSort(sequence, 0, sequence_len)
    PrintOut(sequence, merge_cnt) def main():
    global merge_cnt
    [sequence_len, sequence] = InputData()
    merge_cnt = 0
    mergeSort(sequence, 0, sequence_len)
    PrintOut(sequence, merge_cnt) main
import math

def InputData():
    
    sequence_len = int(input())
    sequence = list(map(int, input().split(" ")))

    return sequence_len, sequence

def merge(sequence, left, mid, right):
    global merge_cnt
    n1 = mid - left
    n2 = right - mid
    sequence_left = sequence[left:left + n1]
    sequence_right = sequence[mid:mid + n2]
    sequence_left.append(float('inf'))
    sequence_right.append(float('inf'))

    left_cnt = 0
    right_cnt = 0
    for i in range(left, right):
        merge_cnt += 1
        if sequence_left[left_cnt] <= sequence_right[right_cnt]:
            # print(sequence_left[left_cnt])
            sequence[i] = sequence_left[left_cnt]
            left_cnt += 1
        else:
            # print(sequence_right[right_cnt])
            sequence[i] = sequence_right[right_cnt]
            right_cnt += 1

def mergeSort(sequence, left, right):
    if left + 1 < right:
        # print(merge_cnt)
        mid = (left + right) // 2
        mergeSort(sequence, left, mid)
        mergeSort(sequence, mid, right)
        merge(sequence, left, mid, right)

def PrintOut(sequence, merge_cnt):
    print(' '.join( map(str, sequence)))
    print(merge_cnt)

def main():
    global merge_cnt
    [sequence_len, sequence] = InputData()
    merge_cnt = 0
    mergeSort(sequence, 0, sequence_len)
    PrintOut(sequence, merge_cnt)

if __name__=="__main__":
    main()


