INF = 10 ** 10

def merge(A, left, mid, right):
    c = 0
    n1 = mid - left
    n2 = right - mid
    Left = [A[left+i] for i in range(n1)]
    Right = [A[mid+i] for i in range(n2)]
    Left.append(INF)
    Right.append(INF)
    i=0
    j=0
    for k in range(left, right):
        c += 1
        if Left[i] <= Right[j]:
            A[k] = Left[i]
            i += 1
        else:
            A[k] = Right[j]
            j += 1
    return c

def mergeSort(hoge, left, right):
    c = 0
    if left+1 < right:
        mid = (left + right) // 2
        c += mergeSort(hoge, left, mid)
        c += mergeSort(hoge, mid, right)
        c += merge(hoge, left, mid, right)
    return c

if __name__ == '__main__':
    _ = input()
    hoge = [int(x) for x in input().split()]
    c = mergeSort(hoge, 0, len(hoge))
    print (' '.join([str(x) for x in hoge]))
    print (c) INF = 10 ** 10 INF 10 ** 10 10 10 def merge(A, left, mid, right):
    c = 0
    n1 = mid - left
    n2 = right - mid
    Left = [A[left+i] for i in range(n1)]
    Right = [A[mid+i] for i in range(n2)]
    Left.append(INF)
    Right.append(INF)
    i=0
    j=0
    for k in range(left, right):
        c += 1
        if Left[i] <= Right[j]:
            A[k] = Left[i]
            i += 1
        else:
            A[k] = Right[j]
            j += 1
    return c merge c = 0 c 0 n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid A[left+i] for i in range(n1) for i in range(n1) i range(n1) range n1 for i in range(n1) A[left+i] A left+i left i Left = [A[left+i] for i in range(n1)] Left [A[left+i] for i in range(n1)] A[mid+i] for i in range(n2) for i in range(n2) i range(n2) range n2 for i in range(n2) A[mid+i] A mid+i mid i Right = [A[mid+i] for i in range(n2)] Right [A[mid+i] for i in range(n2)] Left.append(INF) Left.append Left append INF Right.append(INF) Right.append Right append INF i=0 i 0 j=0 j 0 for k in range(left, right):
        c += 1
        if Left[i] <= Right[j]:
            A[k] = Left[i]
            i += 1
        else:
            A[k] = Right[j]
            j += 1
     k range(left, right) range left right c += 1 c 1 if Left[i] <= Right[j]:
            A[k] = Left[i]
            i += 1
        else:
            A[k] = Right[j]
            j += 1
     Left[i] <= Right[j] Left[i] Left i Right[j] Right j A[k] = Left[i] A[k] A k Left[i] Left i i += 1 i 1 A[k] = Right[j] A[k] A k Right[j] Right j j += 1 j 1 return c c A A left left mid mid right right def mergeSort(hoge, left, right):
    c = 0
    if left+1 < right:
        mid = (left + right) // 2
        c += mergeSort(hoge, left, mid)
        c += mergeSort(hoge, mid, right)
        c += merge(hoge, left, mid, right)
    return c mergeSort c = 0 c 0 if left+1 < right:
        mid = (left + right) // 2
        c += mergeSort(hoge, left, mid)
        c += mergeSort(hoge, mid, right)
        c += merge(hoge, left, mid, right)
     left+1 < right left+1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 c += mergeSort(hoge, left, mid) c mergeSort(hoge, left, mid) mergeSort hoge left mid c += mergeSort(hoge, mid, right) c mergeSort(hoge, mid, right) mergeSort hoge mid right c += merge(hoge, left, mid, right) c merge(hoge, left, mid, right) merge hoge left mid right return c c hoge hoge left left right right if __name__ == '__main__':
    _ = input()
    hoge = [int(x) for x in input().split()]
    c = mergeSort(hoge, 0, len(hoge))
    print (' '.join([str(x) for x in hoge]))
    print (c) __name__ == '__main__' __name__ '__main__' _ = input() _ input() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x hoge = [int(x) for x in input().split()] hoge [int(x) for x in input().split()] c = mergeSort(hoge, 0, len(hoge)) c mergeSort(hoge, 0, len(hoge)) mergeSort hoge 0 len(hoge) len hoge str(x) for x in hoge for x in hoge x hoge for x in hoge str(x) str x print (' '.join([str(x) for x in hoge])) print ' '.join([str(x) for x in hoge]) ' '.join ' ' join [str(x) for x in hoge] print (c) print c def merge(A, left, mid, right):
    c = 0
    n1 = mid - left
    n2 = right - mid
    Left = [A[left+i] for i in range(n1)]
    Right = [A[mid+i] for i in range(n2)]
    Left.append(INF)
    Right.append(INF)
    i=0
    j=0
    for k in range(left, right):
        c += 1
        if Left[i] <= Right[j]:
            A[k] = Left[i]
            i += 1
        else:
            A[k] = Right[j]
            j += 1
    return c def merge(A, left, mid, right):
    c = 0
    n1 = mid - left
    n2 = right - mid
    Left = [A[left+i] for i in range(n1)]
    Right = [A[mid+i] for i in range(n2)]
    Left.append(INF)
    Right.append(INF)
    i=0
    j=0
    for k in range(left, right):
        c += 1
        if Left[i] <= Right[j]:
            A[k] = Left[i]
            i += 1
        else:
            A[k] = Right[j]
            j += 1
    return c merge c = mergeSort(hoge, 0, len(hoge)) mergeSort(hoge, 0, len(hoge)) c INF = 10 ** 10 10 ** 10 INF _ = input() input() _ hoge = [int(x) for x in input().split()] [int(x) for x in input().split()] hoge def mergeSort(hoge, left, right):
    c = 0
    if left+1 < right:
        mid = (left + right) // 2
        c += mergeSort(hoge, left, mid)
        c += mergeSort(hoge, mid, right)
        c += merge(hoge, left, mid, right)
    return c def mergeSort(hoge, left, right):
    c = 0
    if left+1 < right:
        mid = (left + right) // 2
        c += mergeSort(hoge, left, mid)
        c += mergeSort(hoge, mid, right)
        c += merge(hoge, left, mid, right)
    return c mergeSort
INF = 10 ** 10

def merge(A, left, mid, right):
    c = 0
    n1 = mid - left
    n2 = right - mid
    Left = [A[left+i] for i in range(n1)]
    Right = [A[mid+i] for i in range(n2)]
    Left.append(INF)
    Right.append(INF)
    i=0
    j=0
    for k in range(left, right):
        c += 1
        if Left[i] <= Right[j]:
            A[k] = Left[i]
            i += 1
        else:
            A[k] = Right[j]
            j += 1
    return c

def mergeSort(hoge, left, right):
    c = 0
    if left+1 < right:
        mid = (left + right) // 2
        c += mergeSort(hoge, left, mid)
        c += mergeSort(hoge, mid, right)
        c += merge(hoge, left, mid, right)
    return c

if __name__ == '__main__':
    _ = input()
    hoge = [int(x) for x in input().split()]
    c = mergeSort(hoge, 0, len(hoge))
    print (' '.join([str(x) for x in hoge]))
    print (c)
