1032: Divide by 2 or 3

Memory Limit:1024 MB Time Limit:2.000 S
Judge Style:Text Compare Creator:
Submit:22 Solved:10

Description

You are given a sequence of positive integers: lns="http://www.w3.org/1998/Math/MathML">=(1,2,,).
You can choose and perform one of the following operations any number of times, possibly zero.

  • Choose an integer lns="http://www.w3.org/1998/Math/MathML"> such that lns="http://www.w3.org/1998/Math/MathML">1 and lns="http://www.w3.org/1998/Math/MathML"> is a multiple of lns="http://www.w3.org/1998/Math/MathML">2, and replace lns="http://www.w3.org/1998/Math/MathML"> with lns="http://www.w3.org/1998/Math/MathML">2.
  • Choose an integer lns="http://www.w3.org/1998/Math/MathML"> such that lns="http://www.w3.org/1998/Math/MathML">1 and lns="http://www.w3.org/1998/Math/MathML"> is a multiple of lns="http://www.w3.org/1998/Math/MathML">3, and replace lns="http://www.w3.org/1998/Math/MathML"> with lns="http://www.w3.org/1998/Math/MathML">3.

Your objective is to make lns="http://www.w3.org/1998/Math/MathML"> satisfy lns="http://www.w3.org/1998/Math/MathML">1=2==.
Find the minimum total number of times you need to perform an operation to achieve the objective. If there is no way to achieve the objective, print -1 instead.

Input

The input is given from Standard Input in the following format:

 lns="http://www.w3.org/1998/Math/MathML">2 lns="http://www.w3.org/1998/Math/MathML"> lns="http://www.w3.org/1998/Math/MathML">
  • lns="http://www.w3.org/1998/Math/MathML">1109
  • All values in the input are integers.

Output

Print the answer.


Sample Input Copy

3
1 4 3

Sample Output Copy

3

HINT

Here is a way to achieve the objective in three operations, which is the minimum needed.

  • Choose an integer lns="http://www.w3.org/1998/Math/MathML">=2 such that lns="http://www.w3.org/1998/Math/MathML"> is a multiple of lns="http://www.w3.org/1998/Math/MathML">2, and replace lns="http://www.w3.org/1998/Math/MathML">2 with lns="http://www.w3.org/1998/Math/MathML">22lns="http://www.w3.org/1998/Math/MathML"> becomes lns="http://www.w3.org/1998/Math/MathML">(1,2,3).
  • Choose an integer lns="http://www.w3.org/1998/Math/MathML">=2 such that lns="http://www.w3.org/1998/Math/MathML"> is a multiple of lns="http://www.w3.org/1998/Math/MathML">2, and replace lns="http://www.w3.org/1998/Math/MathML">2 with lns="http://www.w3.org/1998/Math/MathML">22lns="http://www.w3.org/1998/Math/MathML"> becomes lns="http://www.w3.org/1998/Math/MathML">(1,1,3).
  • Choose an integer lns="http://www.w3.org/1998/Math/MathML">=3 such that lns="http://www.w3.org/1998/Math/MathML"> is a multiple of lns="http://www.w3.org/1998/Math/MathML">3, and replace lns="http://www.w3.org/1998/Math/MathML">3 with lns="http://www.w3.org/1998/Math/MathML">33lns="http://www.w3.org/1998/Math/MathML"> becomes lns="http://www.w3.org/1998/Math/MathML">(1,1,1).