IWGBST - GENIJALAC

no tags 

Mirko is a genius. But the purpose of his inventions is not always obvious. His latest invention, the Shuffle-o-matic 3175, is one of those. The Shuffle-o-matic is used in a very special way. First Mirko places N paper cards, with numbers 1 to N printed on them, on the Shuffle-o-matic working surface. Then he inputs the shuffle sequence in the special input console and hits the go button. The machine than reads the paper cards and outputs the read sequence of numbers on its output tape. It than shuffles the cards according to the shuffle sequence. After that it reads the newly obtained sequence and writes it onto a new line on its output tape. Then it proceeds to shuffle the cards again according to the same shuffle sequence, scans and writes the output to the tape. The machine does this until it runs out of tape.

After experimenting with the machine Mirko decided to rest a bit on the floor. There he noticed a piece of output tape. The piece is neatly cut just before the A-th output row and just after the B-th output row. It is also missing the first C number and the last D numbers in all rows.

He now wonders how many rows on that piece of paper have the property that all numbers in the row, that are still on the paper, are in the exact same spot they were before all the shuffling began.

Input

The first line of input contains integers N, A, B, C and D in that order(1 ≤ N ≤ 500 000, A ≤ B ≤ 10^12, 0 ≤ C, D ≤ N, C + D < N).

The second line contains the shuffle sequence. The sequence is given as a permutation of numbers 1 to N. If the k-th number in the shuffle sequence is x, after each shuffle the k-th element in the resulting sequence is the x-th
element in the previous sequence.

Output

In the first and only line of input print the number of rows that have the property Mirko is looking for.

Example

Input:
4 1 5 0 1
1 3 4 2

Output:
2

hide comments
Buda IM (retired): 2012-02-19 09:14:56

And again, resource is COCI


Added by:Azat Taryhchiyev
Date:2012-02-16
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ADA95 ASM32 ASM64 GAWK BASH BF C CSHARP C99 CLPS CLOJURE LISP sbcl LISP clisp D ERL FSHARP FORTRAN GO HASK ICON ICK JS-RHINO LUA NEM NICE OCAML PERL PERL6 PHP PRLG-swi RUBY SCALA SCM guile SCM qobi SED ST TCL WHITESPACE
Resource:International Sebat Institutions