Hotel of the Planet Shelezyaka#6314

Hotel of the Planet Shelezyaka

1 second
256 megabytes
Medium

In the well-known cartoon, the planet Shelezyaka is inhabited by robots. When Alisa Selezneva and her fellow travelers from the spaceship "Pegasus" checked into a hotel on this planet, they discovered that their rooms were not suitable for human habitation. Some of her friends faced the same issue. They approached the concierge to request room changes and assistance with moving their heavy luggage. However, the hotel's room-changing system was outdated and cumbersome. Specifically, each room was serviced by a single robot that moved all the luggage to a predetermined room and then returned. Once all robots returned to their original rooms, the process could be repeated simultaneously for all rooms.

Alisa and her friends selected new rooms and decided to attempt the luggage moving procedure multiple times to ensure their belongings ended up in the desired rooms (they planned to address any misplaced luggage later). We are interested in finding out if Alisa succeeded in moving the luggage and where all the guests' belongings are currently located.

Input

The first line contains a single natural number (1 \le N \le 300), representing the number of rooms in the hotel.

The second line contains natural numbers, each separated by at least one space. These numbers indicate the destination room for the luggage from each room, meaning the number at position specifies the room to which the luggage from room is moved in one procedure.

The third line contains non-negative integers, each separated by at least one space. The number at position indicates the desired destination room for the luggage of the occupant of room . A zero indicates that the occupant does not wish to participate in the move and only wants to know the current location of their luggage.

Output

The first line should contain a single non-negative integer , representing the minimum number of times the luggage moving procedure must be executed to achieve the desired relocation of Alisa and her friends' luggage. If it is impossible for Alisa to move the luggage as desired, output instead of . If the move is possible, the second line should contain natural numbers, each separated by a space, indicating the final location of the luggage from each room.

Examples

Example 1

Loading
Loading