N = int(input())
S = list(map(int,input().split()))

def marge(l,r):
    count = 0
    conq = []
    i = 0
    j = 0
    k = len(l) + len(r)
    l.append(float('inf'))
    r.append(float('inf'))
    for o in range(k):
        if l[i] <= r[j]:
            conq.append(l[i])
            i += 1
        else:
            conq.append(r[j])
            j += 1
        count += 1
    return conq,count
           
def margeSort(s):
    n = len(s)
    if n == 1:
        return s,0
    else:
        L, cnt_L = margeSort(s[:n//2])
        R,cnt_R = margeSort(s[n//2:])
        s,cnt = marge(L,R)         
    return s,cnt+cnt_R+cnt_L
S,count = margeSort(S)
print(*S)
print(count) N = int(input()) N int(input()) int input() input S = list(map(int,input().split())) S list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def marge(l,r):
    count = 0
    conq = []
    i = 0
    j = 0
    k = len(l) + len(r)
    l.append(float('inf'))
    r.append(float('inf'))
    for o in range(k):
        if l[i] <= r[j]:
            conq.append(l[i])
            i += 1
        else:
            conq.append(r[j])
            j += 1
        count += 1
    return conq,count
            marge count = 0 count 0 conq = [] conq [] i = 0 i 0 j = 0 j 0 k = len(l) + len(r) k len(l) + len(r) len(l) len l len(r) len r l.append(float('inf')) l.append l append float('inf') float 'inf' r.append(float('inf')) r.append r append float('inf') float 'inf' for o in range(k):
        if l[i] <= r[j]:
            conq.append(l[i])
            i += 1
        else:
            conq.append(r[j])
            j += 1
        count += 1
     o range(k) range k if l[i] <= r[j]:
            conq.append(l[i])
            i += 1
        else:
            conq.append(r[j])
            j += 1
         l[i] <= r[j] l[i] l i r[j] r j conq.append(l[i]) conq.append conq append l[i] l i i += 1 i 1 conq.append(r[j]) conq.append conq append r[j] r j j += 1 j 1 count += 1 count 1 return conq,count return conq,count conq count l l r r def margeSort(s):
    n = len(s)
    if n == 1:
        return s,0
    else:
        L, cnt_L = margeSort(s[:n//2])
        R,cnt_R = margeSort(s[n//2:])
        s,cnt = marge(L,R)         
    return s,cnt+cnt_R+cnt_L margeSort n = len(s) n len(s) len s if n == 1:
        return s,0
    else:
        L, cnt_L = margeSort(s[:n//2])
        R,cnt_R = margeSort(s[n//2:])
        s,cnt = marge(L,R)         
     n == 1 n 1 return s,0 return s,0 s 0 L, cnt_L = margeSort(s[:n//2]) L margeSort(s[:n//2]) margeSort s[:n//2] s :n//2 n//2 n 2 cnt_L R,cnt_R = margeSort(s[n//2:]) R margeSort(s[n//2:]) margeSort s[n//2:] s n//2: n//2 n 2 cnt_R s,cnt = marge(L,R) s marge(L,R) marge L R cnt return s,cnt+cnt_R+cnt_L return s,cnt+cnt_R+cnt_L s cnt+cnt_R+cnt_L cnt+cnt_R cnt cnt_R cnt_L s s S,count = margeSort(S) S margeSort(S) margeSort S count print(*S) print *S S print(count) print count S = list(map(int,input().split())) list(map(int,input().split())) S S,count = margeSort(S) margeSort(S) S def marge(l,r):
    count = 0
    conq = []
    i = 0
    j = 0
    k = len(l) + len(r)
    l.append(float('inf'))
    r.append(float('inf'))
    for o in range(k):
        if l[i] <= r[j]:
            conq.append(l[i])
            i += 1
        else:
            conq.append(r[j])
            j += 1
        count += 1
    return conq,count
            def marge(l,r):
    count = 0
    conq = []
    i = 0
    j = 0
    k = len(l) + len(r)
    l.append(float('inf'))
    r.append(float('inf'))
    for o in range(k):
        if l[i] <= r[j]:
            conq.append(l[i])
            i += 1
        else:
            conq.append(r[j])
            j += 1
        count += 1
    return conq,count
            marge N = int(input()) int(input()) N count = margeSort(S) margeSort(S) count def margeSort(s):
    n = len(s)
    if n == 1:
        return s,0
    else:
        L, cnt_L = margeSort(s[:n//2])
        R,cnt_R = margeSort(s[n//2:])
        s,cnt = marge(L,R)         
    return s,cnt+cnt_R+cnt_L def margeSort(s):
    n = len(s)
    if n == 1:
        return s,0
    else:
        L, cnt_L = margeSort(s[:n//2])
        R,cnt_R = margeSort(s[n//2:])
        s,cnt = marge(L,R)         
    return s,cnt+cnt_R+cnt_L margeSort
N = int(input())
S = list(map(int,input().split()))

def marge(l,r):
    count = 0
    conq = []
    i = 0
    j = 0
    k = len(l) + len(r)
    l.append(float('inf'))
    r.append(float('inf'))
    for o in range(k):
        if l[i] <= r[j]:
            conq.append(l[i])
            i += 1
        else:
            conq.append(r[j])
            j += 1
        count += 1
    return conq,count
           
def margeSort(s):
    n = len(s)
    if n == 1:
        return s,0
    else:
        L, cnt_L = margeSort(s[:n//2])
        R,cnt_R = margeSort(s[n//2:])
        s,cnt = marge(L,R)         
    return s,cnt+cnt_R+cnt_L
S,count = margeSort(S)
print(*S)
print(count)
