#include <stdio.h>
#define M 100000

int A[M],n;

int ptt(int p,int a){
  int x,i,j,t;
  x = A[a];
  i = p-1;
  for(j=p;j<a;j++){
    if(A[j] <= x){
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[a]; A[a]=t;
  return i+1;
}

int main(){
  int i,q;

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

  q = ptt(0,n-1);
  
  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i == q)printf("]");
  }
  printf("\n");

  return 0;
}

