#include #define st first #define nd second #define pb push_back #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define sci(x) int x; cin >> x; #define scvi(v, n) vector v(n); rep(i, 0, n) cin >> v[i]; using namespace std; typedef long long ll; typedef pair ii; typedef vector vi; int x[200042]; int bigDL[200042], bigDR[200042]; int bigUL[200042], bigUR[200042]; bool sameL[200042], sameR[200042]; int smallDL[200042],smallDR[200042]; int smallUL[200042],smallUR[200042]; map poss; constexpr int nn = 262144; int tmin[2*nn], tmax[2*nn]; void build() { for (int i=nn-1; i>0; i--) { tmin[i] = min(tmin[2*i], tmin[2*i+1]); tmax[i] = min(tmax[2*i], tmax[2*i+1]); } } int qmin(int l, int r) { int res = 1e9+9; for(l += nn, r += nn; l < r; l >>= 1, r >>= 1) { if (l&1) res = min(res, tmin[l++]); if (r&1) res = min(res, tmin[--r]); } return res; } int qmax(int l, int r) { int res = 0; for(l += nn, r += nn; l < r; l >>= 1, r >>= 1) { if (l&1) res = max(res, tmax[l++]); if (r&1) res = max(res, tmax[--r]); } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i=0; i> x[i]; tmin[nn+i] = x[i]; tmax[nn+i] = x[i]; poss[x[i]].pb(i); } build(); set wasL; set wasLM; for (int i=0; i x[i]) ? *bUl : -1); auto bDl = wasL.upper_bound(x[i]); bigDL[i] = (wasL.end() != bDl ? *bDl : -1); sameL[i] = (wasL.find(x[i]) != wasL.end()); auto sUl = wasL.begin(); smallUL[i] = (wasL.end() != sUl && (*sUl< x[i]) ? *sUl : -1); auto sDl = wasLM.upper_bound(-x[i]); smallDL[i] = (wasLM.end() != sDl ? -*sDl : -1); wasL.insert(x[i]); wasLM.insert(-x[i]); // cout << i << " " << smallL[i] << " " << sameL[i] << " " << bigL[i] << "\n"; } set wasR; set wasRM; for (int i=n-1; i>=0; i--) { auto bUr = wasR.rbegin(); bigUR[i] = (wasR.rend() != bUr && (*bUr > x[i]) ? *bUr : -1); auto bDr = wasR.upper_bound(x[i]); bigDR[i] = (wasR.end() != bDr ? *bDr : -1); sameR[i] = (wasR.find(x[i]) != wasR.end()); auto sUr = wasR.begin(); smallUR[i] = (wasR.end() != sUr && (*sUr< x[i]) ? *sUr : -1); auto sDr = wasRM.upper_bound(-x[i]); smallDR[i] = (wasRM.end() != sDr ? -*sDr : -1); wasR.insert(x[i]); wasRM.insert(-x[i]); // cout << i << " " << smallR[i] << " " << sameR[i] << " " << bigR[i] << "\n"; } set pos; for (int i=1; i bigDR[i]) pos.insert("312"); if (bigDL[i] != -1 && bigUR[i] != -1 && bigDL[i] < bigUR[i]) pos.insert("213"); if (sameL[i] && bigUR[i] != -1) pos.insert("112"); if (sameL[i] && sameR[i]) pos.insert("111"); if (sameL[i] && smallUR[i] != -1) pos.insert("221"); if (bigUL[i] != -1 && sameR[i]) pos.insert("211"); if (smallUL[i] != -1 && sameR[i]) pos.insert("122"); if (smallUL[i] != -1 && smallDR[i] != -1 && smallUL[i] < smallDR[i]) pos.insert("132"); if (smallDL[i] != -1 && smallUR[i] != -1 && smallDL[i] > smallUR[i]) pos.insert("231"); if (smallUL[i] != -1 && bigUR[i] != -1) pos.insert("123"); if (bigUL[i] != -1 && smallUR[i] != -1) pos.insert("321"); } for (const auto& p : poss) { if (p.second.size() > 1) { if (qmax(p.second[0], p.second.back()) > p.first) { pos.insert("121"); } if (qmin(p.second[0], p.second.back()) < p.first) { pos.insert("212"); } } } for (auto p : pos) cout << p << "\n"; return 0; } // 6 // 5 4 9 1 7 4 // 211 // 212 // 213 // 312 // 321