#include using namespace std; #include using namespace atcoder; using mint = atcoder::modint998244353; #define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++) #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define siz(x) (int)(x).size() template bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; } template bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; } const int inf = 1e9; const ll INF = 4e18; template using pq = priority_queue, less>; template using spq = priority_queue, greater>; vector di = {0, 0, 1, -1}; vector dj = {1, -1, 0, 0}; struct IoSetup { IoSetup() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); } } iosetup; struct Edge { int to; ll cost; }; void solve() { int N; cin >> N; vector P(N); rep(i, 0, N) { cin >> P[i]; P[i]--; } vector> T; rep(i, 0, N) { if (T.empty()) { T.push_back({P[i]}); continue; } int n = siz(T); //どこにつなげられるのか int ok = n, ng = -1; while(ok-ng>1) { int mid = (ok+ng)/2; if (T[mid].back() >= P[i]) ok = mid; else ng = mid; } if (ok == n) { T.push_back({P[i]}); } else { T[ok].push_back(P[i]); } } vector Q(N); rep(i, 0, N) Q[P[i]] = i; for (vector t : T) { int xmin = inf, ymin = inf; for (int pi : t) { chmin(ymin, pi); chmin(xmin, Q[pi]); } cout << xmin+1 << " " << ymin+1 << endl; } } int main() { int T = 1; while(T--) { solve(); } }