#include <stdio.h>
#include <stdlib.h>
int num=0;
void MergeSort(int S[],int left,int mid,int right)
{
	int i=left,j=mid+1,k=0;
	int *s=(int *)malloc(sizeof(int)*(right-left+1));
	while(i<=mid&&j<=right)
	{
		if(S[i]>S[j])
			s[k++]=S[j++];	
		else
			s[k++]=S[i++];
		num++;	
	}
	
	while(i<=mid)
	{
		s[k++]=S[i++];
		num++;
	}	
	while(j<=right)
	{
		s[k++]=S[j++];
		num++;
	}	
	for(i=left,k=0;i<=right;i++,k++)
	S[i]=s[k];
}
void Merge(int S[],int n,int length)
{
	int i;
	for(i=0;i+2*length-1<n;i=i+2*length)
	MergeSort(S,i,i+length-1,i+2*length-1);
	if(i+length-1<n)
	MergeSort(S,i,i+length-1,n-1);
}
int main(int argc, char *argv[])
{
	int n,S[500005],i,count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&S[i]);
	for(i=1;i<n;i=i*2)
	{
	count++;
	Merge(S,n,i);	
	}
	num=num-count;
	for(i=0;i<n;i++)
	if(i+1==n)
	printf("%d\n%d\n",S[i],num);
	else
	printf("%d ",S[i]);
	return 0;
}
