#include <stdio.h>
#include <stdlib.h>
#define INF 2000000000

long merge(long *A, int left, int mid, int right)
{
  int i, j, k;
  int n1, n2;
  long *L, *R;
  int cnt = 0;
 
  n1 = mid - left;
  L = (long *)malloc(n1 * sizeof(long));
  for(i = 0; i < n1; i++)
    {
      L[i] = A[left + i];
    }
  L[n1] = INF;
  
  n2 = right - mid;
  R = (long *)malloc(n2 * sizeof(long));
  for(i = 0; i < n2; i++)
    {
      R[i] = A[mid + i];
    }
  R[n2] = INF;

  i = 0;
  j = 0;

  for(k = left; k < right; k++)
    {
      cnt++;
      if(L[i] <= R[j])
	{
	  A[k] = L[i];
	  i = i + 1;
	}
      else
	{
	  A[k] = R[j];
	  j = j + 1;
	}
    }

  return cnt;
}

long mergeSort(long *A, int left, int right)
{
  long cnt = 0;
  int mid;

  if(left + 1 < right)
    {
      mid = (left + right)/2;
      cnt += mergeSort(A, left, mid);
      cnt += mergeSort(A, mid, right);
      cnt += merge(A, left, mid, right);
    }
  return cnt;
}

int main()
{
  int i;
  int n;
  long  A[500000];
  int cnt;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &A[i]);
    }

  cnt = mergeSort(A, 0, n);

  for(i = 0; i < n - 1; i++)
    {
      printf("%d ", A[i]);
    }
  printf("%d\n%d\n", A[n - 1], cnt);

  return 0;
}