stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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";

   }



}






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



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;



}




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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

}

	


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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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



}


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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

}


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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

}


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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

}

    

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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

}

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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

}


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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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

}

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

int main()

{

  int N,p,a = 0;

  

  scanf("%d",&N);

 

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

    scanf("%d" ,&p);

    if( p != i )

      a++;

  }

 

  if( a == 0 || a == 2)

    printf("YES\n");

  else

    printf("NO\n");

  

  return 0;

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



}




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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

}

	


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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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



}


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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

}


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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

}


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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

}

    

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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

}

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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

}


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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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

}

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



int main()

{

	int tc, num[100000], count=0, i, save, acd[100000];



	scanf("%d", &tc);



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

	{

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

		acd[i] = i;

	}

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

	{

		if(acd[i] == num[i])

            save = 1;

        else

            count++;

	}

    if(count <= 2 && save == 1)

        printf("YES\n");

    else

        printf("NO\n");





	return 0;

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



}




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

int main()

{

    int num,i,j=1,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

        if(count[i]!=j)

        {

            total++;

        }

        j++;



    }

    if(total>2)

    {

        printf("NO");

    }

    else

    {

        printf("YES");

    }

    //printf("%d",total);

    return 0;

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

}

	


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

int main()

{

    int num,i,j=1,k,big=-1,avg,max,total=0,count[50];

    scanf("%d",&max);

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

    {

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

        if(count[i]!=j)

        {

            total++;

        }

        j++;



    }

    if(total>2)

    {

        printf("NO");

    }

    else

    {

        printf("YES");

    }

    //printf("%d",total);

    return 0;

}