#include<stdio.h>
#define MAX 1000000

int A[MAX],n;
int partition(int[] A,int p,int r){
    int x = A[r];
    int i =p-1;
    int t;
    fo(int j=p;j<r;j++){
         if(A[j]<=x){
             i++;
             t=A[i],A[i] =A[j],A[j] = t;
         }
   }
   t = A[i+1],A[i+1]=A[r],A[r] = t;
   return i+1;
}



int main(){
     scant("%d",&n);
     int i;
     for(i=0;i<n;i++){
        scant("%d",&A[i]);
     }
     int p = partition(A,0,n-1);
     for(i=0;i<n;i++){
     	if(i) printf(" ");
     	if(i==p) printf("[");
     	printf("%d",A[i]);
     	if(i==p) printf("]");
     }
     printf("\n");
    return 0; 
}