#include<bits/stdc++.h>
using namespace std;
#define M 100000
int main(){
  int n,a[M],i,j,x;

  cin>>n;
  for(i=0;i<n;i++)cin>>a[i];  
  x=a[i-1];
  i=-1;
  for(j=0;j<n-1;j++){
    if(a[j]<=x){
      i++;
      swap(a[j],a[i]);
    }
  }
  swap(a[i+1],a[n-1]);

  for(int k=0;k<=i;k++){
    cout<<a[k]<<" ";
  }
  cout<<"["<<x<<"] ";
  for(int k=i+2;k<n;k++){
    cout<<a[k];
    if(k<n-1)cout<<" ";
    else cout<<endl;
  }
  return 0;
}

