#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),(x)))
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
string stin() {string s;cin>>s;return s;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
vec iota(int n){vec a(n);iota(all(a),0);return a;}
void print(){putchar(' ');}
void print(bool a){cout<<a;}
void print(int a){cout<<a;}
void print(long long a){cout<<a;}
void print(char a){cout<<a;}
void print(string &a){cout<<a;}
void print(double a){cout<<a;}
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } cout<<endl;}
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ cout<<'(';print(p.first); cout<<","; print(p.second);cout<<')'; }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ cout<<" "; print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
#define _GLIBCXX_DEBU
#define endl '\n'
#ifdef _MY_DEBUG
    #undef endl
    #define debug(x) cout<<#x<<": "<<x<<endl
    void err(){}
    template<class T> void err(const T& t){ print(t);  cout<<" ";}
    template<class Head, class... Tail> void err(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); }
#else
    #define debug(x)
    template<class... T> void err(const T&...){}
#endif
#pragma endregion
const ll MOD=1e9+7;
const int N=1100000;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F _f, const Monoid &_M1) : f(_f), M1(_M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

// RMQ
#define RMQ(n) SegmentTree<int>(n,[](int x,int y){return max(x,y);},0)

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    int n=in();
    vec a;rep(i,n)a.pb(in());
    map<int,int> mp;
    rep(i,n)mp[a[i]]=0;
    int num=0;
    for(auto &e:mp) e.se = num++;
    vecll ans(n);
    {
        auto seg = RMQ(n+1);
        rep3(i,n-1,0){
            int pre = (i ? mp[a[i-1]] : 0);
            int tmp = seg.query(pre+1,n+1);
            ans[i] += tmp;
            seg.update(mp[a[i]],1+seg.query(mp[a[i]]+1,n+1));
        }
    }
    print(ans);
    {
        auto seg = RMQ(n+1);
        rep(i,n){
            seg.update(mp[a[i]],1+seg.query(0,mp[a[i]]-1));
            ans[i] += seg[mp[a[i]]];
        }
    }
    cout << n-1-*max_element(all(ans)) << endl;

}


#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),(x)))
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
string stin() {string s;cin>>s;return s;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
vec iota(int n){vec a(n);iota(all(a),0);return a;}
void print(){putchar(' ');}
void print(bool a){cout<<a;}
void print(int a){cout<<a;}
void print(long long a){cout<<a;}
void print(char a){cout<<a;}
void print(string &a){cout<<a;}
void print(double a){cout<<a;}
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } cout<<endl;}
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ cout<<'(';print(p.first); cout<<","; print(p.second);cout<<')'; }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ cout<<" "; print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
#define _GLIBCXX_DEBU
#define endl '\n'
#ifdef _MY_DEBUG
    #undef endl
    #define debug(x) cout<<#x<<": "<<x<<endl
    void err(){}
    template<class T> void err(const T& t){ print(t);  cout<<" ";}
    template<class Head, class... Tail> void err(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); }
#else
    #define debug(x)
    template<class... T> void err(const T&...){}
#endif
#pragma endregion
const ll MOD=1e9+7;
const int N=1100000;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F _f, const Monoid &_M1) : f(_f), M1(_M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

// RMQ
#define RMQ(n) SegmentTree<int>(n,[](int x,int y){return max(x,y);},0)

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    int n=in();
    vec a;rep(i,n)a.pb(in()-i);
    map<int,int> mp;
    rep(i,n)mp[a[i]]=0;
    int num=0;
    for(auto &e:mp) e.se = num++;
    vecll ans(n);
    {
        auto seg = RMQ(n+1);
        rep3(i,n-1,0){
            int pre = (i ? mp[a[i-1]] : -1);
            int tmp = seg.query(pre+1,n+1);
            ans[i] += tmp;
            seg.update(mp[a[i]],1+max(0,seg.query(mp[a[i]],n+1)));
        }
    }
    {
        auto seg = RMQ(n+1);
        rep(i,n-1){
            seg.update(mp[a[i]],1+seg.query(0,mp[a[i]]+1));
            ans[i+1] += seg[mp[a[i]]];
        }
    }
    cout << n-1-*max_element(all(ans)) << endl;

}


#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),(x)))
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
string stin() {string s;cin>>s;return s;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
vec iota(int n){vec a(n);iota(all(a),0);return a;}
void print(){putchar(' ');}
void print(bool a){cout<<a;}
void print(int a){cout<<a;}
void print(long long a){cout<<a;}
void print(char a){cout<<a;}
void print(string &a){cout<<a;}
void print(double a){cout<<a;}
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } cout<<endl;}
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ cout<<'(';print(p.first); cout<<","; print(p.second);cout<<')'; }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ cout<<" "; print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
#define _GLIBCXX_DEBU
#define endl '\n'
#ifdef _MY_DEBUG
    #undef endl
    #define debug(x) cout<<#x<<": "<<x<<endl
    void err(){}
    template<class T> void err(const T& t){ print(t);  cout<<" ";}
    template<class Head, class... Tail> void err(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); }
#else
    #define debug(x)
    template<class... T> void err(const T&...){}
#endif
#pragma endregion
const ll MOD=1e9+7;
const int N=1100000;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F _f, const Monoid &_M1) : f(_f), M1(_M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

// RMQ
#define RMQ(n) SegmentTree<int>(n,[](int x,int y){return max(x,y);},0)

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    int n=in();
    vec a;rep(i,n)a.pb(in()-i);
    map<int,int> mp;
    rep(i,n)mp[a[i]]=0;
    int num=0;
    for(auto &e:mp) {
        e.se = num++;
    }
    vecll ans(n);
    {
        auto seg = RMQ(n+1);
        rep3(i,n-1,0){
            int pre = (i ? mp[a[i-1]] : -1);
            int tmp = seg.query(pre-1,n+1);
            ans[i] += tmp;
            seg.update(mp[a[i]],1+max(0,seg.query(mp[a[i]],n+1)));
        }
    }
    {
        auto seg = RMQ(n+1);
        rep(i,n-1){
            seg.update(mp[a[i]],1+seg.query(0,mp[a[i]]+1));
            ans[i+1] += seg[mp[a[i]]];
        }
    }
    cout << n-1-*max_element(all(ans)) << endl;

}


#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),(x)))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),(x)))
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
string stin() {string s;cin>>s;return s;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
vec iota(int n){vec a(n);iota(all(a),0);return a;}
void print(){putchar(' ');}
void print(bool a){cout<<a;}
void print(int a){cout<<a;}
void print(long long a){cout<<a;}
void print(char a){cout<<a;}
void print(string &a){cout<<a;}
void print(double a){cout<<a;}
template<class T> void print(const vector<T>&);
template<class T, size_t size> void print(const array<T, size>&);
template<class T, class L> void print(const pair<T, L>& p);
template<class T, size_t size> void print(const T (&)[size]);
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } cout<<endl;}
template<class T> void print(const deque<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, size_t size> void print(const array<T, size>& a){ print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout<<" "; print(*i); } }
template<class T, class L> void print(const pair<T, L>& p){ cout<<'(';print(p.first); cout<<","; print(p.second);cout<<')'; }
template<class T, size_t size> void print(const T (&a)[size]){ print(a[0]); for(auto i = a; ++i != end(a); ){ cout<<" "; print(*i); } }
template<class T> void print(const T& a){ cout << a; }
int out(){ putchar('\n'); return 0; }
template<class T> int out(const T& t){ print(t); putchar('\n'); return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; }
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
#define _GLIBCXX_DEBU
#define endl '\n'
#ifdef _MY_DEBUG
    #undef endl
    #define debug(x) cout<<#x<<": "<<x<<endl
    void err(){}
    template<class T> void err(const T& t){ print(t);  cout<<" ";}
    template<class Head, class... Tail> void err(const Head& head, const Tail&... tail){ print(head); putchar(' '); out(tail...); }
#else
    #define debug(x)
    template<class... T> void err(const T&...){}
#endif
#pragma endregion
const ll MOD=1e9+7;
const int N=1100000;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F _f, const Monoid &_M1) : f(_f), M1(_M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

// RMQ
#define RMQ(n) SegmentTree<int>(n,[](int x,int y){return max(x,y);},0)

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    int n=in();
    vec a;rep(i,n)a.pb(in()-i);
    map<int,int> mp;
    rep(i,n)mp[a[i]]=0;
    int num=0;
    vec rev(n);
    for(auto &e:mp) {
        rev[num]=e.fi;
        e.se = num++;
    }
    vecll ans(n);
    {
        auto seg = RMQ(n+1);
        rep3(i,n-1,0){
            int pre = (i ? mp[a[i-1]] : -1);
            int tmp;
            if( pre <= 0 ){
                tmp = seg.query(0,n+1);
            }
            else {
                tmp = seg.query(pre-(rev[pre-1]==rev[pre]-1),n+1);
            }
            ans[i] += tmp;
            seg.update(mp[a[i]],1+max(0,seg.query(mp[a[i]],n+1)));
        }
    }
    {
        auto seg = RMQ(n+1);
        rep(i,n-1){
            seg.update(mp[a[i]],1+seg.query(0,mp[a[i]]+1));
            ans[i+1] += seg[mp[a[i]]];
        }
    }
    cout << n-1-*max_element(all(ans)) << endl;

}


#include <bits/stdc++.h>

using namespace std;

map<int, int> comp;

void compress(const vector<int>& a)
{
    vector<int> z;
    for(int i = 0; i < a.size(); i++)
    {
        z.push_back(a[i] - i);
        z.push_back(a[i] - i + 1);
    }
    sort(z.begin(), z.end());
    z.erase(unique(z.begin(), z.end()), z.end());
    for(int i = 0; i < z.size(); i++)
        comp[z[i]] = i;
}

const int N = 400043;
const int M = 8000043;

int T[4 * N];
int* where[M];
int val[M];
int st = 0;

void change(int& x, int y)
{
    where[st] = &x;
    val[st] = x;
    st++;
    x = y;
}

void rollback(int new_st)
{
    while(st > new_st)
    {
        st--;
        *(where[st]) = val[st];
    }
}

void build(int v, int l, int r)
{
    T[v] = 0;
    if(l < r - 1)
    {
        int mid = (l + r) / 2;
        build(v * 2 + 1, l, mid);
        build(v * 2 + 2, mid, r);
    }
}

void upd(int v, int l, int r, int pos, int val)
{
    change(T[v], max(T[v], val));
    if (l < r - 1)
    {
        int mid = (l + r) / 2;
        if (pos < mid)
            upd(v * 2 + 1, l, mid, pos, val);
        else
            upd(v * 2 + 2, mid, r, pos, val);
    }
}

int query(int v, int l, int r, int L, int R)
{
    if (L >= R)
        return 0;
    if (l == L && r == R)
        return T[v];
    int mid = (l + r) / 2;
    return max(query(v * 2 + 1, l, mid, L, min(R, mid)), query(v * 2 + 2, mid, r, max(L, mid), R));
}

int T2[4 * N];

void build2(int v, int l, int r)
{
    T2[v] = 0;
    if(l < r - 1)
    {
        int mid = (l + r) / 2;
        build2(v * 2 + 1, l, mid);
        build2(v * 2 + 2, mid, r);
    }
}

void upd2(int v, int l, int r, int pos, int val)
{
    T2[v] = max(T2[v], val);
    if (l < r - 1)
    {
        int mid = (l + r) / 2;
        if (pos < mid)
            upd2(v * 2 + 1, l, mid, pos, val);
        else
            upd2(v * 2 + 2, mid, r, pos, val);
    }
}

int query2(int v, int l, int r, int L, int R)
{
    if (L >= R)
        return 0;
    if (l == L && r == R)
        return T2[v];
    int mid = (l + r) / 2;
    return max(query2(v * 2 + 1, l, mid, L, min(R, mid)), query2(v * 2 + 2, mid, r, max(L, mid), R));
}

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    compress(a);
    int mx = comp.size();
    int ans = 0;
    vector<int> states;
    build(0, 0, mx);
    for(int i = n - 1; i > 0; i--)
    {
        states.push_back(st);
        int cur = comp[a[i] - i + 1];
        int val = query(0, 0, mx, cur, mx);
        upd(0, 0, mx, cur, val + 1);
    }
    build2(0, 0, mx);
    ans = max(ans, query(0, 0, mx, 0, mx));
    for(int i = 0; i < n - 1; i++)
    {
        rollback(states.back());
        states.pop_back();
        int cur = comp[a[i] - i];
        int val = query2(0, 0, mx, 0, cur + 1);
        upd2(0, 0, mx, cur, val + 1);
        ans = max(ans, val + 1 + query(0, 0, mx, cur, mx));
    }
    cout << n - 1 - ans << endl;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

//template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
//template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
//template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 6e5 + 10;
int n, ans;
int arr[N];
int bit[N];
int suf[N];
int pre[N];

vec <int> cur_pre[N];
vec <int> cur_suf[N];

int mod_pre[N];
int mod_suf[N];

vec <int> sml;

void update(int i, int x, int bit[]) {
    for(; i < N; i += lsb(i)) {
        bit[i] = max(bit[i], x);
    }
}

int query(int i, int bit[]) {
    int res = 0;
    for(; i; i -= lsb(i)) {
        res = max(res, bit[i]);
    }
    return res;
}

void update_pre(int i, int x) {
    update(i, x, pre);
}

void update_suf(int i, int x) {
    update(N - i, x, suf);
}

int query_pre(int i) {
    return query(i, pre);
}

int query_suf(int i) {
    return query(N - i, suf);
}

void input() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> arr[i];
        sml.pb(arr[i] - i);
        sml.pb(arr[i] - i - 1);
        sml.pb(arr[i] - i + 1);
    }
}

void compress() {
    sort(all(sml));
    sml.erase(unique(all(sml)), sml.end());
    for(int i = 1; i <= n; ++i) {
        arr[i] = lb(all(sml), arr[i] - i) - sml.begin() + 1;
    }
}

int calc_lis() {
    for(int i = 1; i <= n; ++i) {
        int x = query(arr[i], bit);
        update(arr[i], x + 1, bit);
    }
    return query(N - 1, bit);
}

void calc_pre() {
    for(int i = 0; i <= len(sml) + 1; ++i) {
        cur_pre[i].pb(0);
        cur_suf[i].pb(0);
    }
    for(int i = 1; i <= n; ++i) {
        int x = query_pre(arr[i]);
        update_pre(arr[i], x + 1);
        mod_pre[i] = x + 1;
    }
}

void calc_suf() {
    for(int i = n; i >= 1; --i) {
        int x = query_suf(arr[i]);
        update_suf(arr[i], x + 1);
        mod_suf[i] = x + 1;
        cur_suf[arr[i]].pb(x + 1);
    }
}

int calc_comb() {
    int res = 0;
    for(int i = 1; i < n; ++i) {
        cur_suf[arr[i]].pop_back();
        int x = arr[i + 1];
        res = max(res, cur_pre[x + 1].back() + cur_suf[x].back());
        cur_pre[arr[i]].pb(mod_pre[i]);
    }
    return res;
}

void solve() {
    compress();
    calc_pre();
    calc_suf();
    ans = calc_lis();
    ans = max(ans, calc_comb());
    cout << max(0, n - 1 - ans) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;
int n,a[222222],b[222222],cnt,bit[444444],sz,pre[222222],suf[222222],ans,c[222222];
map<int,int> mp;
void update(int p,int x)
{
	while(p<=sz)
	{
		bit[p]=max(bit[p],x);
		p+=p&(-p);
	}
}
int query(int p)
{
	int res=0;
	while(p>=1)
	{
		res=max(res,bit[p]);
		p-=p&(-p);
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[i]-=i;
		b[i]=a[i];
	}
	sort(a+1,a+n+1);
	cnt=unique(a+1,a+n+1)-a-1;
	for (int i=1;i<=cnt;i++)
	{
		mp[a[i]]=i;
	}
	sz=1;
	while(sz<cnt) sz*=2;
	for (int i=1;i<=n;i++)
	{
		c[i]=b[i];
		b[i]=mp[b[i]];
	}
	for (int i=1;i<=n;i++)
	{
		pre[i]=query(b[i])+1;
		update(b[i],pre[i]);
	}
	memset(bit,0,sizeof(bit));
	for (int i=n;i>=1;i--)
	{
		suf[i]=query(sz-b[i]+1)+1;
		update(sz-b[i]+1,suf[i]);
	}
	for (int i=1;i<=sz;i++) bit[i]=-1e9;
	for (int i=n;i>=1;i--)
	{
		int x=lower_bound(a+1,a+cnt+1,c[i]-1)-a;
		ans=max(ans,max(pre[i],pre[i]+query(sz-x+1)+1));
		if (i<n) update(sz-b[i+1]+1,suf[i+1]);
	}
	printf("%d\n",n-ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;
int n,a[222222],b[222222],cnt,bit[444444],sz,pre[222222],suf[222222],ans,c[222222];
map<int,int> mp;
void update(int p,int x)
{
	while(p<=sz)
	{
		bit[p]=max(bit[p],x);
		p+=p&(-p);
	}
}
int query(int p)
{
	int res=0;
	while(p>=1)
	{
		res=max(res,bit[p]);
		p-=p&(-p);
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[i]-=i;
		b[i]=a[i];
	}
	sort(a+1,a+n+1);
	cnt=unique(a+1,a+n+1)-a-1;
	for (int i=1;i<=cnt;i++)
	{
		mp[a[i]]=i;
	}
	sz=1;
	while(sz<cnt) sz*=2;
	for (int i=1;i<=n;i++)
	{
		c[i]=b[i];
		b[i]=mp[b[i]];
	}
	for (int i=1;i<=n;i++)
	{
		pre[i]=query(b[i])+1;
		update(b[i],pre[i]);
	}
	memset(bit,0,sizeof(bit));
	for (int i=n;i>=1;i--)
	{
		suf[i]=query(sz-b[i]+1)+1;
		update(sz-b[i]+1,suf[i]);
	}
	memset(bit,0,sizeof(bit));
	for (int i=n;i>=1;i--)
	{
		int x=lower_bound(a+1,a+cnt+1,c[i]-1)-a;
		ans=max(ans,max(pre[i],pre[i]+query(sz-x+1)+1));
		if (i<n) update(sz-b[i+1]+1,suf[i+1]);
	}
	if (ans>n) ans=n;
	printf("%d\n",n-ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define M 200005
typedef pair<int, int> pii;

struct segTree
{
    int n;
    vector<int> tree;

    segTree(int n): n(n), tree(4*n, 0) {}

    void treeUpdate(int node, int i, int j, int x, int val)
    {
        int mid = (i+j)>>1;

        if(i == j && i == x)
        {
            tree[node] = val;
            return;
        }
        if(i > x || j < x) return;

        treeUpdate(2*node, i, mid, x, val);
        treeUpdate(2*node+1, mid+1, j, x, val);

        tree[node] = max(tree[2*node], tree[2*node+1]);

        return;
    }

    void update(int idx, int v) { treeUpdate(1, 1, n, idx, v); }

    int treeQuery(int node, int i, int j, int u, int v)
    {
        int mid = (i+j)>>1;

        if(i >= u && j <= v) return tree[node];
        if(i > v || j < u) return 0;

        return max(treeQuery(2*node, i, mid, u, v), treeQuery(2*node+1, mid+1, j, u, v));
    }

    int query(int l, int r) { if(l > r) return 0; return treeQuery(1, 1, n, l, r); }
};

pii ara[M];
int prefMax[M], sufMax[M];
map<int, vector<int>> ma;

int main()
{
    int n;
    scanf("%d", &n);

    for(int i = 1; i <= n; i++) scanf("%d", &ara[i].first);
    for(int i = 1; i <= n; i++) ara[i].second = i;
    for(int i = 1; i <= n; i++) ara[i].first -= ara[i].second;
    for(int i = 1; i <= n; i++) ma[ara[i].first].push_back(i);

    sort(ara+1, ara+n+1);
    segTree tree1(n);

    for(int i = 1; i <= n; i++)
    {
        int j = ara[i].second;

        prefMax[j] = 1+tree1.query(1, j-1);
        tree1.update(j, prefMax[j]);
    }

    reverse(ara+1, ara+n+1);
    segTree tree2(n);

    for(int i = 1; i <= n; i++)
    {
        int j = ara[i].second;

        sufMax[j] = 1+tree2.query(j+1, n);
        tree2.update(j, sufMax[j]);
    }

    int ans = 0;
    reverse(ara+1, ara+n+1);
    segTree tree3(n+1);
    ara[n+1] = {2e9, n+1};

    for(int i = 1; i <= n+1; i++)
    {
        int j = ara[i].second;
        tree3.update(j, prefMax[j]);

        if(j == 1) continue;
        ans = max(ans, tree3.query(1, j-2)+sufMax[j]);

        int x = ara[i].first;
        if(ma.find(x+1) == ma.end()) continue;

        int idx = lower_bound(ma[x+1].begin(), ma[x+1].end(), j-1)-ma[x+1].begin()-1;
        if(idx >= 0) ans = max(ans, prefMax[ma[x+1][idx]]+sufMax[j]);
    }

    ans = n-1-ans;
    for(int i = 1; i <= n; i++) ans = min(ans, n-prefMax[i]);

    printf("%d\n", ans);

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <set>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <math.h>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>

using namespace std;

#define ll long long
typedef int hv;
#define double long double
#define make(type, x) type x; cin>>x
#define make2(type, x, y) type x, y; cin>>x>>y
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z
#define make4(type, x, y, z, q) type x, y, z, q; cin>>x>>y>>z>>q
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define PPII pair<PII, int>
#define M7 1000000007l
#define M9 1000000009l
#define make_v(a, n) VI a(n); FOR(n) cin >> a[i];

const int MAXN = 2e5;
int treePr[MAXN * 4] = { 0 }, treeSf[MAXN * 4] = { 0 };
vector<stack<int>> history;

void setValSf(int pos, int l, int r, int& ind, int& val) {
	if (l == r) {
		history[ind].push(treeSf[pos]);
		treeSf[pos] = val;
		return;
	}
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	if (ind <= mid) setValSf(npos, l, mid, ind, val);
	else setValSf(npos + 1, mid + 1, r, ind, val);
	treeSf[pos] = max(treeSf[npos], treeSf[npos + 1]);
}

void ctrlZSf(int pos, int l, int r, int& ind) {
	if (l == r) {
		treeSf[pos] = history[ind].top();
		history[ind].pop();
		return;
	}
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	if (ind <= mid) ctrlZSf(npos, l, mid, ind);
	else ctrlZSf(npos + 1, mid + 1, r, ind);
	treeSf[pos] = max(treeSf[npos], treeSf[npos + 1]);
}

int getMaxSf(int pos, int l, int r, int ql, int qr) {
	if (l > qr || ql > r) return 0;
	if (l == ql && r == qr) return treeSf[pos];
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	int val1 = getMaxSf(npos, l, mid, ql, min(mid, qr));
	int val2 = getMaxSf(npos + 1, mid + 1, r, max(mid + 1, ql), qr);
	return max(val1, val2);
}

void setValPr(int pos, int l, int r, int& ind, int& val) {
	if (l == r) {
		treePr[pos] = val;
		return;
	}
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	if (ind <= mid) setValPr(npos, l, mid, ind, val);
	else setValPr(npos + 1, mid + 1, r, ind, val);
	treePr[pos] = max(treePr[npos], treePr[npos + 1]);
}

int getMaxPr(int pos, int l, int r, int ql, int qr) {
	if (l > qr || ql > r) return 0;
	if (l == ql && r == qr) return treePr[pos];
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	int val1 = getMaxPr(npos, l, mid, ql, min(mid, qr));
	int val2 = getMaxPr(npos + 1, mid + 1, r, max(mid + 1, ql), qr);
	return max(val1, val2);
}

void Solve() {
	make(int, n);
	VI a(n);
	FOR(n) {
		cin >> a[i];
		a[i] -= i;
	}
	VI b = a;
	sort(ALL(b));
	b.resize(unique(ALL(b)) - b.begin());
	int zN = b.size();
	VI obr(zN);
	history.resize(zN);
	for (int i = 0; i < n; ++i) {
		int j = lower_bound(ALL(b), a[i]) - b.begin();
		obr[j] = a[i];
		a[i] = j;
	}
	for (int i = n - 1; i >= 0; --i) {
		int maxSf = getMaxSf(1, 0, zN - 1, a[i], zN - 1) + 1;
		setValSf(1, 0, zN - 1, a[i], maxSf);
	}
	int pr = 0;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ctrlZSf(1, 0, zN - 1, a[i]);
		int ind = pr;
		if (pr != 0 && obr[pr] == obr[pr - 1] + 1) ind--;
		ans = max(ans, getMaxPr(1, 0, zN - 1, 0, pr) + getMaxSf(1, 0, zN - 1, ind, zN - 1));
		int maxPr = getMaxPr(1, 0, zN - 1, 0, a[i]) + 1;
		setValPr(1, 0, zN - 1, a[i], maxPr);
		pr = a[i];
	}
	cout << n - 1 - ans;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	Solve();
	while (!cin.eof()) {
		string s = "_";
		do getline(cin, s);
		while (!cin.eof() && !s.empty());
		if (cin.eof()) return 0;
		FOR(2) cout << endl;
		Solve();
	}
#else
	Solve();
#endif
	return 0;
	}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <set>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <math.h>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>

using namespace std;

#define ll long long
typedef int hv;
#define double long double
#define make(type, x) type x; cin>>x
#define make2(type, x, y) type x, y; cin>>x>>y
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z
#define make4(type, x, y, z, q) type x, y, z, q; cin>>x>>y>>z>>q
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define PPII pair<PII, int>
#define M7 1000000007l
#define M9 1000000009l
#define make_v(a, n) VI a(n); FOR(n) cin >> a[i];

const int MAXN = 2e5;
int treePr[MAXN * 4] = { 0 }, treeSf[MAXN * 4] = { 0 };
vector<stack<int>> history;

void setValSf(int pos, int l, int r, int& ind, int& val) {
	if (l == r) {
		history[ind].push(treeSf[pos]);
		treeSf[pos] = val;
		return;
	}
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	if (ind <= mid) setValSf(npos, l, mid, ind, val);
	else setValSf(npos + 1, mid + 1, r, ind, val);
	treeSf[pos] = max(treeSf[npos], treeSf[npos + 1]);
}

void ctrlZSf(int pos, int l, int r, int& ind) {
	if (l == r) {
		treeSf[pos] = history[ind].top();
		history[ind].pop();
		return;
	}
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	if (ind <= mid) ctrlZSf(npos, l, mid, ind);
	else ctrlZSf(npos + 1, mid + 1, r, ind);
	treeSf[pos] = max(treeSf[npos], treeSf[npos + 1]);
}

int getMaxSf(int pos, int l, int r, int ql, int qr) {
	if (l > qr || ql > r) return 0;
	if (l == ql && r == qr) return treeSf[pos];
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	int val1 = getMaxSf(npos, l, mid, ql, min(mid, qr));
	int val2 = getMaxSf(npos + 1, mid + 1, r, max(mid + 1, ql), qr);
	return max(val1, val2);
}

void setValPr(int pos, int l, int r, int& ind, int& val) {
	if (l == r) {
		treePr[pos] = val;
		return;
	}
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	if (ind <= mid) setValPr(npos, l, mid, ind, val);
	else setValPr(npos + 1, mid + 1, r, ind, val);
	treePr[pos] = max(treePr[npos], treePr[npos + 1]);
}

int getMaxPr(int pos, int l, int r, int ql, int qr) {
	if (l > qr || ql > r) return 0;
	if (l == ql && r == qr) return treePr[pos];
	int mid = (l + r) >> 1;
	int npos = pos << 1;
	int val1 = getMaxPr(npos, l, mid, ql, min(mid, qr));
	int val2 = getMaxPr(npos + 1, mid + 1, r, max(mid + 1, ql), qr);
	return max(val1, val2);
}

void Solve() {
	make(int, n);
	VI a(n);
	FOR(n) {
		cin >> a[i];
		a[i] -= i;
	}
	VI b = a;
	sort(ALL(b));
	b.resize(unique(ALL(b)) - b.begin());
	int zN = b.size();
	VI obr(zN);
	history.resize(zN);
	for (int i = 0; i < n; ++i) {
		int j = lower_bound(ALL(b), a[i]) - b.begin();
		obr[j] = a[i];
		a[i] = j;
	}
	for (int i = n - 1; i >= 0; --i) {
		int maxSf = getMaxSf(1, 0, zN - 1, a[i], zN - 1) + 1;
		setValSf(1, 0, zN - 1, a[i], maxSf);
	}
	int pr = 0;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ctrlZSf(1, 0, zN - 1, a[i]);
		int ind = pr;
		if (pr != 0 && obr[pr] == obr[pr - 1] + 1) ind--;
		ans = max(ans, getMaxPr(1, 0, zN - 1, 0, pr) + getMaxSf(1, 0, zN - 1, ind, zN - 1));
		int maxPr = getMaxPr(1, 0, zN - 1, 0, a[i]) + 1;
		setValSf(1, 0, zN - 1, a[i], maxPr);
		pr = a[i];
	}
	cout << n - 1 - ans;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	Solve();
	while (!cin.eof()) {
		string s = "_";
		do getline(cin, s);
		while (!cin.eof() && !s.empty());
		if (cin.eof()) return 0;
		FOR(2) cout << endl;
		Solve();
	}
#else
	Solve();
#endif
	return 0;
	}


#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int k,n,m,x,Ans,pos;
int f[2][N];
int main(){
    scanf("%d",&n);
    memset(f,63,sizeof(f));
    f[0][0]=-1e9;
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        int t=upper_bound(f[1]+1,f[1]+n+1,x-i+1)-f[1];
        f[1][t]=x-i+1;Ans=max(Ans,t);
        f[1][pos]=min(f[1][pos],f[0][pos]);Ans=max(Ans,pos);
        t=upper_bound(f[0]+1,f[0]+n+1,x-i)-f[0];
        f[0][pos=t]=x-i;
    }
    printf("%d\n",max(0,n-Ans-1));
    return 0;
}


#include<cstdio>
#include<algorithm>
const int N=2e5+3,K=35,INF=0x3f3f3f3f;
int n,a[N],b[N],dp[N],mx,ans,rt;
#define M (L+R>>1)
struct segment_tree{
	int mx[N*35],ls[N*35],rs[N*35],t;
	void Insert(int p,int a,int L,int R,int&k){
		if(!k)k=++t;
		mx[k]=std::max(mx[k],a);
		if(L==R)return;
		p<=M?Insert(p,a,L,M,ls[k]):Insert(p,a,M+1,R,rs[k]);
	}
	int Max(int l,int r,int L,int R,int k){
		if(!k)return 0;
		if(l<=L&&R<=r)return mx[k];
		if(r<=M)return Max(l,r,L,M,ls[k]);
		if(l >M)return Max(l,r,M+1,R,rs[k]);
		return std::max(Max(l,r,L,M,ls[k]),Max(l,r,M+1,R,rs[k]));
	}
}t;
int main(){
	int l,r,m;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",a+i),a[i]+=n-i+1;
	a[n+1]=INF;
	for(int i=1;i<=n;i++){
	  for(l=0,r=mx;l<r;)m=l+r+1>>1,a[b[m]]<=a[i]?l=m:r=m-1;
	  dp[i]=l+1,b[l+1]=i;
	  if(dp[i]>mx)mx=dp[i];
	  if(i<n)ans=std::max(ans,dp[i]+1);
	}
	ans=std::max(ans,mx);
	for(int i=0;i<=mx;i++)b[i]=0;
	b[0]=n+1;
	for(int i=n;i;i--){
	  for(l=0,r=mx;l<r;)m=l+r+1>>1,a[b[m]]>=a[i]?l=m:r=m-1;
	  b[l+1]=i;
	  if(i>1)ans=std::max(ans,l+2);
	  t.Insert(a[i],l+1,1,INF,rt);
	  if(i>2)ans=std::max(ans,dp[i-2]+t.Max(a[i-2]-1,INF,1,INF,rt)+1);
	}
	printf("%d\n",n-ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
const int N=2e5+3,K=35,INF=0x3f3f3f3f;
int n,a[N],b[N],dp[N],mx,ans,rt;
#define M (L+R>>1)
struct segment_tree{
	int mx[N*35],ls[N*35],rs[N*35],t;
	void Insert(int p,int a,int L,int R,int&k){
		if(!k)k=++t;
		mx[k]=std::max(mx[k],a);
		if(L==R)return;
		p<=M?Insert(p,a,L,M,ls[k]):Insert(p,a,M+1,R,rs[k]);
	}
	int Max(int l,int r,int L,int R,int k){
		if(!k)return 0;
		if(L==R)return mx[k];
		if(r<=M)return Max(l,r,L,M,ls[k]);
		if(l >M)return Max(l,r,M+1,R,rs[k]);
		return std::max(Max(l,r,L,M,ls[k]),Max(l,r,M+1,R,rs[k]));
	}
}t;
int main(){
	int l,r,m;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",a+i),a[i]+=n-i+1;
	a[n+1]=INF;
	for(int i=1;i<=n;i++){
	  for(l=0,r=mx;l<r;)m=l+r+1>>1,a[b[m]]<=a[i]?l=m:r=m-1;
	  dp[i]=l+1,b[l+1]=i;
	  if(dp[i]>mx)mx=dp[i];
	  if(i<n)ans=std::max(ans,dp[i]+1);
	}
	ans=std::max(ans,mx);
	for(int i=0;i<=mx;i++)b[i]=0;
	b[0]=n+1;
	for(int i=n;i;i--){
	  for(l=0,r=mx;l<r;)m=l+r+1>>1,a[b[m]]>=a[i]?l=m:r=m-1;
	  b[l+1]=i;
	  if(i>1)ans=std::max(ans,l+2);
	  t.Insert(a[i],l+1,1,INF,rt);
	  if(i>2)ans=std::max(ans,dp[i-2]+t.Max(a[i-2]-1,INF,1,INF,rt)+1);
	}
	printf("%d\n",n-ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
const int N=2e5+3;
int n,a[N],b[N],dp[N],mx;
int main(){
	int l,r,m;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",a+i),a[i]+=n-i;
	for(int i=1;i<=n;i++){
	  for(l=0,r=mx;l<r;)m=l+r+1>>1,a[b[m]]<=a[i]?l=m:r=m-1;
	  dp[i]=l+1,b[l+1]=i;
	  if(dp[i]>mx)mx=dp[i];
	}
	printf("%d\n",std::max(n-mx-1,0));
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]-=i;
	}

	vector<long long> dp0(n+5,1LL<<50),dp1(n+5,1LL<<50),dp2(n+5,1LL<<50);
	dp0[0]=dp1[0]=dp2[0]=-(1LL<<50);
	dp0[1]=dp2[1]=a[0];
	for(int i=1;i<n;i++){
		int ind0=upper_bound(dp0.begin(),dp0.end(),a[i])-dp0.begin();
		int ind1=upper_bound(dp1.begin(),dp1.end(),a[i-1])-dp1.begin();
		int ind2=upper_bound(dp2.begin(),dp2.end(),a[i])-dp2.begin();
		int ind3=upper_bound(dp1.begin(),dp1.end(),a[i]+1)-dp1.begin();
		dp0[ind0]=min(dp0[ind0],a[i]);
		dp1[ind1]=min(dp1[ind1],a[i-1]);
		dp2[ind2]=min(dp2[ind2],a[i]);
		dp2[ind3]=min(dp2[ind3],a[i]);
	}
	int res=n;
	for(int i=n;i>=0;i--){
		if(dp2[i]<(1LL<<50)){
			res=i;
			break;
		}
	}
	cout << max(0,n-1-res) << "\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]-=i;
	}

	vector<long long> dp0(n+5,1LL<<50),dp1(n+5,1LL<<50);
	dp0[0]=dp1[0]=0;
	for(int i=0;i<n;i++){
		int ind0=upper_bound(dp0.begin(),dp0.end(),a[i]+1)-dp0.begin();
		int ind1=upper_bound(dp0.begin(),dp0.end(),a[i])-dp0.begin();
		int ind2=upper_bound(dp1.begin(),dp1.end(),a[i])-dp1.begin();
		dp1[ind0]=min(dp1[ind0],a[i]);
		dp0[ind1]=min(dp0[ind1],a[i]);
		dp1[ind2]=min(dp1[ind2],a[i]);
	}
	int res=n;
	for(int i=n-1;i>=0;i--){
		if(dp1[i]<(1LL<<50)){
			res=i;
			break;
		}
	}
	cout << max(0,n-1-res) << "\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

class seg_update_sum{//range sum and range update
public:
	vector<long long> arr;
	vector<bool> flag;
	int size;
	int n;
	seg_update_sum(int m){
		n=1;
		while(n<m) n*=2;
		size=n*2;
		arr.resize(size);
		flag.resize(size);
		fill(flag.begin(),flag.end(),false);
	}

	void range_update(int left,int right,long long v){
		left=max(left+n,n),right=min(right+n,size-1);
		if(left>right) return;
		int le=left,ri=right;
		propagate(left);
		propagate(right);
		for(int k=0;left<=right;k++,left=(left+1)>>1,right=(right-1)>>1){
			if(left&1){
				arr[left]=(v << k);
				flag[left]=true;
			}
			if(!(right&1)){
				arr[right]=(v << k);
				flag[right]=true;
			}
		}
		popUp(le);
		popUp(ri);
	}
	void propagate(int i){
		int k=0;
		while(i>>k) k++;
		k--;
		for(;k>=0;k--){
			int j=i>>k;
			if(!flag[j]) continue;
			if(k>0){
				arr[2*j]=arr[j]>>1;
				flag[2*j]=true;
				arr[2*j+1]=arr[j]>>1;
				flag[2*j+1]=true;
			}
			flag[j]=false;
		}
	}
	void popUp(int i){
		for(int k=0;i>1;k++,i/=2){
			if(!flag[i>>1])arr[i>>1]=arr[i]+arr[i^1];
		}
	}
	long long range_sum(int left,int right){
		left=max(left+n,n),right=min(right+n,size-1);
		if(left>right) return 0;
		propagate(left);
		propagate(right);
		long long res=0;
		for(;left<=right;left=(left+1)>>1,right=(right-1)>>1){
			if(left&1){
				res+=arr[left];
			}
			if(!(right&1)){
				res+=arr[right];
			}
		}
		return res;
	}
};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]-=i;
	}

	vector<long long> dp0(n+5,1LL<<40);
	seg_update_sum dp1(n+5);
	for(int i=0;i<(n+5);i++) dp1.range_update(i,i,1LL<<40);
	dp0[0]=-(1LL<<40);
	dp1.range_update(0,0,-(1LL<<40));
	dp1.range_update(1,1,a[0]);
	for(int i=1;i<n;i++){
		int ind0=upper_bound(dp0.begin(),dp0.end(),a[i-1])-dp0.begin();
		int ind1=upper_bound(dp0.begin(),dp0.end(),a[i]+1)-dp0.begin();
		int left=0,right=n+4;
		while(left<right){
			int mid=(left+right)/2;
			if(dp1.range_sum(mid,mid)<=a[i]) left=mid+1;
			else right=mid;
		}
		int ind2=left;

		dp0[ind0]=min(dp0[ind0],a[i-1]);
		long long v=min(a[i],dp1.range_sum(ind1,ind1));
		dp1.range_update(ind1,ind1,v);
		left=0,right=ind1-1;
		while(left<right){
			int mid=(left+right+1)/2;
			if(dp1.range_sum(mid,mid)<v) left=mid;
			else right=mid-1;
		}
		left++;
		dp1.range_update(left,ind1,v);

		v=min(a[i],dp1.range_sum(ind2,ind2));
		dp1.range_update(ind2,ind2,v);
		left=0,right=ind2-1;
		while(left<right){
			int mid=(left+right+1)/2;
			if(dp1.range_sum(mid,mid)<v) left=mid;
			else right=mid-1;
		}
		left++;
		dp1.range_update(left,ind2,v);
	}
	int res=0;
	for(int i=n;i>=0;i--){
		if(dp1.range_sum(i,i)<(1LL<<40)){
			res=max(0,n-1-i);
			break;
		}
	}
	cout << res << "\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

class seg_update_sum{//range sum and range update
public:
	vector<long long> arr;
	vector<bool> flag;
	int size;
	int n;
	seg_update_sum(int m){
		n=1;
		while(n<m) n*=2;
		size=n*2;
		arr.resize(size);
		flag.resize(size);
		fill(flag.begin(),flag.end(),false);
	}

	void range_update(int left,int right,long long v){
		left=max(left+n,n),right=min(right+n,size-1);
		if(left>right) return;
		int le=left,ri=right;
		propagate(left);
		propagate(right);
		for(int k=0;left<=right;k++,left=(left+1)>>1,right=(right-1)>>1){
			if(left&1){
				arr[left]=(v << k);
				flag[left]=true;
			}
			if(!(right&1)){
				arr[right]=(v << k);
				flag[right]=true;
			}
		}
		popUp(le);
		popUp(ri);
	}
	void propagate(int i){
		int k=0;
		while(i>>k) k++;
		k--;
		for(;k>=0;k--){
			int j=i>>k;
			if(!flag[j]) continue;
			if(k>0){
				arr[2*j]=arr[j]>>1;
				flag[2*j]=true;
				arr[2*j+1]=arr[j]>>1;
				flag[2*j+1]=true;
			}
			flag[j]=false;
		}
	}
	void popUp(int i){
		for(int k=0;i>1;k++,i/=2){
			if(!flag[i>>1])arr[i>>1]=arr[i]+arr[i^1];
		}
	}
	long long range_sum(int left,int right){
		left=max(left+n,n),right=min(right+n,size-1);
		if(left>right) return 0;
		propagate(left);
		propagate(right);
		long long res=0;
		for(;left<=right;left=(left+1)>>1,right=(right-1)>>1){
			if(left&1){
				res+=arr[left];
			}
			if(!(right&1)){
				res+=arr[right];
			}
		}
		return res;
	}
};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]-=i;
	}

	vector<long long> dp0(n+5,1LL<<40);
	seg_update_sum dp1(n+5);
	for(int i=0;i<(n+5);i++) dp1.range_update(i,i,1LL<<40);
	dp0[0]=-(1LL<<40);
	dp1.range_update(0,0,-(1LL<<40));
	dp1.range_update(1,1,a[0]);
	for(int i=1;i<n;i++){
		int ind0=upper_bound(dp0.begin(),dp0.end(),a[i-1])-dp0.begin();
		int ind1=upper_bound(dp0.begin(),dp0.end(),a[i]+1)-dp0.begin();
		int left=0,right=n+4;
		while(left<right){
			int mid=(left+right)/2;
			if(dp1.range_sum(mid,mid)<=a[i]) left=mid+1;
			else right=mid;
		}
		int ind2=left;

		dp0[ind0]=min(dp0[ind0],a[i-1]);

		long long v=min(a[i],dp1.range_sum(ind2,ind2));
		dp1.range_update(ind2,ind2,v);

		v=min(a[i],dp1.range_sum(ind1,ind1));
		dp1.range_update(ind1,ind1,v);
		left=0,right=ind1-1;
		while(left<right){
			int mid=(left+right+1)/2;
			if(dp1.range_sum(mid,mid)<v) left=mid;
			else right=mid-1;
		}
		left++;
		dp1.range_update(left,ind1,v);
	}
	int res=0;
	for(int i=n;i>=0;i--){
		if(dp1.range_sum(i,i)<(1LL<<40)){
			res=max(0,n-1-i);
			break;
		}
	}
	cout << res << "\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]-=i;
	}

	vector<long long> dp0(n+5,1LL<<50),dp1(n+5,1LL<<50);
	dp0[0]=dp1[0]=0;
	for(int i=0;i<n;i++){
		int ind=upper_bound(dp0.begin(),dp0.end(),a[i]+1)-dp0.begin();
		ind--;
		dp1[ind+1]=min(dp1[ind+1],a[i]);

		ind=upper_bound(dp0.begin(),dp0.end(),a[i])-dp0.begin();
		ind--;
		dp0[ind+1]=min(dp0[ind+1],a[i]);

		ind=upper_bound(dp1.begin(),dp1.end(),a[i])-dp1.end();
		ind--;
		dp1[ind+1]=min(dp1[ind+1],a[i]);
	}
	int res=n;
	for(int i=n-1;i>=0;i--){
		if(dp1[i]<(1LL<<50)){
			res=i;
			break;
		}
	}
	cout << max(0,n-1-res) << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 2e5 + 10;
