stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

int main()

{

   int a[100],b[100],n,c=0,v=0;

   cin>>n;

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

   {

     cin>>a[i];

   }

   copy(a,a+n,b);

   sort(b,b+n);

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

   {

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

       {

         c++;

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



       }

   }

   if(c<=2)

   {

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

      {

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

         {

            v++;

         }

      }

      if(v==n)

      {

         cout<<"YES";

      }

      else

      {

         cout<<"NO";

      }

   }

   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;



using ll = long long;

using ull = unsigned long long;



const long long MOD = 1e9 + 7;





#define INPUT(x)                freopen(x,"r",stdin)

#define OUTPUT(x)               freopen (x,"w",stdout)





#define pb                      push_back

#define endl                    '\n'

#define LCM(a,b)                (a/__gcd(a,b))*b

#define GCD(a,b)                __gcd(a,b)

#define SP(x,y)                 fixed<<setprecision((y))<<(x)

#define PI                      acos(-1.0)

#define distance(x1,y1,x2,y2)   sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))

#define MAX                     1e9 + 9



#define taratari                ios_base::sync_with_stdio(0);cin.tie(NULL);





int main()

{

    taratari



    int n;

    cin>>n;



    vector <int> a;

    vector <int> b;



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

    {

        int x;

        cin>>x;



        a.pb(x);

        b.pb(x);

    }



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



    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";

    }







    return 0;



}




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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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;





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

#define pb push_back

#define f(i,x,n) for(i=x;i<n;i++)

#define rf(i,x,n) for(i=n;i>x;i--)

#define ll long long

#define GCD(a,b) __gcd(a,b)

#define ff first

#define ss second

#define adios return 0;



/*

tacet aquilae

*/



int main()

{

    ONSPEED;

    ll t,n,k,a,b,c,d,s=0,i,j,flag;

    string x,y;

    cin>>n;

    std::vector<ll> v1(n),v2;

    f(i,0,n) 

    {

    	cin>>v1[i];

    }

    v2=v1;

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

    f(i,0,n)

    {

    	if(v1[i]!=v2[i])s++;

    }

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

    else cout<<"NO";









    adios;

}

	


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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;

#define endl '\n'

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, a[60], b[60], i, cnt=0;

    cin>>n;

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

    {

        cin>>a[i];

        b[i]=a[i];

    }

    sort(a, a+n);

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

    {

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

            cnt++;

    }

    if(cnt<=2)

        cout<<"YES";

    else

        cout<<"NO";



}


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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



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

#define read       freopen("input.txt", "r", stdin);

#define write      freopen("output.txt", "w", stdout);

#define endd        '\n'

#define ll         long long

#define sq(a)      ((a) * (a))



using namespace std;

int main()

{

      faster;

      double pi = 2 * acos(0.0);

      ll int n,i,t,j,k,m=0,a,b,c,d,p,q,r,x=250,y=10,z,count=0;

      cin>>n;

      ll int ara[n+1]={};

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

            cin>>ara[i];

            if(i!=ara[i])count++;

      }

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

      else cout<<"NO"<<endl;

      return 0;

}

//Sheikh Tafsir Rahman

//CSE IUT

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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 a[10000],i,j,n,c=0,b[100000];

    cin>>n;



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

    {

        cin>>a[i];

        b[i]=a[i];

    }

    sort(a,a+n);





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

    {

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

    }



    if(n-c==2 || c==n) cout<<"YES"<<endl;

    else cout<<"NO"<<endl;



    return 0;

}


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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;

    cin>>n;

    int p[100];



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

    {

       cin>>p[i];

    }

    int c=0;

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

    {

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

        {

            c++;

        }

    }



    if(c<=2)

    {

        cout<<"YES"<<endl;

    }

    else

    {

        cout<<"NO"<<endl;

    }

    return 0;

}


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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

#include<algorithm>

using namespace std;

int main()

{

	ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int n, p[100], q[100], x=0, i;

    cin>>n;

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

    	cin>>p[i], q[i]=p[i];

    sort(p, p+n);

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

    {

    	if(p[i]!=q[i])

    		x++;

    }

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

}

    

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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 i , j , k=0 , n ;

	cin >> n ;

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

	{

		cin >> j ;

		if(i!=j)

		k++;

	}

	if(k<=2)

	cout << "YES";

	else

	cout << "NO";

	return 0;

}

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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

#include <iomanip>

#include <vector>

#include <bits/stdc++.h>

#include <string.h>

#include <algorithm>

#define ll long long int

#define test_case int t,i;cin>>t;for(i=0;i<t;i++)

using namespace std;



int main()

{

    int n,i,x,c=0;

    cin>>n;



    vector<int>a;

    vector<int>sorted;



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

    {

        cin>>x;

        a.push_back(x);

        sorted.push_back(x);

    }



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

    

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

    {

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

            c++;

    }



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

        cout<<"YES\n";

    else

        cout<<"NO\n";



    return 0;

}


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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,cnt=0,m=0;

    vector <int> entered;

    vector <int> required;

    cin >>N;

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

        cin>>m;

        entered.push_back(m);

    }

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

        required.push_back(i);

    }

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

        if(entered[i] != required[i]){

            cnt++;

        }

    }

    if(cnt>2){

        cout << "NO";

    }

    else{

        cout << "YES";

    }

    return 0;

}

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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

#define Tayeb ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

typedef long long ll;

using namespace std;

int main()

{

    Tayeb;

    int N,val1,count=0;

    cin >> N;

    int arr[N],arr2[N];

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

    {

        cin >> arr[i];

        arr2[i]=arr[i];



    }

    sort(arr,arr+N);



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

    {

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

        count++;

    }

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

    cout << "YES\n";

    else

    cout << "NO\n";



    return 0;



}


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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

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

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

