프로그램 명: coci_genijalac
제한시간: 5 초

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 obtaind sequence and writes it onto a new line on its output tape. Then it procedes to shuffle the cards again acording 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 nad 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.

입력

출력

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

입출력 예

input

4 1 5 0 1
1 3 4 2

output

2

description
Schuffle-o-matic
outputs:
1 2 3 4
1 3 4 2
1 4 2 3
1 2 3 4
1 3 4 2
1 4 2 3
1 2 3 4
Mirko finds:
1 2 3
1 3 4
1 4 2
1 2 3
1 3 4
The first and forth
row are interesting
to Mirko.

input

7 3 8 1 2
2 3 1 6 4 7 5

output

0

description
Schuffle-o-matic
outputs:
1 2 3 4 5 6 7
2 3 1 6 4 7 5
3 1 2 7 6 5 4
1 2 3 5 7 4 6
2 3 1 4 5 6 7
3 1 2 6 4 7 5
1 2 3 7 6 5 4
2 3 1 5 7 4 6
3 1 2 4 5 6 7
1 2 3 6 4 7 5

input

6 2 11 3 0
6 3 5 4 2 1

output

1

description
Schuffle-o-matic
outputs:
1 2 3 4 5 6
6 3 5 4 2 1
1 5 2 4 3 6
6 2 3 4 5 1
1 3 5 4 2 6
6 5 2 4 3 1
1 2 3 4 5 6
6 3 5 4 2 1
1 5 2 4 3 6
6 2 3 4 5 1
1 3 5 4 2 6
출처: coci 2009/2010 contest1 5/6

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]