#include <stdio.h>
#include <stdlib.h>
#define INFTY 100000000
int *merge(int *, int, int, int);
int *mergesort(int *, int, int);
int n, count;

int main()
{
  int left, right, i;
  int *s;

  scanf("%d", &n);
  s = (int *)malloc(n*sizeof(int));
  for(i=0; i<n; i++) {
    scanf("%d", &s[i]);
  }
  left = 0;
  right = i;

  for(i=0; i<n; i++) {
    printf("%d ", mergesort(s, left, right)[i]);
  }
  printf("\n%d\n", count);

  return 0;
}

int *merge(int *a, int left, int mid, int right)
{
  int n1, n2, i, j, k;
  int *l, *r;

  n1 = mid-left;
  n2 = right-mid;
  l = (int *)malloc(n1*sizeof(int));
  r = (int *)malloc(n2*sizeof(int));

  for(i=0; i<n1; i++) {
    l[i] = a[left+i];
  }
  for(i=0; i<n2; i++) {
    r[i] = a[mid+i];
  }
  l[n1] = INFTY;
  r[n2] = INFTY;
  i = 0;
  j = 0;
  for(k=left; k<right; k++) {
    count++;
    if(l[i] <= r[j]) {
      a[k] = l[i];
      i++;
    }
    else {
      a[k] = r[j];
      j++;
    }
  }
  return a;
}

int *mergesort(int *a, int left, int right) {
  int mid;
  
  if(left+1 < right) {
    mid = (left+right)/2;
    mergesort(a, left, mid);
    mergesort(a, mid, right);
    return merge(a, left, mid, right);
  }
}