stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;



int main()

{

    int n, i;



    cin>>n;



    vector<int>P(n);



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

    {

        cin>>P.at(i);

    }

    int j, k=0;



    for(j=0; j<n; j++)

    {

        if(P.at(j)!=j+1)

            k++;

    }

    if (k<=2)

        cout<<"YES"<<endl;



    else

        cout<<"NO"<<endl;



        return 0;

}

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



int main()

{

    int i,j,a[60],b[60],n,flag;



    scanf("%d",&n);



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

    {

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

    }



    for(i=0,j=1;i<n;i++,j++)

    {

        b[i] = j;

    }



    for(i=0,flag=0;i<n;i++)

    {

        if(a[i]!=b[i])

            flag++;

    }



    if(flag<=2)

        printf("YES");

    else

        printf("NO");



    return 0;

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

using namespace std;

 

int main(){

  int N;

  cin>>N;

  vector<int> P(N);

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

    cin>>P.at(i);

  }

  int k=0;

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

    if(P.at(j)!=j+1) k++;

  }

  if (k<=2) cout<<"YES"<<endl;

  else cout<<"NO"<<endl;

 

}

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



int main()

{

    int i,j,a[60],b[60],n,flag;



    scanf("%d",&n);



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

    {

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

    }



    for(i=0,j=1;i<n;i++,j++)

    {

        b[i] = j;

    }



    for(i=0,flag=0;i<n;i++)

    {

        if(a[i]!=b[i])

            flag++;

    }



    if(flag<=2)

        printf("YES");

    else

        printf("NO");



    return 0;

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

#include <bits/stdc++.h>

using namespace std;





int main() {

    int n;

    cin>>n;

    vector<int> p(n);

    int count=0;

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

    {

        cin>>p[i];

        if(p[i]!=i+1) 

        count++;

    }

    if(count==2 || count==0)

     cout<<"YES"<<endl;

    else

     cout<<"NO"<<endl;

}


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



int main()

{

    int i,j,a[60],b[60],n,flag;



    scanf("%d",&n);



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

    {

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

    }



    for(i=0,j=1;i<n;i++,j++)

    {

        b[i] = j;

    }



    for(i=0,flag=0;i<n;i++)

    {

        if(a[i]!=b[i])

            flag++;

    }



    if(flag<=2)

        printf("YES");

    else

        printf("NO");



    return 0;

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

#include <stdio.h>

#include <string.h>

#include <string>

#include <vector>

#include <deque>

#include <list>

#include <queue>

#include <math.h>

#include <assert.h>

#include <set>

#include <map>

#include <bitset>

#include <ctime>

#include <time.h>

#include <algorithm>

#include <cstdio>

#include <fstream>

#include <stack>

#include <ctype.h>

#include <numeric>

#include <sstream>

#include <unistd.h>

#include <unordered_map>

#include <limits>

#include <random>

#include <chrono>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main(int argv, char **argc){

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



    int n, a[50], b[50], cnt = 0;

    cin >> n;

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

        cin >> a[i];

        b[i] = a[i];

    }

    sort(a, a + n);

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

        cnt += (a[i] != b[i]);

    }

    printf("%s\n", cnt <= 2 ? "YES" : "NO");

}

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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

 

  using namespace std; 







int main()

{

     int n,i=0,c=0,num;

     scanf("%d",&n);

     vector<pair<int, int> >v,s;

     while(n>0)

     {

         scanf("%d",&num);

         v.push_back(make_pair(num,i));

         i++;

          n--;

     }

     s=v;

     sort(s.begin(),s.end());

     for(i=0;i<v.size();i++)

     {

         if(v[i].first!=s[i].first)

         {

             c++;

         }

     }

     if(c==2 || c==0)

     {

         printf("YES");

     }

     else

     {

         printf("NO");

     }

     

     

}

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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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



using namespace std;



void swapp(int a[],int i,int j);

bool sorted(int a[],int s);



int main()

{

    int n;

    bool x = false;

    cin>>n;

    int arr[n];

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

    {

        cin>>arr[i];

    }

    if(sorted(arr,n))

    {

        cout<<"YES";

    }

    else

    {

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

        {

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

            {

                if(arr[j]<arr[i])

                {

                    swapp(arr,i,j);

                    if(sorted(arr,n))

                    {

                        x = true;

                        break;

                    }

                    swapp(arr,j,i);

                }

            }

        }

        if(x)

        {

            cout<<"YES";

        }

        else

        {

            cout<<"NO";

        }

    }

}



void swapp(int a[],int i,int j)

{

    int temp = a[j];

    a[j] = a[i];

    a[i] = temp;

}



bool sorted(int a[],int s)

{

    bool x = true;

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

    {

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

        {

            x = false;

            break;

        }

    }

    return x;

}


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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

#include <algorithm>

using namespace std;

int main()

{

    int n,i;

    cin >> n;

    int a[n];

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

        cin >> a[i];

    }

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

        int flag=0;

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

            continue;

        }

        else{

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

                if(i==a[j]){

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

                    flag=1;

                    break;

                }

            }

        }

        if(flag==1){

            break;

        }

    }

    int count=0,flag=0;

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

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

            flag=1;

            break;

        }

    }

    if(flag==0){

        cout<<"YES"<<'\n';

    }

    else{

        cout << "NO"<<'\n';

    }

    return 0;

}








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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

 

using namespace std;

 

int main()

{

    int t,flag=0;

    cin>>t;

    int num[t];

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

    {

        cin>>num[i];

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

        {

            flag +=1;

        }

    }

    if(flag>2)

        cout<<"NO"<<endl;

    else

        cout<<"YES"<<endl;

}

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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

}
// Slower C++ solution:
//#pragma GCC optimize("Ofast")

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

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

 

//Tariquzzaman Faisal

//_Faisal101_

//IUT_CSE'19

//190041101

 

#include<iostream>

#include<stdio.h>

#include<vector>

#include<deque>

#include<map>

#include<stack>

#include<queue>

#include<algorithm>

#include<cstring>

#include<climits>

#include<cmath>

#include<iterator>

#include<set>

#define fileOut freopen("out.txt","w",stdout)

#define fileIn freopen("in.txt","r",stdout)

#define testcases ll TC,T; cin >> TC; for(T=1; T<=TC; T++)

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)

#define INFLL 9223372036854775807

#define INF 2147483647

#define pi acos(-1.0)

#define ll long long

#define endll printf("\n")

#define CASE printf("Case %lld: ",T)

#define ff first

#define ss second

#define mem(ara,n) memset(ara,n,sizeof ara)

#define ull unsigned long long

#define max3(a,b,c) max(a,max(b,c))

#define min3(a,b,c) min(a,min(b,c))

#define mid3(a,b,c) min(max(a,b),max(b,c),max(a,b))

#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define min4(a,b,c,d) min(min(a,b),min(c,d))

#define endl '\n'

#define ld long double

 

 

using namespace std;





int main(){

    ll n, x;

    cin >> n;

    ll counter = 0;

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

    {

        cin >> x;

        if(x != i+1){

            counter++;

        }

    }

    if(counter <= 2){

        cout<<"YES"<<endl;

    }

    else{

        cout <<"NO" <<endl;

    }

    return 0;

}

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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

#include <cstring>

#include <bits/stdc++.h>

using namespace std;



int main()

{

  int i, n, cnt = 0;

  cin >> n;

  int s[n+5];



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

  	 cin >> s[i];



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

    {

      if(s[i] != i) cnt ++;

    }



    if(cnt <= 2) cout << "YES";

    else cout << "NO";

   

}

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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

using namespace std;



int main()

{

	vector<int> data,test;

	int i,j,n,count=0;

	cin >> n;

	

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

	{

		cin >> j;

		data.push_back(j);

		test.push_back(j);

	}

	

	sort(data.begin(),data.end());

	

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

	{

		if(data[i]!=test[i]) count++;

	}

	

	if(count == 2 || data == test) cout << "YES";

	else cout << "NO";

}

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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

using namespace std;



int main()

{

    int n,c=0;

    cin>>n;

    int p[n];

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

        cin>>p[i];

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

    {

        if(p[i]!=i+1)

            c++;

    }

    if(c==0||c==2)

        cout<<"YES";

    else

        cout<<"NO";

    return 0;

}



//YES You can sort p in ascending order by swapping p 1 and p5


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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

using namespace std;



int main(){

    int n, c=0;

    cin >> n;

    int arr1[n],arr2[n];

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

        cin >> arr1[i];

        arr2[i]=arr1[i];

    }

    sort(arr1, arr1+n);

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

        if(arr1[i]!=arr2[i])

            c++;

    }

    if(c==0 || c==2)

        cout << "YES" << endl;

    else

        cout << "NO" << endl;



    return 0;

}


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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

