import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

void main(){
	long n = read.to!long;
	long[] ps = readln.split.map!(to!long).array;
	
	long[] qs = solve(ps);
	
	qs.map!(to!string).array.join(" ").writeln;
	}

long[] solve(long[] ps){
	if(ps.length <= 2) return ps;
	int i0;
	long pmin = long.max;
	for(int i = 0; i < ps.length; i += 2){
		if(ps[i] < pmin) pmin = ps[i], i0 = i;
		}
	debug writeln(ps, " -> ", i0);
	long[] ps1 = ps[0 .. i0];
	long[] ps2 = ps[i0 .. $];
	long[] qs1 = (ps1.length > 2)? [ps1[0], ps1[$ - 1]] ~ solve(ps1[1 .. $ - 1]): ps1;
	long[] qs2 = (ps2.length > 2)? [ps2[0], ps2[$ - 1]] ~ solve(ps2[1 .. $ - 1]): ps2;
	return merge(qs1, qs2);
	}

long[] mw;
long[] merge(long[] ps1, long[] ps2){
	if(!mw.length) mw = new long[](200000);
	int i1 = 0, i2 = 0;
	int j = 0;
	while(i1 < ps1.length || i2 < ps2.length){
		if(i1 >= ps1.length) mw[j] = ps2[i2], mw[j + 1] = ps2[i2 + 1], j += 2, i2 += 2;
		else if(i2 >= ps2.length) mw[j] = ps1[i1], mw[j + 1] = ps1[i1 + 1], j += 2, i1 += 2;
		else if(ps1[i1] < ps2[i2]) mw[j] = ps1[i1], mw[j + 1] = ps1[i1 + 1], j += 2, i1 += 2;
		else mw[j] = ps2[i2], mw[j + 1] = ps2[i2 + 1], j += 2, i2 += 2;
		}
	return mw[0 .. ps1.length + ps2.length];
	}