#include <stdio.h>

#define N 100000
int A[N];
int n;

int partition(int,int);

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

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