Brother Sobertino, getting tired after struggling with up to million operations in previous exercise (see Two Buckets) is sitting under the tree in the garden, tasting the bewerage and pondering on generalization of the task.
He suspects if he take 3
buckets instead of just 2
, work could be completed faster than with any pair of
these three. So he picked some random values and is trying to conduct "thought experiment", being bit too tired
(or maybe too lazy) to go to the library for pencil and paper or Babbage's calculating machine.
However due to slight effects of beer he feels a bit confused with calculations. Help him please :)
Input data has the target volume (T
) in the first line. Next line give volumes of buckets, say U
, V
, W
.
Answer should give single value - minimum number of operations to get target volume in any of jugs - or
the word impossible
.
Example1
input data:
141
331 169 267
answer:
20
Example2
input data:
107
256 422 454
answer:
impossible