function partition(a,p,r){
    var x = a[r];
    var i = p - 1;
    for(var j = p;j < r;j++){
        if(a[j] <= x){
            i++;
            var b = a[i];
            a[i] = a[j];
            a[j] = b;
        }
    }
    b = a[i + 1];
    a[i + 1] = a[r];
    a[r] = b;
    return i + 1;
}

function Main(input){
    input = input.split("\n");
    var n = parseInt(input[0],10);
    input[1] = input[1].split(" ");
    var a = new Array(n);
    for(var i = 0;i < n;i++){
        a[i] = parseInt(input[1][i],10);
    }

    var j = partition(a,0,n - 1);

    for(var i = 0;i < n;i++)
        String(a[i]);
    var ans = a[0];
    for(var i = 1;i < n;i++){
        if(i == j)
            ans += " " + "[" + a[i] + "]";
        else
            ans += " " + a[i];
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));