#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) struct Node { int value; int depth; int child; Node *left; Node *right; }; struct Node* insert(struct Node *node, int x, int dp) { if (node == NULL) { struct Node *newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->value = x; newNode->depth = dp; newNode->child = 0; newNode->left = NULL; newNode->right = NULL; return newNode; } if (x < node->value) node->left = insert(node->left, x, dp + 1); else node->right = insert(node->right, x, dp + 1); int cl = node->left == NULL ? 0 : node->left->child + 1; int cr = node->right == NULL ? 0 : node->right->child + 1; node->child = cl + cr; return node; } int main() { int n; cin >> n; vector a(n), ainv(n+1); rep(i, n) { cin >> a[i]; ainv[a[i]] = i; } struct Node *tree; rep(i, n) { tree = insert(tree, a[i], 0); } vector b(n), c(n); auto dfs = [&](auto dfs, struct Node *node) -> void { if (node == NULL) return; b[ainv[node->value]] = node->depth; c[ainv[node->value]] = node->child; dfs(dfs, node->left); dfs(dfs, node->right); }; dfs(dfs, tree); rep(i, n) { cout << b[i]; if (i < n-1) cout << " "; else cout << endl; } rep(i, n) { cout << c[i]; if (i < n-1) cout << " "; else cout << endl; } return 0; }