Problem: For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order.

Constraints

* $1 \leq n \leq 9$
* $a_i$ consist of $1, 2, ..., n$

Input

A sequence is given in the following format.


$n$
$a_0 \; a_1 \; ... \; a_{n-1}$


Output

Print the previous permutation, the given sequence and the next permutation in the 1st, 2nd and 3rd lines respectively. Separate adjacency elements by a space character. Note that if there is no permutation, print nothing in the corresponding line.

Examples

Input

3
2 1 3


Output

1 3 2
2 1 3
2 3 1


Input

3
3 2 1


Output

3 1 2
3 2 1

Solution (in CPP):

Solution:
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	int v,w;
	ll d;
	char t;
	string name;
	bool operator<(const Data& rhs){
		if(v==rhs.v){
			if(w==rhs.w){
				if(t==rhs.t){
					if(d==rhs.d){
						return name<rhs.name;
					}
					return d<rhs.d;
				}
				return t<rhs.t;
			}
			return w<rhs.w;
		}
		return v<rhs.v;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto P=vecin(N);
	auto PP(P),NP(P);
	
	if(prev_permutation(ALL(PP))){
		REP(i,N-1){
			cout << PP[i] << ' ';
		}
		out(PP[N-1]);
	}
	REP(i,N-1){
		cout << P[i] << ' ';
	}
	out(P[N-1]);
	if(next_permutation(ALL(NP))){
		REP(i,N-1){
			cout << NP[i] << ' ';
		}
		out(NP[N-1]);
	}
	
	return 0;
}