#include<cstring>

#include<algorithm>

#include<math.h>

using namespace std;

int main()

{

    long long int i,n,j=0,k,t,c,d,b,a[60];

    cin>>n;

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

{

    cin>>a[i];

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

    j++;

}

if(j==2 ||j==0)

cout<<"YES"<<endl;

else

cout<<"NO"<<endl;

}


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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

#define ll long long

using namespace std;

int main()

{

	int n,ok=0;

	cin>>n;

	int a[n],b[n];

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

	{

		cin>>a[i];

	}

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

	{

		b[i]=a[i];

	}

	sort(b,b+n);

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

	{

		if(a[i]!=b[i])

		{

			ok++;

		}

	}

	if(ok>2)

	{

		cout<<"NO"<<endl;

	}

	else

	{

		cout<<"YES"<<endl;

	}

	return 0;

}

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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

using namespace std;

int main()

{

    int n,p,c=0,i=0;

    vector<int>v;

    vector<int>v1;

    cin>>n;

    int t=n,x;

    while(t--)

    {

        cin>>x;

        v.push_back(x);

        v1.push_back(x);



    }

    sort(v1.begin(),v1.end());

    while(i<v.size())

    {

        if(v1[i]==v[i])

            c++;

        i++;

    }

    //cout<<c<<endl;

    if(c>=n-2)

        cout<<"YES"<<endl;

    else

        cout<<"NO"<<endl;

    return 0;

}




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

int main()

{

    int a,z=1,i,sum=0;

    scanf("%d",&a);

    int c[a];

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

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

    }

    for(i=0;i<a;i++,z++)

    {

       if(c[i]!=z) sum++;

    }

    if(sum<=2)printf("YES\n");

    else printf("NO\n");

    return 0;

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

#include <stdio.h>

#include <string.h>

#include <string>

#include <vector>

#include <deque>

#include <list>

#include <queue>

#include <math.h>

#include <assert.h>

#include <set>

#include <map>

#include <bitset>

#include <ctime>

#include <time.h>

#include <algorithm>

#include <cstdio>

#include <fstream>

#include <stack>

#include <ctype.h>

#include <numeric>

#include <sstream>

#include <unistd.h>

#include <unordered_map>

#include <limits>

#include <random>

#include <chrono>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main(int argv, char **argc){

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



    int n, a[50], b[50], cnt = 0;

    cin >> n;

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

        cin >> a[i];

        b[i] = a[i];

    }

    sort(a, a + n);

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

        cnt += (a[i] != b[i]);

    }

    printf("%s\n", cnt <= 2 ? "YES" : "NO");

}

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

#define size_t 100010

int main() {

 int n,a[size_t],i,count=0;

  scanf("%d",&n);

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

  {

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

  }  

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

  {

   if(a[i]!=i)

   { count++; }

  } 

  if(count<=2)

  {printf("YES\n");}

  else { printf("NO\n"); }

    return 0;

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

 

  using namespace std; 







int main()

{

     int n,i=0,c=0,num;

     scanf("%d",&n);

     vector<pair<int, int> >v,s;

     while(n>0)

     {

         scanf("%d",&num);

         v.push_back(make_pair(num,i));

         i++;

          n--;

     }

     s=v;

     sort(s.begin(),s.end());

     for(i=0;i<v.size();i++)

     {

         if(v[i].first!=s[i].first)

         {

             c++;

         }

     }

     if(c==2 || c==0)

     {

         printf("YES");

     }

     else

     {

         printf("NO");

     }

     

     

}

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

#define size_t 100010

int main() {

 int n,a[size_t],i,count=0;

  scanf("%d",&n);

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

  {

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

  }  

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

  {

   if(a[i]!=i)

   { count++; }

  } 

  if(count<=2)

  {printf("YES\n");}

  else { printf("NO\n"); }

    return 0;

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



using namespace std;



void swapp(int a[],int i,int j);

bool sorted(int a[],int s);



int main()

{

    int n;

    bool x = false;

    cin>>n;

    int arr[n];

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

    {

        cin>>arr[i];

    }

    if(sorted(arr,n))

    {

        cout<<"YES";

    }

    else

    {

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

        {

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

            {

                if(arr[j]<arr[i])

                {

                    swapp(arr,i,j);

                    if(sorted(arr,n))

                    {

                        x = true;

                        break;

                    }

                    swapp(arr,j,i);

                }

            }

        }

        if(x)

        {

            cout<<"YES";

        }

        else

        {

            cout<<"NO";

        }

    }

}



void swapp(int a[],int i,int j)

{

    int temp = a[j];

    a[j] = a[i];

    a[i] = temp;

}



bool sorted(int a[],int s)

{

    bool x = true;

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

    {

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

        {

            x = false;

            break;

        }

    }

    return x;

}


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

#define size_t 100010

int main() {

 int n,a[size_t],i,count=0;

  scanf("%d",&n);

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

  {

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

  }  

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

  {

   if(a[i]!=i)

   { count++; }

  } 

  if(count<=2)

  {printf("YES\n");}

  else { printf("NO\n"); }

    return 0;

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

#include <algorithm>

using namespace std;

int main()

{

    int n,i;

    cin >> n;

    int a[n];

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

        cin >> a[i];

    }

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

        int flag=0;

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

            continue;

        }

        else{

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

                if(i==a[j]){

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

                    flag=1;

                    break;

                }

            }

        }

        if(flag==1){

            break;

        }

    }

    int count=0,flag=0;

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

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

            flag=1;

            break;

        }

    }

    if(flag==0){

        cout<<"YES"<<'\n';

    }

    else{

        cout << "NO"<<'\n';

    }

    return 0;

}








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