int a[maxn];

int dp[2][maxn], fen[2][2 * maxn];

void add(bool w, int idx, int val){
	for (; idx < 2 * maxn; idx += idx & -idx)
		fen[w][idx] = max(fen[w][idx], val);
}

int get(bool w, int idx){
	int ret = 0;
	for (; idx; idx -= idx & -idx)
		ret = max(ret, fen[w][idx]);
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> cmp;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		a[i] -= i;
		cmp.push_back(a[i]);
		cmp.push_back(a[i] + 1);
	}
	sort(cmp.begin(), cmp.end());
	cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());
	for (int i = 0; i < n; i++)
		a[i] = lower_bound(cmp.begin(), cmp.end(), a[i]) - cmp.begin() + 1;
	int answer = n;
	for (int i = 0; i < n; i++){
		dp[0][i] = get(0, a[i]) + 1;
		dp[1][i] = max(dp[1][i], get(1, a[i]) + 1);
		dp[1][i + 1] = get(0, a[i + 1] + 1) + 1;
		add(0, a[i], dp[0][i]);
		add(1, a[i], dp[1][i]);
		answer = min(answer, n - dp[1][i] - 1);
	}
	cout << max(answer, 0) << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 2e5 + 10;
int a[maxn];

int dp[2][maxn], fen[2][2 * maxn];

