const solve = xs => {
    let rs = [];

    if (xs.length === 0) return rs;

    let i = -1; j = 0;
    let p = xs[xs.length - 1];

    while (j < xs.length) {
        if (xs[j] <= p) {
            i = i + 1;
            t = xs[i]; xs[i] = xs[j]; xs[j] = t;
        }
        j = j + 1;
    }


    for (let k = 0; k < xs.length; k++) {
        if (k === i) {
            rs.push("[" + xs[k] + "]");
        } else {
            rs.push(String(xs[k]));
        }
    }

    return rs;
}


const main = () => {
    args =
        require('fs').
        readFileSync('/dev/stdin', 'UTF-8').
        split("\n").
        map(line => line.split(' ').map(c => parseInt(c)));

    args.pop();

    const cs = solve(args[1].concat());

    console.log(cs.join(' '));
}

main();