#define size_t 100010

int main() {

 int n,a[size_t],i,count=0;

  scanf("%d",&n);

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

  {

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

  }  

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

  {

   if(a[i]!=i)

   { count++; }

  } 

  if(count<=2)

  {printf("YES\n");}

  else { printf("NO\n"); }

    return 0;

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

 

using namespace std;

 

int main()

{

    int t,flag=0;

    cin>>t;

    int num[t];

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

    {

        cin>>num[i];

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

        {

            flag +=1;

        }

    }

    if(flag>2)

        cout<<"NO"<<endl;

    else

        cout<<"YES"<<endl;

}

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

#define size_t 100010

int main() {

 int n,a[size_t],i,count=0;

  scanf("%d",&n);

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

  {

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

  }  

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

  {

   if(a[i]!=i)

   { count++; }

  } 

  if(count<=2)

  {printf("YES\n");}

  else { printf("NO\n"); }

    return 0;

    }
// Slower C++ solution:
//#pragma GCC optimize("Ofast")

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

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

 

//Tariquzzaman Faisal

//_Faisal101_

//IUT_CSE'19

//190041101

 

#include<iostream>

#include<stdio.h>

#include<vector>

#include<deque>

#include<map>

#include<stack>

#include<queue>

#include<algorithm>

#include<cstring>

#include<climits>

#include<cmath>

#include<iterator>

#include<set>

#define fileOut freopen("out.txt","w",stdout)

#define fileIn freopen("in.txt","r",stdout)

#define testcases ll TC,T; cin >> TC; for(T=1; T<=TC; T++)

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)

#define INFLL 9223372036854775807

#define INF 2147483647

#define pi acos(-1.0)

#define ll long long

#define endll printf("\n")

#define CASE printf("Case %lld: ",T)

#define ff first

#define ss second

#define mem(ara,n) memset(ara,n,sizeof ara)

#define ull unsigned long long

#define max3(a,b,c) max(a,max(b,c))

#define min3(a,b,c) min(a,min(b,c))

#define mid3(a,b,c) min(max(a,b),max(b,c),max(a,b))

#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define min4(a,b,c,d) min(min(a,b),min(c,d))

#define endl '\n'

#define ld long double

 

 

using namespace std;





int main(){

    ll n, x;

    cin >> n;

    ll counter = 0;

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

    {

        cin >> x;

        if(x != i+1){

            counter++;

        }

    }

    if(counter <= 2){

        cout<<"YES"<<endl;

    }

    else{

        cout <<"NO" <<endl;

    }

    return 0;

}

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

#define size_t 100010

int main() {

 int n,a[size_t],i,count=0;

  scanf("%d",&n);

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

  {

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

  }  

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

  {

   if(a[i]!=i)

   { count++; }

  } 

  if(count<=2)

  {printf("YES\n");}

  else { printf("NO\n"); }

    return 0;

    }