#include<stdio.h>
#define N 100000

int n,A[N];

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

  return j+1;
}
int main(){
  int i,q;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  q = partition(0,n-1);

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


  return 0;
}

