#abc276d. [abc276_d]Divide by 2 or 3
[abc276_d]Divide by 2 or 3
Problem Statement
You are given a sequence of positive integers: .
You can choose and perform one of the following operations any number of times, possibly zero.
- Choose an integer such that and is a multiple of , and replace with .
- Choose an integer such that and is a multiple of , and replace with .
Your objective is to make satisfy .
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.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 4 3
Sample Output 1
3
Here is a way to achieve the objective in three operations, which is the minimum needed.
- Choose an integer such that is a multiple of , and replace with . becomes .
- Choose an integer such that is a multiple of , and replace with . becomes .
- Choose an integer such that is a multiple of , and replace with . becomes .
Sample Input 2
3
2 7 6
Sample Output 2
-1
There is no way to achieve the objective.
Sample Input 3
6
1 1 1 1 1 1
Sample Output 3
0