stablegradients/pie-gem5-pairs huggingface dataset:
// 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.082633142371699x):
#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()

{

	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.1404799995206725x):
#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 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.083039901661106x):
#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, 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.09807142434262x):
#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<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.092829333996597x):
#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>

#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.10031091272349x):
#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,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.1539952422396995x):
#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>

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

}


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

}

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

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

}


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

}

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

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;

}

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

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

}


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

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



}


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

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

}

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

}


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



}


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

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

}


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

}


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

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











}

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

}

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



}


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



}


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

}

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





}


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

   }

}