#include <iostream>

using namespace std;

int main(void)
{
  int i, j, box, n, A[100000];

  cin >> n;

  for(i = 0;i < n;i++){
    cin >> A[i]; 
  }

  int x = A[n - 1];
  i = 0;

  for(j = 0;j < n - 1;j++){
    if(A[j] <= x){
      box = A[i];
      A[i] = A[j];
      A[j] = box;
      i++;
    }
  }

  box = A[n - 1];
  A[n - 1] = A[i];
  A[i] = box;

  for(j = 0;j < n - 1;j++){
    if(j == i){
      cout << '[' << A[j] << "] ";
    }
    else{
      cout << A[j] << ' ';
    }
  }

  cout << A[j] << endl;
  
  return 0;
}

