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



#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.361657489345225x):
#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;

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.334100222057286x):
#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;

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.289989817332704x):
#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<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.354563747248152x):
#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<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.278768066900367x):
#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 <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.338714681728843x):
#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;



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.337969958903306x):
#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>

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

typedef long long ll;

using namespace std;

int main()

{

    Tayeb;

    int N,val1,count=0;

    cin >> N;

    int arr[N],arr2[N];

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

    {

        cin >> arr[i];

        arr2[i]=arr[i];



    }

    sort(arr,arr+N);



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

    {

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

        count++;

    }

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

    cout << "YES\n";

    else

    cout << "NO\n";



    return 0;



}


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



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.420953541000495x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.416792847013155x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.364199057554446x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.3712662112455964x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.343659558088039x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.299470102321359x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.364159756326941x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.288228241190165x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.3482822874149765x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.347536229958398x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

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

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

typedef long long ll;

using namespace std;

int main()

{

    Tayeb;

    int N,val1,count=0;

    cin >> N;

    int arr[N],arr2[N];

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

    {

        cin >> arr[i];

        arr2[i]=arr[i];



    }

    sort(arr,arr+N);



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

    {

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

        count++;

    }

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

    cout << "YES\n";

    else

    cout << "NO\n";



    return 0;



}


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



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

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

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

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

#define mp make_pair

#define pb push_back

#define F first

#define S second

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

#define endl "\n"

#define noob (main)

typedef long long ll;

using namespace  std;

typedef vector<ll> vi;

const ll INF = 1e18;

const ll MOD = 1e9 + 7;

const int N = 55 ;



bool is_sorted(vector<int> V){

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

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

            return false;

        }

    }

    return true;

}

int noob(){

    fastIO;

    int n ;

    cin>>n;

    vector<int> A(N);

    int cnt = 0;

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

        cin>>A[i];

        if(A[i] != i ){

            cnt++;

        }

    }

    if(cnt>2){

        cout<<"NO";

    }

    else cout<<"YES";



}

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



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.360432450307744x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}
// 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.330762687006008x):
#include<stdio.h>



int main()

{

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



    scanf("%d", &n);



    int P[n+2];



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

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

        if(i != P[i]){

            if(j==3){

                ans=0;

                break;

            }

            j++;

        }

    }



    if(ans)

        printf("YES\n");

    else

        printf("NO\n");



    return 0;

}