You are given an array of N integers a1,a2,…,aN. You can apply two kinds of operations to this array.
- Delete a contiguous block of length m from the array.
- Add 1 to a number ai in the array, or subtract 1 from it.
Operation 1 can be used at most once in total, and operation 2 can be used at most once on each number. When you use operation 1, 1≤m<N must hold, so you cannot delete the whole array.
Operation 1 costs m×A, and each use of operation 2 costs B. After every operation is done, the greatest common divisor of the remaining array has to be greater than 1. Write a program that finds the minimum cost needed for this.