# ALDS1_5_B Merge Sort
import sys
count = 0

def merge(A, left, mid, right):
    global count
    l = A[left: mid]
    r = A[mid: right]

    l.append(float('inf'))
    r.append(float('inf'))

    i = 0
    j = 0

    for k in range(left, right, 1):
        count += 1
        if l[i] <= r[j]:
            A[k] = l[i]
            i += 1
        else:
            A[k] = r[j]
            j += 1


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


n = int(input())
S = [int(i) for i in sys.stdin.readline().strip().split()]

merge_sort(S, 0, n)
print(' '.join(map(str, S)))
print(count) import sys sys count = 0 count 0 def merge(A, left, mid, right):
    global count
    l = A[left: mid]
    r = A[mid: right]

    l.append(float('inf'))
    r.append(float('inf'))

    i = 0
    j = 0

    for k in range(left, right, 1):
        count += 1
        if l[i] <= r[j]:
            A[k] = l[i]
            i += 1
        else:
            A[k] = r[j]
            j += 1 merge global count l = A[left: mid] l A[left: mid] A left: mid left mid r = A[mid: right] r A[mid: right] A 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, 1):
        count += 1
        if l[i] <= r[j]:
            A[k] = l[i]
            i += 1
        else:
            A[k] = r[j]
            j += 1 k range(left, right, 1) range left right 1 count += 1 count 1 if l[i] <= r[j]:
            A[k] = l[i]
            i += 1
        else:
            A[k] = r[j]
            j += 1 l[i] <= r[j] l[i] l i r[j] r j A[k] = l[i] A[k] A k l[i] l i i += 1 i 1 A[k] = r[j] A[k] A k r[j] r j j += 1 j 1 A A left left mid mid right right def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) merge_sort if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, 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(A, left, mid) merge_sort A left mid merge_sort(A, mid, right) merge_sort A mid right merge(A, left, mid, right) merge A left mid right A A left left right right n = int(input()) n int(input()) int input() input int(i) for i in sys.stdin.readline().strip().split() for i in sys.stdin.readline().strip().split() i sys.stdin.readline().strip().split() sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split for i in sys.stdin.readline().strip().split() int(i) int i S = [int(i) for i in sys.stdin.readline().strip().split()] S [int(i) for i in sys.stdin.readline().strip().split()] merge_sort(S, 0, n) merge_sort S 0 n print(' '.join(map(str, S))) print ' '.join(map(str, S)) ' '.join ' ' join map(str, S) map str S print(count) print count S = [int(i) for i in sys.stdin.readline().strip().split()] [int(i) for i in sys.stdin.readline().strip().split()] S count = 0 0 count def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right) merge_sort n = int(input()) int(input()) n def merge(A, left, mid, right):
    global count
    l = A[left: mid]
    r = A[mid: right]

    l.append(float('inf'))
    r.append(float('inf'))

    i = 0
    j = 0

    for k in range(left, right, 1):
        count += 1
        if l[i] <= r[j]:
            A[k] = l[i]
            i += 1
        else:
            A[k] = r[j]
            j += 1 def merge(A, left, mid, right):
    global count
    l = A[left: mid]
    r = A[mid: right]

    l.append(float('inf'))
    r.append(float('inf'))

    i = 0
    j = 0

    for k in range(left, right, 1):
        count += 1
        if l[i] <= r[j]:
            A[k] = l[i]
            i += 1
        else:
            A[k] = r[j]
            j += 1 merge
# ALDS1_5_B Merge Sort
import sys
count = 0

def merge(A, left, mid, right):
    global count
    l = A[left: mid]
    r = A[mid: right]

    l.append(float('inf'))
    r.append(float('inf'))

    i = 0
    j = 0

    for k in range(left, right, 1):
        count += 1
        if l[i] <= r[j]:
            A[k] = l[i]
            i += 1
        else:
            A[k] = r[j]
            j += 1


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


n = int(input())
S = [int(i) for i in sys.stdin.readline().strip().split()]

merge_sort(S, 0, n)
print(' '.join(map(str, S)))
print(count)
