#include<stdio.h>

void mergesort1(int[],int,int,int);
void mergesort2(int[],int,int);

int count = 0;

int main(void){
  int num = 0;
  int set[500000];
  int change = 0;
  int i;

  scanf("%d",&num);

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

  mergesort2(set,change,num);

  printf("%d\n",count);
  return 0;
}

void mergesort1(int ans[],int changeleft,int mid,int changeright){
  int num1;
  int num2;
  int i = 0;
  int j = 0;
  int k;

  num1 = mid - changeleft;
  num2 = changeright - mid;

  int left[num1 + 1];
  int right[num2 + 1];

  for(i = 0;i < num2;i++){
    left[i] = ans[changeleft + i];
  }
  for(i = 0;i < num2;i++){
    right[i] = ans[mid + i];
  }

  left[num1] = 1000000000;
  right[num2] = 1000000000;

i = 0;
j = 0;

  for(k = changeleft;k < changeright;k++){
    if(left[i] <= right[i]){
      ans[k] = left[i];
      i = i + 1;
      count++;
    }
    else{
      ans[k] = right[j];
      j = j + 1;
      count++;
    }
  }
}

void mergesort2(int ans2[],int changeleft,int changeright){
  int mid;
  int i;

  if(changeleft + 1 < changeright){
    mid = (changeleft + changeright) / 2;
    mergesort2(ans2,changeleft,mid);
    mergesort2(ans2,mid,changeright);
    mergesort1(ans2,changeleft,mid,changeright);
  }
}

