stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8056195926003973x):
//      https://youtu.be/X_hMZYDMps4



#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;

typedef long long unsigned llu;

typedef pair<long long, long long> pll;

const long long inf = 2000000000000000000LL;    // 2e18

#define pi                  acos(-1.0)

#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define nl                  "\n"

#define ff                  first

#define ss                  second

#define pb                  push_back

#define pf                  push_front

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

#define debug(x)            cout<<"debug "<<x<<"\n"



int main()

{

    fast;

    ll t,i,j,k,l,m,n,o,p,q,temp,ans=0,flag=0,mod=1000000007;

    cin>>n;

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

        cin>>temp;

        if(temp!=i) ans++;

    }

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

    else cout<<"NO";

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

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


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

using namespace std;

int main()

{

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

    scanf("%d",&n);

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

    {

        cin>>a[i];

    }

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

    {

        b[i]=a[i];

    }

    sort(a,a+n);

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

    {

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

        {

            c++;

        }

    }

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

    {

        cout<<"YES"<<endl;

    }

    else

    {

        cout<<"NO"<<endl;

    }

    return 0;

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

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


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

#include <cstring>

#include <ctype.h>

#include<stdlib.h>



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

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

#define ll              long long

#define ull             unsigned long long

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

#define nl              '\n'

#define nll             '\0'

#define pb              push_back

#define bdyptb          return 0;

#define sorted(x)       sort(x.begin(), x.end())

#define reversed(x)     reverse(x.begin(), x.end())

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

#define mset(a, b)      memset(a, b, sizeof(a));

#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)



#define pi acos(-1.00)   

#define mx 1000007



using namespace std;



int main()

{

    fastio;

    int n;

    cin>>n;

    int a[n];

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

    {

        cin>>a[i];

    }

    int x=0; 

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

    {

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

    }

    if(x==2 ||x==0)cout<<"YES\n";

    else cout<<"NO\n";

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

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


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

#include <stdio.h>

#include <math.h>

int main ()

{

    int n, c=0;

    scanf ("%d", &n);

    int a[n];

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

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

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

    }

    if (c>2) printf ("NO");

    else printf ("YES");

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

using namespace std;

#define ll long long

int main()

{

    ll n,i,j,k,l,a,b,c,d;

    cin>>n;

    ll arr[n+10];

    c=0;

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

    {

        cin>>arr[i];

    }

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

    {

        if(arr[i]!=i)

        {

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

            {

                if(arr[j]==i)

                {

                    arr[j]=arr[i];

                    arr[i]=i;

                    break;

                    break;



                }

            }

            break;

        }

    }

    c=-1;

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

    {

        if(arr[i]==i){c=1;}

        else{c=0;break;}

    }

    if(c==1)

    {

        cout<<"YES"<<endl;

    }

    else if(c==0)

    {

        cout<<"NO"<<endl;

    }

    return 0;

}


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

#include <stdio.h>

#include <math.h>

int main ()

{

    int n, c=0;

    scanf ("%d", &n);

    int a[n];

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

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

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

    }

    if (c>2) printf ("NO");

    else printf ("YES");

}
// Slower C++ solution:


///HELLO THERE~!

///CREATED BY MD SADMAN MEHEDI SIVAN(IUT CSE[SWE'19])



#include<bits/stdc++.h>

using namespace std;



#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

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

#define WRITE           freopen("red.txt","w",stdout);



using ll=long long;

using ull=unsigned long long;

const double pi = 2*acos(0.0);

const long long MX = 2e5+7;



int main()

{

    FASTIO;

    long long n;

    cin>>n;

    long long a[n+1];

    ll f=0;

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

    {

        cin>>a[i];

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

            f++;

    }

    if(f==0 || f==2)

    {

        cout<<"YES";

    }

    else

        cout<<"NO";







    return 0;







}


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

#include <stdio.h>

#include <math.h>

int main ()

{

    int n, c=0;

    scanf ("%d", &n);

    int a[n];

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

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

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

    }

    if (c>2) printf ("NO");

    else printf ("YES");

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

using namespace std;



int main()



{

   long long a=0,b,c,d,e,f,g,h,i,j,k,l,m,n,t;



   cin>>n;



   long long ar[n];



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

   {

       cin>>ar[i];



       if(ar[i]!=i) a++;

   }



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



   else if(a>2) cout<<"NO"<<endl;

}


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

#include <stdio.h>

#include <math.h>

int main ()

{

    int n, c=0;

    scanf ("%d", &n);

    int a[n];

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

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

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

    }

    if (c>2) printf ("NO");

    else printf ("YES");

}
// Slower C++ solution:
//      https://youtu.be/X_hMZYDMps4



