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

#include <cstdio>

#include <vector>

#include <cstdlib>

#include <cassert>

#include <cstring>

#include<stdio.h>

#include <iostream>

#include <algorithm>

#include<bits/stdc++.h>

#define endl "\n"

#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;

using namespace std;

#define ll long long int

#define pb push_back

#define mp make_pair

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



int main()

{

    int i,x,n,j,flag,temp=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)

        {

            flag=1;

            break;

        }

    }

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

    {

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

        {

            break;

        }

    }

    if (flag==1)

    {

        x=a[i];

        a[i]=a[j];

        a[j]=x;

    }



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

    {

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

        {

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

            temp=1;

            break;

        }

    }

    if (temp==0)

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

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.2771702346123215x):
#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>

using namespace std;

int main(){

int n,i,f=0;

cin>>n;

int p[n];

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

    cin>>p[i];

  }

  i=0;

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

if(p[i]!=i){f++;}

    }

    if(f<=2){

    cout<<"YES"<<endl;

}

else{

    cout<<"NO"<<endl;

}







}


// Faster C++ solution for the same problem (measured speedup: 5.287754841185543x):
#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,ara[52],flag=0;

    cin>>n;



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

    {

        cin>>ara[i];

    }



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

    {

        if(ara[i]!=i)

        {

            flag++;

        }

    }



    if(flag==0 || flag==2)

    {

        cout<<"YES"<<endl;

    }

    else

        cout<<"NO"<<endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.286876666116024x):
#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>



void Sort(int a[], int n) 

{

   int i, j, min, temp;

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

      min = i;

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

      if (a[j] < a[min])

      min = j;

      temp = a[i];

      a[i] = a[min];

      a[min] = temp;

   }

}

int main()

{

	int n,wrong=0;

	std::cin>>n;

	int arr[n],sortedarr[n];

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

	{

		std::cin>>arr[i];

		sortedarr[i]=arr[i];

	}	

	Sort(sortedarr,n);

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

	{

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

			wrong++;

	}

	if(wrong<=2)

		std::cout<<"YES";

	else

		std::cout<<"NO";



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.2794093629260175x):
#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;



#define ll long long

#define endl "\n"



int main()

{

    ll n;

    cin >> n;

    ll a[n], b[n];

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

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

    sort(b, b + n);

    ll ans = 0;

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

    {

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

            ++ans;

    }

    if (ans > 2)

    {

        cout << "NO\n";

        return 0;

    }

    cout << "YES\n";

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.275783802079786x):
#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>

 

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

}

// Faster C++ solution for the same problem (measured speedup: 5.284280239085083x):
#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:
//  ©   ___MRX___



#include <bits/stdc++.h>

    using namespace std;



#define ll long long int



int main()

{

    int n, i, flag = 0;

    cin >> n;

    vector<int> vec(n);

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

        cin >> vec[i];

    }

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

        if(vec[i] != i + 1) flag++;

    }



    if(flag <= 2) cout << "YES" << "\n";

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



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.323488320463274x):
#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 <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;

}

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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
#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;

}

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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
#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;

}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:


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

} 


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
#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;

}






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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
/*  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;



}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
#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;

}

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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

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

#include <stdlib.h>

#include <iomanip>

//#include <string.h>



using namespace std;



int main()

{

    int n,a[100],i,ass=0;

    cin>>n;

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

    {

        cin>>a[i];

    }

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

    {

        if(a[i]!=i)

            ass++;

    }

    if(ass>2)

        cout<<"NO";

    else

        cout<<"YES";

    return 0;

}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

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

#include <cstdio>

#include <vector>

#include <cstdlib>

#include <cassert>

#include <cstring>

#include<stdio.h>

#include <iostream>

#include <algorithm>

#include<bits/stdc++.h>

#define endl "\n"

#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;

using namespace std;

#define ll long long int

#define pb push_back

#define mp make_pair

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



int main()

{

    int i,x,n,j,flag,temp=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)

        {

            flag=1;

            break;

        }

    }

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

    {

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

        {

            break;

        }

    }

    if (flag==1)

    {

        x=a[i];

        a[i]=a[j];

        a[j]=x;

    }



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

    {

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

        {

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

            temp=1;

            break;

        }

    }

    if (temp==0)

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

    return 0;

}




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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

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

using namespace std;

int main(){

int n,i,f=0;

cin>>n;

int p[n];

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

    cin>>p[i];

  }

  i=0;

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

if(p[i]!=i){f++;}

    }

    if(f<=2){

    cout<<"YES"<<endl;

}

else{

    cout<<"NO"<<endl;

}







}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

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



using namespace std;



int main()

{

    int n,ara[52],flag=0;

    cin>>n;



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

    {

        cin>>ara[i];

    }



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

    {

        if(ara[i]!=i)

        {

            flag++;

        }

    }



    if(flag==0 || flag==2)

    {

        cout<<"YES"<<endl;

    }

    else

        cout<<"NO"<<endl;



    return 0;

}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

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



void Sort(int a[], int n) 

{

   int i, j, min, temp;

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

      min = i;

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

      if (a[j] < a[min])

      min = j;

      temp = a[i];

      a[i] = a[min];

      a[min] = temp;

   }

}

int main()

{

	int n,wrong=0;

	std::cin>>n;

	int arr[n],sortedarr[n];

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

	{

		std::cin>>arr[i];

		sortedarr[i]=arr[i];

	}	

	Sort(sortedarr,n);

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

	{

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

			wrong++;

	}

	if(wrong<=2)

		std::cout<<"YES";

	else

		std::cout<<"NO";



	return 0;

}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

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



using namespace std;



#define ll long long

#define endl "\n"



int main()

{

    ll n;

    cin >> n;

    ll a[n], b[n];

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

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

    sort(b, b + n);

    ll ans = 0;

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

    {

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

            ++ans;

    }

    if (ans > 2)

    {

        cout << "NO\n";

        return 0;

    }

    cout << "YES\n";

    return 0;

}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
#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";

}

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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
//  ©   ___MRX___



#include <bits/stdc++.h>

    using namespace std;



#define ll long long int



int main()

{

    int n, i, flag = 0;

    cin >> n;

    vector<int> vec(n);

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

        cin >> vec[i];

    }

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

        if(vec[i] != i + 1) flag++;

    }



    if(flag <= 2) cout << "YES" << "\n";

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



    return 0;

}


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

#define size 55

int main()

{

    int i,j,n,a[size],cnt=0;

    scanf("%d",&n);

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

    {

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

    }

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

    {

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

    }

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

    else printf("NO");

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.150371039664976x):
#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");

   }

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.121863957245869x):
#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");

   }

}