#include #define F(i,a,b) for ( int i = (int)(a); i < (int)(b); ++i ) #define ff first #define ss second using namespace std; using ii = pair; using vi = vector; const int INF = 1e9+7; int main() { ios::sync_with_stdio(0); int n; cin >> n; vi a(n); F(i,0,n) cin >> a[i]; set res, active; multiset L, R; map leftmost, rightmost; F(i,0,n) { int x = a[i]; R.insert(x); if (!leftmost.count(x)) leftmost[x] = i; rightmost[x] = i; } F(i,0,n) { int x = a[i]; R.erase(R.find(x)); if (leftmost[x] == i) active.insert(x); if (rightmost[x] == i) active.erase(x); if (active.size() && *active.begin() < x) res.insert(121); if (active.size() && *active.rbegin() > x) res.insert(212); bool onLeft = L.find(x) != L.end(); bool onRight = R.find(x) != R.end(); auto Lmin = L.size() ? *L.begin() : 0; auto Lless = L.lower_bound(x) == L.begin() ? 0 : *--L.lower_bound(x); auto Lmore = L.upper_bound(x) == L.end() ? 0 : *L.upper_bound(x); auto Lmax = L.size() ? *L.rbegin() : 0; auto Rmin = R.size() ? *R.begin() : 0; auto Rless = R.lower_bound(x) == R.begin() ? 0 : *--R.lower_bound(x); auto Rmore = R.upper_bound(x) == R.end() ? 0 : *R.upper_bound(x); auto Rmax = R.size() ? *R.rbegin() : 0; if (onLeft && onRight) res.insert(111); if (onLeft && Rmax && Rmax > x) res.insert(112); if (Lmin && Lmin < x && onRight) res.insert(122); if (Lmax && Lmax > x && onRight) res.insert(211); if (Rmin && Rmin < x && onLeft) res.insert(221); if (Lmin && Rmax && Lmin < x && Rmax > x) res.insert(123); if (Lmin && Rless && Lmin < Rless && Rless < x) res.insert(132); if (Lmore && Rmax && Lmore > x && Lmore < Rmax) res.insert(213); if (Lless && Rmin && Lless < x && Lless > Rmin) res.insert(231); if (Lmax && Rmore && Lmax > Rmore && Rmore > x) res.insert(312); if (Lmax && Rless && Lmax > x && x > Rless) res.insert(321); L.insert(x); } for (auto t : res) { cout << t << endl; } return 0; }