stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define all(v) ((v).begin()),((v).end())

#define ll long long

#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

double const EPS = 1e-12, PI = acos(-1);

const int N = 3e3 + 9, M = 5e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;

const ll inf = 1e18;



vector<int> vec[N];

int played[N];

int kam[N];



int main() {

  fastIO;

#ifdef LOCAL

  freopen("input.in", "rt", stdin);

#endif

  int n, a;

  cin >> n;

  queue<int> Q;

  for (int i = 1; i <= n; ++i) {

    for (int j = 1; j < n; ++j) {

      cin >> a;

      vec[i].push_back(a);

    }

//    reverse(vec[i].begin(), vec[i].end());

    Q.push(i);

  }

  int day = 1;

  int matches = (ll)(n) * (ll)(n - 1) / 2;

  while(!Q.empty()) {

    queue<int> Q2;

    int sz = Q.size();

    while(sz--) {

      int me = Q.front();

      Q.pop();

      if(kam[me] == n - 1)

        continue;

      int to = vec[me][kam[me]];

      if(kam[to] == n - 1 || to == me)

        continue;

      int toTo = vec[to][kam[to]];

      if(toTo != me) continue;

      if(played[me] < day && played[to] < day) {

        played[me] = day;

        played[to] = day;

        kam[me]++;

        kam[to]++;

        if(kam[me] != n - 1)

          Q2.push(me);

        if(kam[to] != n - 1)

          Q2.push(to);

        --matches;

      }

    }

    swap(Q, Q2);

    if(!matches)

      break;

    ++day;

  }

  if(matches)

    cout << -1;

  else

    cout << day;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.0979332780443125x):
#include <iostream>

#define ll long long

using namespace std;

ll a,c[1000][1000],p[10000],la[1000],day,id;

int main() {

    cin>>a;

    for(int i=0;i<a;i++){

        for(int j=0;j<a-1;j++){

            cin>>c[i][j];

            c[i][j]--;

        }

    }

    bool tor = 1;

    while(tor){

        day++;

        tor = 0;

        for(int i=0;i<a;i++){

            if(p[i] < a-1){

                id = c[i][p[i]] ;

                if(la[i] < day && la[id]<day && p[id]<a-1 && c[id][p[id]] == i){

                    la[id] = day;

                    la[i] = day;

                    p[i] ++;

                    p[id]++;

                    tor = 1;

                }

            }

        }

        

    }

    for(int i=0;i<a;i++){

        if(p[i] != a-1){

            cout<<-1;

            return 0;

        }

    }

    cout<<day-1;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.560185721534371x):
#include <iostream>



using namespace std;

long long n,j=0;

const long long MAXN=1e5 +10;

long long o=0;

long long x[MAXN],d[MAXN];

int main() {

	cin>>n;

	for(long long i=0;i<n;i++)

	{

		cin>>x[i];

		if(x[i]==(i+1))

		{

			d[o]=i;

			o++;

		}

	}

	for(long long i=0;i<o;i++)

	{

		if(x[d[i]]==d[i]+1)

		{

			if(i<n-1)

			swap(x[d[i]],x[d[i]+1]);

			else swap(x[d[i]],x[d[i]-1]);

			j++;

		}

	}

	cout<<j;

	return 0;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.5148550888868533x):
#include <iostream>

#include <algorithm>

#include <math.h>

#include <vector>

#include <iomanip>

#include <map>

#include <queue>

#include <set>

using namespace std;

typedef long long int ll;

#define pb push_back

#define F first

#define S second

#define mkp make_pair

#define pow2(i) (1 << (i))

#define modi(a,b) ((a%b+b)%b)

#define uni(a,b) (((a+b)*(a+b+1)/2)+b)

const int MAXN=1e9+7;

ll int_pow(ll base, ll exp){

	ll result=1;

	while (exp){

		if (exp & 1)

		   result *= base;

		exp/=2;

		base*=base;

	}

	return result;

}

ll a[1000000];

