{"raw_statement":[{"iden":"problem statement","content":"Consider a **binary tree** with $N$ vertices numbered $1, 2, \\ldots, N$. Here, a binary tree is a rooted tree where each vertex has at most two children. Specifically, each vertex in a binary tree has at most one **left child** and at most one **right child**.\nDetermine whether there exists a binary tree rooted at Vertex $1$ satisfying the conditions below, and present such a tree if it exists.\n\n*   The depth-first traversal of the tree in [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR) is $(P_1, P_2, \\ldots, P_N)$.\n*   The depth-first traversal of the tree in [in-order](https://en.wikipedia.org/wiki/Tree_traversal#In-order,_LNR) is $(I_1, I_2, \\ldots, I_N)$."},{"iden":"constraints","content":"*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $N$ is an integer.\n*   $(P_1, P_2, \\ldots, P_N)$ is a permutation of $(1, 2, \\ldots, N)$.\n*   $(I_1, I_2, \\ldots, I_N)$ is a permutation of $(1, 2, \\ldots, N)$."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$P_1$ $P_2$ $\\ldots$ $P_N$\n$I_1$ $I_2$ $\\ldots$ $I_N$"},{"iden":"sample input 1","content":"6\n1 3 5 6 4 2\n3 5 1 4 6 2"},{"iden":"sample output 1","content":"3 6\n0 0\n0 5\n0 0\n0 0\n4 2\n\nThe binary tree rooted at Vertex $1$ shown in the following image satisfies the conditions.\n![image](https://img.atcoder.jp/abc255/b51399e8953ae1723d1d9e83617f9be9.png)"},{"iden":"sample input 2","content":"2\n2 1\n1 2"},{"iden":"sample output 2","content":"\\-1\n\nNo binary tree rooted at Vertex $1$ satisfies the conditions, so $-1$ should be printed."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}