#include<stdio.h>
#define N 100000
#define G 100000

int partition(int A[],int p,int r){
  int x,i,j,V,Q;

  x=A[r];
  i=p-1;

  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      V=A[i];
      A[i]=A[j];
      A[j]=V;
    }
  }
  Q=A[i+1];
  A[i+1]=A[r];
  A[r]=Q;

  return i+1;
}
      


int main(){
  int A[N],B[N],i,x,g;

  scanf("%d",&x);

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

  g=partition(A,0,x-1);
  
  for(i=0;i<x;i++){
    if(i==g) printf("[%d]",A[g]);
    else printf("%d",A[i]);
    if(i>=0) printf(" ");
	   }


  printf("\n");
  return 0;
}