stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}








// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
//#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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";

   

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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";

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

#define omar main

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

//push_back make_pair emplace vector double float _unordered_map unodered_set queue stack sort begin end clear second first

using namespace std;



int omar() { fastIO

	int n; cin >> n;

	vector<int> arr, piv; 

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

		int e; cin >> e;

		arr.push_back(e);

		piv.push_back(e);

	}

	int dif = 0;

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

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

		if (arr[i] != piv[i])dif++;

	} cout << ((dif <= 2)? "YES" : "NO") << endl;

}


// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;

int main(){

    int n,a,i,c=0;

    cin>>n;

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

        cin>>a;

        if(i!=a){

            c++;

        }

    }

    if(c>=0 && c<=2){

        cout<<"YES";

    }

    else{

        cout<<"NO";

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#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;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int n;

    cin >> n;

    vector<int> vec, sor;

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

        int a;

        cin >> a;

        vec.push_back(a);

        sor.push_back(a);

    }

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

    bool g = true;

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

        if (vec[i] != sor[i])

            g = false;

    if (g) return cout << "YES\n", 0;



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

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

            vector<int> v;

            for (auto a: vec) v.push_back(a);

            swap(v[i], v[j]);

            bool good = true;

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

                if (v[k] != sor[k]) good = false;

            if (good) return cout << "YES", 0;

        }

    }

    cout << "NO";

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>



#define endl '\n'



int main()

{

    int n, i, m=0;

    scanf("%d", &n);

    int ara[n];



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

    {

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

        if(ara[i]-i-1) m++;

    }



    !m || m==2? printf("YES"): printf("NO");



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define F first

#define S second

using namespace std;

typedef long long ll;

typedef pair<ll, ll>pll;

int main()

{

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

    ll n, c = 0;

    cin >> n;

    ll arr[n + 5];

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

    {

        ll x;

        cin >> x;

        c += (x != i);

    }

    cout << (c <= 2 ? "YES" : "NO");

    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>



#define endl '\n'



int main()

{

    int n, i, m=0;

    scanf("%d", &n);

    int ara[n];



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

    {

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

        if(ara[i]-i-1) m++;

    }



    !m || m==2? printf("YES"): printf("NO");



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main()

{

    int n,i,j,count=0;

    cin>>n;

    int a[n];

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

        cin>>a[i];

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

    {

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

            count++;

    }

    if(count<=2)

        cout<<"YES";

    else

        cout<<"NO";



}


// Optimized solution to the same problem (faster):
#include <stdio.h>



#define endl '\n'



int main()

{

    int n, i, m=0;

    scanf("%d", &n);

    int ara[n];



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

    {

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

        if(ara[i]-i-1) m++;

    }



    !m || m==2? printf("YES"): printf("NO");



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include <bits/stdc++.h>

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

#define endl '\n'

using namespace std;

int main()

{

    fastio;

    long long n,i;

    cin>>n;

    long long a[n+1];

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

    {

        cin>>a[i];

    }

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

    {

        if(a[i]!=i)

        {

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

            break;

        }

    }

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

    {

        if(a[i]!=i)

        {

            cout<<"NO";

            return 0;

        }

    }

    cout<<"YES";

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*    Mohammed Sami Khan

                       মোহাম্মদ সামী খান

*/

#include<bits/stdc++.h>

using namespace std;

#define pi acos(-1.0)

#define mp(a,b) make_pair(a,b)

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

typedef long long ll;

typedef unsigned long long ull;



bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){

    return (a.second < b.second);

}



int main()

{

    fastio;

    ll t, n, m, x=0, y, p, q, r, i, j, d, f=0;

    cin>>n;

    ll a[n];

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

        cin>>a[i];

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

    }

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

    else cout<<"NO";

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <sstream>

#include <cstdio>

#include <cmath>

#include <cstring>

#include <cctype>

#include <string>

#include <vector>

#include <list>

#include <set>

#include <map>

#include <queue>

#include <stack>

#include <algorithm>

#include <functional>

#include<cstdlib>





#define REP(i,n) for(int i=0;i<(n);i++)

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

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

#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];

#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;



typedef long long ll;

using namespace std;



int main()

{

     ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);

     int n,i,k,l,c=0,d,p,nl,np;

    int a[51],b;

   cin>>n;

   vector<int> v(n);



   REP(i,n)

   {

    cin>>v[i];



   }

   REP(i,n)

   {

       if(v[i]!=i+1)c++;



   }



   if(c==2 || c==0)cout<<"YES";

   else cout<<"NO";











}

// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main(){



    int t, i, j, b, h=0;

    cin >> t ;

    int a[t];



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

        cin >> a[i] ;

    }

    for(j=1; j<=t; j++){

        if(a[j]!=j){

           h++;

        }

    }

    if(h<=2){

            cout << "YES" << endl;

        }

        else{

            cout << "NO" << endl;

        }



    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#include "iostream"



using namespace std;

int main()

{  //freopen("D:\\input.txt","r",stdin);

    int n,c=0,o=0;

    cin>>n;

    int p[1000],pp[1000];

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

        {cin>>p[i];

        pp[i]=p[i];

        }

    sort(p,p+n);



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

    {

        if(p[i]==pp[i])

           {

           o++;

           continue;

           }

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

        {

           // cout<<p[i]<<pp[i]<<c<<o<<endl;

         if(p[i]==pp[j] && p[j]==pp[i])

            {c++;



        }

      }

    }



            if(c<=2 && o>=n-2)

                cout<<"YES"<<endl;

            else

                cout<<"NO"<<endl;



}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    cin>>n;

    vector<int> given(n);

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

        cin>>given.at(i);

    vector<int> sorted(given);

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

    int count=0;

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

    {

        if(given.at(i)!=sorted.at(i))

            count++;

    }

    if(count > 2)

        cout<<"NO"<<endl;

    else

        cout<<"YES"<<endl;

    return 0;



}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main(){

	ios::sync_with_stdio(0);

	cin.tie(0);



	int n, notSorted = 0;

	cin>>n;



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

		int num;

		cin>>num;

		if(num != i)

			notSorted++;

	}



	string s = notSorted < 3?"YES\n":"NO\n";

	cout<<s;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;



int main() {

	int n;

	cin>>n;

	int a[n], b[n];



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

        cin>>a[i]; b[i]=a[i];

    }





	sort(a, a+n);





 



	int c=0;

	for(int i=0; i<n; i++) if(a[i]!=b[i]) c++;



	if(c==2 || c==0) cout<<"YES";

	else cout<<"NO";





}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



int main() {

	int n, count = 0;

	std::cin >> n;

	int* ara = new int[n];

	int* arb = new int[n];



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

		std::cin >> ara[i];

		arb[i] = ara[i];

	}



	std::sort(ara, ara + n);



	for (int i = 0; i < n; i++) if (ara[i] != arb[i]) count++;



	if (count == 2 || count == 0) std::cout << "YES";

	else std::cout << "NO";

}

// Optimized solution to the same problem (faster):
#include<stdio.h>



int main()



{

   int i,j,tc,a[100000],cnt=0,z;



   scanf("%d",&tc);



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

   {

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

   }



   for(j=1,z=0;j<=tc;j++,z++)

   {

      if(j!=a[z])

      {

         cnt++;

      }

   }



   if(cnt<=2)

   {

      printf("YES\n");

   }



   else

   {

      printf("NO\n");

   }

}


// Fastest known solution for this problem: