#include<bits/stdc++.h>usingnamespace std;// #include <ext/pb_ds/assoc_container.hpp>// using namespace __gnu_pbds;// struct splitmix64 {// size_t operator()(size_t x) const {// static const size_t fixed = chrono::steady_clock::now().time_since_epoch().count();// x += 0x9e3779b97f4a7c15 + fixed;// x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;// x = (x ^ (x >> 27)) * 0x94d049bb133111eb;// return x ^ (x >> 31);// }// };// const int N = 1e5+5, S = 300;// int n, a[N];// // for small d case: b[i] = number of elements in bucket i// int b[N*S];// // for large d case: dp[i][j] = maximum length of a path ending// // at index i, such that all edges in the path have label j// unordered_map<int, int, splitmix64> dp[N];// // solve under the assumption that d >= 0// int solve() {// int ans = 0;// // d < S// for (int d = 0; d < S; d++) {// for (int i = 0; i < n; i++)// ans = max(ans, ++b[a[i]+(n-i)*d]);// for (int i = 0; i < n; i++)// b[a[i]+(n-i)*d] = 0;// }// // S <= d < N// for (int i = 0; i < n; i++) {// for (int j = max(0, i-N/S); j < i; j++) {// int d = (a[i]-a[j])/(i-j);// int r = (a[i]-a[j])%(i-j);// if (r == 0 && d >= S) {// dp[i][d] = max(dp[i][d], dp[j][d]+1);// ans = max(ans, dp[i][d]+1);// }// }// }// for (int i = 0; i < n; i++)// dp[i].clear();// return ans;// }// int main() {// ios_base::sync_with_stdio(0); cin.tie(0);// cin >> n;// for (int i = 0; i < n; i++)// cin >> a[i];// int ans = solve();// reverse(a, a+n);// ans = max(ans, solve());// cout << n-ans << "\n";// }#include<iostream>#include<vector>#include<string>#include<set>#include<algorithm>#include<map>#include<queue>#include<chrono>#include<math.h>#include<unordered_map>usingnamespace std;constint N =1e5+5;constint S =500;int m[N*S];structsplitmix64{
size_t operator()(size_t x)const{staticconst size_t fixed = chrono::steady_clock::now().time_since_epoch().count();
x +=0x9e3779b97f4a7c15+ fixed;
x =(x ^(x >>30))*0xbf58476d1ce4e5b9;
x =(x ^(x >>27))*0x94d049bb133111eb;return x ^(x >>31);}};intsolve(int a[],int n,int m_s){int remain =1;for(int d =0;d<=m_s;d++){
unordered_map<int,int,splitmix64> b;for(int i =0;i<n;i++)//公差为d的值{
remain =max(++m[n*d + a[i]-i*d],remain);}for(int i =0;i<n;i++) m[n*d + a[i]-i*d]=0;}
unordered_map<int,int,splitmix64> b[n]; m_s++;for(int i = n-2;i>=0;i--){for(int j = i+1;j<n&&(j-i)<=m_s;j++){int d =(a[j]-a[i])/(j-i);if((a[j]-a[i])%(j-i)==0&& d>=m_s){
b[i][d]=max(b[j][d]+1,b[i][d]);
remain =max(remain,b[i][d]+1);}}}return remain;}intmain(){int n; cin >> n;int a[n];int maximal =-1;for(int i =0;i<n;i++){cin >> a[i];maximal =max(maximal,a[i]);}// d <= sqrt(maximal),使用int m_s =(int)sqrt((double)maximal);int ans_1 =solve(a,n,m_s);reverse(a,a+n);
ans_1 =max(ans_1,solve(a,n,m_s));
cout << n - ans_1 << endl;system("pause");return0;}