void add(bool w, int idx, int val){
	for (; idx < 2 * maxn; idx += idx & -idx)
		fen[w][idx] = max(fen[w][idx], val);
}

int get(bool w, int idx){
	int ret = 0;
	for (; idx; idx -= idx & -idx)
		ret = max(ret, fen[w][idx]);
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> cmp;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		a[i] -= i;
		cmp.push_back(a[i]);
		cmp.push_back(a[i] + 1);
	}
	sort(cmp.begin(), cmp.end());
	cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());
	for (int i = 0; i < n; i++)
		a[i] = lower_bound(cmp.begin(), cmp.end(), a[i]) - cmp.begin() + 1;
	int answer = n;
	for (int i = 0; i < n; i++){
		dp[0][i] = get(0, a[i]) + 1;
		dp[1][i] = max(get(1, a[i]) + 1, get(0, a[i] + 1) + 1);
		add(0, a[i], dp[0][i]);
		add(1, a[i], dp[1][i]);
		answer = min(answer, n - dp[1][i] - 1);
	}
	cout << max(answer, 0) << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 2e5 + 10;
int a[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		a[i] -= i;
	}
	multiset<int> s;
	for (int i = 0; i < n; i++){
		if (s.upper_bound(a[i]) != s.end())
			s.erase(s.upper_bound(a[i]));
		s.insert(a[i]);
	}
	if (s.size() == n)
		return cout << 0 << endl, 0;
	cout << n - s.size() - 1 << endl;
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i%2==0)
            {
                if(j%2==0)
                {
                    printf("c");
                }
                else
                {
                    printf(".");
                }
            }
            else
            {
                if(j%2==0)
                {
                    printf(".");
                }
                else
                {
                    printf("c");
                }
            }
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i%2==0)
            {
                if(j%2==0)
                {
                    printf("C");
                }
                else
                {
                    printf(".");
                }
            }
            else
            {
                if(j%2==0)
                {
                    printf(".");
                }
                else
                {
                    printf("C");
                }
            }
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",n);
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i%2==0)
            {
                if(j%2==0)
                {
                    printf("C");
                }
                else
                {
                    printf(".");
                }
            }
            else
            {
                if(j%2==0)
                {
                    printf(".");
                }
                else
                {
                    printf("C");
                }
            }
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int main ()
{
    int i,n,a;
    scanf("%d",&n);
    char string1[n+1],string2[n+1];
    a=ceil((n*n)/2.0);
    printf("%ld\n",a);
    for(i=0; i<n; i++)
    {
        if(i%2==0)
        {
            string1[i]='C';
            string2[i]='.';
        }
        else if(i%2==1)
        {
            string1[i]='.';
            string2[i]='C';
        }
    }
    string1[n]='\0';
    string2[n]='\0';

    for(i=1; i<=n; i++)
    {
        if(i%2==1)
            printf("%s\n",string1);
        else if(i%2==0)
            printf("%s\n",string2);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int i,n,a;
char string1[1000],string2[1000];
int main ()
{
    scanf("%d",&n);
    a=ceil((n*n)/2.0);
    printf("%ld\n",a);
    for(i=0; i<n; i++)
    {
        if(i%2==0)
        {
            string1[i]='c';
            string2[i]='.';
        }
        else if(i%2==1)
        {
            string1[i]='.';
            string2[i]='c';
        }
    }

    for(i=1;i<=n;i++)
    {
        if(i%2==1)
            printf("%s\n",string1);
        else if(i%2==0)
            printf("%s\n",string2);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int i,n,a;
char string1[1000],string2[1000];
int main ()
{
    scanf("%d",&n);
    a=ceil((n*n)/2.0);
    printf("%ld\n",a);
    for(i=0; i<n; i++)
    {
        if(i%2==0)
        {
            string1[i]='C';
            string2[i]='.';
        }
        else if(i%2==1)
        {
            string1[i]='.';
            string2[i]='C';
        }
    }

    for(i=1;i<=n;i++)
    {
        if(i%2==1)
            printf("%s\n",string1);
        else if(i%2==0)
            printf("%s\n",string2);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int main ()
{
    int i,n,a;
    scanf("%d",&n);
    char string1[n+1],string2[n+1];
    a=ceil((n*n)/2.0);
    printf("%ld\n",a);
    for(i=0; i<n; i++)
    {
        if(i%2==0)
        {
            string1[i]='c';
            string2[i]='.';
        }
        else if(i%2==1)
        {
            string1[i]='.';
            string2[i]='c';
        }
    }
    string1[n]='\0';
    string2[n]='\0';

    for(i=1; i<=n; i++)
    {
        if(i%2==1)
            printf("%s\n",string1);
        else if(i%2==0)
            printf("%s\n",string2);
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,count=0,k=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(k%2!=0)
            {
                printf("C");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf(".");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }
            else
            {
                printf(".");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf("C");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }

        }
        k++;
        count=0;
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,count=0,k=1;
    scanf("%d",&n);
    char c1='C',c2='.';
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(k%2!=0)
            {
                printf("%c",c1);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf("%c",c2);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }
            else
            {
                printf("%c",c2);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf("%c",c1);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }

        }
        k++;
        count=0;
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,count=0,k=1,a,b;
    scanf("%d",&n);
    if(n%2==0)
    {
        printf("%d",n*(n/2));
        printf("\n");
    }
    else
    {
        a=((n/2)+1)*((n/2)+1);
        b=(n/2)*(n/2);
        printf("%d",a+b);
        printf("\n");
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(k%2!=0)
            {
                printf("C");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf(".");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }
            else
            {
                printf(".");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf("C");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }

        }
        k++;
        count=0;
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,count=0,k=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(k%2!=0)
            {
                printf("c");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf(".");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }
            else
            {
                printf(".");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf("c");
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }

        }
        k++;
        count=0;
    }
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,j,count=0,k=1;
    scanf("%d",&n);
    int c1='C',c2='.';
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(k%2!=0)
            {
                printf("%c",c1);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf("%c",c2);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }
            else
            {
                printf("%c",c2);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
                printf("%c",c1);
                count++;
                if(count==n)
                {
                    printf("\n");
                    break;
                }
            }

        }
        k++;
        count=0;
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i=0,n,j=0;
    scanf("%d",&n);
    while(i!=n)
    {
        if(i==j)
        {
            printf("C");
        }
        else
        {
            printf(".");
        }
        ++j;
        if(j==n&&i!=n)
        {
            ++i;
            j=0;
            printf("\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i=0,n,j=0;
    scanf("%d",&n);
    while(i!=n)
    {
        if(i==j)
        {
            printf("c");
        }
        else
        {
            printf(".");
        }
        ++j;
        if(j==n&&i!=n)
        {
            ++i;
            j=0;
            printf("\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i=0,n,j=0;
    scanf("%d",&n);
    printf("%d\n",n);
    while(i!=n)
    {
        if(i==j)
        {
            printf("C");
        }
        else
        {
            printf(".");
        }
        ++j;
        if(j==n&&i!=n)
        {
            ++i;
            j=0;
            printf("\n");
        }
    }
    return 0;
}


#include<stdio.h>

int main()
{
    int n,i,j,t1,t2,ans;
    scanf("%d",&n);
    t1= n/2;
    t2= (n+1)/2; //ceil(n/2)
    ans= t1*t1 + t2*t2;
    printf("%d\n",ans);

    if(!(n&1)) { //n is not odd

        for(j=0;j<t1;j++) {

            for(i=0;i<t1;i++) printf("C.");
            printf("\n");

            for(i=0;i<t1;i++) printf(".C");
            printf("\n");
        }

    }

    else {
        printf("C");
        for(i=0;i<t1;i++) printf(".C");
        printf("\n");

        for(j=0;j<t1;j++) {

            printf(".");
            for(i=0;i<t1;i++) printf("C.");
            printf("\n");

            printf("C");
            for(i=0;i<t1;i++) printf(".C");
            printf("\n");
        }
    }

    return 0;
}


#include<stdio.h>

void print(int n)
{
	int i,j;

	 for(i=1;i<=n;i++)
            {
                if(i%2==1)
                    for(j=1;j<=n;j++)
                        {
                            if(j%2==1) printf("C");
                            else printf(".");
                        }
                else
                    for(j=1;j<=n;j++)
                        {
                            if(j%2==1) printf(".");
                            else printf("C");
                        }
                printf("\n");
            }
}

int main()
{
    int n,i,j,a,b;

    scanf("%d",&n);

    if(n%2==0)
    {
    	printf("%d\n",n*n/2);
    	print(n);
    }
    else
    {
        a= (n+1)/2;
        b= (n-1)/2;
        printf("%d\n",a*a+b*b);

        print(n);
    }

    return 0;

}


#include <stdio.h>

int main(){

    int n = 0;
    scanf("%d", &n);
    printf("%d\n", (n * n + 1) / 2);
    int row = 0, col = 0;
    for(row = 0; row < n; row++){
        for(col = 0; col < n; col++){
            if((row + col)%2){
              printf(".");
            }
            else{
              printf("C");
            }
        }
        printf("\n");
    }
    return 0;
}


#include <cstdio>

int main(){

    int n(0); scanf("%d", &n);
    printf("%d\n", (n * n + 1) / 2);

    for(int row = 0; row < n; row++){
        for(int col = 0; col < n; col++){
            if((row + col)%2){printf(".");}
            else{printf("C");}
        }
        printf("\n");
    }
    return 0;
}


#include <cstdio>

int main(){

    int n(0); scanf("%d", &n);
    printf("%d\n", (n * n + 1) / 2);

    for(int row = 0; row < n; row++){
        for(int col = 0; col < n; col++){
            if((row + col)%2){
              printf(".");
            }
            else{
              printf("C");
            }
        }
        printf("\n");
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main()
{
int n,k;
scanf("%d",&n);

for(int i =0;i<n;i++)
{
 k=0;
 if(i%2==0)
 {
 for(int j=0;j<n;j++)
 {
  if(k%2 == 0)
  {
    printf("C");
    k++;
  }
  else
  {
    printf(".");
    k++;
  }

 }
 }
 else
 {
  for(int j=0;j<n;j++)
  {
   if(k%2 == 0)
   {
    printf(".");
    k++;
   }
   else
   {
    printf("C");
    k++;
   }
  }
  }
  printf("\n");
}

 return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main()
{
int k,n,nb = 0;
scanf("%d",&n);

for(int i =0;i<n;i++)
{
 k=0;
 if(i%2==0)
 {
 for(int j=0;j<n;j++)
 {
  if(k%2 == 0)
  {
   // printf("C");
    k++;
    nb++;
  }
  else
  {
  //  printf(".");
    k++;
  }

 }
 }
 else
 {
  for(int j=0;j<n;j++)
  {
   if(k%2 == 0)
   {
   // printf(".");
    k++;
   }
   else
   {
   // printf("C");
    k++;
    nb++;
   }
  }
  }
  //printf("\n");
}

printf("%d\n",nb);

for(int i =0;i<n;i++)
{
 k=0;
 if(i%2==0)
 {
 for(int j=0;j<n;j++)
 {
  if(k%2 == 0)
  {
    printf("C");
    k++;
    nb++;
  }
  else
  {
    printf(".");
    k++;
  }

 }
 }
 else
 {
  for(int j=0;j<n;j++)
  {
   if(k%2 == 0)
   {
    printf(".");
    k++;
   }
   else
   {
    printf("C");
    k++;
    nb++;
   }
  }
  }
  printf("\n");
}

 return 0;
}


#include<stdio.h>
//#include<conio.h>
int main(){
int n,i,j,c;
scanf("%d",&n);
if(n%2==0)
c=n*n/2;
else c=(n*n+1)/2;
printf("%d\n",c);
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i%2!=0){
if(j%2!=0)
printf("C");
else printf(".");
}
else{
     if(j%2!=0) printf(".");
     else printf("C");
     }
     }
     printf("\n");
     }
    .// getch();
     return 0;
     }


#include<stdio.h>
#include<conio.h>
int main(){
int n,i,j,c;
scanf("%d",&n);
if(n%2==0)
c=n*n/2;
else c=(n*n+1)/2;
printf("%d\n",c);
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i%2!=0){
if(j%2!=0)
printf("C");
else printf(".");
}
else{
     if(j%2!=0) printf(".");
     else printf("C");
     }
     }
     printf("\n");
     }
     getch();
     return 0;
     }


#include<stdio.h>
int main(){
int n,i,j,c;
scanf("%d",&n);
if(n%2==0)
c=n*n/2;
else c=(n*n+1)/2;
printf("%d\n",c);
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if(i%2!=0){
if(j%2!=0)
printf("C");
else printf(".");
}
else{
     if(j%2!=0) printf(".");
     else printf("C");
     }
     }
     printf("\n");
     }
     return 0;
     }


#include<stdio.h>
#include<string.h>

int main(){
	int i,j,x;
	scanf("%d",&x);

	for(i=0;i<x;i++)
   {
		for(j=0;j<x;j++)
		{
			if(i&1)
			{	if(j&1)
					printf("C");
	         else
					printf(".");   }
	      else
			{	if(j&1)
					printf(".");
	         else
					printf("C");   }
		}

	   printf("\n");
   }

	return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
	int i,j,x;
	scanf("%d",&x);

   printf("%d\n",x);

	for(i=0;i<x;i++)
   {
		for(j=0;j<x;j++)
		{
			if(i&1)
			{	if(j&1)
					printf("C");
	         else
					printf(".");   }
	      else
			{	if(j&1)
					printf(".");
	         else
					printf("C");   }
		}

	   printf("\n");
   }

	return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
	int i,j,x;
	scanf("%d",&x);

   if(x&1)   printf("%d\n",x*x/2+1);
	else      printf("%d\n",x*x/2);

	for(i=0;i<x;i++)
   {
		for(j=0;j<x;j++)
		{
			if(i&1)
			{	if(j&1)
					printf("C");
	         else
					printf(".");   }
	      else
			{	if(j&1)
					printf(".");
	         else
					printf("C");   }
		}

	   printf("\n");
   }

	return 0;
}


#include <stdio.h>

int main(void)
{
	int n, ans, i, j, c[2] = {'C', '.'};

	scanf("%d", &n);
	if ((n & 1) == 0)
	{
		ans = n * n/2;
	}
	else
	{
		ans = (n * n + 1) / 2;
	}
	printf("%d\n", ans);
	for (i = 0; i < n; ++i)
	{
		int x = i & 1, s = c[x];

		for (j = 0; j < n; ++j)
		{
			putchar(s);
			x = 1-x;
			s = c[x];
		}
		putchar('\n');
	}
	return 0;
}


#include <stdio.h>

int main(void)
{
	int n, i, j, c[2] = {'C', '.'};

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		int x = i & 1, s = c[x];

		for (j = 0; j < n; ++j)
		{
			putchar(s);
			x = 1-x;
			s = c[x];
		}
		putchar('\n');
	}
	return 0;
}


#include <stdio.h>

int main(void)
{
	int n, i, j, c[2] = {'C', '.'};

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		int x = i & 1, s = c[x];

		for (j = 0; j < n; ++j)
		{
			putchar(s);
			putchar(' ');
			x = 1-x;
			s = c[x];
		}
		putchar('\n');
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
    int n,i,j,test;
    char chaine[1000][1000];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {

        for(j=0;j<n;j++)
        {
            if((i%2==0)&&(j%2==0))
                printf("C");
            else if ((i%2==0)&&(j%2==1))
                printf(".");
            else if((i%2==1)&&(j%2==1))
                printf("C");
            else if((i%2==1)&&(j%2==0))
                printf(".");
        }
        printf("\n");
    }
    return (EXIT_SUCCESS);
}


# include <stdio.h>

main ()
{
    int n;
    int i, j;

    scanf("%d", &n);
    if (n%2 == 0)
        printf("%d\n", n*n/2);
    else
        printf("%d\n", n*n/2+1);
    for (i=0; i<n; i++){
        for(j=0; j<n; j++)
        {
                if(i%2 == 0){
                    if (j%2 == 0)
                        printf("c");
                    else
                        printf(".");
                }
                else
                {
                    if (j%2 == 1)
                        printf("c");
                    else
                        printf(".");
                }
        }
        printf("\n");
    }
    return 0;
}


# include <stdio.h>

main ()
{
    int n;
    int i, j;

    scanf("%d", &n);
    for (i=0; i<n; i++){
        for(j=0; j<n; j++)
        {
                if(i%2 == 0){
                    if (j%2 == 0)
                        printf("c");
                    else
                        printf(".");
                }
                else
                {
                    if (j%2 == 1)
                        printf("c");
                    else
                        printf(".");
                }
        }
        printf("\n");
    }
    return 0;
}


# include <stdio.h>

main ()
{
    int n;
    int i, j;

    scanf("%d", &n);
    if (n%2 == 0)
        printf("%d\n", n*n/2);
    else
        printf("%d\n", n*n/2+1);
    for (i=0; i<n; i++){
        for(j=0; j<n; j++)
        {
                if(i%2 == 0){
                    if (j%2 == 0)
                        printf("C");
                    else
                        printf(".");
                }
                else
                {
                    if (j%2 == 1)
                        printf("C");
                    else
                        printf(".");
                }
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
int main(){
    int n,i;
    scanf("%d",&n);
    if(n%2==0)
        printf("%ld\n",(n*n)/2);
        else
            printf("%ld\n",((n*n)+1)/2);
            int j;
        for(i=1;i<=n;i++){
           if(i%2!=0){
            for(j=1;j<=n;j++){
                if(j%2!=0)
                    printf("C");
                else printf(".");
            }
            printf("\n");
        }
      else{
            for(j=1;j<=n;j++){
                if(j%2!=0)
                    printf(".");
                else printf("C");
            }
            printf("\n");
        }
    }
       return 0;
}


#include<stdio.h>
int main(){
    int n,i,j;
    scanf("%d",&n);
    printf("%d",n);
    printf("\n");
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if(i==j)
                printf("C");
            else printf(".");
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>
int main(){
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if(i==j)
                printf("C");
            else printf(".");
        }
        printf("\n");
    }
    return 0;
}


#include <stdio.h>

int main()
{
    int n;
    int i,j,tt,pp;
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",n);
        tt=0;
        for(i=0;i<n;i++)
        {
            tt++;
            pp=0;
            for(j=0;j<n;j++)
            {
                if(tt%2==1&&j==0)pp=1;

                if(pp%2==1)printf("C");
                else printf(".");
                pp++;
            }
            puts("");
        }
    }

    return 0;
}


#include <stdio.h>

int main()
{
    int n;
    int i,j,tt,pp;
    while(scanf("%d",&n)!=EOF)
    {
        tt=0;
        for(i=0;i<n;i++)
        {
            tt++;
            pp=0;
            for(j=0;j<n;j++)
            {
                if(tt%2==1&&j==0)pp=1;

                if(pp%2==1)printf("C");
                else printf(".");
                pp++;
            }
            puts("");
        }
    }

    return 0;
}


#include<stdio.h>
int main()
{
	int n,count=0;
	scanf("%d",&n);
	int i,j;
	if(n%2==0)
		count=(n*n)/2;
	else
		count=((n*n)+1)/2;
	printf("%d\n",count);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i%2==0)
			{
				if(j%2==0)
					printf("C");
				else
					printf(".");
			}
			else
			{
				if(j%2==0)
					printf(".");
				else
					printf("C");
			}
		}
		printf("\n");
	}
	return 0;
}


#include<stdio.h>

int main()
{
    int n,j,i;
    while(scanf("%d",&n)!=EOF)
    {
        if(n%2==0)
          printf("%d\n",n*n/2);
        else
          printf("%d\n",n*n/2+1);
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if((i+j)%2==0)
                {
                   printf("c");
                }else{
                   printf(".");
                }
            }
            printf("\n");
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<cmath>

int main()
{
	int n,j,i;
	while(scanf("%d",&n)!=EOF)
	{
		if(n%2==0)
		  printf("%d\n",n*n/2);
		else
		  printf("%d\n",n*n/2+1);
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
			    if((i+j)%2==0)
				{
				   printf("c");
				}else{
				   printf(".");
				}
			}
			printf("\n");
		}
	}
	return 0;
}


#include<stdio.h>

int main()
{
    int n,j,i;
    while(scanf("%d",&n)!=EOF)
    {
        if(n%2==0)
          printf("%d\n",n*n/2);
        else
          printf("%d\n",n*n/2+1);
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                if((i+j)%2==0)
                {
                   printf("C");
                }else{
                   printf(".");
                }
            }
            printf("\n");
        }
    }
    return 0;
}


#include <stdio.h>
#include<string.h>
int main()
{  int n,ans,i,j;
	scanf("%d",&n);
	if ( n%2==0)
	{
		ans = (n*n);
                ans = ans/2;
	}
	if (n%2!=0)
	{
		ans = ((n*n)+1);
                ans = ans /2;
        }
	printf("%d\n",ans);
	for ( i=0;i<n;i++)
	{for (j=0;j<n;j++)
		{ if ( (i+j)%2==0)
			{
				printf("C");

			}
			else
			{
			       	printf(".");
			}
		}
			 printf("\n");
	}
 return 0;

}


