#include<stdio.h>
#define N 100000
int A[N],n;

int Partition(int *A,int p,int r){
  int x,i,j,exc;
  x = A[r];
  i = p - 1;
  for(j=1;j<r;j++){
    if(A[j]<=x){
      i = i+1;
      exc = A[i];
      A[i] = A[j];
      A[j] = exc;
    }
  }
  exc = A[i+1];
  A[i+1]=A[r];
  A[r]= exc;
  
  return i+1;
}

int main(){
  int i,part,p,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  p=0;
  r=n-1;
  part = Partition(A,p,r);
  
  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    if(part==i) printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
  printf("\n");
  return 0;
}