#include <iostream>
using namespace std;

void MySwap(int &a, int &b){
  int tmp = a;
  a = b;
  b = tmp;
}
  

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

int main(){
  int A[100000], n, place;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  place = partition(A, 0, n-1);
  for(int i = 0; i < n; i++)
    cout << (i==place?"[":"") << A[i] << (i==place?"]":"") << (i==n-1?'\n':' ');
  return 0;
}

#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i;
  int a[10],b[10];
  for(i=0;i<10;i++)
    cin>>a[i];
  for(i=0;i<10;i++)
    cin>>b[i];
  do{
    h=0;
    for(i=1;i<10;i++){
      if(a[i-1]<a[i]){
	swap(a[i-1],a[i]);
	h=1;
      }
    }
  }while(h);
  do{
    h=0;
    for(i=1;i<10;i++){
      if(b[i-1]<b[i]){
	swap(b[i-1],b[i]);
	h=1;
      }
    }
  }while(h);
  cout<<a[0]+a[1]+a[2]<<" "<<b[0]+b[1]+b[2]<<endl;
  return 0;
}