#include <stdio.h>
#define MAX 100000

int partition(int,int,int[]);

int main(){
  int n,i,o;
  int A[MAX];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  o=partition(0,n-1,A);
  for(i=0;i<n;i++){
    if(i>0)printf(" ");
    if(i==o)printf("[");
    printf("%d",A[i]);
    if(i==o)printf("]");
    
    
  }
  printf("\n");
  return 0;
}


int partition(int b,int a,int A[]){
  int x,y,i,j;
  x=A[a];
  i=b-1;
  for(j=b;j<a;j++){
    if(A[j]<=x){
      i++;
      y=A[i];
      A[i]=A[j];
      A[j]=y;
      
      }
  }
  y=A[i+1];
  A[i+1]=A[a];
  A[a]=y;
  return i+1;
}

