<PREV Problem:
NEXT>
Solved by 23 users: tourist, Stefan.Bialucha, Tulegenov_Amir, LoLitter, JohnJones_001, rvashegin, WsemirZ, wInuX, Zhukov_Dmitry, dan, Jarovit, zloy_mipt, KZ, mazahaka, RAVEman, defrager, UdH-WiNGeR, MIKseR, avg79, EAA2008, Dest, Robert_Gerbicz, NIGHTFIT.
UserDateAttemptTimeCMSC
WsemirZ19 jul 2008Kylix14000.96283 
Tulegenov_Amir01 aug 2008Kylix5300.62290 
MIKseR23 mar 2009Kylix900.90297 
WsemirZ19 jul 2008Kylix13600.91297 
WsemirZ19 jul 2008C++14300.90300 
Tulegenov_Amir01 aug 2008Kylix5400.55340 
RAVEman19 jan 2009C++1700.69362 
JohnJones_00124 jun 2008C++400.84447 
rvashegin10 jul 2008C++2600.31449 
NIGHTFIT22 sep 2014C++600.72455 
Zhukov_Dmitry12 sep 2008C++1400.13474 
Stefan.Bialucha27 mar 2008C2800.65474 
RAVEman19 jan 2009C++1600.57488 
Jarovit22 oct 2008C++2400.50508 
Languages
C++
15
Kylix
4
Java
2
C
2
FPC
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

Cylinders

Time limit = 1 second(s)

Byteman urgently needs to measure l milliliters of water, so he went to a shop that sells technical glass. Unfortunately, water measuring glass is out of date now and the shop was being wound up at the moment. Most of the glass was sold out and there were only two identical defective cylinders. Their defect was that each of them had only a few of all necessary scales (in milliliters). Byteman had no choice: he needed those cylinders, so he bought them. He is facing a new problem now: how to measure l milliliters of water using his cylinders?

In the beginning both cylinders are empty. Possible actions that can be performed are:

*) pouring water from a tap to a cylinder until water reaches one of the cylinder's scales,

*) pouring water from a cylinder to the sink until water reaches one of the cylinder's scales,

*) pouring water from one cylinder to the other until water reaches one of the first cylinder's scales,

*) pouring water from one cylinder to the other until water reaches one of the second cylinder's scales.

Each of these actions takes the same amount of time. Byteman is in a hurry, so he would like to measure the necessary amount of water as quickly as possible. Your task is to either compute the minimal number of actions that Byteman needs to perform in order to obtain exactly l milliliters of water in one of his cylinders or check that the measurement is impossible.

Input

The first line of the input file contains one positive integer n (3<=n<=25), denoting the number of scales in each of the cylinders. The second line contains an increasing sequence of integers x1, ..., xn (separated by single spaces) denoting the scales values. x1 is always equal to 0 and xn (xn ≤ 100 000) is equal to the capacity of each of the cylinders. The third and last line of the input file contains one integer l (0<=l<=xn).

Output

If Byteman cannot measure the desired amount of water, your program should output a single word IMPOSSIBLE. Otherwise your program should output the minimal number of actions that are needed to perform the measurement.

Input#1
4
0 2 5 15
9
Output#1
5

Author:
Jakub Pawlewicz

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 200ms

SW soft NIX
ID = 3.235.172.213