#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;

typedef long long unsigned llu;

typedef pair<long long, long long> pll;

const long long inf = 2000000000000000000LL;    // 2e18

#define pi                  acos(-1.0)

#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define nl                  "\n"

#define ff                  first

#define ss                  second

#define pb                  push_back

#define pf                  push_front

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

#define debug(x)            cout<<"debug "<<x<<"\n"



int main()

{

    fast;

    ll t,i,j,k,l,m,n,o,p,q,temp,ans=0,flag=0,mod=1000000007;

    cin>>n;

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

        cin>>temp;

        if(temp!=i) ans++;

    }

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

    else cout<<"NO";

}


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

#include <stdio.h>

#include <math.h>

int main ()

{

    int n, c=0;

    scanf ("%d", &n);

    int a[n];

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

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

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

    }

    if (c>2) printf ("NO");

    else printf ("YES");

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

using namespace std;

int main()

{

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

    scanf("%d",&n);

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

    {

        cin>>a[i];

    }

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

    {

        b[i]=a[i];

    }

    sort(a,a+n);

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

    {

        if(a[i]!=b[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.3266456319195665x):
#include <string.h>

#include <stdio.h>

#include <math.h>

int main ()

{

    int n, c=0;

    scanf ("%d", &n);

    int a[n];

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

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

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

    }

    if (c>2) printf ("NO");

    else printf ("YES");

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

#include <cstring>

#include <ctype.h>

#include<stdlib.h>



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

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

#define ll              long long

#define ull             unsigned long long

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

#define nl              '\n'

#define nll             '\0'

#define pb              push_back

#define bdyptb          return 0;

#define sorted(x)       sort(x.begin(), x.end())

#define reversed(x)     reverse(x.begin(), x.end())

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

#define mset(a, b)      memset(a, b, sizeof(a));

#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)



#define pi acos(-1.00)   

#define mx 1000007



using namespace std;



int main()

{

    fastio;

    int n;

    cin>>n;

    int a[n];

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

    {

        cin>>a[i];

    }

    int x=0; 

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

    {

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

    }

    if(x==2 ||x==0)cout<<"YES\n";

    else cout<<"NO\n";

}

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

#include <stdio.h>

#include <math.h>

int main ()

{

    int n, c=0;

    scanf ("%d", &n);

    int a[n];

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

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

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

    }

    if (c>2) printf ("NO");

    else printf ("YES");

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

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.8225123374439303x):
#include <iostream>

#include <vector>

using namespace std;



int main()

{

    int n, i;



    cin>>n;



    vector<int>P(n);



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

    {

        cin>>P.at(i);

    }

    int j, k=0;



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

    {

        if(P.at(j)!=j+1)

            k++;

    }

    if (k<=2)

        cout<<"YES"<<endl;



    else

        cout<<"NO"<<endl;



        return 0;

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

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


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

using namespace std;

 

int main(){

  int N;

  cin>>N;

  vector<int> P(N);

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

    cin>>P.at(i);

  }

  int k=0;

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

    if(P.at(j)!=j+1) k++;

  }

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

  else cout<<"NO"<<endl;

 

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

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.808384231298311x):
#include <iostream>

#include <bits/stdc++.h>

using namespace std;





int main() {

    int n;

    cin>>n;

    vector<int> p(n);

    int count=0;

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

    {

        cin>>p[i];

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

        count++;

    }

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

     cout<<"YES"<<endl;

    else

     cout<<"NO"<<endl;

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

#define ll long long int

using namespace std;



int main()

{

    ll n,a[100000+9],b[100000+9]= {0},i,j,f=0,c=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])

        {

            f=1;

            c++;

        }

    }



    if(f==0)

    {

        cout<<"YES"<<endl;

    }

    else if(f==1)

    {

        if(c==2)

        {

            cout<<"YES"<<endl;

        }

        else

        {

            cout<<"NO"<<endl;

        }

    }

    return 0;

}


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

