#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; struct Node { int val, depth, children; shared_ptr left, right; }; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; vector> nodes(n); shared_ptr root; root = make_shared(Node { a[0], 0, 0, nullptr, nullptr }); nodes[0] = root; for (int i = 1; i < n; ++i) { shared_ptr cur = root; while (true) { cur->children++; if (a[i] < cur->val) { if (cur->left == nullptr) { cur->left = make_shared(Node { a[i], cur->depth + 1, 0, nullptr, nullptr }); nodes[i] = cur->left; break; } else { cur = cur->left; } } else { if (cur->right == nullptr) { cur->right = make_shared(Node { a[i], cur->depth + 1, 0, nullptr, nullptr }); nodes[i] = cur->right; break; } else { cur = cur->right; } } } } rep(i, n) cout << nodes[i]->depth << ' '; cout << '\n'; rep(i, n) cout << nodes[i]->children << ' '; cout << '\n'; return 0; }