Tommy Vercetti has completed the infamous RC helicopter mission after many attempts. And now he needs your help flying a real helicopter.
There are bombs and helipads. And there is one Helikopter. Initially all bombs, the Helikopter and Tommy Vercetti are at helipad number . All the bombs need to be transported to helipad . Each bomb from to has a weight of .
There is a customs officer on each helipad. Officer will check the cargo of a Helikopter if and only if the cargo weight exceeds while landing on helipad . Tommy does not want to be caught carrying bombs. And that is why his friend Lance Vance ওরফে কালা জাহাঙ্গীর has built hiding compartments in each helipad to store bombs temporarily.
The following rules are applicable for flying the Helikopter:
Taking off from helipad , the Helikopter must land at helipad or , which takes unit of time.
Helikopter can carry any number of bombs.
While parked on a helipad, Helikopter can drop or pickup any number of bombs from the hiding compartment instantaneously.
If it is possible to transport all bombs to helipad (without Tommy getting caught of course) then print the minimum time in which it can be done. Otherwise print -1
.
Input is given from Standard Input in the following format:
Constraints
Print the answer.
Input | Output |
---|---|
2 10 1 1 2 | -1 |
Tommy will be caught by the officer of helipad . |
Input | Output |
---|---|
5 20 20 20 20 20 3 5 5 5 | 4 |
Helikopter takes all bombs together in one go. |
Input | Output |
---|---|
3 1 1 1 3 1 1 1 | 10 |
Helikopter takes bomb from to and then comes back to moves. (During this, bomb number and are in hiding compartment of helipad ) Helikopter takes bomb from to and then comes back to moves. (During this, bomb number is in hiding compartment of helipad ) Helikopter takes bomb from to moves. Total moves. |
Here is a song to help you visualize the problem.
Helikopter, helikopter
Para kofer, para kofer
Helikopter, helikopter
Šaljem ako treba
Para kofer, para kofer
Da bacaš sa neba
Helikopter, helikopter
Kol’ko treba zlata
Samo da od doma otvoriš mi vrata?
Majko moja, kakva je
Stvorena je za mene
Majko moja, vidi je
Vrh ljepote, takva je
Ne postoji blago to
A ni cijena ta
Na koju ne pristajem
Da je imam ja
Helikopter, helikopter
Šaljem ako treba
Para kofer, para kofer
Da bacaš sa nеba
Helikopter, helikoptеr
Kol’ko treba zlata
Samo da od doma otvoriš mi vrata?
Kao da je dragi Bog
Baš za sebe stvorio
Moje oko nikad ljepšu
Od nje nije vidjelo
Ne postoji blago to
A ni cijena ta
Na koju ne pristajem
Da je imam ja
Helikopter, helikopter
Šaljem ako treba
Para kofer, para kofer
Da bacaš sa neba
Helikopter, helikopter
Kol’ko treba zlata
Samo da od doma otvoriš mi vrata?