#include<stdio.h>
#define MAX 100000

int partition(int *A,int p,int r);

int main(){
  int n,i;
  int *A;
  
  scanf("%d",&n);
  
  A = malloc(sizeof(int)*n+2);

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

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

  return 0;
}
    

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