def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    lcount = 0
    rcount = 0
    merged = []
    while lpos < len(left) and rpos < len(right):
        if left[lpos] <= right[rpos]:
            merged.append(left[lpos])
            lpos += 1
            lcount += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += 1
    
    if left[lpos:]:
        merged.extend(left[lpos:])
        lcount += len(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
        rcount += len(right[rpos:])
        
    return merged, lcount + rcount

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    
    sorted, count = merge_sort(A)
    print ' '.join(str(x) for x in sorted)
    print count def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count merge_sort if len(A) <= 1:
        return A, 0
     len(A) <= 1 len(A) len A 1 return A, 0 return A, 0 A 0 mid = len(A) // 2 mid len(A) // 2 len(A) len A 2 left, lcount = merge_sort(A[:mid]) left merge_sort(A[:mid]) merge_sort A[:mid] A :mid mid lcount right, rcount = merge_sort(A[mid:]) right merge_sort(A[mid:]) merge_sort A[mid:] A mid: mid rcount merged, count = merge(left, right) merged merge(left, right) merge left right count return merged, lcount + rcount + count return merged, lcount + rcount + count merged lcount + rcount + count lcount + rcount lcount rcount count A A def merge(left, right):
    lpos = 0
    rpos = 0
    lcount = 0
    rcount = 0
    merged = []
    while lpos < len(left) and rpos < len(right):
        if left[lpos] <= right[rpos]:
            merged.append(left[lpos])
            lpos += 1
            lcount += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += 1
    
    if left[lpos:]:
        merged.extend(left[lpos:])
        lcount += len(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
        rcount += len(right[rpos:])
        
    return merged, lcount + rcount merge lpos = 0 lpos 0 rpos = 0 rpos 0 lcount = 0 lcount 0 rcount = 0 rcount 0 merged = [] merged [] while lpos < len(left) and rpos < len(right):
        if left[lpos] <= right[rpos]:
            merged.append(left[lpos])
            lpos += 1
            lcount += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += 1
    
     lpos < len(left) and rpos < len(right) lpos < len(left) lpos len(left) len left rpos < len(right) rpos len(right) len right if left[lpos] <= right[rpos]:
            merged.append(left[lpos])
            lpos += 1
            lcount += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += 1
    
     left[lpos] <= right[rpos] left[lpos] left lpos right[rpos] right rpos merged.append(left[lpos]) merged.append merged append left[lpos] left lpos lpos += 1 lpos 1 lcount += 1 lcount 1 merged.append(right[rpos]) merged.append merged append right[rpos] right rpos rpos += 1 rpos 1 rcount += 1 rcount 1 if left[lpos:]:
        merged.extend(left[lpos:])
        lcount += len(left[lpos:])
     left[lpos:] left lpos: lpos merged.extend(left[lpos:]) merged.extend merged extend left[lpos:] left lpos: lpos lcount += len(left[lpos:]) lcount len(left[lpos:]) len left[lpos:] left lpos: lpos if right[rpos:]:
        merged.extend(right[rpos:])
        rcount += len(right[rpos:])
        
     right[rpos:] right rpos: rpos merged.extend(right[rpos:]) merged.extend merged extend right[rpos:] right rpos: rpos rcount += len(right[rpos:]) rcount len(right[rpos:]) len right[rpos:] right rpos: rpos return merged, lcount + rcount return merged, lcount + rcount merged lcount + rcount lcount rcount left left right right if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    
    sorted, count = merge_sort(A)
    print ' '.join(str(x) for x in sorted)
    print count __name__ == '__main__' __name__ '__main__' n = int(raw_input()) n int(raw_input()) int raw_input() raw_input A = map(int, raw_input().split()) A map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split sorted, count = merge_sort(A) sorted merge_sort(A) merge_sort A count print ' '.join(str(x) for x in sorted) ' '.join ' ' join str(x) str x print n = int(raw_input()) int(raw_input()) n A = map(int, raw_input().split()) map(int, raw_input().split()) A def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count merge_sort sorted, count = merge_sort(A) merge_sort(A) sorted def merge(left, right):
    lpos = 0
    rpos = 0
    lcount = 0
    rcount = 0
    merged = []
    while lpos < len(left) and rpos < len(right):
        if left[lpos] <= right[rpos]:
            merged.append(left[lpos])
            lpos += 1
            lcount += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += 1
    
    if left[lpos:]:
        merged.extend(left[lpos:])
        lcount += len(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
        rcount += len(right[rpos:])
        
    return merged, lcount + rcount def merge(left, right):
    lpos = 0
    rpos = 0
    lcount = 0
    rcount = 0
    merged = []
    while lpos < len(left) and rpos < len(right):
        if left[lpos] <= right[rpos]:
            merged.append(left[lpos])
            lpos += 1
            lcount += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += 1
    
    if left[lpos:]:
        merged.extend(left[lpos:])
        lcount += len(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
        rcount += len(right[rpos:])
        
    return merged, lcount + rcount merge count = merge_sort(A) merge_sort(A) count
def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    lcount = 0
    rcount = 0
    merged = []
    while lpos < len(left) and rpos < len(right):
        if left[lpos] <= right[rpos]:
            merged.append(left[lpos])
            lpos += 1
            lcount += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += 1
    
    if left[lpos:]:
        merged.extend(left[lpos:])
        lcount += len(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
        rcount += len(right[rpos:])
        
    return merged, lcount + rcount

if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    
    sorted, count = merge_sort(A)
    print ' '.join(str(x) for x in sorted)
    print count