#include<stdio.h>
#define LEN 100010

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

int main(){
  int A[LEN];
  int p,r;
  int i,j,n;

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

  p=0;
  r=n-1;
  j=partition(&A[0],p,r);

  printf("%d",A[0]);
  for(i=1;i<n;i++){
    if(i==j)printf(" [%d]",A[i]);
    else printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}