def m(L,R):

 global c

 i=j=0

 for _ in L[:-1]+R[:-1]:

  if L[i]<R[j]:yield L[i];i+=1

  else:yield R[j];j+=1

  c+=1

def d(A):

 s=len(A)//2

 if len(A)>1:A[:]=m(d(A[:s])+[1e9],d(A[s:])+[1e9])

 return A

c=0

eval(input())

print((*d(list(map(int,input().split())))))

print(c)

def m(L,R):

 global c;c+=len(L)+len(R)

 T=[];j=0

 for l in L:

  while j<len(R)and R[j]<l:T+=[R[j]];j+=1

  T+=[l]

 while j<len(R):T+=[R[j]];j+=1

 return T

def d(A):s=len(A)//2;return m(d(A[:s]),d(A[s:])) if len(A)>1 else A

c=0

eval(input())

print((*d(list(map(int,input().split())))))

print(c)

def m(L, R):
    global c
    i = j = 0
    for _ in L[:-1] + R[:-1]:
        if L[i] < R[j]:
            yield L[i]
            i += 1
        else:
            yield R[j]
            j += 1
        c += 1


def d(A):
    s = len(A) // 2
    if len(A) > 1:
        A[:] = m(d(A[:s]) + [1e9], d(A[s:]) + [1e9])
    return A


c = 0
eval(input())
print((*d(list(map(int, input().split())))))
print(c)

def m(L, R):
    global c
    c += len(L) + len(R)
    T = []
    j = 0
    for l in L:
        while j < len(R) and R[j] < l:
            T += [R[j]]
            j += 1
        T += [l]
    while j < len(R):
        T += [R[j]]
        j += 1
    return T


def d(A):
    s = len(A) // 2
    return m(d(A[:s]), d(A[s:])) if len(A) > 1 else A


c = 0
eval(input())
print((*d(list(map(int, input().split())))))
print(c)

-    i = j = 0 -    for _ in L[:-1] + R[:-1]: -        if L[i] < R[j]: -            yield L[i] -            i += 1 -        else: -            yield R[j] +    c += len(L) + len(R) +    T = [] +    j = 0 +    for l in L: +        while j < len(R) and R[j] < l: +            T += [R[j]] -        c += 1 +        T += [l] +    while j < len(R): +        T += [R[j]] +        j += 1 +    return T -    if len(A) > 1: -        A[:] = m(d(A[:s]) + [1e9], d(A[s:]) + [1e9]) -    return A +    return m(d(A[:s]), d(A[s:])) if len(A) > 1 else A