int main() {

	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	ll n,j=1,ans=0;cin >> n;

	for (ll i=0;i<n;i++){

		cin >> a[i];

		a[i]--;

	}

	for (ll i=0;i<n-1;i++){

		if (a[i] != i)continue;

		swap(a[i], a[i+1]);

		ans++;

		i++;

	}

	if (a[n-1] == n-1)ans++;

	cout << ans;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.5523884242581274x):
# include <bits/stdc++.h>



# define pb push_back

# define fr first

# define sc second

# define mk make_pair



using namespace std;



const int inf = 1e9 + 7;

const int N = 1e6 + 5;



typedef long long ll;



int n, a[N], ans;



int main()

{

      cin >> n;



      for(int i = 1; i <= n; i ++)

      {

            cin >> a[i];

            if(a[i] == i) ans ++;

      }



      for(int i = 1; i <= n; i ++)

      {

            if(a[i] == i && a[i + 1] == (i + 1))

            {

                  ans --;

                  i ++;

            }

      }



      cout << ans << endl;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.5431356539002627x):
#include <iostream>

#include <vector>

#include <deque>

#include <math.h>

#include <set>

#include <iomanip>

#include <time.h>

#include <list>

#include <stdio.h>

#include <queue>

#include <map>

#include <algorithm>

#include <assert.h>

#include <memory.h>



#define mk make_pair

#define sc second

#define fr first

#define pb emplace_back

#define all(s) s.begin(), s.end()

#define sz(s) ( (int)s.size() )



using namespace std;



const int N = 1e5 + 5;



int n, ar[N], ans;



main ()

{

    cin >> n;

    for (int i = 1; i <= n; i++)

        scanf("%d", &ar[i]);



    for (int i = 1; i < n; i++)

        if (ar[i] == i)

            swap( ar[i], ar[i + 1] ), ans++;



    for (int i = 2; i <= n; i++)

        if (ar[i] == i)

            swap( ar[i], ar[i - 1] ), ans++;



    cout << ans << endl;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.5531549200085055x):
#include <bits/stdc++.h>



using namespace std;

const long nmax=100005;

int n,a[nmax],t,k,s;

int main()

{

    cin>>n; s=0; t=0; k=0;

    for(int i=1;i<=n;i++){

        cin>>a[i];

        if(a[i]==i){

            t++;

            k++;

        }

        else t=0;

        if(t==2){

            k=k-1;

            t=0;

        }

    }

    cout<<k<<endl;

    return 0;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.5064729926096745x):
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main ()

{

	ll n,count=0,arr[100000];

	cin>>n;

	for(ll i=1;i<=n;i++)

		cin >> arr[i];

	for (ll i=1;i<=n;i++)

	{

		if (arr[i]==i)

		{

			count++;

			if (i==n)

				swap(arr[i],arr[i-1]);

			else

				swap(arr[i],arr[i+1]);

		}

	}

	cout<<count;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.4851750719480257x):
#include<bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

using namespace std;

#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long int

#define llu long long unsigned int

#define pf printf

#define sf scanf

#define f first

#define s second

#define pb push_back

#define mk make_pair

#define pii pair<int ,int>

#define PII pair<ll ,ll>

 

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};

int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int dx4[] = {0, 0, 1, -1};

int dy4[] = {1, -1, 0, 0};

 

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int Set(int N,int pos){return N=N | (1<<pos);}

int reset(int N,int pos){return N= N & ~(1<<pos);}

bool check(int N,int pos){return (bool)(N & (1<<pos));}

double eps =000000000.1;

const int Max=1e9+100;

const ll  MAX=1e18+500;

const int sz=1e3+100;

map<ll,int> mp;

int main()

{

    Khela

    ll  a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx,A,B;

    char ch;

    double d;

    string str1,str2,str;

    bool bl,bl1;

    int t,cs=1;

    while(cin>>n)

    {

        int sum[n+2];

        for(i=1;i<=n;i++){

            cin>>x;

            if(x==i) sum[i]=1;

            else sum[i]=0;

        }

        

        int tot=0;

        int last=0;

        for(i=1;i<=n;i++){

            if(sum[i]==1) ++last;

            else{

                if(last>0){

                    tot+=(int)(ceil((double)(last)/2.00));

                }

                last=0;

            }

        }

                    if(last>0){

                    tot+=(int)(ceil((double)(last)/2.00));

                    }

                   last=0;

                   cout<<tot<<endl;

    }









}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.507727012374323x):
//pragma

