Tree Isomorphism#3680

Tree Isomorphism

1 second
256 megabytes
Easy

Two trees, each consisting of nodes, are provided. These trees are considered isomorphic if they share the same structure.

Specifically, trees and are isomorphic if there exists a permutation p = (p_1, \ldots, p_N) such that node is the root in tree if and only if node p_i is the root in tree . Additionally, node is the parent of node in tree if and only if p_i is the parent of p_j in tree .

Input

The first line of the input contains a natural number (1 \leq N \leq 10^5). The second and third lines describe the trees. Each line contains integers a_1, a_2, \ldots, a_N, where a_i indicates the parent node number for node , or is if node is the root.

Output

The output should consist of numbers representing the permutation that maps the first tree onto the second. If multiple permutations exist, any valid one can be provided. If the trees are not isomorphic, output a single number .

Examples

Example 1

Loading
Loading