Hide

Problem E
Möbius Music

Erlend the entertainer has just composed another piece that will impress the world. The piece takes the idea of cyclic form to the next level, the song is constructed to be a perfect loop, where the end of the song beautifully connects to the beginning.

To make a number out of this on the next concert, Erlend has written his notes on a Möbius strip. A Möbius strip is a geometric shape with only one face, meaning that the piece when written on the strip is only a single line of notes, but its end and start connect. This was thought to be a brilliant idea, but just before the concert Erlend realised his mistake, he cannot tell where the piece begins! Luckily you remember all the notes and can use that to help him find where it begins. Time is running out, so tell him where the first note of the song is, relative to where Erlend is currently looking on the strip.

Input

The first line contains $N$, the number of notes in the entire piece. Then follows a line with the music piece from start to finish, it is represented as $N$ integers $m_1$ to $m_ N$, where each integer represents a specific note. Then follows a second line, which has the same format as the music piece on the previous line, except it is from the perspective of Erlend. This means that the first integer on the line describes the note he is currently looking at.

Output

To help Erlend quickly prepare for the concert, you should print the smallest number of notes he has to move his sheet either to the left or the right to correctly align the sheet with the start of the piece. Output “left” or “right” followed by the number of notes Erlend has to move his gaze to be looking at the first note of the piece. Tiebreaks favor looking at a note to the right. If he is already looking at the right place, print “you are ready!”.

Limits

  • $1 \leq N \leq 100\, 000$

  • $1 \leq m_ i \leq 1000$

  • It is always possible to align Erlend’s sheet to the start of the music piece.

Sample Input 1 Sample Output 1
4
1 2 3 4
3 4 1 2
right 2
Sample Input 2 Sample Output 2
4
1 2 3 4
2 3 4 1
left 1
Sample Input 3 Sample Output 3
2
10 100
10 100
you are ready!

Please log in to submit a solution to this problem

Log in