#include <stdio.h>
#define N 100000
int A[N],total;
int partition(int a,int b){
      int real,i,j,jeep;
      real=A[b];
      i=a-1;
      for(j=a;j<b;j++){
        if(A[j]<=real){
          i++;
          jeep=A[i];
          A[i]=A[j];
          A[j]=jeep;
        }
      }
      jeep=A[i+1];
      A[i+1]=A[b];
      A[b]=jeep;
      return i+1;
    }
    int main(){
    int i,dybala;
  scanf("%d",&total);
  for(i=0;i<total;i++)
    scanf("%d",&A[i]);
  dybala=partition(0,total-1);
     for(i=0;i<total;i++){
      if(i)printf(" ");
      if(i==dybala)printf("[%d]",A[i]);
         else printf("%d",A[i]);
         }
      printf("\n");
      return 0;
    }
