func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, a, b;   int primect = 0;   int primes[40000];   int arr[1000000];   set<int> pset;   long long costl[1000000];   long long costr[1000000];   long long minCosts[30];   long long inf = numeric_limits<long long>::max();   void fillInPrimes() {     primes[0] = 2;     primect = 1;     for (int i = 3; i <= sqrt(1000000000); i += 2) {       bool isprime = true;       for (int j = 0; j < primect; j++) {         if (i % primes[j] == 0) {           isprime = false;           break;         }       }       if (isprime) {         primes[primect] = i;         primect++;       }     }   }   long long calcCost(int l, int r) {     long long cost = a * (long long)(r - l + 1);     if (l > 0) {       if (costl[l - 1] == inf) {         return inf;       } else {         cost += costl[l - 1];       }     }     if (r < n - 1) {       if (costr[r + 1] == inf) {         return inf;       } else {         cost += costr[r + 1];       }     }     return cost;   }   int main() {     cin >> n >> a >> b;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     fillInPrimes();     for (int i = 0; i < n; i = n - 1) {       for (int j = -1; j <= 1; j++) {         bool factored = false;         int fac = arr[i] + j;         int k = 0;         if (fac < 2) {           continue;         }         while (k < primect && primes[k] <= fac) {           if (fac % primes[k] == 0) {             pset.insert(primes[k]);             fac /= primes[k];             factored = true;           } else {             k++;           }         }         if (fac > 2) {           pset.insert(fac);         }       }       if (i == n - 1) {         break;       }     }     int pi = 0;     for (auto it = pset.begin(); it != pset.end(); it++) {       int p = *it;       for (int i = 0; i < n; i++) {         int mod = arr[i] % p;         if (mod == 0) {           costl[i] = 0;           costr[i] = 0;         } else if (mod == 1 || mod == p - 1) {           costl[i] = b;           costr[i] = b;         } else {           costl[i] = inf;           costr[i] = inf;         }       }       for (int i = 1; i < n; i++) {         if (costl[i - 1] == inf) {           costl[i] = inf;         } else if (costl[i] != inf) {           costl[i] += costl[i - 1];         }         if (costr[n - i] == inf) {           costr[n - i - 1] = inf;         } else if (costr[n - i - 1] != inf) {           costr[n - i - 1] += costr[n - i];         }       }       int firstInf = n;       int lastInf = 0;       for (int i = 0; i < n; i++) {         if (costl[i] == inf) {           firstInf = i;           break;         }       }       for (int i = n - 1; i >= 0; i--) {         if (costr[i] == inf) {           lastInf = i;           break;         }       }       long long minEndingHere = inf;       long long minLeft = 0;       long long minSoFar = costr[0];       for (int i = 0; i < n; i++) {         int l = min(i, firstInf);         int r = max(i, lastInf);         long long cost;         if (calcCost(minLeft, r) <= calcCost(l, r)) {           cost = calcCost(minLeft, r);         } else {           minLeft = l;           cost = calcCost(l, r);         }         if (cost < minSoFar) {           minSoFar = cost;         }       }       minCosts[pi] = minSoFar;       pi++;     }     long long minn = inf;     for (int i = 0; i < pset.size(); i++) {       minn = min(minn, minCosts[i]);     }     cout << minn << endl;     return 0;   }   