//#pragma GCC optimize("Ofast")

//#pragma GCC optimize("unroll-loops")



#include <bits/stdc++.h>



#define YOU using

#define DONT namespace

#define SAY std



YOU DONT SAY;



typedef long long ll;

typedef unsigned long long ull;

typedef pair<int,int> pii;

typedef pair<ll,ll> pll;

typedef pair<ll,int> pli;

typedef pair<int,ll> pil;

typedef vector<int> vi;

typedef vector<pii> vii;

typedef vector<pll> vll;



#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)

#define REP(i,a,b) REPP(i,a,b,1)

#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)

#define REV(i,a,b) REVV(i,a,b,1)



#define FOR(i,a) for(int i=0; i<a; i++)

#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)



#define pb push_back

#define F first

#define S second



const int OO = 1e9;

const ll INF = 1e18;



const int irand(int lo,int hi){

	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;

}



const ll lrand(ll lo,ll hi){

	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;

}



#define getc getchar

template<typename T>

T getnum(){

	int sign = 1;

	T ret = 0;

	char c;



	do{

		c = getc();

	}while(c == ' ' || c == '\n');

	if(c == '-')sign = -1;

	else ret = c-'0';

	while(1){

		c = getc();

		if(c < '0' || c > '9')break;

		ret = 10*ret + c-'0';

	}

	return sign * ret;

}



inline void ini(int& x){

	x = getnum<int>();

}



inline void scani(int& x){

	scanf("%d",&x);

}



//end of macro



const int N = 1e5 + 5;



int n;

int arr[N];

    

int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    #define endl '\n'

    cout.setf(ios::fixed);

    cout.setf(ios::showpoint);

    cout.precision(10);

    

    cin>>n;

    REP(i,1,n)cin>>arr[i];

    

    int ans = 0;

    int i=1, j=n;

    while(1){

    	while(i <= n && arr[i] != i)i++;

    	while(j >= 1 && arr[j] != j)j--;

    	

    	if(i > j)break;

    	swap(arr[i], arr[i+1]);

    	i += 2;

    	ans++;

	}

	

	cout << ans << endl;

    

    return 0;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.5520030559348097x):
#include <iostream>

#include <string>

#include <string.h>

#include <algorithm>

#include <math.h>

#include <vector>

#include <stdio.h>

using namespace std;

vector<int>a;

int num[110000];

void change(int a,int b)

{

    int temp;

    temp=num[a];

    num[a]=num[b];

    num[b]=temp;

}

int main()

{

    int n,sum=0;

    cin>>n;

    for(int i=1; i<=n; i++)

        cin>>num[i];

    for(int i=1; i<=n; i++)

    {

        if(num[i]==i&&num[i+1]==i+1)

        {

            change(i,i+1);

            sum++;

        }

    }

    for(int i=1; i<=n; i++)

    {

        if(num[i]==i&&i<n)

        {

            change(i,i+1);

            sum++;

        }

        if(num[i]==i&&i==n)

        {

            change(i-1,i);

            sum++;

        }

    }

    cout<<sum<<endl;

    return 0;

}
// Slower C++ solution:
// be name khoda

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define pb push_back

const ll maxn=100009;

vector <ll> adj[maxn];

ll p[maxn];

int main()

{

	ios_base::sync_with_stdio(false);

	ll n;	cin >> n; 

	ll cnt=0;

	for (ll i=0;i<n;i++)	{cin >> p[i];p[i]--;}

	for(ll i=0;i<n-1;i++)

	{

		if (p[i]==i)

		{	

			swap(p[i],p[i+1]);

			cnt++;

		}

	}

	if (p[n-1]==n-1) cnt++;

	cout<<cnt;

}


// Faster C++ solution for the same problem (measured speedup: 3.5444831708834528x):
#include<stdio.h>

#include<iostream>

#include<string>

#include<stack>

#include<stdlib.h>

#include<algorithm>

using namespace std;

int main()

