#include<stdio.h>
#define MAX 100000

int partition(int *,int,int);
int n;

int main() {

  int i;
  int num[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&num[i]);

  int a = partition(num,0,n-1);

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

  return 0;

}

int partition(int A[n],int p,int r) {
  
  int x = A[r];
  int i = p-1;
  int j,a;

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