#include <stdio.h>
#include<string.h>
int main()
{  int n,ans,i,j;
	scanf("%d",&n);
	if ( n%2==0)
	{
		ans = (n*n);
                ans = ans/2;
	}
	if (n%2!=0)
	{
		ans = ((n*n)+1);
                ans = ans /2;
        }
	printf("%d\n",ans);
	for ( i=0;i<n;i++)
	{for (j=0;j<n;j++)
		{ if ( (i+j)%2==0)
			{
				printf("c");
			}
			else
			{
			       	printf(".");
			}
		}
			 printf("\n");
	}
 return 0;

}


#include <iostream>
using namespace std;
const int mx = 105;
int a[mx];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		int sum = 0;
		cin >> n >> m;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			sum += a[i];
		}
		if (sum == m)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <iomanip>
#include <set>
#include <stack>
#include <math.h>

using namespace std;
#define ll long long
int main()
{
	int t = 1;
	cin >> t;
	while (t--) {
		int n, x, m;
		cin >> n >> m;
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> x;
			sum += x;
		}
		if (sum == m) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int arr[105];

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		int sum = 0;
		for (int i = 1; i <= n; i++)
		{
			cin >> arr[i];
			sum += arr[i];
		}

		if (sum == m) cout << "YES" << endl;
		else cout << "NO" << endl;

	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable :4996)
