def merge_sort(a):
    return _merge_sort(a)

def _merge_sort(a):
    if len(a) == 1:
        return a,0
    m = len(a)/2
    b,count1 = _merge_sort(a[0:m])
    c,count2 = _merge_sort(a[m:len(a)])
    ret,count3 = merge(b,c)
    return (ret,count1+count2+count3)

def merge(b,c):
    a = []
    i = 0
    j = 0
    count = 0
    while i < len(b) and j < len(c):
        count += 1
        if b[i] > c[j]:
            a.append(c[j])
            j += 1
        else:
            a.append(b[i])
            i += 1
    if i == len(b):
        while j < len(c):
            count += 1
            a.append(c[j])
            j += 1
    elif j == len(c):
        while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
    return a,count

n = int(raw_input())
a = map(int,raw_input().split(' '))
ret,count = merge_sort(a)
print ' '.join(map(str,ret))
print count def merge_sort(a):
    return _merge_sort(a) merge_sort return _merge_sort(a) _merge_sort(a) _merge_sort a a a def _merge_sort(a):
    if len(a) == 1:
        return a,0
    m = len(a)/2
    b,count1 = _merge_sort(a[0:m])
    c,count2 = _merge_sort(a[m:len(a)])
    ret,count3 = merge(b,c)
    return (ret,count1+count2+count3) _merge_sort if len(a) == 1:
        return a,0
     len(a) == 1 len(a) len a 1 return a,0 return a,0 a 0 m = len(a)/2 m len(a)/2 len(a) len a 2 b,count1 = _merge_sort(a[0:m]) b _merge_sort(a[0:m]) _merge_sort a[0:m] a 0:m 0 m count1 c,count2 = _merge_sort(a[m:len(a)]) c _merge_sort(a[m:len(a)]) _merge_sort a[m:len(a)] a m:len(a) m len(a) len a count2 ret,count3 = merge(b,c) ret merge(b,c) merge b c count3 return (ret,count1+count2+count3) (ret,count1+count2+count3) ret count1+count2+count3 count1+count2 count1 count2 count3 a a def merge(b,c):
    a = []
    i = 0
    j = 0
    count = 0
    while i < len(b) and j < len(c):
        count += 1
        if b[i] > c[j]:
            a.append(c[j])
            j += 1
        else:
            a.append(b[i])
            i += 1
    if i == len(b):
        while j < len(c):
            count += 1
            a.append(c[j])
            j += 1
    elif j == len(c):
        while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
    return a,count merge a = [] a [] i = 0 i 0 j = 0 j 0 count = 0 count 0 while i < len(b) and j < len(c):
        count += 1
        if b[i] > c[j]:
            a.append(c[j])
            j += 1
        else:
            a.append(b[i])
            i += 1
     i < len(b) and j < len(c) i < len(b) i len(b) len b j < len(c) j len(c) len c count += 1 count 1 if b[i] > c[j]:
            a.append(c[j])
            j += 1
        else:
            a.append(b[i])
            i += 1
     b[i] > c[j] b[i] b i c[j] c j a.append(c[j]) a.append a append c[j] c j j += 1 j 1 a.append(b[i]) a.append a append b[i] b i i += 1 i 1 if i == len(b):
        while j < len(c):
            count += 1
            a.append(c[j])
            j += 1
    elif j == len(c):
        while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
     i == len(b) i len(b) len b while j < len(c):
            count += 1
            a.append(c[j])
            j += 1
     j < len(c) j len(c) len c count += 1 count 1 a.append(c[j]) a.append a append c[j] c j j += 1 j 1 elif j == len(c):
        while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
     j == len(c) j len(c) len c while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
     i < len(b) i len(b) len b count += 1 count 1 a.append(b[i]) a.append a append b[i] b i i += 1 i 1 return a,count return a,count a count b b c c n = int(raw_input()) n int(raw_input()) int raw_input() raw_input a = map(int,raw_input().split(' ')) a map(int,raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' ret,count = merge_sort(a) ret merge_sort(a) merge_sort a count print ' '.join(map(str,ret)) ' '.join ' ' join map(str,ret) map str ret print def merge_sort(a):
    return _merge_sort(a) def merge_sort(a):
    return _merge_sort(a) merge_sort a = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) a count = merge_sort(a) merge_sort(a) count def _merge_sort(a):
    if len(a) == 1:
        return a,0
    m = len(a)/2
    b,count1 = _merge_sort(a[0:m])
    c,count2 = _merge_sort(a[m:len(a)])
    ret,count3 = merge(b,c)
    return (ret,count1+count2+count3) def _merge_sort(a):
    if len(a) == 1:
        return a,0
    m = len(a)/2
    b,count1 = _merge_sort(a[0:m])
    c,count2 = _merge_sort(a[m:len(a)])
    ret,count3 = merge(b,c)
    return (ret,count1+count2+count3) _merge_sort def merge(b,c):
    a = []
    i = 0
    j = 0
    count = 0
    while i < len(b) and j < len(c):
        count += 1
        if b[i] > c[j]:
            a.append(c[j])
            j += 1
        else:
            a.append(b[i])
            i += 1
    if i == len(b):
        while j < len(c):
            count += 1
            a.append(c[j])
            j += 1
    elif j == len(c):
        while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
    return a,count def merge(b,c):
    a = []
    i = 0
    j = 0
    count = 0
    while i < len(b) and j < len(c):
        count += 1
        if b[i] > c[j]:
            a.append(c[j])
            j += 1
        else:
            a.append(b[i])
            i += 1
    if i == len(b):
        while j < len(c):
            count += 1
            a.append(c[j])
            j += 1
    elif j == len(c):
        while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
    return a,count merge n = int(raw_input()) int(raw_input()) n ret,count = merge_sort(a) merge_sort(a) ret
def merge_sort(a):
    return _merge_sort(a)

def _merge_sort(a):
    if len(a) == 1:
        return a,0
    m = len(a)/2
    b,count1 = _merge_sort(a[0:m])
    c,count2 = _merge_sort(a[m:len(a)])
    ret,count3 = merge(b,c)
    return (ret,count1+count2+count3)

def merge(b,c):
    a = []
    i = 0
    j = 0
    count = 0
    while i < len(b) and j < len(c):
        count += 1
        if b[i] > c[j]:
            a.append(c[j])
            j += 1
        else:
            a.append(b[i])
            i += 1
    if i == len(b):
        while j < len(c):
            count += 1
            a.append(c[j])
            j += 1
    elif j == len(c):
        while i < len(b):
            count += 1
            a.append(b[i])
            i += 1
    return a,count

n = int(raw_input())
a = map(int,raw_input().split(' '))
ret,count = merge_sort(a)
print ' '.join(map(str,ret))
print count