INF = 10**10


def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]

    lry.append(INF)
    rry.append(INF)
    i = 0
    j = 0

    for k in range(left, right):
        if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

    return right - left


def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)
    return cnt


if __name__ == '__main__':
    n = int(input())
    ary = [int(_) for _ in input().split()]
    cnt = merge_sort(ary, 0, n)
    print(*ary)
    print(cnt)
 INF = 10**10 INF 10**10 10 10 def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]

    lry.append(INF)
    rry.append(INF)
    i = 0
    j = 0

    for k in range(left, right):
        if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

    return right - left merge lry = ary[left:mid] lry ary[left:mid] ary left:mid left mid rry = ary[mid:right] rry ary[mid:right] ary mid:right mid right lry.append(INF) lry.append lry append INF rry.append(INF) rry.append rry append INF i = 0 i 0 j = 0 j 0 for k in range(left, right):
        if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

     k range(left, right) range left right if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

     lry[i] <= rry[j] lry[i] lry i rry[j] rry j ary[k] = lry[i] ary[k] ary k lry[i] lry i i += 1 i 1 ary[k] = rry[j] ary[k] ary k rry[j] rry j j += 1 j 1 return right - left right - left right left ary ary left left mid mid right right def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)
    return cnt merge_sort cnt = 0 cnt 0 if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)
     left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 cnt += merge_sort(ary, left, mid) cnt merge_sort(ary, left, mid) merge_sort ary left mid cnt += merge_sort(ary, mid, right) cnt merge_sort(ary, mid, right) merge_sort ary mid right cnt += merge(ary, left, mid, right) cnt merge(ary, left, mid, right) merge ary left mid right return cnt cnt ary ary left left right right if __name__ == '__main__':
    n = int(input())
    ary = [int(_) for _ in input().split()]
    cnt = merge_sort(ary, 0, n)
    print(*ary)
    print(cnt) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ ary = [int(_) for _ in input().split()] ary [int(_) for _ in input().split()] cnt = merge_sort(ary, 0, n) cnt merge_sort(ary, 0, n) merge_sort ary 0 n print(*ary) print *ary ary print(cnt) print cnt def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)
    return cnt def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)
    return cnt merge_sort def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]

    lry.append(INF)
    rry.append(INF)
    i = 0
    j = 0

    for k in range(left, right):
        if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

    return right - left def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]

    lry.append(INF)
    rry.append(INF)
    i = 0
    j = 0

    for k in range(left, right):
        if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

    return right - left merge n = int(input()) int(input()) n INF = 10**10 10**10 INF cnt = merge_sort(ary, 0, n) merge_sort(ary, 0, n) cnt ary = [int(_) for _ in input().split()] [int(_) for _ in input().split()] ary
INF = 10**10


def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]

    lry.append(INF)
    rry.append(INF)
    i = 0
    j = 0

    for k in range(left, right):
        if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

    return right - left


def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)
    return cnt


if __name__ == '__main__':
    n = int(input())
    ary = [int(_) for _ in input().split()]
    cnt = merge_sort(ary, 0, n)
    print(*ary)
    print(cnt)

