func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 3;   const long long OO = 0x3f3f3f3f3f3f3f3f;   long long n, a, b;   vector<int> primes, v;   long long mem[N][3];   void fact(int num) {     if (num % 2 == 0) primes.push_back(2);     while (num % 2 == 0) num /= 2;     for (int i = 3; i * i <= num; ++i) {       if (num % i == 0) primes.push_back(i);       while (num % i == 0) num /= i;     }     if (num > 1) primes.push_back(num);   }   long long solve(int idx, int typ, const int& gcd) {     if (idx == n) return 0;     long long& ret = mem[idx][typ];     if (~ret) return ret;     ret = OO;     if (typ < 2) {       ret = min(ret, a + solve(idx + 1, 1, gcd));     }     if (typ == 1) typ = 2;     for (int i = -1; i <= 1; ++i) {       if (((v[idx] + i) % gcd) == 0)         ret = min(ret, (i == 0 ? 0 : b) + solve(idx + 1, typ, gcd));     }     return ret;   }   int main() {     cin >> n >> a >> b;     v = vector<int>(n);     for (auto& it : v) cin >> it;     for (int i = -1; i <= 1; ++i) {       fact(v[0] + i);       fact(v[n - 1] + i);     }     set<int> st(primes.begin(), primes.end());     primes = vector<int>(st.begin(), st.end());     long long ans = OO;     for (auto it : primes) {       memset(mem, -1, sizeof mem);       long long rt = solve(0, 0, it);       ans = min(ans, rt);     }     cout << ans;     return 0;   }   