#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define Max 255

int A[Max];

int inputdata(void){
  int n,i;
  printf("n= ");
  scanf("%d",&n);
  srand(time(NULL));
  for(i=1; i<=n; i++){
    A[i]=1+rand()%30;
  }
  printf("A[%d]={%d,",n,A[1]);
  for(i=2;i<n;i++) printf("%d,",A[i]);
  printf("%d}\n",A[n]);
  return(n);
}


void merge(int p, int q, int r){
  int i,j,k,B[Max];
  i=p; j=q+1;
  for(k=p;k<=r;k++){
    if((j>r) || ((i<=q)&&(A[i]<=A[j]))){
      B[k]=A[i]; i++;
    }else{
      B[k]=A[j]; j++;
    }
  }
  for(k=p; k<=r; k++) A[k]=B[k];
}

void merge_sort(int p, int r){
  int q;
  if(p<r){
    q=(p+r)/2;
    merge_sort(p,q);
    merge_sort(q+1,r);
    merge(p,q,r);
  }
}


void printdata(int n){
  int i;
  printf("A[%d]={%d,",n,A[1]);
  for(i=2; i<n; i++) printf("%d,",A[i]);
  printf("%d}\n",A[n]);
}


int main(void){
  int n,k;
  int w=1; 
  n=inputdata();
  merge_sort(w,n);
  printdata(n);
  return(0);
}