#define mp make_pair

#define pb push_back

#define F first

#define S second

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

#define endl "\n"

#define noob (main)

typedef long long ll;

using namespace  std;

typedef vector<ll> vi;

const ll INF = 1e18;

const ll MOD = 1e9 + 7;

const int N = 55 ;



bool is_sorted(vector<int> V){

    for(int i = 1 ; i< V.size();i++){

        if(V[i]<V[i-1]){

            return false;

        }

    }

    return true;

}

int noob(){

    fastIO;

    int n ;

    cin>>n;

    vector<int> A(N);

    int cnt = 0;

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

        cin>>A[i];

        if(A[i] != i ){

            cnt++;

        }

    }

    if(cnt>2){

        cout<<"NO";

    }

    else cout<<"YES";



}

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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

#include <cmath>

#include <vector>

#include <algorithm>



using namespace std;



int main() {

	int num,diff = 0;

	cin >> num;

	vector<int> v(num);

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

		cin >> v[i];

	vector<int> v2(v);



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



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

	{

		if (v[i] != v2[i])

			diff++;

	}

	if (diff == 2 || diff == 0)

		cout << "YES";

	else

		cout << "NO";

	system("pause");

	return 0;

}

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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 a, result{0};

	scanf ("%d", &a);

	int b[a];

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

	{

		cin>>b[i];

	}

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

	{

		if (b[j]!=j+1) result++;

	}

	if (result>2) cout<<"NO"<<endl;

	else cout<<"YES"<<endl;

	return 0;

}

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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, x;

  	vector<int> nums, sortNums;

  

  	cin >> n;	

  

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

    	cin >> x;

      	nums.push_back(x);

    }

  	

  	sortNums = nums;

  	sort(sortNums.begin(), sortNums.begin()+n);

  

    if(nums == sortNums){

      cout << "YES\n";

      return 0;

    } 

  

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

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

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

        	if(nums == sortNums){

              	cout << "YES\n";

              	return 0;

            } 

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

        }

    }

  

  	cout << "NO\n";

  

	return 0;

}


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        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;

  

bool checkingAlgo(int koyta, int seq[]) 

{  

    int duplicate[koyta]; 

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

        duplicate[i] = seq[i]; 

    sort(duplicate, duplicate + koyta); 

  

 

    int swap = 0; 

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

        if (seq[i] != duplicate[i]) 

            swap++; 

    if (swap == 0 || swap == 2) 

        return true; 

    else

        return false; 

} 

  



int main() 

{   

    int koyta;

    cin >> koyta;



    int seq[koyta]; 

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

        cin >> seq[i]; 

     



    if (checkingAlgo(koyta, seq)) 

        cout << "YES"; 

    else

        cout << "NO"; 

    return 0; 

} 


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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

#include <string>

#include <algorithm>



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

#define e '\n'

#define ll long long int



#define ii InputInteger()

#define il InputLong()

#define is InputString()



using namespace std;



void Ia(int arr[], int n)

{

    f

    {

        cin >> arr[i];

    }

}

void Pa(int arr[], int n)

{

    f

    {

        cout << arr[i] << e;

    }

}

int InputInteger()

{

    int n;

    cin >> n;

    return n;

}

ll InputLong()

{

	ll n;

	cin >> n;

	return n;

}

string InputString()

{

	string s;

	cin >> s;

	return s;

}

void Ca(int arr[], int n)

{

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

    {

        arr[ i ] = 0;

    }

}

int main()

{

    ios_base::sync_with_stdio( false );



        int n = ii, p = 0;

        int a[n], s[n];

        Ia(a, n);

        f

        {

            s[i] = a[i];

        }

        sort(s, s+n);

        f

        {

            if(a[i] != s[i]) p++;

        }

       if (p>2) cout << "NO";

       else cout << "YES";



    return 0;

}






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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
/*  TAHMID RAHMAN

    DAMIAN FOREVER

     MATH LOVER

    NEVER GIVE UP

*/

#include<bits/stdc++.h>

using namespace std;

#define pi acos(-1.0)

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

#define ll long long

#define pb push_back

#define fi first

#define se second

#define in insert

#define mp make_pair

#define GCD(a,b) __gcd(a,b);

#define endl "\n"

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

#define FRO freopen("in.txt","r",stdin)

#define INFLL 9223372036854775807

#define debug 0

#define MAXN   100001

#define ar array

const int mxN=2e5;

const int MOD=1e9+7;

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}

//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;

int main()

{



    ll n,i;

    cin>>n;

    vector<ll>v(n);

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

    {

        cin>>v[i];

    }

    set<ll>s;

    vector<ll>a(v.begin(),v.end());

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

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

    {

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

        {

            s.in(a[i]);

            s.in(v[i]);

        }

    }

    if(s.size()==0||s.size()==2)

    {

        cout<<"YES"<<endl;

    }

    else

        cout<<"NO"<<endl;



}


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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




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

using namespace std;

#include<bits/stdc++.h>

#define PI			2*acos(0.0)

int main()

{

    int n,i;

    cin >>n;

    int a[n+1],c=0,y1,y2=0;

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

    {

        cin >>a[i];

        if(a[i]!=i)

        {

            if(c==0)

            {

                c++;

                y1=i;

            }

            else if(c==1)

            {

                c++;

                if(a[i]==y1)

                {

                    y2=1;

                }

            }

            

        }

    }

    if(c==2&&y2==1)

    {

        cout <<"YES";

    }

    else if(c==0)

    {

        cout <<"YES";

    }

    else

        cout <<"NO";

    return 0;

}

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



int main()

{

    int n, i, ans=1, j=1;



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}




// Fastest known solution for this problem: