#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,d,h;
	cin>>n>>d>>h;
	if((d>2*h) || (h==1 && d==1 && n!=2) || (h==(n-1) && d!=h) )
		cout<<-1<<endl;
	else
	{
		int i;
		int count=0;
		for(i=1;i<=h;i++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
		}
		i++;
			if(d!=h)
			{
				cout<<1<<" "<<i<<endl;
				count++;
			}
			for(int j=2;j<=(d-h);j++)
			{
				cout<<i<<" "<<i+1<<endl;
				count++;
				i++;
			}
			i++;
			if(d==h)
			{
				i--;
			}
			while(count<n-1)
			{
				cout<<h<<" "<<i<<endl;
				i++;
				count++;
			}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,d,h;
	cin>>n>>d>>h;
	if(d>2*h || (d==h) && n!=(h+1) )
		cout<<-1<<endl;
	else
	{
		int i;
		int count=0;
		for(i=1;i<=h;i++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
		}
		i++;
		if(d!=h)
		{
			cout<<1<<" "<<i<<endl;
			count++;
		}
		for(int j=2;j<=(d-h);j++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
			i++;
		}
		i++;
		while(count<n-1)
		{
			cout<<1<<" "<<i<<endl;
			i++;
			count++;
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,d,h;
	cin>>n>>d>>h;
	if(d>2*h || (d==h) && n!=(h+1) )
		cout<<-1<<endl;
	else
	{
		int i;
		int count=0;
		for(i=1;i<=h;i++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
		}
		i++;
		if(d!=h)
		{
			cout<<1<<" "<<i<<endl;
			count++;
		}

		for(int j=2;j<=(d-h);j++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
			i++;
		}
		if((d-h)>=2)
		{
			i++;
		}
		while(count<n-1)
		{
			cout<<1<<" "<<i<<endl;
			i++;
			count++;
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,d,h;
	cin>>n>>d>>h;
	if(d>2*h || (d==h) && h!=(n-1) || h==(n-1) && d!=h || d==(n-1) && h!=d)
		cout<<-1<<endl;
	else
	{
		int i;
		int count=0;
		for(i=1;i<=h;i++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
		}
		i++;
		if(d!=h)
		{
			cout<<1<<" "<<i<<endl;
			count++;
		}
		for(int j=2;j<=(d-h);j++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
			i++;
		}
		i++;
		while(count<n-1)
		{
			cout<<1<<" "<<i<<endl;
			i++;
			count++;
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,d,h;
	cin>>n>>d>>h;
	if((d>2*h) || (h==1 && d==1 && n!=2) || (h==(n-1) && d!=h) || (d==(n-1) && h!=d) )
		cout<<-1<<endl;
	else
	{
		int i;
		int count=0;
		for(i=1;i<=h;i++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
		}
		i++;
			if(d!=h)
			{
				cout<<1<<" "<<i<<endl;
				count++;
			}
			for(int j=2;j<=(d-h);j++)
			{
				cout<<i<<" "<<i+1<<endl;
				count++;
				i++;
			}
			i++;
			if(d==h)
			{
				i--;
			}
			while(count<n-1)
			{
				cout<<h<<" "<<i<<endl;
				i++;
				count++;
			}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,d,h;
	cin>>n>>d>>h;
	if((d>2*h) || (h==1 && d==1 && n!=2) || (h==(n-1) && d!=h) || (d==(n-1) && h!=d) )
		cout<<-1<<endl;
	else
	{
		int i;
		int count=0;
		for(i=1;i<=h;i++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
		}
		i++;
		ll y=i-2;
		if(d==h && count!=(n-1))
		{
			while(count!=(n-1))
			{
				cout<<y<<" "<<i<<endl;
			i++;
			count++;
			}
		}
		else
		{
			if(d!=h)
		{
			cout<<1<<" "<<i<<endl;
			count++;
		}
		for(int j=2;j<=(d-h);j++)
		{
			cout<<i<<" "<<i+1<<endl;
			count++;
			i++;
		}
		i++;
		while(count<n-1)
		{
			cout<<1<<" "<<i<<endl;
			i++;
			count++;
		}
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
int n,d,h;
int main(){
	cin >> n >> d >> h;
	if(d > 2*h || d < h)
		printf("-1\n");
	else if(n>2 && (h>1)){
		printf("1 2\n");
		--d;--h;
		for(int i=1;i<=h;++i)
			printf("%d %d\n",2+i-1,2+i);
		for(int i=1;i<=d-h;++i)
			printf("%d %d\n",i==1?2:2+h+i-1,2+h+i );
		for(int i=1;i<=n-d-1;++i)
			printf("2 %d\n",2+d+i );
	}else{
		if(n==2){
			if(d == 1 && h == 1){
				printf("1 2\n");
			}else
				printf("-1\n");
		}else{
			if(d == 1){
				printf("-1\n");
			}else{
				for(int i=2;i<=n;++i)
					printf("1 %d\n",i );
			}

		}

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
int n,d,h;
int main(){
	cin >> n >> d >> h;
	if(d > 2*h || d < h || d < (n+1)/2 )
		printf("-1\n");
	else{
		for(int i=2;i<=d-h+1;++i)
			printf("%d %d\n",i-1,i );
		for(int i=d-h+2;i<=d+1;++i)
			printf("%d %d\n",i==d-h+2?1:i-1,i );
		for(int i=d+2;i<=n;++i)
			printf(d == h ?"2 %d\n":"1 %d\n",i );
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
int n,d,h;
int main(){
	cin >> n >> d >> h;
	if(d > 2*h || d < h)
		printf("-1\n");
	else if(n>2 && (h>1)){
		printf("1 2\n");
		//--d;
		--h;
		for(int i=1;i<=h;++i)
			printf("%d %d\n",2+i-1,2+i);
		for(int i=1;i<=d-h;++i)
			printf("%d %d\n",i==1?2:2+h+i-1,2+h+i );
		for(int i=1;i<=n-d-1;++i)
			printf("3 %d\n",2+d+i );
	}else{
		if(n==2){
			if(d == 1 && h == 1){
				printf("1 2\n");
			}else
				printf("-1\n");
		}else{
			if(d == 1){
				printf("-1\n");
			}else{
				for(int i=2;i<=n;++i)
					printf("1 %d\n",i );
			}

		}

	}

	return 0;
}


#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n,d,h;
	cin >> n >> d >> h;
	if(d > 2*h || (n>2 && d==1)){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=d;++i){
		if(i == h+1)
			printf("%d %d\n",1,i+1);
		else
			printf("%d %d\n",i,i+1);
	}
	for(int i=d+2;i<=n;++i){
		if(h == d)
			printf("%d %d\n",2,i);
		else
			printf("%d %d\n",1,i);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;++i)
int n,d,h;
int main(){
	cin >> n >> d >> h;
	if(d > 2*h || d < h)
		printf("-1\n");
	else if(n>2 && (h>1)){
		printf("1 2\n");
		//--d;
		--h;
		for(int i=1;i<=h;++i)
			printf("%d %d\n",2+i-1,2+i);
		for(int i=1;i<=d-h;++i)
			printf("%d %d\n",i==1?2:2+h+i-1,2+h+i );
		for(int i=1;i<=n-d-1;++i)
			printf("2 %d\n",2+d+i );
	}else{
		if(n==2){
			if(d == 1 && h == 1){
				printf("1 2\n");
			}else
				printf("-1\n");
		}else{
			if(d == 1){
				printf("-1\n");
			}else{
				for(int i=2;i<=n;++i)
					printf("1 %d\n",i );
			}

		}

	}

	return 0;
}


#include <vector>
using namespace std;
void find_lis(vector<int> &a, vector<int> &b)
{
  vector<int> p(a.size());
  int u, v;

  if (a.empty()) return;

  b.push_back(0);

  for (size_t i = 1; i < a.size(); i++) {
      if (a[b.back()] < a[i]) {
          p[i] = b.back();
          b.push_back(i);
          continue;
      }

      for (u = 0, v = b.size()-1; u < v;) {
          int c = (u + v) / 2;
          if (a[b[c]] < a[i]) u=c+1; else v=c;
      }

      if (a[i] < a[b[u]]) {
          if (u > 0) p[i] = b[u-1];
          b[u] = i;
      }
  }

  for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v;
}
bool f[1000000001];
#include <cstdio>
int main()
{
  int n;
  scanf("%d",&n);
  int i;
  int a[n];
  int j=0;
  int v;
  for(i=0;i<n;i++)
  {
  	scanf("%d",&v);
	if(!f[v])
	{
		a[j++]=v;
		f[v]=true;
	}
  }
  /*for(int i=0;i<j;i++)
	  printf("%d\n",a[i]);*/
  vector<int> seq(a, a+j);
  vector<int> lis;
        find_lis(seq, lis);
 // printf("%d\n",lis.size());
  if(j-lis.size()>2)
	  printf("NO\n");
  else
	  printf("YES\n");
  return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int x[n];
	int y[n];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x[i]);
		y[i]=x[i];
	}
	sort(y,y+n);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(x[i]!=y[i])
		{
			cnt++;
		}
	}
	if(cnt>2)printf("NO\n");
	else printf("YES\n");
	return 0;

}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <limits>
#include <vector>
#include <bitset>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <time.h>
#include <map>
#include <stack>
#include <string>
#include <climits>
#include <ctime>
#include <fstream>
#include <sstream>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define LD long double
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,n) for(int i=(n);i>=0;i--)
#define DB(x) cout<<"\n"<<#x<<" = "<<(x)<<"\n";
#define CL(a,b) memset(a,b,sizeof(a))
#define GOLD ((1+sqrt(5))/2)
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
void swaps (char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}
void swapi(int *a,int *b){int temp;temp=*a;*a=*b;*b=temp;}
ULL gcd(ULL a,ULL b){if(a==0)return b;if(b==0)return a;if(a==1||b==1)return 1;
if(a==b)return a;if(a>b)return gcd(b,a%b);else return gcd(a,b%a);}
int main()
{
    int n;
    cin>>n;
    int x[n],y[n];
    int cnt=0;
    FOR(i,0,n)
    {
	    cin>>x[i];
	    y[i] = x[i];
    }
    sort(y,y+n);
    FOR(i,0,n)
    {
	    if(y[i]!=x[i])
		    cnt+=1;
    }
    if(cnt>2)
	    cout<<"NO"<<endl;
    else
	    cout<<"YES"<<endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&x[i]);
}


#include <vector>
using namespace std;
void find_lis(vector<int> &a, vector<int> &b)
{
  vector<int> p(a.size());
  int u, v;

  if (a.empty()) return;

  b.push_back(0);

  for (size_t i = 1; i < a.size(); i++) {
      if (a[b.back()] < a[i]) {
          p[i] = b.back();
          b.push_back(i);
          continue;
      }

      for (u = 0, v = b.size()-1; u < v;) {
          int c = (u + v) / 2;
          if (a[b[c]] < a[i]) u=c+1; else v=c;
      }

      if (a[i] < a[b[u]]) {
          if (u > 0) p[i] = b[u-1];
          b[u] = i;
      }
  }

  for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v;
}

#include <cstdio>
int main()
{
  int n;
  scanf("%d",&n);
  int i;
  int a[n];
  for(i=0;i<n;i++)
  scanf("%d",&a[i]);
  vector<int> seq(a, a+sizeof(a)/sizeof(a[0]));
  vector<int> lis;
        find_lis(seq, lis);
  if(n-lis.size()>2)
	  printf("NO\n");
  else
	  printf("YES\n");
  return 0;
}


/*
priyanka_14
25.12.2014
A. Little Elephant and Problem

*/
#include <iostream>

using namespace std;

int main()
{
        int n, i, j, k, l;
        cin >> n;

        int a[n];
        for (i = 0; i < n; i++) {
                cin >> a[i];
        }
        j = 0;
        for (i = 1; i < n; i++) {
                if (a[i] < a[i - 1]) {
                        j++;
                        if (j == 1) {
                                k = i - 1;
                        } else if (j == 2) {
                                l = i;
                        }
                }
        }
        if (j == 0) {
                cout << "YES\n";
        } else if (j < 3) {
                if (j == 1) {
                        int t = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = t;
                } else {
                        int t = a[k];
                        a[k] = a[l];
                        a[l] = t;
                }
                j = 0;
                for (i = 1; i < n; i++) {
                        if (a[i] < a[i - 1]) {
                                j++;
                        }
                }
                if (j == 0)
                        cout << "YES\n";
                else
                        cout << "NO\n";
        } else {
                cout << "NO\n";
        }

//        system("pause");
        return 0;
}


/*
priyanka_14
25.12.2014
A. Little Elephant and Problem

*/
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
        int n, i, j, k, l;
        cin >> n;

        int a[n];
        int b[n];
        for (i = 0; i < n; i++) {
                cin >> a[i];
                b[i] = a[i];
        }
        sort(b, b + n);
        j = 0;
        for (i = 0; i < n; i++) {
                if (a[i] != b[i]) j++;
        }
        if (j == 0 || j == 2) {
                cout << "YES\n";
        } else {
                cout << "NO\n";
        }

//        system("pause");
        return 0;
}


/*
priyanka_14
25.12.2014
A. Little Elephant and Problem

*/
#include <iostream>

using namespace std;

int main()
{
        int n, i, j, k, l;
        cin >> n;

        int a[n];
        for (i = 0; i < n; i++) {
                cin >> a[i];
        }
        j = 0;
        for (i = 1; i < n; i++) {
                if (a[i] < a[i - 1]) {
                        j++;
                        if (j == 1) {
                                k = i;
                        } else if (j == 2) {
                                l = i;
                        }
                }
        }
        if (j < 3) {
                if (j == 1) {
                        int t = a[k];
                        a[k] = a[k - 1];
                        a[k - 1] = t;
                } else if (j == 2){
                        int t = a[k];
                        a[k] = a[l];
                        a[l] = t;
                }
                j = 0;
                for (i = 1; i < n; i++) {
                        if (a[i] < a[i - 1]) {
                                j++;
                        }
                }
                if (j == 0)
                        cout << "YES\n";
                else
                        cout << "NO\n";
        } else {
                cout << "NO\n";
        }

//        system("pause");
        return 0;
}


/*
priyanka_14
25.12.2014
A. Little Elephant and Problem

*/
#include <iostream>

using namespace std;

int main()
{
        int n, i, j, k, l;
        cin >> n;

        int a[n];
        for (i = 0; i < n; i++) {
                cin >> a[i];
        }
        j = 0;
        for (i = 1; i < n; i++) {
                if (a[i] < a[i - 1]) {
                        j++;
                        if (j == 1) {
                                k = i;
                        } else if (j == 2) {
                                l = i;
                        }
                }
        }
        if (j < 3) {
                if (j == 1) {
                        int t = a[k];
                        a[k] = a[k - 1];
                        a[k - 1] = t;
                } else {
                        int t = a[k];
                        a[k] = a[l];
                        a[l] = t;
                }
                j = 0;
                for (i = 1; i < n; i++) {
                        if (a[i] < a[i - 1]) {
                                j++;
                        }
                }
                if (j == 0)
                        cout << "YES\n";
                else
                        cout << "NO\n";
        } else {
                cout << "NO\n";
        }

//        system("pause");
        return 0;
}


/*
priyanka_14
25.12.2014
A. Little Elephant and Problem

*/
#include <iostream>

using namespace std;

int main()
{
        int n, i, j;

        cin >> n;

        int a[n];
        for (i = 0; i < n; i++) {
                cin >> a[i];
        }
        j = 0;
        for (i = 1; i < n; i++) {
                if (a[i] < a[i - 1]) {
                        j++;
                }
        }
        if (j < 3) {
                cout << "YES\n";
        } else {
                cout << "NO\n";
        }

//        system("pause");
        return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>

#define maxlongint 2147483647
#define LL long long
#define pb push_back

using namespace std;

int main()
{
    int n,a[100020];
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    a[0]=-1;a[n+1]=maxlongint;
    bool flag=true;
    for(int i=1;i<=n;i++)
        if((a[i]>=a[i-1])&&(a[i]<=a[i+1]))
            continue;
        else
            flag=false;
    if(flag)
    {
        cout<<"YES"<<endl;
//        system("pause");
        return 0;
    }
    int w1=0,w2=0;
    for(int i=1;i<=n;i++)
    {
        if((a[i]>=a[i-1])&&(a[i]>=a[i+1])&&(w1==0))w1=i;
        if((a[i]<=a[i-1])&&(a[i]<=a[i+1]))w2=i;
    }
//    cout<<w1<<" "<<w2<<endl;
    int t;
    t=a[w1];a[w1]=a[w2];a[w2]=t;
    flag=true;
    for(int i=1;i<=n;i++)
        if((a[i]>=a[i-1])&&(a[i]<=a[i+1]))
            continue;
        else
            flag=false;
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
//    system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>

#define maxlongint 2147483647
#define LL long long
#define pb push_back

using namespace std;

int main()
{
    int n,a[100020];
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    a[0]=-1;a[n+1]=maxlongint;
    int w1=0,w2=0;
    for(int i=1;i<=n;i++)
    {
        if((a[i]>a[i-1])&&(a[i]>a[i+1]))w1=i;
        if((a[i]<a[i-1])&&(a[i]<a[i+1]))w2=i;
    }
    if((w1==0)&&(w2==0))
    {
        cout<<"YES"<<endl;
        return 0;
    }
    int t;
    t=a[w1];a[w1]=a[w2];a[w2]=t;
    bool flag=true;
    for(int i=1;i<=n;i++)
        if((a[i]>a[i-1])&&(a[i]<a[i+1]))
            continue;
        else
            flag=false;
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
//    system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>

#define maxlongint 2147483647
#define LL long long
#define pb push_back

using namespace std;

int main()
{
    int n,a[100020];
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    a[0]=-1;a[n+1]=maxlongint;
    int w1=0,w2=0;
    for(int i=1;i<=n;i++)
    {
        if((a[i]>=a[i-1])&&(a[i]>=a[i+1]))w1=i;
        if((a[i]<=a[i-1])&&(a[i]<=a[i+1]))w2=i;
    }
    if((w1==0)&&(w2==0))
    {
        cout<<"YES"<<endl;
//        system("pause");
        return 0;
    }
    int t;
    t=a[w1];a[w1]=a[w2];a[w2]=t;
    bool flag=true;
    for(int i=1;i<=n;i++)
        if((a[i]>=a[i-1])&&(a[i]<=a[i+1]))
            continue;
        else
            flag=false;
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
//    system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>

#define maxlongint 2147483647
#define LL long long
#define pb push_back

using namespace std;

int main()
{
    int n,a[100020];
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    a[0]=-1;a[n+1]=maxlongint;
    int w1=0,w2=0;
    for(int i=1;i<=n;i++)
    {
        if((a[i]>=a[i-1])&&(a[i]>=a[i+1]))w1=i;
        if((a[i]<=a[i-1])&&(a[i]<=a[i+1]))w2=i;
    }
    if((w1==0)&&(w2==0))
    {
        cout<<"YES"<<endl;
        return 0;
    }
    int t;
    t=a[w1];a[w1]=a[w2];a[w2]=t;
    bool flag=true;
    for(int i=1;i<=n;i++)
        if((a[i]>a[i-1])&&(a[i]<a[i+1]))
            continue;
        else
            flag=false;
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
//    system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>

#define maxlongint 2147483647
#define LL long long
#define pb push_back

using namespace std;

int main()
{
    int n,a[100020];
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    a[0]=-1;a[n+1]=maxlongint;
    int w1=0,w2=0;
    for(int i=1;i<=n;i++)
    {
        if((a[i]>=a[i-1])&&(a[i]>=a[i+1])&&(w1==0))w1=i;
        if((a[i]<=a[i-1])&&(a[i]<=a[i+1]))w2=i;
    }
//    cout<<w1<<" "<<w2<<endl;
    if((w1==0)&&(w2==0))
    {
        cout<<"YES"<<endl;
//        system("pause");
        return 0;
    }
    int t;
    t=a[w1];a[w1]=a[w2];a[w2]=t;
    bool flag=true;
    for(int i=1;i<=n;i++)
        if((a[i]>=a[i-1])&&(a[i]<=a[i+1]))
            continue;
        else
            flag=false;
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
//    system("pause");
    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>

#define maxlongint 2147483647
#define LL long long
#define pb push_back

using namespace std;

int main()
{
    int n,a[100000],b[100000];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    int diff=0;
    for(int i=0;i<n;i++)if(a[i]!=b[i])diff++;
    if(diff<=2)cout<<"YES";else cout<<"NO";
    cout<<endl;
//    system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n) return 0;
    if (x==y)
    {
        if (a[x]>=a[y] && a[y]>=a[x-1] && a[x]<=a[y+1]) return 1;
    }
    else
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && judge(x,y))
        {
            puts("YES");
            return 0;
        }
        y=x;
        while (a[y]==a[x]) y--;
        if (judge(x+1,y+1)) puts("YES");
        else
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<30)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n || x==y) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int y=x+1;
        while (a[x+1]==a[y] && y<=n) y++;
        if (judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        y=x;
        while (a[y]==a[x] && y>=1) y--;
        if (judge(x+1,y+1)) puts("YES");
        else
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=0; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];

        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && a[y-1]<=a[x] && a[x]<=a[y+1])
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n || x==y) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && judge(x,y))
        {
            puts("YES");
            return 0;
        }
        y=x;
        while (a[y]==a[x] && y>=1) y--;
        if (judge(x+1,y+1)) puts("YES");
        else
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n || x==y) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=0; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];

        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && a[y-1]<=a[x] && a[x]<=a[y+1])
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<30)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n || x==y) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    printf("%d\n",INF);
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && judge(x,y))
        {
            puts("YES");
            return 0;
        }
        y=x;
        while (a[y]==a[x] && y>=1) y--;
        if (judge(x+1,y+1)) puts("YES");
        else
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n) return 0;
    if (x==y)
    {
        if (a[x]>=a[y] && a[y]>=a[x-1] && a[x]<=a[y+1]) return 1;
    }
    else
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && judge(x,y))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n) return 0;
    if (x==y)
    {
        if (a[x]>=a[y] && a[y]>=a[x-1] && a[x]<=a[y+1]) return 1;
    }
    else
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && judge(x,y+1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n || x==y) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];

        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && a[y-1]<=a[x] && a[x]<=a[y+1])
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<30)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n || x==y) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        y=x+1;
        while (a[x+1]==a[y] && y<=n) y++;
        if (judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        y=x;
        while (a[y]==a[x] && y>=1) y--;
        if (judge(x+1,y+1)) puts("YES");
        else
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<30)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;

bool judge(int x,int y)
{
    if (x<1 || x>n || y<1 || y>n || x==y) return 0;
    if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        return 1;
    return 0;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=-INF; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x++;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        x-=2;
        if (judge(x,y) || judge(x,y+1) || judge(x,y-1))
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && judge(x,y))
        {
            puts("YES");
            return 0;
        }
        y=x;
        while (a[y]==a[x] && y>=1) y--;
        if (judge(x+1,y+1)) puts("YES");
        else
        puts("NO");
    }
    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<30)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN] , b[MAXN];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int ans=0;
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]) , b[i]=a[i];
    sort(b+1,b+n+1);
    rep(i,1,n) ans+=(a[i]!=b[i]);
    if (ans>2) puts("NO");
    else puts("YES");

    //system("pause");
    return 0;
}


//c++  #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define INF (1<<29)
#define eps (1e-5)
#define pb push_back
using namespace std;
/*
struct Edge{
    int v,next,w;
}edge[MAXN*3];
int E,list[MAXN];
void init() {memset(list,E=-1,sizeof(list)); }
void add(int u,int v,int w)
{
    edge[++E].v=v; edge[E].w=w; edge[E].next=list[u]; list[u]=E;
}
*/
int input()
{
    int a,k=1; char c;
    while ( (c=getchar())>'9' || c<'0')
        if (c=='-') k=-1;
    a=c-'0';
    while ( (c=getchar())<='9' && c>='0') a=a*10+c-'0';
    return a*k;
}
#define MAXN 100005
int n,a[MAXN];
vector<int> b;
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d",&n);
    a[0]=0; a[n+1]=INF;
    rep(i,1,n) scanf("%d",&a[i]);
    b.clear();
    rep(i,1,n-1)
        if (a[i]>a[i+1])
            b.pb(i);
    if (b.size()==0) puts("YES");
    else
    if (b.size()>2) puts("NO");
    else
    if (b.size()==2)
    {
        int x=b[0];
        int y=b[1];
        if (a[x]<=a[y+1] && a[x]>=a[y-1]
        && a[y]<=a[x+1] && a[y]>=a[x-1])
        {
            puts("YES");
            return 0;
        }
        if (a[x]<=a[y+2] && a[x]>=a[y]
        && a[y+1]<=a[x+1] && a[y+1]>=a[x-1])
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }else
    if (b.size()==1)
    {
        int x=b[0];
        int l,r,mid,y=-1;
        l=x+1; r=n;
        while (l<=r)
        {
            mid=(l+r)>>1;
            if (a[mid]<=a[x]) l=mid+1 , y=mid;
            else r=mid-1;
        }
        if (y!=-1 && a[y-1]<=a[x] && a[x]<=a[y+1])
        {
            puts("YES");
            return 0;
        }
        puts("NO");
    }
    //system("pause");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n,i,temp,mismatch=0,x[100007],j; cin >> n;
	vector<int> a,b;
	a.reserve(100007);
	b.reserve(100007);

	for(i=0;i<n;i++) {
		cin >> temp;
		a[i] = temp;
		b[i] = temp;
	}

	//sort a
	sort(a.begin(),a.end());

	j=0;
	for(i=0;i<n;i++) {
		if(a[i]!= b[i]) { mismatch++; //x[j] = i; j++; }
	}

	// bool twoMismatch = (mismatch==2);//&&(a[x[0]]==b[x[1]]&&a[x[1]]==b[x[0]]);

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

	}
	else {
		cout << "NO\n";

	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n,i,temp,mismatch=0,x[100007],j; cin >> n;
	vector<int> a,b;
	a.reserve(100007);
	b.reserve(100007);

	for(i=0;i<n;i++) {
		cin >> temp;
		a[i] = temp;
		b[i] = temp;
	}

	//sort a
	sort(a.begin(),a.end());

	j=0;
	for(i=0;i<n;i++) {
		if(a[i]!= b[i]) { mismatch++; x[j] = i; j++; }
	}

	bool twoMismatch = (mismatch==2);//&&(a[x[0]]==b[x[1]]&&a[x[1]]==b[x[0]]);

	if(twoMismatch||mismatch==0){
		cout << "YES\n";

	}
	else {
		cout << "NO\n";

	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n,i,temp,mismatch=0,x[100007],j; cin >> n;
	vector<int> a,b;
	a.reserve(100007);
	b.reserve(100007);

	for(i=0;i<n;i++) {
		cin >> temp;
		a[i] = temp;
		b[i] = temp;
	}

	//sort a
	sort(a.begin(),a.end());

	j=0;
	for(i=0;i<n;i++) {
		if(a[i]!= b[i]) mismatch++; //x[j] = i; j++; }
	}

	// bool twoMismatch = (mismatch==2);//&&(a[x[0]]==b[x[1]]&&a[x[1]]==b[x[0]]);

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

	}
	else {
		cout << "NO\n";

	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n,i,temp,mismatch=0,x[100007],j; cin >> n;
	vector<int> a,b;
	a.reserve(100007);
	b.reserve(100007);

	for(i=0;i<n;i++) {
		cin >> temp;
		a[i] = temp;
		b[i] = temp;
	}

	//sort a
	sort(a.begin(),a.end());

	j=0;
	for(i=0;i<n;i++) {
		if(a[i]!= b[i]) { mismatch++; x[j] = i; j++; }
	}

	bool twoMismatch = (mismatch==2)&&(a[x[0]]==b[x[1]]&&a[x[1]]==b[x[0]]);

	if(twoMismatch||mismatch==0){
		cout << "YES\n";

	}
	else {
		cout << "NO\n";
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n,i,temp,mismatch=0,x[100007],j; cin >> n;
	vector<int> a,b;
	a.reserve(100007);
	b.reserve(100007);

	for(i=0;i<n;i++) {
		cin >> temp;
		a.push_back(temp);
		b.push_back(temp);
	}
// cout << a.size() << endl ;
	//sort a
	sort(a.begin(),a.end());

	j=0;
	for(i=0;i<n;i++) {
		if(a[i] != b[i]) mismatch++; //x[j] = i; j++; }
	}

	// bool twoMismatch = (mismatch==2);//&&(a[x[0]]==b[x[1]]&&a[x[1]]==b[x[0]]);
cout << mismatch << endl;
	if(mismatch<=2){
		cout << "YES\n";

	}
	else {
		cout << "NO\n";

	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n,i,temp,mismatch=0,x[100007],j; cin >> n;
	vector<int> a,b;
	a.reserve(100007);
	b.reserve(100007);

	for(i=0;i<n;i++) {
		cin >> temp;
		a.push_back(temp);
		b.push_back(temp);
	}
// cout << a.size() << endl ;
	//sort a
	sort(a.begin(),a.end());

	j=0;
	for(i=0;i<n;i++) {
		if(a[i] != b[i]) mismatch++; //x[j] = i; j++; }
	}

	// bool twoMismatch = (mismatch==2);//&&(a[x[0]]==b[x[1]]&&a[x[1]]==b[x[0]]);

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

	}
	else {
		cout << "NO\n";

	}

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long int n,arr1[100001],arr[100001],i,j,count=0,temp,flag=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr1[i]=arr[i];
		for(j=1;j<=i;j++)
		{
			if(arr[i]<arr[j])
			{
				temp=arr[i];
				arr[i]=arr[j];
				arr[j]=temp;
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		if(arr[i]!=arr1[i])
			count++;
		if(count>2)
		{
			flag=1;
			break;
		}
	}
	if(flag==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,j,count=0,flag=0;
	long int temp;
	cin>>n;
	vector <long int > arr(n+1),arr1(n+1);
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr1[i]=arr[i];
	}
	sort(arr.begin(),arr.end());
	for(i=1;i<=n;i++)
	{
		if(arr[i]!=arr1[i])
			count++;
		if(count>2)
		{
			flag=1;
			break;
		}
	}
	if(flag==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,arr1[100001],arr[100001],i,j,count=0,temp,flag=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr1[i]=arr[i];
	}
	for(i=1;i<n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			if(arr[i]>arr[j])
			{
				temp=arr[i];
				arr[i]=arr[j];
				arr[j]=temp;
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		if(arr[i]!=arr1[i])
			count++;
		if(count>2)
		{
			flag=1;
			break;
		}
	}
	if(flag==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,arr1[100001],arr[100001],i,j,count=0,temp,flag=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr1[i]=arr[i];
		for(j=1;j<=i;j++)
		{
			if(arr[i]<arr[j])
			{
				temp=arr[i];
				arr[i]=arr[j];
				arr[j]=temp;
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		if(arr[i]!=arr1[i])
			count++;
		if(count>2)
		{
			flag=1;
			break;
		}
	}
	if(flag==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,i,j,count=0,flag=0;
	cin>>n;
	long long int arr[n+1],arr1[n+1],temp;
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr1[i]=arr[i];
		for(j=1;j<=i;j++)
		{
			if(arr[i]<arr[j])
			{
				temp=arr[i];
				arr[i]=arr[j];
				arr[j]=temp;
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		if(arr[i]!=arr1[i])
			count++;
		if(count>2)
		{
			flag=1;
			break;
		}
	}
	if(flag==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;

	return 0;
}


   #include <iostream>
   #include <cstdio>
   using namespace std;

   int main()
   {
      int n;
      int i;
      int x = -1,y = -1;
      int r = 1;
      long long a[10000];
      scanf("%d", &n);
      for (i=0; i<n; i++)
        scanf("%I64d", &a[i]);
      for (i=1; i<n&&r==1; i++)
      {
        if (a[i] < a[i-1])
        {
        if(x==-1)
            x =i-1;
        else if (y==-1)
            y = i;
        else
            r=0;
        }
      }

      if (y==-1)
        printf("YES");
      else if (r==0)
        printf("NO");
      else
      {
                if ( (x==0||a[x-1]<=a[y])&&(y==(n-1)||a[x]<=a[y+1])&&(a[y]<=a[x+1])&&(a[y-1]<=a[x]) )

          printf("YES");
      else
        printf("NO");
      }

      return 0;

      }


   #include <iostream>
   #include <cstdio>
   #include <algorithm>
   using namespace std;

   int main()
   {
      int n;
      int i;
      int r = 0;
      long long a[10000];
      long long b[10000];

      scanf("%d", &n);
      for (i=0; i<n; i++){
        scanf("%I64d", &a[i]);
        b[i] = a[i];
      }

      sort(b, b+n);

      for (i=0; i<n; i++){
        if (a[i]!=b[i])
            r++;
      }

      if (r<=2)
           printf("YES");
      else
           printf("NO");

      return 0;

}


#include <iostream>
   #include <cstdio>
   #include <algorithm>
   using namespace std;

   int main()
   {
      int n;
      int i;
      int r = 0;
      int a[10000];
      int b[10000];

      scanf("%d", &n);
      for (i=0; i<n; i++){
        scanf("%d", &a[i]);
        b[i] = a[i];
      }

      sort(b, b+n);

      for (i=0; i<n; i++){
        if (a[i]!=b[i])
            r++;
      }

      if (r<=2)
           printf("YES");
      else
           printf("NO");

      return 0;

}


   #include <iostream>
   #include <cstdio>
   using namespace std;

   int main()
   {
      int n;
      int i;
      int x = -1,y = -1;
      int r = 1;
      long long a[100000];
      scanf("%d", &n);
      for (i=0; i<n; i++)
        scanf("%I64d", &a[i]);
      for (i=1; i<n&&r==1; i++)
      {
        if (a[i] < a[i-1])
        {
        if(x==-1)
            x =i-1;
        else if (y==-1)
            y = i;
        else
            r=0;
        }
      }

      if (y==-1)
        printf("YES");
      else if (r==0)
        printf("NO");
      else
      {
                if ( (x==0||a[x-1]<=a[y])&&(y==(n-1)||a[x]<=a[y+1])&&(a[y]<=a[x+1])&&(a[y-1]<=a[x]) )

          printf("YES");
      else
        printf("NO");
      }

      return 0;

      }


#include <iostream>
   #include <cstdio>
   #include <algorithm>
   using namespace std;

   int main()
   {
      int n;
      int i;
      int r = 0;
      int a[100000];
      int b[100000];

      scanf("%d", &n);
      for (i=0; i<n; i++){
        scanf("%d", &a[i]);
        b[i] = a[i];
      }

      sort(b, b+n);

      for (i=0; i<n; i++){
        if (a[i]!=b[i])
            r++;
      }

      if (r<=2)
           printf("YES");
      else
           printf("NO");

      return 0;

}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <ctime>
using namespace std;
#define SQR(x) ((x)*(x))
#define mid(x,y) (x+y)>>1
#define ll long long
#define vi vector<int>
#define sz(v) ((int)(v).size())
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define fill(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define lson i*2, x, z
#define rson i*2+1, z+1, y

#define N 1000000

int i,j,k,m,n,l;
int a[N+10], b[N+10];

int main()
{
    while (~scanf("%d", &n))
    {
        rep(i, n) scanf("%d", &a[i]);
        memcpy(b, a,sizeof(a));
        sort(b, b+n);
        k=0;
        rep(i, n) if (a[i]!=b[i]) k++;
        if (k<=2)
          puts("YES");
        else
          puts("NO");
    }
    return 0;
}


   #include <iostream>
   #include <cstdio>
   using namespace std;

   int main()
   {
      int n;
      int i;
      int x[2];
      int r = 0;
      long long a[10000];
      long long b[10000];

      scanf("%d", &n);
      for (i=0; i<n; i++){
        scanf("%I64d", &a[i]);
        b[i] = a[i];
      }

      sort(b, b+n);

      for (i=0; i<n; i++){
        if (a[i]!=b[i])
        {
            r++;
            if (r<3){
                x[r-1] = i;
            }else
                break;
        }
      }

      if (r==0 || ( r<3 &&  b[x[0]]==a[x[1]] ) )
           printf("YES");
      else
           printf("NO");

      return 0;

}


   #include <iostream>
   #include <cstdio>
   #include <algorithm>
   using namespace std;

   int main()
   {
      int n;
      int i;
      int x[2];
      int r = 0;
      long long a[10000];
      long long b[10000];

      scanf("%d", &n);
      for (i=0; i<n; i++){
        scanf("%I64d", &a[i]);
        b[i] = a[i];
      }

      sort(b, b+n);

      for (i=0; i<n; i++){
        if (a[i]!=b[i])
        {
            r++;
            if (r<3){
                x[r-1] = i;
            }else
                break;
        }
      }

      if (r==0 || ( r<3 &&  b[x[0]]==a[x[1]] ) )
           printf("YES");
      else
           printf("NO");

      return 0;

}


#include<iostream>
using namespace std;
int d,k;
int a[100000],b[100000];
int main()
{
    cin>>k;
    for (int i=0;i<k;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+k);
    for (int i=0;i<k;i++)
    {
        if (a[i]!=b[i]) d++;
    }
    if (((d==2) || (d==0)))
    {
               cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<iostream>
using namespace std;
int k,d;
int a[100000],b[100000];
int main()
{
    cin>>k;
    for (int i=0;i<k;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+k);
    for (int i=0;i<k;i++)
    {
        if (a[i]!=b[i]) d++;
    }
    if ((d==2) || (d==0))
    {
               cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int k,d;
int a[100000],b[100000];
int main()
{
    cin>>k;
    for (int i=0;i<k;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+k);
    for (int i=0;i<k;i++)
    {
        if (a[i]!=b[i]) d++;
    }
    if ((d==2) || (d==0))
    {
               cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<iostream>
using namespace std;
int d,k;
int a[100000],b[100000];
int main()
{
    cin>>k;
    for (int i=0;i<k;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+k);
    for (int i=0;i<k;i++)
    {
        if (a[i]!=b[i]) d++;
    }
    if ((d==2) || (d==0))
    {
               cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<iostream>
using namespace std;
int k,d,p;
int a[100000],b[100000];
int main()
{
    cin>>k;
    for (int i=0;i<k;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    for (int i=0;i<k;i++)
    {
        for (int j=i+1;j<k;j++)
        {
            if (b[i]>b[j])
            {
                p=b[i];
                b[i]=b[j];
                b[j]=p;
            }
        }
    }
    for (int i=0;i<k;i++)
    {
        if (a[i]!=b[i]) d++;
    }
    if ((d==2) || (d==0))
    {
               cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


#include<iostream>
using namespace std;
int n,k,d,i,x,cnt,j,a[1005][1005];
int main()
{
 int n,b;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) b++;
}
if((b>2)||(b==2)) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
main(){
unsigned int n,i,a[100005], b[100005],l=0;
cin>>n;
for(i=0;i<n; i++){
cin>>a[i];
b[i]=a[i];
}
sort(b,b+n);
for(i=0;i<n;i++)
if(a[i]!=b[i]) l++;
if(l>2) cout<<"NO"; else cout<<"YES";
}


#include<iostream>
using namespace std;
int main()
{
 int n,b,q;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) {
	b++;
	q=i;}
}
//cout<<"the values are "<<b<<" "<<q<<endl;
if(((b==1)||(q==n-2))&&(a[n-1]>a[n-3])) cout<<"YES";
else if(b==1) cout<<"NO";
else
if((b>2)||(q==n-1)) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include<iostream>
using namespace std;
int main()
{
 int n,b,q;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) {
	b++;
	q=i;}
}
if((b==1)||(q==n-1)) cout<<"NO";
else
if((b>2)||(q==n-1)) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include<iostream>
using namespace std;
int n,k,d,i,x,cnt,j,a[1005][1005];
int main()
{
 int n,b;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;int q;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) b++;
	q=i+1;
}
if((b==1)&&(a[0]>a[1])) {
	if(a[0]>a[n-1]) cout<<"YES";
	return 0;
}
if((b==1)&&(q==n-1))
{
	for(i=0;i<n-1;i++)
	{
	if(a[i]>a[q]) break;
	}
	if(a[i]==a[q-1])
	cout<<"YES";
	else cout<<"NO";
	return 0;

}
else
if(b>2) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include<iostream>
using namespace std;
int n,k,d,i,x,cnt,j,a[1005][1005];
int main()
{
 int n,b;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;int q;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) b++;
	q=i+1;
}
if((b==1)&&(q==n-1))
{
	for(i=0;i<n-1;i++)
	{
	if(a[i]>a[q]) break;
	}
	if(a[i]==a[q-1])
	cout<<"YES";
	else cout<<"NO";
	return 0;

}
else
if(b>2) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include<iostream>
using namespace std;
int main()
{
 int n,b,q;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) {
	b++;
	q=i;}
}
//cout<<"the values are "<<b<<" "<<q<<endl;
if(((b==1)||(q==n-2))&&(a[n-1]>a[n-3])) cout<<"YES";
else if((b==1)&&(a[n-1]<a[0])) cout<<"YES";
else if(b==1) cout<<"NO";
else
if((b>2)||(q==n-1)) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include<iostream>
using namespace std;
int n,k,d,i,x,cnt,j,a[1005][1005];
int main()
{
 int n,b;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) b++;
}
if(b>2) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include<iostream>
using namespace std;
int n,k,d,i,x,cnt,j,a[1005][1005];
int main()
{
 int n,b;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++) cin>>a[i];
 if(n==2){
 	cout<<"YES";
 	return 0;
 }
 b=0;
 for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1]) b++;
}
if((b>2)||(b==1)) cout<<"NO";
else cout<<"YES";
  return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    int n ,k=0;
    cin >> n;
    int *arr = new int [n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    for (int i = 0; i < n; i++){
        if (n <= 3){
            if (arr[i]>arr[n - 1]){
                n--;
                k++;
            }

        }
        else {
            if (arr[i]>arr[i + 1])
                k++;
            }
        }

    if (k<=1) cout << "YES";
    else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    int n ,k=0;
    cin >> n;
    int *arr = new int [n];
    int *arr1 = new int[n];

    for (int i = 0; i < n; i++){
        cin >> arr[i];
        arr1[i] = arr[i];
    }
    sort(arr1,arr1+n);

    for (int i = 0; i < n; i++){
        if (arr1[i]!=arr[i]) k++;

    }

    if (k<=1) cout << "YES";
    else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int SelectionSort(int *arr,int n){
    int k = 0;
    arr = new int[n];
    for (int i = 0; i < n; i++){
        for (int j = i; j < n; j++){
            if (arr[i] > arr[j]){
                swap(arr[i], arr[j]);
                k++;
                if (k > 1) break;
            }
            if (k > 1) break;
        }
    }
    return k;
}
int main(){
    int n ,k=0;
    cin >> n;
    int *arr = new int [n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    for (int i = 0; i < n; i++){
        if (arr[i]>arr[n-1]){
            n--;
            k++;
            if (k > 1) break;
        }

    }

    if (k<=1) cout << "YES";
    else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    int n ,k=0;
    cin >> n;
    int *arr = new int [n];
    int *arr1 = new int[n];

    for (int i = 0; i < n; i++){
        cin >> arr[i];
        arr1[i] = arr[i];
    }
    sort(arr1,arr1+n);

    for (int i = 0; i < n; i++){
        if (arr1[i]!=arr[i]) k++;

    }

    if (k<=2) cout << "YES";
    else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    int n ,k=0;
    cin >> n;
    int *arr = new int [n];
    int *arr1 = new int[n];

    for (int i = 0; i < n; i++){
        cin >> arr[i];
        arr1[i] = arr[i];
    }
    sort(arr1,arr1+n);

    for (int i = 0; i < n; i++){
        if (arr1[i]>arr[i]) k++;

    }

    if (k<=1) cout << "YES";
    else cout << "NO";

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
    int n ,k=0;
    cin >> n;
    int *arr = new int [n];
    int *arr1 = new int[n];

    for (int i = 0; i < n; i++){
        cin >> arr[i];
        arr1[i] = arr[i];
    }
    sort(arr1,arr1+n);

    for (int i = 0; i < n; i++){
        if (arr[i]>arr1[i]) k++;

    }

    if (k<=1) cout << "YES";
    else cout << "NO";

    return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,a[100010],b[100010];

int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)b[i]=a[i];
	sort(b,b+n);
	int c=0;
	rep(i,n)c+=a[i]!=b[i];
	cout<<(c<=2?"YES":"NO");
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,a[100010];

int main(){
	cin>>n;
	a[0]=-INF;
	rep(i,n)cin>>a[i+1];
	a[n+1]=INF;
	int c1=0,c2=0;
	vi v;
	rep(i,n+1)if(a[i]>a[i+1]){
		v.pb(i);
		v.pb(i+1);
	}
	if(v.sz==0){cout<<"YES";return 0;}
	if(v.sz>=6){cout<<"NO";return 0;}
	if(v.sz==4)rep(i,v.sz)rep(j,v.sz){
		swap(a[v[i]],a[v[j]]);
		rep(k,n+1)if(a[k]>a[k+1])goto fail;
		//cout<<i<<" "<<j<<endl;
		cout<<"YES";
		return 0;
		fail:;
		swap(a[v[i]],a[v[j]]);
	}
	if(v.sz==2){
		rep(i,v.sz){
			int num=a[v[i]];
			int bef=a[v[i]-1],aft=a[v[i]+1];
			rep2(j,1,n+1){
				if(a[j-1]<=num && num<=a[j+1] && bef<=a[j] && a[j]<=aft){
					cout<<"YES";return 0;
				}
			}
		}
	}
	cout<<"NO";
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,a[100010];

int main(){
	cin>>n;
	a[0]=-INF;
	rep(i,n)cin>>a[i+1];
	a[n+1]=INF;
	int c1=0,c2=0;
	vi v;
	rep(i,n+1)if(a[i]>a[i+1]){
		v.pb(i);
		v.pb(i+1);
	}
	if(v.sz==0){cout<<"YES";return 0;}
	if(v.sz>=6){cout<<"NO";return 0;}
	if(v.sz==4)rep(i,v.sz)rep(j,v.sz){
		swap(a[v[i]],a[v[j]]);
		rep(k,n+1)if(a[k]>a[k+1])goto fail;
		//cout<<i<<" "<<j<<endl;
		cout<<"YES";
		return 0;
		fail:;
		swap(a[v[i]],a[v[j]]);
	}
	if(v.sz==2){
		rep(i,v.sz){
			rep2(j,1,n+1){
				swap(a[v[i]],a[j]);
				if(a[v[i]-1]<=a[v[i]] && a[v[i]]<=a[v[i]+1]
					&& a[j-1]<=a[j] && a[j]<=a[j+1]){
					cout<<"YES";return 0;
				}
				swap(a[v[i]],a[j]);
			}
		}
	}
	cout<<"NO";
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,a[100010];

int main(){
	cin>>n;
	a[0]=-INF;
	rep(i,n)cin>>a[i+1];
	a[n+1]=INF;
	int c1=0,c2=0;
	vi v;
	rep(i,n+1)if(a[i]>a[i+1]){
		v.pb(i);
		v.pb(i+1);
	}
	if(v.sz==0){cout<<"YES";return 0;}
	if(v.sz>=12){cout<<"NO";return 0;}
	if(v.sz>2)rep(i,v.sz)rep(j,v.sz){
		swap(a[v[i]],a[v[j]]);
		rep(k,n+1)if(a[k]>a[k+1])goto fail;
		//cout<<i<<" "<<j<<endl;
		cout<<"YES";
		return 0;
		fail:;
		swap(a[v[i]],a[v[j]]);
	}
	if(v.sz==2){
		rep(i,v.sz){
			rep2(j,1,n+1){
				swap(a[v[i]],a[j]);
				if(a[v[i]-1]<=a[v[i]] && a[v[i]]<=a[v[i]+1]
					&& a[j-1]<=a[j] && a[j]<=a[j+1]){
					cout<<"YES";return 0;
				}
				swap(a[v[i]],a[j]);
			}
		}
	}
	cout<<"NO";
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,a[100010];

int main(){
	cin>>n;
	a[0]=-INF;
	rep(i,n)cin>>a[i+1];
	a[n+1]=INF;
	int c1=0,c2=0;
	vi v;
	rep(i,n+1)if(a[i]>a[i+1]){
		v.pb(i);
		v.pb(i+1);
	}
	if(v.sz==0){cout<<"YES";return 0;}
	if(v.sz>=12){cout<<"NO";return 0;}
	if(v.sz>2)rep(i,v.sz)rep(j,v.sz){
		swap(a[v[i]],a[v[j]]);
		rep(k,n+1)if(a[k]>a[k+1])goto fail;
		//cout<<i<<" "<<j<<endl;
		cout<<"YES";
		return 0;
		fail:;
		swap(a[v[i]],a[v[j]]);
	}
	if(v.sz==2){
		rep(i,v.sz){
			int num=a[v[i]];
			int bef=a[v[i]-1],aft=a[v[i]+1];
			rep2(j,1,n+1){
				if(a[j-1]<=num && num<=a[j+1] && bef<=a[j] && a[j]<=aft){
					cout<<"YES";return 0;
				}
			}
		}
	}
	cout<<"NO";
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,a[100010];

int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	int c1=0,c2=0;
	vi v;
	rep(i,n-1)if(a[i]>a[i+1]){
		v.pb(i);
		v.pb(i+1);
	}
	if(v.sz==0){cout<<"YES";return 0;}
	if(v.sz>=6){cout<<"NO";return 0;}
	rep(i,v.sz)rep2(j,i+1,v.sz){
		swap(a[v[i]],a[v[j]]);
		rep(k,n-1)if(a[k]>a[k+1])goto fail;
		//cout<<i<<" "<<j<<endl;
		cout<<"YES";
		return 0;
		fail:;
		swap(a[v[i]],a[v[j]]);
	}
	cout<<"NO";
}


#include<iostream>
#include<cstdio>
using namespace std;

long b[100002],a[100002];

void qsort(long l,long r)
{
     long i=l,j=r,k,z;
     z=a[(l+r)/2];
     do
     {
          while (a[i]<z) ++i;
          while (a[j]>z) --j;
          if (i<=j)
          {
              k=a[i];a[i]=a[j];
              a[j]=k;++i;--j;
          }
     }while (i<=j);
     if (i<r) qsort(i,r);
     if (j>l) qsort(l,j);
}

int main()
{
    long i,n;
    scanf("%d",&n);
    for (i=0;i<n;++i)
    {
          scanf("%d",&a[i]);
          b[i]=a[i];
    }
    qsort(0,n-1);
    long ans=0;
    for (i=0;i<n;++i)
      if (a[i]!=b[i])
      {
          ++ans;
          if (ans==3) break;
      }
    if (ans>2) printf("NO\n");
      else printf("YES\n");
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int a[100005],b[100005];

void qsort(int l,int r)
{
     int i=l,j=r,k,z=a[(l+r)/2];
     while(i<=j)
     {
         while(a[i]<z) ++i;
         while(a[j]>z) --j;
         if (i<=j)
         {
              k=a[i];a[i]=a[j];a[j]=k;
              ++i;--j;
         }
     }
     if (i<r) qsort(i,r);
     if (j>l) qsort(l,j);
}

int main()
{
    int k,ans=0,t,i,j,n;
    scanf("%d",&n);
    for (i=1;i<=n;++i)
    {
         scanf("%d",&a[i-1]);
         b[i-1]=a[i-1];
    }
    qsort(0,n-1);
    for (i=0;i<n;++i)
    {
         if (a[i]!=b[i]) ++ans;
         if (ans>2) break;
    }
    if (ans<=2) cout <<"YES\n";
      else cout <<"NO\n";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<ctime>
#include<cstdlib>
using namespace std;

long n,b[100002],a[100002];

void qsort(long l,long r)
{
     long i=l,j=r,k,z;
     z=l+rand()%(r-l+1);
     z=a[z];
     do
     {
          while (a[i]<z) ++i;
          while (a[j]>z) --j;
          if (i<=j)
          {
              k=a[i];a[i]=a[j];
              a[j]=k;++i;--j;
          }
     }while (i<=j);
     if (i<r) qsort(i,r);
     if (j>l) qsort(l,j);
}

int main()
{
    long i;
    srand(time(NULL));
    scanf("%d",&n);
    for (i=0;i<n;++i)
    {
          scanf("%d",&a[i]);
          b[i]=a[i];
    }
    qsort(0,n-1);
    long ans=0;
    for (i=0;i<n;++i)
      if (a[i]!=b[i])
      {
          ++ans;
          if (ans==3) break;
      }
    if (ans>2) printf("NO\n");
      else printf("YES\n");
    return 0;
}


#include<iostream>
using namespace std;
int main()
{

       int n,ans=0,s,i;
       cin>>n;

       int a[100005];
       for(i=1;i<=n;i++)
         cin>>a[i];
       for(i=1;i<n;i++)
       {
           if(a[i]>a[i+1])
              ans++;
           if(ans==1)
           s=i;
           if(ans==2)
             if(a[i+1]>a[s-1])
              ans++;
           if(ans==3) break;
        }
        if(ans==3) cout<<"YES";
          else cout<<"NO";

    return 0;
}


#include<iostream>
#include<cstdio>
#include<ctime>
using namespace std;

long n,b[100002],a[100002];

void qsort(long l,long r)
{
     long i=l,j=r,k,z;
     z=l+rand()%(r-l+1);
     z=a[z];
     do
     {
          while (a[i]<z) ++i;
          while (a[j]>z) --j;
          if (i<=j)
          {
              k=a[i];a[i]=a[j];
              a[j]=k;++i;--j;
          }
     }while (i<=j);
     if (i<r) qsort(i,r);
     if (j>l) qsort(l,j);
}

int main()
{
    long i;
    srand(time(NULL));
    scanf("%d",&n);
    for (i=0;i<n;++i)
    {
          scanf("%d",&a[i]);
          b[i]=a[i];
    }
    qsort(0,n-1);
    long ans=0;
    for (i=0;i<n;++i)
      if (a[i]!=b[i])
      {
          ++ans;
          if (ans==3) break;
      }
    if (ans>2) printf("NO\n");
      else printf("YES\n");
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int b[100002],a[100002];

void qsort(int l,int r)
{
     int i=l,j=r,k,z;
     z=a[(l+r)/2];
     do
     {
          while (a[i]<z) ++i;
          while (a[j]>z) --j;
          if (i<=j)
          {
              k=a[i];a[i]=a[j];
              a[j]=k;++i;--j;
          }
     }while (i<=j);
     if (i<r) qsort(i,r);
     if (j>l) qsort(l,j);
}

int main()
{
    int i,n;
    scanf("%d",&n);
    for (i=0;i<n;++i)
    {
          scanf("%d",&a[i]);
          b[i]=a[i];
    }
    qsort(0,n-1);
    int ans=0;
    for (i=0;i<n;++i)
      if (a[i]!=b[i])
      {
          ++ans;
          if (ans==3) break;
      }
    if (ans>2) printf("NO\n");
      else printf("YES\n");
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int b[100002],a[100002];

void qsort(int l,int r)
{
     int i=l,j=r,k,z;
     z=a[(l+r)/2];
     do
     {
          while (a[i]<z) ++i;
          while (a[j]>z) --j;
          if (i<=j)
          {
              k=a[i];a[i]=a[j];
              a[j]=k;++i;--j;
          }
     }while (i<=j);
     if (i<r) qsort(i,r);
     if (j>l) qsort(l,j);
}

int main()
{
    int i,n;
    cin >>n;
    for (i=0;i<n;++i)
    {
          scanf("%d",&a[i]);
          b[i]=a[i];
    }
    qsort(0,n-1);
    int ans=0;
    for (i=0;i<n;++i)
      if (a[i]!=b[i])
      {
          ++ans;
          if (ans==3) break;
      }
    if (ans>2) cout <<"NO" <<endl;
      else cout <<"YES" <<endl;
    return 0;
}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 111111

int a[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n;

	int flag=0,j;

	gn(n);

	for(int i=0;i<n;i++) gn(a[i]);

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

		if(a[i]<a[i-1]) {flag=1; j=i;break;}

	}

	if(flag==0) return puts("YES");

	flag=0;

	swap(a[j],a[j-1]);

	for(int i=1;i<n;i++)	if(a[i]<a[i-1]) {flag=1; break;}

	if(flag) puts("NO");

	else puts("YES");

	}

}


#include <bits/stdc++.h>

using namespace std;

#define NN 100100

int a[NN], b[NN];

int main(){

int n;

cin >> n;

for(int i=0; i<n; i++) scanf("%d", a+i), b[i]=a[i];

sort(b, b+i);

int cnt=0;

for(int i=0; i<n; i++) cnt+=a[i]!=b[i];

puts(cnt <=2 ? "YES" : "NO");

}


#include <bits/stdc++.h>

using namespace std;

#define NN 100100

int a[NN], b[NN];

int main(){

int n;

cin >> n;

for(int i=0; i<n; i++) scanf("%d", a+i), b[i]=a[i];

sort(b, b+n);

int cnt=0;

for(int i=0; i<n; i++) cnt+=a[i]!=b[i];

puts(cnt<=2 ? "YES" : "NO");

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

int power(int a, int b, int m, int ans=1) {

	for(; b; b>>=1, a=(INT)a*a%m) if(b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 100010

int a[NN], b[NN];

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n;

	gn(n);

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

		gn(a[i]);

		b[i]=a[i];

	}

	sort(a, a+n);

	int num=0;

	for(int i=0; i<n; i++) if(a[i]!=b[i]) {

		num++;

	}

	if(num>2) puts("NO");

	else puts("YES");

}


#include<bits/stdc++.h>

#define NN 111111

using namespace std;

int a[NN],cmp[NN];

int main(){

	int n,cnt=0;

	scanf("%d",&n);

	for(int i=0;i<n;i++) scanf("%d",&a[i]);

	for(int i=0;i<n;i++) cmp[i]=a[i];

	sort(cmp,cmp+n);

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

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

	}

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

	else printf("YES");

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define INF 0x3f3f3f3f3f3f3f3fLL

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctzl(x) (__builtin_ctzll(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

int power(int a, int b, int m, int ans=1) {

	for(; b; b>>=1, a=(INT)a*a%m) if(b&1) ans=(INT)ans*a%m;

	return ans;

}

#define NN 100010

int a[NN], b[NN];

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n;

	gn(n);

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

		gn(a[i]);

		b[i]=a[i];

	}

	sort(a, a+n);

	int num=0;

	for(int i=0; i<n; i++) if(a[i]!=b[i]) {

		num++;

	}

	if(num>=2) puts("NO");

	else puts("YES");

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define mp make_pair

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

inline void gn(long long&x){

	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');

	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;

}

inline void gn(int&x){long long t;gn(t);x=t;}

inline void gn(unsigned long long&x){long long t;gn(t);x=t;}

inline void gn(double&x){double t;scanf("%lf",&t);x=t;}

inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

int a[100010],b[100010];

int main(){

	int n, cnt=0;

	scanf("%d", &n);

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

		scanf("%d", a+i);

		b[i]=a[i];

	}

	sort(a, a+n);

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

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

	if(cnt<3) puts("YES");

	else puts("NO");

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 111111

int a[NN],b[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n;

	int flag=0,x,y;

	int cnt=0;

	gn(n);

	for(int i=0;i<n;i++) gn(a[i]),b[i]=a[i];

	sort(b,b+n);

	for(int i=0;i<n;i++)	if(a[i]!=b[i]) cnt++;

	if(cnt>2) return puts("NO");

	return puts("YES");

}


#include<bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<class T>inline void printsp(T x) {print(x); putchar(' ');}

template<class T>inline void println(T x) {print(x); putchar('\n');}

template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}

template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 111111

int a[NN];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n;

	int flag=0,j;

	gn(n);

	for(int i=0;i<n;i++) gn(a[i]);

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

		if(a[i]<a[i-1]) {flag=1; j=i;break;}

	}

	if(flag==0) return puts("YES");

	flag=0;

	swap(a[j],a[j-1]);

	for(int i=1;i<n;i++)	if(a[i]<a[i-1]) {flag=1; break;}

	if(flag) puts("NO");

	else puts("YES");

}


#include <stdio.h>
#include <algorithm>

int	a[110000],b[110000];

int main()
{
	int max = -1,maxp;
	int n;
	scanf("%d",&n);

	for(int i = 0;i<n;i++)
	{
		scanf("%d",a+i);
		b[i] = a[i];
	}

	std::sort(a,a+n);

	int temp = 0;
	for(int i =0;i<n;i++)
	{
		if(a[i] != b[i])
			temp++;
	}

	if(temp == 2|| temp == 0)
		printf("YES");
	else
		printf("NO");
	return 0;
}


#include <stdio.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int n = 0;
while(scanf("%d",&n)!=EOF){
	int num[100001],num1[100001];
	int i = 0;
	int sum = 0;
	for(i=0;i<n;i++){
		scanf("%d",&num[i]);
		num1[i] = num[i];
	}

	int j = 0;
	for(j=0;j<n;j++){
	for(i=0;i<n-1;i++){
		if(num[i]>num[i+1]){
			int s = num[i];
			num[i] = num[i+1];
			num[i+1] = s;
		}
	}
	}

		for(i=0;i<n;i++){
		if(num[i]!=num1[i]){
			sum++;
		}
	}

	if(sum<=2){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

}
	return 0;
}


#include<stdio.h>
#include<algorithm>
#define N 100010
int a[N],b[N];
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int i;
		for(i=1;i<=n;i++){
			scanf("%d",&a[i]);
			b[i]=a[i];
			}
		std::sort(b+1,b+n+1);
		int res=0;
		for(i=1;i<=n;i++)if(a[i]!=b[i])res++;
	//	printf("%d\n",res);
		if(res==2||res==0)printf("YES\n");
		else printf("NO\n");
		}
	return 0;
	}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int n[100010]={0};
int q[100010]={0};
int tempArr[3]={0};

int comp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}

int main()
{
	int i;
	int m;
	int j,k;
	int tmp=0;
	scanf("%d",&m);
	for(i=0;i<m;i++)
	{
		scanf("%d",&n[i]);
		q[i]=n[i];
	}
	qsort(n,m,sizeof(int),comp);
	for(i=0;i<m;i++)
	{
		if(n[i]!=q[i])
		{
			if(tmp>=2)
			{
				printf("NO\n");
				return 0;
			}
			tempArr[tmp]=i;
			tmp++;
		}
	}

	// tmp == 0 or 1
	if(tmp==0)
	{
		printf("YES\n");
	}
	else
	{
		j=tempArr[0];k=tempArr[1];
		if(q[j]==n[k]||n[j]==q[k])
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int a[100000], b[100000];

int main()
{
    int i;
    int n, temp;
    cin >> n;
    for( i = 0; i < n; i++ )
    {
        scanf( "%d", &a[i] );
        b[i] = a[i];
    }
    sort( a, a + n );
    temp = 0;
    for( i = 0; i < n; i++ )
    {
        if( a[i] != b[i] )
            temp++;
        if( temp > 2 )
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}