#include <stdio.h>
int A[2000000],n;

int Partition(int,int);


int main(){
  int i,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(k==i) printf("[%d] ",A[i]);
    else if(i==n) printf("%d ",A[i]);
    else printf("%d ",A[i]);
    
  }
  return 0;
}
 

int Partition(int p,int r){
  int x,i,j,y;

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