import java.util.Scanner;
public class 快速排序 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int[] ar=new int[a];
for(int i=0;i<a;i++){
ar[i]=sc.nextInt();
}
System.out.println("y"+(ar.length-1));
Fast(ar,0,ar.length-1);
for(int l=0;l<ar.length;l++){
System.out.print(ar[l]);}
}
static void Fast(int[] ar,int x,int y){
if(x>=y) {
return;
}
int n=y;
int j=x;
int i=x;
for(int m=x;m<y;m++){
if(ar[m]<=ar[n]){
int b=ar[i];
ar[i]=ar[m];
ar[m]=b;
i++;
j++;
}
else if(ar[m]>ar[n]){
int b=ar[j];
ar[j]=ar[m];
ar[m]=b;
j++;
}
}
System.out.println("***i"+i);
int b=ar[i];
ar[i]=ar[n];
ar[n]=b;
System.out.println("*******x"+x+"***y"+y+"***i"+i);
Fast(ar,x,i-1);
Fast(ar,i+1,y);
}
}