#include #include #include #include #include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; using vi = vector; using vvi = vector; using vvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vmi = vector; using vvmi = vector; using vvvmi = vector; #define all(a) (a).begin(), (a).end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) int op(int a, int b){ return max(a, b); } int e(){return 0;} int main(){ int n; cin >> n; vi p(n); rep(i, n)cin >> p[i]; rep(i, n)p[i]--; vi pos(n); rep(i, n)pos[p[i]] = i; segtree seg(n); rep(i, n){ int c = pos[i]; if(c == 0){ seg.set(c, 1); continue; } seg.set(c, seg.prod(0, c) + 1); } int size = seg.all_prod(); vvi ans(size, vi(2, 1e9)); rep(i, n){ int u = seg.get(i) - 1; ans[u][0] = min(ans[u][0], i+1); ans[u][1] = min(ans[u][1], p[i]+1); } rep(i, size){ cout << ans[i][0] << " " << ans[i][1] << endl; } return 0; }