#include<stdio.h>

int r;

void partition(int A[]){
  int i=0,j,k;
  int x;

  for(j=0;j<=r;j++){
    if(A[j]<=A[r]){
      if(r==j) r = i;
      x = A[i];
      A[i] = A[j];
      A[j] = x;
      i++;
    }
    
  }
}

int main(){

  int n,i;
  scanf("%d",&n);

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

  r=n-1;

  partition(A);

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

  return 0;
}

