Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 2767
88's function

Time Limit: 2 Seconds      Memory Limit: 65536 KB

88 is the nickname of freecity, the most famous bbs in ZJU. It has so many user, and the number of articles in all boards are getting more and more every minute. It was hard to find an article even when you knew its index. But now, 88 has a new function, with which you can goto the article you want immediately after inputing its index. For example , when you want to goto the article at with index 75 , you can simply press the key '7' and '5' and at last the 'Enter' key, then you'll see you cursor before the 75th article. You can also use 'up' and 'down' key to go up or down one article respectively. If you want to goto '76', you can press '7' ,'5', 'Enter','down' four keys sequentially. (Though it is not a good way to goto '76', here it is just for explaining the function) 68 M swinge Jul 28 . missing you tonight.

69 M CoolBug Jul 29 Re: ec last night
70 M supercooker Jul 30 . Love in ec
71 M supercooker Jul 31 . Dancing on SuDi
72 M supercooker Jul 31 . Falling in love at first sight in EC
73 M freshboy Aug 1 . My experience of last night ec.
74 M zzx Aug 1 . A probable suicide of a PPMM
75 M supercooker Aug 2 . 88 to 88,ec,eb,and you all!
76 M freshboy Aug 2 . The ec of last night in my eyes!
77 M freshboy Aug 2 . The morning ec!
78 M nisson Aug 3 . A sight in last night's get-together
79 M freshboy Aug 4 . Crazy For English
80 M freshboy Aug 4 . My First Klatch With Friends Of English Board
81 M guyun Aug 4 . ec of park six this morning!

Topiori likes surfing on 88, and spends so much time on it that it is a great part of his daily life. But his keyboard has met some problems recently - some number keys do not work, while he still want to use it to surfing on 88. Now he is asking you for help: he wants to use the keyboard as least as possible to go to the correct article he's interesting in. He believe a good programmer like you can easily find the best way.
In this problem you can only use the number keys '0'-'9'(with some exceptions of bad keys specified in the input) and the 'Enter', 'up','down' keys, and every key can be used many times.

*Be a little difference from the real 88 operate, can't press 'down' key to go from the last article to the first one, also can't press 'up' key to go from the first one to the last.

Input

There are multiple test cases.
The first line of each case is an integer N (0 <= N <= 10), the number of bad keys. The next line are N integers, the bad number keys. The last line are two indices T and M. T is the beginning position of the cursor, and M is the index of the article wanted by topiori (0 < T,M <= 1,000,000).
In the example above, the best way is to press number key '7' and '5', then press the 'Enter' key.
And the total number of article is changing every second, so in this problem, you can consider the total number is large enough.

Output

With every case you just needed to output one line with one integer K, the least times of key pressing.

Sample Input

1
5
69 75

Sample Output

4

(Hint: '7', '4', 'Enter', 'down', or '7', '6', 'Enter', 'up')


Author: YANG, Xuan
Source: ZOJ Monthly, October 2006
Submit    Status