int main() {
	int t = 0;

	scanf("%d", &t);
	for (int l = 1; l <= t; l++) {
		int n = 0;
		double sum = 0, arr[100] = { 0 }, m = 0;

		scanf("%d%lf", &n, &m);
		for (int h = 0; h < n; h++) {
			scanf("%lf", &arr[h]);
		}
		for (int h = 0; h < n; h++) {
			for (int k = 0; k <= h; k++) {
				if (arr[k] > arr[h]) {
					double temp = arr[k];
					arr[k] = arr[h];
					arr[h] = temp;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = i ; j < n; j++) {
				sum += arr[j] / (j+1);
				//printf("sum=%lf \n", sum);
			}
		}
		//printf("%lf", m);
		if (m == sum) {
			printf("YES\n");
		}else printf("NO\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable :4996)
int main() {
	int t = 0;

	scanf("%d", &t);
	for (int l = 1; l <= t; l++) {
		int n = 0, m = 0;
		float sum = 0, arr[100] = { 0 };
		scanf("%d%d", &n, &m);
		for (int h = 0; h < n; h++) {
			scanf("%f", &arr[h]);
		}
		for (int i = 0; i < n; i++) {
			for (int j = i ; j < n; j++) {
				sum += arr[j] / (j+1);

			}
		}
		//printf("sum=%f \n", sum);
		if (m == sum) {
			printf("YES\n");
		}
		else printf("NO\n");
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable :4996)
int main() {
	int t = 0;

	scanf("%d", &t);
	for (int l = 1; l <= t; l++) {
		int n = 0;
		double sum = 0, arr[100] = { 0 }, m = 0;

		scanf("%d%lf", &n, &m);
		for (int h = 0; h < n; h++) {
			scanf("%lf", &arr[h]);
		}
		/*for (int h = 0; h < n; h++) {
			for (int k = 0; k <= h; k++) {
				if (arr[k] > arr[h]) {
					double temp = arr[k];
					arr[k] = arr[h];
					arr[h] = temp;
				}
			}
		}*/
		for (int i = 0; i < n; i++) {

				sum += arr[i];
				//printf("sum=%lf \n", sum);
			}

		//printf("%lf\n", m);
		if (sum == m) {
			printf("YES\n");
		}else printf("NO\n");
	}
	return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
	int t;
	cin >> t;
	for (int q = 0; q < t; ++q){
		int n, m;
		cin >> n >> m;
		int s = 0;
		for (int i = 0; i < n; ++i) {
			int x;
			cin >> x;
			s += x;
		}
		if (s == m) cout << "YES";
		else cout << "NO";
		cout << endl;
	}
}


#include <array>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>;
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (const auto &x : v) os << x << " "; return os << endl; }

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

//constexpr int INT_MAX = 2147483647;
//constexpr int INT_MIN = -2147483648;
ll ceil_div(ll a, ll b) { return (a + b - 1) / b; }

void solve() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int sum = 0;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	bool ans = sum == m;
	cout << (ans ? "YES" : "NO") << endl;
}

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
	ifstream in("inputA.txt");
	cin.rdbuf(in.rdbuf()); //redirect cin to input.txt!
	ofstream out("outA.txt");
	cout.rdbuf(out.rdbuf()); //redirect cout to out.txt!
#endif
	int T;
	cin >> T;
	for (int t=0; t<T; t++)
		solve();
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t,n,m,i,sum;
	cin>>t;
	while(t)
	{t--;cin>>n>>m;sum=0;
	while(n)
	{n--;cin>>i;sum+=i;}if (sum==m) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t,n,m,i,sum=0;
	cin>>t;
	while(t)
	{t--;cin>>n>>m;
	while(n)
	{n--;cin>>i;sum+=i;}if (sum==m) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
    long long t;
    cin>>t;
    while(t--){
        long long n,m;
        cin>>n>>m;
        int a[n],s=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            s=s+a[i];
        }
        if(s==m){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}


#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        long long n,m;
        cin>>n>>m;
        long long x,s=0;
        for(int i=0;i<n;i++){
            cin>>x;
            s=s+x;
        }
        if(s==m){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}


#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int a[n],s=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            s=s+a[i];
        }
        if(s==m){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}


#include <iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, m, a[100],s=0,i;
		cin >> n >> m;
		for (i = 1; i <= n; i++) {
			cin >> a[i];
			s = s + a[i];

		}
		if (s == m)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

}


#include <iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, m, a[101],i;
		long long s = 0;
		cin >> n >> m;
		for (i = 1; i <= n; i++) {
			cin >> a[i];
			s = s + a[i];

		}
		if (s == m)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

}


#include <iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int n, m, a[100],i;
		long long s = 0;
		cin >> n >> m;
		for (i = 1; i <= n; i++) {
			cin >> a[i];
			s = s + a[i];

		}
		if (s == m)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

}


#include<iostream>
#include<vector>
#include<numeric>

int main()
{
    int testcase{};
    std::cin>>testcase;

    for(int i{0}; i < testcase; i++)
    {
        int size{},m{};
        std::cin>>size>>m;

        std::vector<int, size> array{};

        for(int j{0}; j < size; j++)
        {
            int input{};
            std::cin>>input;
            array.push_back(input);
        }

        int sum{ std::reduce(array.begin(),array.end())};
        if(sum == m)
        {
            std::cout<<"YES\n";
        }
        else
        {
            std::cout<<"No\n";
        }

    }
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include<iostream>
#include<vector>
#include<numeric>

int main()
{
    int testcase{};
    std::cin>>testcase;

    for(int i{0}; i < testcase; i++)
    {
        int size{},m{};
        std::cin>>size>>m;

        std::vector<int> array(size);

        for(int j{0}; j < size; j++)
        {
            int input{};
            std::cin>>input;
            array.push_back(input);
        }

        int sum{ std::reduce(array.begin(),array.end())};
        if(sum == m)
        {
            std::cout<<"YES\n";
        }
        else
        {
            std::cout<<"No\n";
        }

    }
    return 0;
}


#include<iostream>
#include<vector>

int main()
{
    int testcase{};
    std::cin>>testcase;

    for(int i{0}; i < testcase; i++)
    {
        int size{},m{};
        std::cin>>size>>m;

        int sum{0};

        for(int j{0}; j < size; j++)
        {
            int input{};
            std::cin>>input;
            sum+=input;
        }

        if(sum == m)
        {
            std::cout<<"YES\n";
        }
        else
        {
            std::cout<<"No\n";
        }

    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algoritm>

int main()
{
    int testcase{};
    std::cin>>testcase;

    for(int i{0}; i < testcase; i++)
    {
        int size{},m{};
        std::cin>>size>>m;

        std::vector<int> array(size);

        for(int j{0}; j < size; j++)
        {
            int input{};
            std::cin>>input;
            array.push_back(input);
        }

        int sum{ std::reduce(array.begin(),array.end())};
        if(sum == m)
        {
            std::cout<<"YES\n";
        }
        else
        {
            std::cout<<"No\n";
        }

    }
    return 0;
}


#include<iostream>
#include<vector>
#include<numeric>

int main()
{
    int testcase{};
    std::cin>>testcase;

    for(int i{0}; i < testcase; i++)
    {
        int size{},m{};
        std::cin>>size>>m;

        std::vector<int> array(size);

        for(int j{0}; j < size; j++)
        {
            int input{};
            std::cin>>input;
            array.push_back(input);
        }

        int sum{ std::reduce(array.begin(),array.end())};
        if(sum == m)
        {
            std::cout<<"YES\n";
        }
        else
        {
            std::cout<<"No\n";
        }

    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>

int main()
{
    int testcase{};
    std::cin>>testcase;

    for(int i{0}; i < testcase; i++)
    {
        int size{},m{};
        std::cin>>size>>m;

        std::vector<int> array(size);

        for(int j{0}; j < size; j++)
        {
            int input{};
            std::cin>>input;
            array.push_back(input);
        }

        int sum{ std::reduce(array.begin(),array.end())};
        if(sum == m)
        {
            std::cout<<"YES\n";
        }
        else
        {
            std::cout<<"No\n";
        }

    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define  N 106
typedef long long ll;
ll mass[N] = { 0 };

inline int scan() {
    int a = 0;
    char c = getchar();
    while ((c >= '0') && (c <= '9')) {
        a = (a << 3) + (a << 1) + c - '0';
        c = getchar();
    }
    return a;
}

int main() {
    int t = scan();
    int sum;
    for(int i = 0;i< t;i++){
        int n = scan();
        int m = scan();
        sum = 0;
        for (int j = 0; j < n; j++) {
            sum += scan();
        }
        if (sum == m) std::cout << "YES" << '\n';
        else std::cout << "NO" << '\n';
    }
    return 0;
}


#include <iostream>
using namespace std;

void solve()
{
    int n,m,sum=0,x;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {   cin>>x;
        sum=sum+x;
    }
    if(sum==m)
    cout<<"YES";
    else cout<<"NO";
    cout<<'\n';
}
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n,m,sum=0,x;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {   cin>>x;
        sum=sum+x;
    }
    if(sum==m)
    cout<<"YES";
    else cout<<"NO";
    cout<<'\n';
}
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	    solve();
	}
	return 0;
}


#include <iostream>

using namespace std;

int main() {
	int t, sum, m, n, a;
	cin >> t;
	while (t--) {
		sum = 0;
		cin >> n >> m;
		while(n--){
			cin >> a;
			sum += a;
		}
		if (sum == m)
			cout << "YES\n";
		else
			cout << "NO\n";
	}

}


#include<iostream>
using namespace std;
void sort(int *a,int n)
{
	int i,j,t;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(a[j]>a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
}

void print(int *a,int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		cout<<a[i];
	}
}

int main()
{
	int i,t,n,k,m,j;
	double s=0,h;
	cin>>t;
	int a[10001];
	int b[10001];
	for(i=0;i<t;i++)
	{
		s=0;
		cin>>n>>m;
		for(j=0;j<n;j++)
		{
			cin>>a[j];
		}
		sort(a,n);
		for(j=0;j<n;j++)
		{
			for(k=j;k<n;k++)
			{
				h=k+1;
				s+=a[k]/h;
			}
		}
		if(s==m)
		{
			b[i]=1;
		}
		if(s!=m)
		{
			b[i]=0;
		}
	}
	for(i=0;i<t;i++)
	{
		if(b[i]==1)
		{
			cout<<"YES"<<endl;
		}
		if(b[i]==0)
		{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
void sort(int *a,int n)
{
	int i,j,t;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(a[j]>a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
}

void print(int *a,int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		cout<<a[i];
	}
}

int main()
{
	int i,t,n,k,m,j;
	double s=0,h;
	cin>>t;
	int a[10001];
	int b[10001];
	for(i=0;i<t;i++)
	{
		s=0;
		cin>>n>>m;
		for(j=0;j<n;j++)
		{
			cin>>a[j];
		}
		sort(a,n);
		for(j=0;j<n;j++)
		{
			for(k=j;k<n;k++)
			{
				h=k+1;
				s+=((double)a[k])/h;
			}
		}
		if(s==m)
		{
			b[i]=1;
		}
		if(s!=m)
		{
			b[i]=0;
		}
	}
	for(i=0;i<t;i++)
	{
		if(b[i]==1)
		{
			cout<<"YES"<<endl;
		}
		if(b[i]==0)
		{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
typedef long long ll;

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        int a[101] = {0};
        int n, m;
        double suma = 0;

        cin >> n >> m;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];

        }
        sort(a+1, a + n+1);
        for (int j = 1; j <= n; j++) {
              //  cout<<"a[j]="<<a[j]<<" "<<"j="<<j<<" "<<double(a[j])/double(j)<<" ";
                suma += a[j];
            }
    //    cout<<endl;
      //  cout << "suma=" << suma << endl;
        if (suma == m) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}


#include<iostream>
using namespace std;
void sort(int *a,int n)
{
	int i,j,t;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(a[j]>a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
}

void print(int *a,int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		cout<<a[i];
	}
}

int main()
{
	int i,t,n,k,m,j;
	double s=0,h;
	cin>>t;
	int a[10001];
	int b[10001];
	for(i=0;i<t;i++)
	{
		cin>>n>>m;
		for(j=0;j<n;j++)
		{
			cin>>a[j];
		}
		sort(a,n);
		for(j=0;j<n;j++)
		{
			for(k=j;k<n;k++)
			{
				h=k+1;
				s+=a[k]/h;
			}
		}
		if(s==m)
		{
			b[i]=1;
		}
		if(s!=m)
		{
			b[i]=0;
		}
	}
	for(i=0;i<t;i++)
	{
		if(b[i]==1)
		{
			cout<<"YES"<<endl;
		}
		if(b[i]==0)
		{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
void sort(int *a,int n)
{
	int i,j,t;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<i;j++)
		{
			if(a[j]>a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
}

void print(int *a,int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		cout<<a[i];
	}
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int i,t,n,k,m,j;
	double s=0,h;
	cin>>t;
	for(i=0;i<t;i++)
	{
		int a[101]={0};
		s=0;
		cin>>n>>m;
		for(j=0;j<n;j++)
		{
			cin>>a[j];
		}
		sort(a,n);
		for(j=0;j<n;j++)
		{
			for(k=j;k<n;k++)
			{
				h=k+1;
				s+=((double)a[k])/h;
			}
		}
		if(s==m)
		{
			cout<<"YES"<<endl;
		}
		if(s!=m)
		{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}