#P1770H. Koxia, Mahiru and Winter Festival
Koxia, Mahiru and Winter Festival
Description
Koxia and Mahiru are enjoying the Winter Festival. The streets of the Winter Festival can be represented as a undirected grid graph. Formally, the set of vertices is and two vertices and are connected by an edge if and only if .
Koxia and Mahiru are planning to visit The Winter Festival by traversing routes. Although routes are not planned yet, the endpoints of the routes are already planned as follows:
- In the -th route, they want to start from vertex and end at vertex , where is a permutation of length .
- In the -th route, they want to start from vertex and end at vertex , where is a permutation of length .
Your task is to find a routing scheme — paths where each path connects the specified endpoints. Let's define the congestion of an edge as the number of times it is used (both directions combined) in the routing scheme. In order to ensure that Koxia and Mahiru won't get too bored because of traversing repeated edges, please find a routing scheme that minimizes the maximum congestion among all edges.
The first line contains an integer () — the size of the network.
The second line contains integers ().
The third line contains integers ().
It is guaranteed that both and are permutations of length .
Output lines, each line describing a route.
The first lines should describe the connections from top to bottom. The -th line should describe the route starting at vertex and ending at vertex .
The next lines should describe the connections from left to right. The -th line should describe the route starting at vertex and ending at vertex .
Each line describing a route should start with an integer () — the number of vertices the route passes, including the starting and ending vertices. Then output all the vertices on the route in order. In other words, if the route is , then output . Note that should holds for .
If there are multiple solutions that minimize the maximum congestion, you may output any.
Input
The first line contains an integer () — the size of the network.
The second line contains integers ().
The third line contains integers ().
It is guaranteed that both and are permutations of length .
Output
Output lines, each line describing a route.
The first lines should describe the connections from top to bottom. The -th line should describe the route starting at vertex and ending at vertex .
The next lines should describe the connections from left to right. The -th line should describe the route starting at vertex and ending at vertex .
Each line describing a route should start with an integer () — the number of vertices the route passes, including the starting and ending vertices. Then output all the vertices on the route in order. In other words, if the route is , then output . Note that should holds for .
If there are multiple solutions that minimize the maximum congestion, you may output any.
Note
The first example corresponds to the figures in the problem statement.
The output for examples and respectively are visualized below: