This is an Approximate problem!
The Museum of Tomorrow (Museu do Amanhã) is a science museum in the city of Rio de Janeiro, Brazil. The main exhibition takes visitors through five main areas: Cosmos, Earth, Anthropocene, Tomorrow and Now via a number of experiments and experiences. The museum mixes science with an innovative design to focus on sustainable cities.
Today, manager of the museum is planning to conduct a quiz in which visitors can participate and win free ticket to the museum.
There are n cards on the table and each card has a unique integer ( from 1 to n ) written on it. The cards represent a permutation p of size n. A visitor can perform many operations. In one operation, a visitor will select a continuous segment of cards and reverse the order of the cards. The task is to convert p into identity permutation ( i.e. all the cards have to be in strictly increasing order ).
To decide the winner of the quiz, the manager will give a score to the sequence of operations. The score will depend on the length of continuous segments the visitor will select and another permutation a of size n.
The score is computed in the following way:
Let's define a sequence of lengths of all the continuous segments selected by a visitor as and an infinite sequence b: . Consider a sub-sequence of b which is equal to and have the smallest position of the last element. Let the smallest possible position of last element be . Then, the score of the operation will be .
The visitor who's score is maximum will win and will get a free ticket to the museum.
Input format
The first line of input contains the single integer n (.
The second line of input contains n integers () - permutation p.
The third line of input contains n integers () - permutation a.
Output format
In the first line of input print single integer q () - number of operations.
Then print q lines. In the i-th of them print two integers and () - continuous segment of cards which you want to reverse.
Note that .
Scoring
This is approximate problem and total score is sum of score of all test-cases and points of a solution is scaled based on best solution. Details of scoring is mentioned above.
Tests
There are tests. For each test independently: n was generated randomly from interval . After both p and a were generated randomly.
After contest ending we will add more random tests in same manner but with new seeds.
=
b =
Find the subsequence: . So and score for this test will be .