count = 0

n = int(input())
l = [int(i) for i in input().split()]


def merge_sort(a):
    if len(a) == 1:
        return [a[0]]
    mid = len(a) // 2
    l1 = merge_sort(a[:mid])
    l2 = merge_sort(a[mid:])
    merged = merge(l1, l2)
    return merged


def merge(l1, l2):
    global count
    len_l1 = len(l1)
    len_l2 = len(l2)
    l1c = l1.copy()
    l2c = l2.copy()

    l1c.append(10 ** 10)
    l2c.append(10 ** 10)

    i = 0
    j = 0
    r = []
    # print("l1", l1)
    # print("l2", l2)
    for k in range(len_l1 + len_l2):
        # print("i", i)
        # print("j", j)
        count += 1
        if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
    return r


r = merge_sort(l)
print(" ".join([str(i) for i in r]))
print(count)
 count = 0 count 0 n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i l = [int(i) for i in input().split()] l [int(i) for i in input().split()] def merge_sort(a):
    if len(a) == 1:
        return [a[0]]
    mid = len(a) // 2
    l1 = merge_sort(a[:mid])
    l2 = merge_sort(a[mid:])
    merged = merge(l1, l2)
    return merged merge_sort if len(a) == 1:
        return [a[0]]
     len(a) == 1 len(a) len a 1 return [a[0]] [a[0]] a[0] a 0 mid = len(a) // 2 mid len(a) // 2 len(a) len a 2 l1 = merge_sort(a[:mid]) l1 merge_sort(a[:mid]) merge_sort a[:mid] a :mid mid l2 = merge_sort(a[mid:]) l2 merge_sort(a[mid:]) merge_sort a[mid:] a mid: mid merged = merge(l1, l2) merged merge(l1, l2) merge l1 l2 return merged merged a a def merge(l1, l2):
    global count
    len_l1 = len(l1)
    len_l2 = len(l2)
    l1c = l1.copy()
    l2c = l2.copy()

    l1c.append(10 ** 10)
    l2c.append(10 ** 10)

    i = 0
    j = 0
    r = []
    # print("l1", l1)
    # print("l2", l2)
    for k in range(len_l1 + len_l2):
        # print("i", i)
        # print("j", j)
        count += 1
        if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
    return r merge global count len_l1 = len(l1) len_l1 len(l1) len l1 len_l2 = len(l2) len_l2 len(l2) len l2 l1c = l1.copy() l1c l1.copy() l1.copy l1 copy l2c = l2.copy() l2c l2.copy() l2.copy l2 copy l1c.append(10 ** 10) l1c.append l1c append 10 ** 10 10 10 l2c.append(10 ** 10) l2c.append l2c append 10 ** 10 10 10 i = 0 i 0 j = 0 j 0 r = [] r [] for k in range(len_l1 + len_l2):
        # print("i", i)
        # print("j", j)
        count += 1
        if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
     k range(len_l1 + len_l2) range len_l1 + len_l2 len_l1 len_l2 count += 1 count 1 if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
     l1c[i] <= l2c[j] l1c[i] l1c i l2c[j] l2c j r.append(l1c[i]) r.append r append l1c[i] l1c i i += 1 i 1 r.append(l2c[j]) r.append r append l2c[j] l2c j j += 1 j 1 return r r l1 l1 l2 l2 r = merge_sort(l) r merge_sort(l) merge_sort l str(i) for i in r for i in r i r for i in r str(i) str i print(" ".join([str(i) for i in r])) print " ".join([str(i) for i in r]) " ".join " " join [str(i) for i in r] print(count) print count count = 0 0 count n = int(input()) int(input()) n def merge_sort(a):
    if len(a) == 1:
        return [a[0]]
    mid = len(a) // 2
    l1 = merge_sort(a[:mid])
    l2 = merge_sort(a[mid:])
    merged = merge(l1, l2)
    return merged def merge_sort(a):
    if len(a) == 1:
        return [a[0]]
    mid = len(a) // 2
    l1 = merge_sort(a[:mid])
    l2 = merge_sort(a[mid:])
    merged = merge(l1, l2)
    return merged merge_sort l = [int(i) for i in input().split()] [int(i) for i in input().split()] l def merge(l1, l2):
    global count
    len_l1 = len(l1)
    len_l2 = len(l2)
    l1c = l1.copy()
    l2c = l2.copy()

    l1c.append(10 ** 10)
    l2c.append(10 ** 10)

    i = 0
    j = 0
    r = []
    # print("l1", l1)
    # print("l2", l2)
    for k in range(len_l1 + len_l2):
        # print("i", i)
        # print("j", j)
        count += 1
        if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
    return r def merge(l1, l2):
    global count
    len_l1 = len(l1)
    len_l2 = len(l2)
    l1c = l1.copy()
    l2c = l2.copy()

    l1c.append(10 ** 10)
    l2c.append(10 ** 10)

    i = 0
    j = 0
    r = []
    # print("l1", l1)
    # print("l2", l2)
    for k in range(len_l1 + len_l2):
        # print("i", i)
        # print("j", j)
        count += 1
        if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
    return r merge r = merge_sort(l) merge_sort(l) r
count = 0

n = int(input())
l = [int(i) for i in input().split()]


def merge_sort(a):
    if len(a) == 1:
        return [a[0]]
    mid = len(a) // 2
    l1 = merge_sort(a[:mid])
    l2 = merge_sort(a[mid:])
    merged = merge(l1, l2)
    return merged


def merge(l1, l2):
    global count
    len_l1 = len(l1)
    len_l2 = len(l2)
    l1c = l1.copy()
    l2c = l2.copy()

    l1c.append(10 ** 10)
    l2c.append(10 ** 10)

    i = 0
    j = 0
    r = []
    # print("l1", l1)
    # print("l2", l2)
    for k in range(len_l1 + len_l2):
        # print("i", i)
        # print("j", j)
        count += 1
        if l1c[i] <= l2c[j]:
            r.append(l1c[i])
            i += 1
        else:
            r.append(l2c[j])
            j += 1
    return r


r = merge_sort(l)
print(" ".join([str(i) for i in r]))
print(count)

