n = int(raw_input())
S = map(int,raw_input().strip().split(' '))

comp = 0

def merge_sort(S):
    if len(S) <= 1:
        return S
    S1,S2 = split(S)
    return merge(merge_sort(S1),merge_sort(S2))

def split(S):
    mid = len(S)/2
    return S[:mid],S[mid:]

def merge(S1,S2):
    S = []
    S1.append(100000000000)
    S2.append(100000000000)
    global comp
    i = 0
    j = 0
    for k in range(len(S1)+len(S2)-2):
        comp += 1
        if S1[i] <= S2[j]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
    return S

sorted_S = merge_sort(S)
for s in sorted_S:
    print s,
print
print comp n = int(raw_input()) n int(raw_input()) int raw_input() raw_input S = map(int,raw_input().strip().split(' ')) S map(int,raw_input().strip().split(' ')) map int raw_input().strip().split(' ') ().strip().split ().strip() ().strip () raw_input strip split ' ' comp = 0 comp 0 def merge_sort(S):
    if len(S) <= 1:
        return S
    S1,S2 = split(S)
    return merge(merge_sort(S1),merge_sort(S2)) merge_sort if len(S) <= 1:
        return S
     len(S) <= 1 len(S) len S 1 return S S S1,S2 = split(S) S1 split(S) split S S2 return merge(merge_sort(S1),merge_sort(S2)) merge(merge_sort(S1),merge_sort(S2)) merge merge_sort(S1) merge_sort S1 merge_sort(S2) merge_sort S2 S S def split(S):
    mid = len(S)/2
    return S[:mid],S[mid:] split mid = len(S)/2 mid len(S)/2 len(S) len S 2 return S[:mid],S[mid:] return S[:mid],S[mid:] S[:mid] S :mid mid S[mid:] S mid: mid S S def merge(S1,S2):
    S = []
    S1.append(100000000000)
    S2.append(100000000000)
    global comp
    i = 0
    j = 0
    for k in range(len(S1)+len(S2)-2):
        comp += 1
        if S1[i] <= S2[j]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
    return S merge S = [] S [] S1.append(100000000000) S1.append S1 append 100000000000 S2.append(100000000000) S2.append S2 append 100000000000 global comp i = 0 i 0 j = 0 j 0 for k in range(len(S1)+len(S2)-2):
        comp += 1
        if S1[i] <= S2[j]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
     k range(len(S1)+len(S2)-2) range len(S1)+len(S2)-2 len(S1)+len(S2) len(S1) len S1 len(S2) len S2 2 comp += 1 comp 1 if S1[i] <= S2[j]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
     S1[i] <= S2[j] S1[i] S1 i S2[j] S2 j S.append(S1[i]) S.append S append S1[i] S1 i i += 1 i 1 S.append(S2[j]) S.append S append S2[j] S2 j j += 1 j 1 return S S S1 S1 S2 S2 sorted_S = merge_sort(S) sorted_S merge_sort(S) merge_sort S for s in sorted_S:
    print s, s sorted_S print s print print n = int(raw_input()) int(raw_input()) n comp = 0 0 comp def merge(S1,S2):
    S = []
    S1.append(100000000000)
    S2.append(100000000000)
    global comp
    i = 0
    j = 0
    for k in range(len(S1)+len(S2)-2):
        comp += 1
        if S1[i] <= S2[j]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
    return S def merge(S1,S2):
    S = []
    S1.append(100000000000)
    S2.append(100000000000)
    global comp
    i = 0
    j = 0
    for k in range(len(S1)+len(S2)-2):
        comp += 1
        if S1[i] <= S2[j]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
    return S merge def merge_sort(S):
    if len(S) <= 1:
        return S
    S1,S2 = split(S)
    return merge(merge_sort(S1),merge_sort(S2)) def merge_sort(S):
    if len(S) <= 1:
        return S
    S1,S2 = split(S)
    return merge(merge_sort(S1),merge_sort(S2)) merge_sort S = map(int,raw_input().strip().split(' ')) map(int,raw_input().strip().split(' ')) S def split(S):
    mid = len(S)/2
    return S[:mid],S[mid:] def split(S):
    mid = len(S)/2
    return S[:mid],S[mid:] split sorted_S = merge_sort(S) merge_sort(S) sorted_S
n = int(raw_input())
S = map(int,raw_input().strip().split(' '))

comp = 0

def merge_sort(S):
    if len(S) <= 1:
        return S
    S1,S2 = split(S)
    return merge(merge_sort(S1),merge_sort(S2))

def split(S):
    mid = len(S)/2
    return S[:mid],S[mid:]

def merge(S1,S2):
    S = []
    S1.append(100000000000)
    S2.append(100000000000)
    global comp
    i = 0
    j = 0
    for k in range(len(S1)+len(S2)-2):
        comp += 1
        if S1[i] <= S2[j]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
    return S

sorted_S = merge_sort(S)
for s in sorted_S:
    print s,
print
print comp