int main()

{

    ll n,i,j,k,l,a,b,c,d;

    cin>>n;

    ll arr[n+10];

    c=0;

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

    {

        cin>>arr[i];

    }

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

    {

        if(arr[i]!=i)

        {

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

            {

                if(arr[j]==i)

                {

                    arr[j]=arr[i];

                    arr[i]=i;

                    break;

                    break;



                }

            }

            break;

        }

    }

    c=-1;

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

    {

        if(arr[i]==i){c=1;}

        else{c=0;break;}

    }

    if(c==1)

    {

        cout<<"YES"<<endl;

    }

    else if(c==0)

    {

        cout<<"NO"<<endl;

    }

    return 0;

}


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


///HELLO THERE~!

///CREATED BY MD SADMAN MEHEDI SIVAN(IUT CSE[SWE'19])



#include<bits/stdc++.h>

using namespace std;



#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

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

#define WRITE           freopen("red.txt","w",stdout);



using ll=long long;

using ull=unsigned long long;

const double pi = 2*acos(0.0);

const long long MX = 2e5+7;



int main()

{

    FASTIO;

    long long n;

    cin>>n;

    long long a[n+1];

    ll f=0;

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

    {

        cin>>a[i];

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

            f++;

    }

    if(f==0 || f==2)

    {

        cout<<"YES";

    }

    else

        cout<<"NO";







    return 0;







}


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



{

   long long a=0,b,c,d,e,f,g,h,i,j,k,l,m,n,t;



   cin>>n;



   long long ar[n];



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

   {

       cin>>ar[i];



       if(ar[i]!=i) a++;

   }



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



   else if(a>2) cout<<"NO"<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 5.285561826157352x):
#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:
//      https://youtu.be/X_hMZYDMps4



#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef long double ld;

typedef long long unsigned llu;

typedef pair<long long, long long> pll;

const long long inf = 2000000000000000000LL;    // 2e18

#define pi                  acos(-1.0)

#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define nl                  "\n"

#define ff                  first

#define ss                  second

#define pb                  push_back

#define pf                  push_front

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

#define debug(x)            cout<<"debug "<<x<<"\n"



int main()

{

    fast;

    ll t,i,j,k,l,m,n,o,p,q,temp,ans=0,flag=0,mod=1000000007;

    cin>>n;

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

        cin>>temp;

        if(temp!=i) ans++;

    }

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

    else cout<<"NO";

}


// Faster C++ solution for the same problem (measured speedup: 5.347241492695052x):
#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,a[100],b[100],c=0;

    scanf("%d",&n);

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

    {

        cin>>a[i];

    }

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

    {

        b[i]=a[i];

    }

    sort(a,a+n);

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

    {

        if(a[i]!=b[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.317358679912032x):
#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>

#include <cstring>

#include <ctype.h>

#include<stdlib.h>



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

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

#define ll              long long

#define ull             unsigned long long

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

#define nl              '\n'

#define nll             '\0'

#define pb              push_back

#define bdyptb          return 0;

#define sorted(x)       sort(x.begin(), x.end())

#define reversed(x)     reverse(x.begin(), x.end())

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

#define mset(a, b)      memset(a, b, sizeof(a));

#define testcase        ll t,tt; cin>>tt; for(t=1;t<=tt;t++)



#define pi acos(-1.00)   

#define mx 1000007



using namespace std;



int main()

{

    fastio;

    int n;

    cin>>n;

    int a[n];

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

    {

        cin>>a[i];

    }

    int x=0; 

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

    {

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

    }

    if(x==2 ||x==0)cout<<"YES\n";

    else cout<<"NO\n";

}

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

}