Let N be a positive even number.

We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below.

First, let q be an empty sequence. Then, perform the following operation until p becomes empty:

* Select two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.



When p becomes empty, q will be a permutation of (1, 2, ..., N).

Find the lexicographically smallest permutation that can be obtained as q.

Constraints

* N is an even number.
* 2 ≤ N ≤ 2 × 10^5
* p is a permutation of (1, 2, ..., N).

Input

Input is given from Standard Input in the following format:


N
p_1 p_2 ... p_N


Output

Print the lexicographically smallest permutation, with spaces in between.

Examples

Input

4
3 2 4 1


Output

3 1 2 4


Input

2
1 2


Output

1 2


Input

8
4 6 3 2 8 5 7 1


Output

3 1 2 7 4 6 8 5
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=200010,inf=0x3f3f3f3f;
int a[maxn],n,logs[maxn],d[2][maxn][30],pos[maxn];
struct cyc{
    int l,r,x;
    bool operator <(const cyc &a)const
    {return x>a.x;}
};
priority_queue<cyc>q;

void RMQ_INIT(int k){
    for(int j=1;(1<<j)<=n;j++)
        for(int i=1;i+(1<<j)-1<=n;i++)
            d[k][i][j]=min(d[k][i][j-1],d[k][i+(1<<(j-1))][j-1]);
}
int rmq(int l,int r,int k){
    int K=logs[r-l+1]; 
     return min(d[k][l][K],d[k][r-(1<<K)+1][K]);
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        d[i&1][i][0]=a[i];//1奇数 
        d[(i&1)^1][i][0]=inf;//0偶数 
        pos[a[i]]=i;//因为是排列可以直接记位置，省去RMQ的位置记录。 
    }
    logs[0]=-1;for(int i=1;i<=n;i++)logs[i]=logs[i>>1]+1;
    RMQ_INIT(0);RMQ_INIT(1);
    q.push((cyc){1,n,rmq(1,n,1)});
    int L,R,p1,p2;
    while(!q.empty()){
        cyc x=q.top();q.pop();
        L=x.l;R=x.r;p1=pos[x.x];
        p2=pos[rmq(p1+1,R,(p1&1)^1)];
        printf("%d %d ",a[p1],a[p2]);
        if(L<p1)q.push((cyc){L,p1-1,rmq(L,p1-1,(L&1))});
        if(p1<p2-1)q.push((cyc){p1+1,p2-1,rmq(p1+1,p2-1,(p1+1)&1)});
        if(p2<R)q.push((cyc){p2+1,R,rmq(p2+1,R,(p2+1)&1)});
    }
    return 0;
}