P5181 [COCI 2009/2010 #1] GENIJALAC
Description
**Translated from [COCI 2009.10](http://hsin.hr/coci/archive/2009_2010/) T5 “[GENIJALAC](http://hsin.hr/coci/archive/2009_2010/contest1_tasks.pdf)”.**
Mirko invented a shuffling machine. The machine takes a paper tape with $N$ columns and infinitely many rows as both input and output. These $N$ columns are numbered $1 \ldots N$ in order.
At the beginning, only the first row of the tape contains numbers, and every row below it is blank.
In the first row, each column contains an integer: column $i$ contains the integer $i$.
In addition, Mirko is given a shuffle permutation, which is a permutation of length $N$: $s_1,$ $s_2,$ $\ldots,$ $s_N$.
There is a row pointer, which initially points to the first row.
Each time the machine runs, for every $i$, it moves the number in column $i$ of the current row (the row pointed to by the pointer) to column $s_i$ of the next row. After all $N$ numbers are placed, the pointer moves down by one row.
Mirko runs the machine infinitely many times. Now Mirko cuts off the first $C$ columns and the last $D$ columns of the tape; we call the result the new tape.
Question: among rows $A \sim B$ of the new tape, how many rows are identical to the first row of the new tape?
Input Format
The first line contains five integers $N, A, B, C, D$.
The second line contains $N$ integers $s_1,$ $s_2,$ $\ldots,$ $s_N$.
Output Format
One line with one integer: the number of rows among rows $A \sim B$ of the new tape that are identical to the first row of the new tape.
Explanation/Hint
#### Sample Explanation 1
```plain
+-----+
|1 2 3|4