#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
def merge(target_list, left_index, right_index):
    global count
    mid_index = (left_index + right_index) // 2
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list)
def merge_sort(target_list, left_index, right_index):
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, right_index)
    
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    global count
    count = 0
    merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count) def merge(target_list, left_index, right_index):
    global count
    mid_index = (left_index + right_index) // 2
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list) merge global count mid_index = (left_index + right_index) // 2 mid_index (left_index + right_index) // 2 left_index + right_index left_index right_index 2 l = target_list[left_index:mid_index] + [pow(10,9) + 1] l target_list[left_index:mid_index] + [pow(10,9) + 1] target_list[left_index:mid_index] target_list left_index:mid_index left_index mid_index [pow(10,9) + 1] pow(10,9) + 1 pow(10,9) pow 10 9 1 r = target_list[mid_index:right_index] + [pow(10,9) + 1] r target_list[mid_index:right_index] + [pow(10,9) + 1] target_list[mid_index:right_index] target_list mid_index:right_index mid_index right_index [pow(10,9) + 1] pow(10,9) + 1 pow(10,9) pow 10 9 1 l_target = 0 l_target 0 r_target = 0 r_target 0 for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list) k range(left_index, right_index) range left_index right_index count += 1 count 1 if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list) l[l_target] < r[r_target] l[l_target] l l_target r[r_target] r r_target target_list[k] = l[l_target] target_list[k] target_list k l[l_target] l l_target l_target += 1 l_target 1 target_list[k] = r[r_target] target_list[k] target_list k r[r_target] r r_target r_target += 1 r_target 1 target_list target_list left_index left_index right_index right_index def merge_sort(target_list, left_index, right_index):
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, right_index)
     merge_sort if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, right_index)
     left_index + 1 < right_index left_index + 1 left_index 1 right_index mid_index = (left_index + right_index) // 2 mid_index (left_index + right_index) // 2 left_index + right_index left_index right_index 2 merge_sort(target_list, left_index, mid_index) merge_sort target_list left_index mid_index merge_sort(target_list, mid_index, right_index) merge_sort target_list mid_index right_index merge(target_list, left_index, right_index) merge target_list left_index right_index target_list target_list left_index left_index right_index right_index if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    global count
    count = 0
    merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count) __name__ == "__main__" __name__ "__main__" l = input() l input() input int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a target_list = [int(a) for a in input().split()] target_list [int(a) for a in input().split()] global count count = 0 count 0 merge_sort(target_list, 0, len(target_list)) merge_sort target_list 0 len(target_list) len target_list str(n) for n in target_list for n in target_list n target_list for n in target_list str(n) str n print(" ".join([str(n) for n in target_list])) print " ".join([str(n) for n in target_list]) " ".join " " join [str(n) for n in target_list] print(count) print count def merge(target_list, left_index, right_index):
    global count
    mid_index = (left_index + right_index) // 2
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list) def merge(target_list, left_index, right_index):
    global count
    mid_index = (left_index + right_index) // 2
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list) merge count = 0 0 count def merge_sort(target_list, left_index, right_index):
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, right_index)
     def merge_sort(target_list, left_index, right_index):
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, right_index)
     merge_sort l = input() input() l global count target_list = [int(a) for a in input().split()] [int(a) for a in input().split()] target_list
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
def merge(target_list, left_index, right_index):
    global count
    mid_index = (left_index + right_index) // 2
    l = target_list[left_index:mid_index] + [pow(10,9) + 1]
    r = target_list[mid_index:right_index] + [pow(10,9) + 1]
    l_target = 0
    r_target = 0
    #print(left_index, right_index, mid_index, l,r)
    for k in range(left_index, right_index):
        count += 1
        if l[l_target] < r[r_target]:
            target_list[k] = l[l_target]
            l_target += 1
        else:
            target_list[k] = r[r_target]
            r_target += 1
    #print(target_list)
def merge_sort(target_list, left_index, right_index):
    if left_index + 1 < right_index:
        mid_index = (left_index + right_index) // 2

        merge_sort(target_list, left_index, mid_index)
        merge_sort(target_list, mid_index, right_index)
        merge(target_list, left_index, right_index)
    
if __name__ == "__main__":
    l = input()
    target_list = [int(a) for a in input().split()]
    global count
    count = 0
    merge_sort(target_list, 0, len(target_list))
    print(" ".join([str(n) for n in target_list]))
    print(count)