{

    int N,i,t,a[100005],num=0;

    scanf("%d",&N);

    for(i=0;i<N;i++)

        scanf("%d",&a[i]);

    for(i=0;i<N-1;i++)

    {

        if(a[i]==i+1)

        {

            t=a[i];

            a[i]=a[i+1];

            a[i+1]=t;

            num++;

        }

    }

    if(a[N-1]==N)

    {

        t=a[N-1];

        a[N-1]=a[N-2];

        a[N-2]=t;

        num++;

    }

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

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

using namespace std;

int n, s, a[100005];

int main() {

	int i;

	scanf("%d", &n);

	for(i=1; i<=n; i++) scanf("%d", &a[i]);

	for(i=1; i<n; i++) if(a[i]==i) swap(a[i], a[i+1]), s++;

	if(a[n]==n) s++;

	cout<<s;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.243153894898333x):
#include <cstdio>

int n, s, a;

int main() {

	scanf("%d", &n);

	for(int i=1; i<=n; i++) {

		scanf("%d", &a);

		if(a==i) {

			s++;

			scanf("%*d"), i++;

		}

	}

	printf("%d", s);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define inf 1LL<<62



ll n, a[100010];



int main() {

	cin>>n;

	for(int i=1;i<=n;i++){

		cin>>a[i];

	}

	ll ans=0;

	for(int i=1;i<100002;i++){

		if(a[i]==i){

			swap(a[i],a[i+1]);

			ans++;

		}

	}

	cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 1.4526962972215192x):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1LL<<62

#define inf 1000000007



ll a[100010];

int main() {

	ll n;

	cin>>n;

	for(int i=0;i<n;i++){

		ll x;

		cin>>x;

		x--;

		a[i]=x;

	}

	ll ans=0;

	for(int i=0;i<n-1;i++){

		if(a[i]==i){

			swap(a[i],a[i+1]);

				ans++;

		}

	}

	if(a[n-1]==n-1){

		ans++;

	}

	cout << ans;

    // your code goes here

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <map>

#include <cmath>

#include <queue>

#include <numeric>

#include <climits>

#include <iterator>

#include <iomanip>

#include <stack>

#include <set>

#include <bitset>

#include <functional>

using namespace std;

const constexpr int INF = 1e9;

//typedef std::pair<std::string,double> P;





#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)

#define REP(i, n) FOR(i, 0, n)



typedef long long ll;

typedef vector<int> VI;

const constexpr ll MOD = 1e9+7;

vector<pair<int, int> > vp;

 

struct Less {

    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {

        return x.first > y.first;

    }

};



ll GCD(ll a, ll b){

    if(b==0) return a;

    return GCD(b, a%b);

}





//グラフの隣接リスト

VI g[200010];

//頂点の入次数を管理

int h[100010];

int s[100010];

int main(void) {

    int N; cin >> N;

    REP(i, N) {

        int a; cin >>a; a--;

        s[i] = a;

    }

    s[N]=0;

    int cnt=0;

    for(int i=0; i<N; ++i){

        if(s[i]==i){

            swap(s[i], s[i+1]);

            cnt++;

        }

    }

    cout << cnt << endl;

    

}

// Faster C++ solution for the same problem (measured speedup: 6.467188461005794x):
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <cmath>

#include <algorithm>

#include <iomanip>

#include <queue>

using ll = long long;

using namespace std;

int a[100010];

int main(void)

{

    int N;

    cin >> N;

    for (int i = 0; i < N; ++i)

    {

        cin >> a[i];

        a[i]--;

    }



    int ans = 0;



    for (int i = 0; i < N; ++i)

    {

        if (i == a[i])

        {

            ans++;

            i++;

        }

    }

    cout << ans << endl;

    return 0;

}
// Slower C++ solution:
#include<iostream>



using namespace std;



int main() {

	int n, a, b[100001]{ 0 };

	cin >> n;

	for (int i = 0; i<n; i++) {

		cin >> a;

		if (a == i + 1)b[i] = 1;

	}

	int cnt = 0;

	for (int i = 0; i < n;) {

		if (b[i]) {

			cnt++;

			i += 2;

		}

		else i++;

	}

	cout << cnt << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.3856584639172889x):
#include <iostream>

#include <stdio.h>

#include <algorithm>

#include <string>

#include <cmath>

#include <vector>

#include <functional>

#include <stack>

#include <utility>

#include <map>

#include <queue>

#include <set>

#include <array>

#include <climits>



using namespace std;



int main() {

	int n,a[100005],ans = 0;

	cin >> n;

	for (int i = 0; i < n; i++)cin >> a[i];

	for (int i = 0; i < n - 1; i++) {

		if (a[i] == i + 1) {

			int tmp = a[i];

			a[i] = a[i + 1];

			a[i + 1] = tmp;

			ans++;

		}

	}

    if (a[n - 1] == n)ans++;

	cout << ans << endl;

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define MAX 100005

using namespace std;

 

int main(){

  int n, a, ans = 0, cnt = 1;

  scanf("%d", &n);

  for(int i = 1; i <= n; i++){

    scanf("%d", &a);

    if(a != i){

      ans += cnt/2;

      cnt = 1;

    }else cnt++;

  }

  ans += cnt/2;

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

}


// Faster C++ solution for the same problem (measured speedup: 5.170402505385762x):
#include<cstdio>

int main(){

  int n, a, ans = 0;

  bool t = false;

  scanf("%d", &n);

  for(int i = 1; i <= n; i++){

    scanf("%d", &a);

   if(t = a == i && !t) ans++;

  }

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

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

long n,a[100005],res;

int main()

{

    cin >> n;

    for (long i = 1 ; i <= n ; i++)

        cin >> a[i];

    res = 0;

    if (a[1]==1) {

        res++;

        swap(a[1],a[2]);

    }

    for (long i = 2 ; i <= n ; i++)

        if (a[i]==i) {

            swap(a[i],a[i+1]);

            res++;

        }

    cout << res;

}


// Faster C++ solution for the same problem (measured speedup: 5.218814685472734x):
#include<stdio.h>

int a[100005];

int main()

{

    int n;

    int flag=0;

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

        scanf("%d",&a[i]);

    for(int i=1;i<=n;i++)

    {

        if(a[i]==i)

        {

           int t=a[i+1];

           a[i+1]=a[i];

           a[i]=t;

           flag++;

        }

    }

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

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long n,a[1000005],dem;

bool d[1000005];

int main(){

cin>>n;

for(int i=1;i<=n;i++){

    cin>>a[i];

    if(a[i]==i) d[i]=true;

}

int i=1;

while(i<=n){

    if(d[i]==true&&d[i+1]==true) {swap(a[i],a[i+1]);i=i+2;dem++;}

    else if(d[i]==true) {swap(a[i],a[i+1]);i=i+1;dem++;}

    else i++;



}

cout<<dem;}


// Faster C++ solution for the same problem (measured speedup: 5.219814860936253x):
#include<stdio.h>

int a[100005];

int main()

{

    int n;

    int flag=0;

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

        scanf("%d",&a[i]);

    for(int i=1;i<=n;i++)

    {

        if(a[i]==i)

        {

           int t=a[i+1];

           a[i+1]=a[i];

           a[i]=t;

           flag++;

        }

    }

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

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main()

{

    long long n;

    cin >> n;

    vector<long long> a(n);

    for (auto &x : a)

    {

        cin >> x;

    }

    long long ans = 0;

    for (long long i = 0; i < n; i++)

    {

        if (a[i] == i + 1)

        {

            if (i == n - 1)

            {

                swap(a[i], a[i - 1]);

                ans++;

                break;

            }

            swap(a[i], a[i + 1]);

            ans++;

            if (a[i + 1] == i + 2)

            {

                i++;

            }

        }

    }

    cout << ans << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.233668128899777x):
#include<stdio.h>

int a[100005];

int main()

{

    int n;

    int flag=0;

    scanf("%d",&n);

    for(int i=1;i<=n;i++)

        scanf("%d",&a[i]);

    for(int i=1;i<=n;i++)

    {

        if(a[i]==i)

        {

           int t=a[i+1];

           a[i+1]=a[i];

           a[i]=t;

           flag++;

        }

    }

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

    return 0;

}