#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iterator>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <stdio.h>
#include <cstring>

#define ii <int , int>

#define mp make_pair
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define sz(v) (int)v.size()
#define X first
#define Y second

#define Pi(x) printf("%d ", (x))
#define Pii(x, y) printf("%d %d ", (x), (y))
#define Piii(x, y, z) printf("%d %d %d", (x), (y), (z))
#define Pl(x) printf("%I64d ", (x))
#define Pll(x, y) printf("%I64d I64d ", (x), (y))
#define Plll(x, y, z) printf("%I64d I64d I64d ", (x), (y), (z))
#define Ps(x) printf("%s", (x))
#define Pe() printf("\n")
#define Pe1(i) for (int j = 0; j < i; j++) printf(" ")

#define Si(x) scanf("%d",&x)
#define Sii(x, y) scanf("%d %d", (&x), (&y))
#define Siii(x, y, z) scanf("%d %d %d", (&x), (&y), (&z))
#define Sl(x) scanf("%I64d", (&x))
#define Sll(x, y) scanf("%I64d %I64d", (&x), (&y))
#define Slll(x, y, z) scanf("%I64d %I64d %I64d", (&x), (&y), (&z))
#define Ss(x) scanf("%s", (&x))

using namespace std;

typedef long long ll;
typedef vector<int > vi;
typedef vector<vi> vvi;
typedef pair ii pii;
typedef vector <pii> vii;
typedef map ii mii;
typedef set <int > si;
typedef multiset <int > msi;
typedef multimap <int , int> mmi;
typedef vector <ll> vl;
typedef pair<ll, ll> pll;
typedef vector <pll> vll;

const ll nInf = -1000000000;
const ll pInf = 1000000000;
const ll mod    = 1000000007;
const int MAXN = 1e6 + 10;

void getdata();
void preproc();
void solve();
char s[MAXN];
int n;

int main()
{
	//freopen( "input.txt", "r" , stdin);
	//freopen( "output.txt", "w" , stdout);
	int t = 1;
	//scanf("%d", &t);
	for (int i = 0;i < t; i++)
	{
		getdata();
		preproc();
		solve();
	}
	return 0;
}

void getdata()
{
	scanf("%s", &s);
	n = strlen(s);
}

void preproc()
{

}

void solve()
{
	int bal = 0;
	int f = 0;
	int am = 1;
	int maxres = 0;
	si pos;
	for (int i = 0;i < n; i++)
	{
		if (s[i] == ')') bal--;
		else bal++;
		if (bal < 0)
		{
			pos.clear();
			bal = 0;
			f = i + 1;
		}
		else if (bal >= 0)
		{
			if (s[i] == '(')
			{
				pos.insert(i);
			}
			else
			{
				si::iterator it = pos.end();
				it--;
				int curres = i - (*it) + 1;
				if (maxres < curres)
				{
					maxres = curres;
					am = 1;
				}
				else if (maxres == curres)
				{
					am++;
				}
				pos.erase(it);
			}
		}
	}
	printf("%d %d\n", maxres, am);
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iterator>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <stdio.h>
#include <cstring>

#define ii <int , int>

#define mp make_pair
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define sz(v) (int)v.size()
#define X first
#define Y second

#define Pi(x) printf("%d ", (x))
#define Pii(x, y) printf("%d %d ", (x), (y))
#define Piii(x, y, z) printf("%d %d %d", (x), (y), (z))
#define Pl(x) printf("%I64d ", (x))
#define Pll(x, y) printf("%I64d I64d ", (x), (y))
#define Plll(x, y, z) printf("%I64d I64d I64d ", (x), (y), (z))
#define Ps(x) printf("%s", (x))
#define Pe() printf("\n")
#define Pe1(i) for (int j = 0; j < i; j++) printf(" ")

#define Si(x) scanf("%d",&x)
#define Sii(x, y) scanf("%d %d", (&x), (&y))
#define Siii(x, y, z) scanf("%d %d %d", (&x), (&y), (&z))
#define Sl(x) scanf("%I64d", (&x))
#define Sll(x, y) scanf("%I64d %I64d", (&x), (&y))
#define Slll(x, y, z) scanf("%I64d %I64d %I64d", (&x), (&y), (&z))
#define Ss(x) scanf("%s", (&x))

using namespace std;

typedef long long ll;
typedef vector<int > vi;
typedef vector<vi> vvi;
typedef pair ii pii;
typedef vector <pii> vii;
typedef map ii mii;
typedef set <int > si;
typedef multiset <int > msi;
typedef multimap <int , int> mmi;
typedef vector <ll> vl;
typedef pair<ll, ll> pll;
typedef vector <pll> vll;

const ll nInf = -1000000000;
const ll pInf = 1000000000;
const ll mod    = 1000000007;
const int MAXN = 1e6 + 10;

void getdata();
void preproc();
void solve();
char s[MAXN];
int n;

int main()
{
	//freopen( "input.txt", "r" , stdin);
	//freopen( "output.txt", "w" , stdout);
	int t = 1;
	//scanf("%d", &t);
	for (int i = 0;i < t; i++)
	{
		getdata();
		preproc();
		solve();
	}
	return 0;
}

void getdata()
{
	scanf("%s", &s);
	n = strlen(s);
}

void preproc()
{

}

void solve()
{
	int bal = 0;
	int f = 0;
	int l = -1;
	int lastlen = 0;
	int am = 1;
	int maxres = 0;
	si pos;
	int len[MAXN];

	fill(len, len + MAXN, 0);
	for (int i = 0;i < n; i++)
	{
		if (s[i] == ')') bal--;
		else bal++;
		if (bal < 0)
		{
			pos.clear();
			bal = 0;
			f = -1;
		}

		else if (bal > 0)
		{
			if (s[i] == '(')
			{
				pos.insert(i);
			}
			else
			{
				si::iterator it = pos.end();
				it--;
				int curres = i - (*it) + 1;
				curres += len[i - curres];
				len[i] = curres;
				if (maxres < curres)
				{
					maxres = curres;
					am = 1;
				}
				else if (maxres == curres)
				{
					am++;
				}
				pos.erase(it);
			}
		}
		else if (bal == 0)
		{
				si::iterator it = pos.end();
				it--;
				if (f == -1)
					f = (*it);
				else
					f = min((*it), f);
				int curres = i - f + 1;

				if (maxres < curres)
				{
					maxres = curres;
					am = 1;
				}
				else if (maxres == curres)
				{
					am++;
				}
				pos.erase(it);
				l = i;
				lastlen = l - f + 1;
				len[i] = l - f + 1;
		}
	}
	printf("%d %d\n", maxres, am);
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iterator>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <stdio.h>
#include <cstring>

#define ii <int , int>

#define mp make_pair
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define sz(v) (int)v.size()
#define X first
#define Y second

#define Pi(x) printf("%d ", (x))
#define Pii(x, y) printf("%d %d ", (x), (y))
#define Piii(x, y, z) printf("%d %d %d", (x), (y), (z))
#define Pl(x) printf("%I64d ", (x))
#define Pll(x, y) printf("%I64d I64d ", (x), (y))
#define Plll(x, y, z) printf("%I64d I64d I64d ", (x), (y), (z))
#define Ps(x) printf("%s", (x))
#define Pe() printf("\n")
#define Pe1(i) for (int j = 0; j < i; j++) printf(" ")

#define Si(x) scanf("%d",&x)
#define Sii(x, y) scanf("%d %d", (&x), (&y))
#define Siii(x, y, z) scanf("%d %d %d", (&x), (&y), (&z))
#define Sl(x) scanf("%I64d", (&x))
#define Sll(x, y) scanf("%I64d %I64d", (&x), (&y))
#define Slll(x, y, z) scanf("%I64d %I64d %I64d", (&x), (&y), (&z))
#define Ss(x) scanf("%s", (&x))

using namespace std;

typedef long long ll;
typedef vector<int > vi;
typedef vector<vi> vvi;
typedef pair ii pii;
typedef vector <pii> vii;
typedef map ii mii;
typedef set <int > si;
typedef multiset <int > msi;
typedef multimap <int , int> mmi;
typedef vector <ll> vl;
typedef pair<ll, ll> pll;
typedef vector <pll> vll;

const ll nInf = -1000000000;
const ll pInf = 1000000000;
const ll mod    = 1000000007;
const int MAXN = 1e2 + 10;

void getdata();
void preproc();
void solve();
char s[MAXN];
int n;

int main()
{
	//freopen( "input.txt", "r" , stdin);
	//freopen( "output.txt", "w" , stdout);
	int t = 1;
	//scanf("%d", &t);
	for (int i = 0;i < t; i++)
	{
		getdata();
		preproc();
		solve();
	}
	return 0;
}

void getdata()
{
	scanf("%s", &s);
	n = strlen(s);
}

void preproc()
{

}

void solve()
{
	int bal = 0;
	int f = 0;
	int am = 1;
	int maxres = 0;
	si pos;
	for (int i = 0;i < n; i++)
	{
		if (s[i] == ')') bal--;
		else bal++;
		if (bal < 0)
		{
			pos.clear();
			bal = 0;
			f = i + 1;
		}
		else if (bal >= 0)
		{
			if (s[i] == '(')
			{
				pos.insert(i);
			}
			else
			{
				si::iterator it = pos.end();
				it--;
				int curres = i - (*it) + 1;
				if (maxres < curres)
				{
					maxres = curres;
					am = 1;
				}
				else if (maxres == curres)
				{
					am++;
				}
				pos.erase(it);
			}
		}
	}
	printf("%d %d\n", maxres, am);
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iterator>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <stdio.h>
#include <cstring>

#define ii <int , int>

#define mp make_pair
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define sz(v) (int)v.size()
#define X first
#define Y second

#define Pi(x) printf("%d ", (x))
#define Pii(x, y) printf("%d %d ", (x), (y))
#define Piii(x, y, z) printf("%d %d %d", (x), (y), (z))
#define Pl(x) printf("%I64d ", (x))
#define Pll(x, y) printf("%I64d I64d ", (x), (y))
#define Plll(x, y, z) printf("%I64d I64d I64d ", (x), (y), (z))
#define Ps(x) printf("%s", (x))
#define Pe() printf("\n")
#define Pe1(i) for (int j = 0; j < i; j++) printf(" ")

#define Si(x) scanf("%d",&x)
#define Sii(x, y) scanf("%d %d", (&x), (&y))
#define Siii(x, y, z) scanf("%d %d %d", (&x), (&y), (&z))
#define Sl(x) scanf("%I64d", (&x))
#define Sll(x, y) scanf("%I64d %I64d", (&x), (&y))
#define Slll(x, y, z) scanf("%I64d %I64d %I64d", (&x), (&y), (&z))
#define Ss(x) scanf("%s", (&x))

using namespace std;

typedef long long ll;
typedef vector<int > vi;
typedef vector<vi> vvi;
typedef pair ii pii;
typedef vector <pii> vii;
typedef map ii mii;
typedef set <int > si;
typedef multiset <int > msi;
typedef multimap <int , int> mmi;
typedef vector <ll> vl;
typedef pair<ll, ll> pll;
typedef vector <pll> vll;

const ll nInf = -1000000000;
const ll pInf = 1000000000;
const ll mod    = 1000000007;
const int MAXN = 1e6 + 10;

void getdata();
void preproc();
void solve();
char s[MAXN];
int n;

int main()
{
	//freopen( "input.txt", "r" , stdin);
	//freopen( "output.txt", "w" , stdout);
	int t = 1;
	//scanf("%d", &t);
	for (int i = 0;i < t; i++)
	{
		getdata();
		preproc();
		solve();
	}
	return 0;
}

void getdata()
{
	scanf("%s", &s);
	n = strlen(s);
}

void preproc()
{

}

void solve()
{
	int bal = 0;
	int f = 0;
	int am = 1;
	int maxres = 0;
	si pos;
	for (int i = 0;i < n; i++)
	{
		if (s[i] == ')') bal--;
		else bal++;
		if (bal < 0)
		{
			pos.clear();
			bal = 0;
			f = i + 1;
		}
		else if (bal >= 0)
		{
			if (s[i] == '(')
			{
				pos.insert(i);
			}
			else
			{
				si::iterator it = pos.end();
				it--;
				f = min((*it), f);
				int curres = i - f + 1;

				if (maxres < curres)
				{
					maxres = curres;
					am = 1;
				}
				else if (maxres == curres)
				{
					am++;
				}
				pos.erase(it);
			}
		}
	}
	printf("%d %d\n", maxres, am);
}


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

char str[1000005];
int top, ans, s[1000005], count;

int main() {
	while(gets(str+1) ) {
		int L = strlen(str+1);
		top = 1; count = 0;  ans = 0;
		s[0] = 0;
		for(int i = 1; i <= L; i ++) {
			if(str[i] == '(' || top == 1) {
				s[top++] = i;
			}else if(str[i] == ')') {
				if(str[s[top-1]] == '(') {
					top --;
				} else {
					s[top++] = i;
				}
			}
		}
		s[top] = L + 1;
		for(int i = 0; i < top; i ++) {
			if( ans == s[i+1] - s[i] - 1 ) {
				count ++;
			}
			if(ans < s[i+1] - s[i] - 1 ) {
				ans = s[i+1] - s[i] - 1;
				count = 1;
			}
		}
		if(count == 0) {
			ans = 0, count = 1;
		}
		printf("%d %d\n", ans, count);
	}
}


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

char str[1000005];
int top, ans, s[1000005], count;

int main() {
    while(gets(str+1) ) {
        int L = strlen(str+1);
        top = 1; count = 0;  ans = 0;
        s[0] = 0;
        for(int i = 1; i <= L; i ++) {
            if(str[i] == '(' || top == 1) {
                s[top++] = i;
            }else if(str[i] == ')') {
                if(str[s[top-1]] == '(') {
                    top --;
                } else {
                    s[top++] = i;
                }
            }
        }
        s[top] = L + 1;
        for(int i = 0; i < top; i ++) {
            if( s[i+1] - s[i] > 1 ) {
                count ++;
            }
            if(ans < s[i+1] - s[i] - 1 )
                ans = s[i+1] - s[i] - 1;
        }
        if(count == 0) {
            ans = 0, count = 1;
        }
        printf("%d %d\n", ans, count);
    }
}


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

char str[1000001];
int top, maxx, count, flag, s[1000001], depth;
int times[1000001];

int main() {
    while(gets(str+1) ) {
        int L = strlen(str+1);
        top = 1; depth = -1; count = 0; flag = 0;
        memset(times, 0, sizeof(times));
        s[0] = 0;
        for(int i = 1; i <= L; i ++) {
            if(str[i] == '(') {
                s[top++] = i;
            }else if(str[i] == ')') {
                if(str[s[top-1]] == '(') {
                    if(depth < i - s[top-1] + 1)
                        depth = i - s[top-1] + 1;
                    top --;
                    times[s[top-1]] ++;
                }
            }
            //printf("d = %d\n", depth);
//          for(int j = 1; j < top; j ++) {
//              printf("%c", str[s[j]]);
//          }puts("");
        }
        for(int i = 0; i < top; i ++) {
            count += times[s[i]];
        }
        if(count == 0) {
            depth = 0, count = 1;
        }
        printf("%d %d\n", depth, count);
    }
}


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

#define N 1000005

char s[N];
int num[N];

int main()
{
    scanf("%s",s);
    int sum=0,i,len=strlen(s);

    for(i=0;i<len;i++)
    {
             if(s[i]==')')sum--;
        else if(s[i]=='(')
        {
              if(sum>=0)
              {
                 sum++;
              }
              else
              {
                  sum=1;
              }
        }

        num[i]=sum;
        //printf("%d ",sum);
    }

    int ans=0,x=1,temp=0;
    for(i=len-1;i>=0;i--)
    {
             if(num[i]==0)temp=1;
        else if(num[i]>0 && temp)temp++;
        else             temp=0;

        if(ans<temp)
        {
           ans=temp;
           x=1;
        }
        else if(ans==temp)
        {
           x++;
        }
    }

    //puts("");

    if(ans)printf("%d %d\n",ans,x);
    else   puts("0 1");
}


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

char str[1000005];
int top, ans, s[1000005], count;

int main() {
    while(gets(str+1) ) {
        int L = strlen(str+1);
        top = 1; count = 0;  ans = 0;
        s[0] = 0;
        for(int i = 1; i <= L; i ++) {
            if(str[i] == '(' || top == 1) {
                s[top++] = i;
            }else if(str[i] == ')') {
                if(str[s[top-1]] == '(') {
                    top --;
                } else {
                    s[top++] = i;
                }
            }
        }
        s[top] = L + 1;
        for(int i = 0; i < top; i ++) {
            if( ans == s[i+1] - s[i] - 1 && ans != 0) {
                count ++;
            }
            if(ans < s[i+1] - s[i] - 1 ) {
                ans = s[i+1] - s[i] - 1;
                count = 1;
            }
        }
        if(count == 0) {
            ans = 0, count = 1;
        }
        printf("%d %d\n", ans, count);
    }
}


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

#define N 1000005

char s[N];
int num[N];

int main()
{
    while(scanf("%s",s)!=EOF)
    {
        int sum=0,i,len=strlen(s);

        for(i=0;i<len;i++)
        {
                 if(s[i]==')')sum--;
            else if(s[i]=='(')
            {
                  if(sum>=0)
                  {
                     sum++;
                  }
                  else
                  {
                      sum=1;
                  }
            }

            num[i]=sum;
            //printf("%d ",sum);
        }

        int ans=0,x=1,temp=0;
        for(i=len-1;i>=0;i--)
        {
            if(num[i]==0)temp++;
            else if(num[i]>0 && temp)temp++;
            else             temp=0;

            if(ans<temp)
            {
               ans=temp;
               x=1;
            }
            else if(ans==temp)
            {
               x++;
            }
        }

        //puts("");

        if(ans)printf("%d %d\n",ans,x);
        else   puts("0 1");
    }
}


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

char str[1000005];
int top, maxx, count, flag, s[1000005], depth, ans;
int times[1000005];

int main() {
	while(gets(str+1) ) {
		int L = strlen(str+1);
		top = 1; depth = 0; count = 0; flag = 0; ans = 0;
		memset(times, 0, sizeof(times));
		s[0] = 0;
		for(int i = 1; i <= L; i ++) {
			if(str[i] == '(') {
				s[top++] = i;
				depth = 0;
			}else if(str[i] == ')') {
				if(str[s[top-1]] == '(') {
					top --;
					depth ++;
					times[s[top-1]] ++;
					if(ans < 2*depth) ans = 2*depth;
				}
			}
			//printf("d = %d\n", depth);
//			for(int j = 1; j < top; j ++) {
//				printf("%c", str[s[j]]);
//			}puts("");
		}
		for(int i = 0; i < top; i ++) {
			count += times[s[i]];
		}
		if(count == 0) {
			ans = 0, count = 1;
		}
		printf("%d %d\n", ans, count);
	}
}


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

#define N 1000005

struct node
{
    char c;
    int w;
}stack[N];

char s[N];

int main()
{
    while(scanf("%s",s)!=EOF)
    {
          int i,len=strlen(s),top=0;
          int ans=0,num=0;

          stack[0].c='0';
          stack[0].w=0;

          for(i=0;i<len;i++)
          {
              if(s[i]=='(')
              {
                 stack[++top].c='(';

                 if(stack[top-1].c==')')
                 stack[top].w=stack[top-1].w;
                 else         stack[top].w=0;
              }
              else if(s[i]==')')
              {
                 if(top>=1 && stack[top].c=='(')
                 {
                    int w=stack[top].w+2;

                    if(ans<w)
                    {
                       ans=w;
                       num=1;
                    }
                    else if(ans==w)
                    {
                       num++;
                    }
                    top--;
                    stack[top].w+=w;
                 }
                 else
                 {
                     stack[++top].c=')';
                     stack[top].w=0;
                 }
              }
          }

          if(ans)printf("%d %d\n",ans,num);
          else   puts("0 1");
    }
}


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

#define N 1000005

struct node
{
    char c;
    int w;
}stack[N];

char s[N];

int main()
{
    while(scanf("%s",s)!=EOF)
    {
          int i,len=strlen(s),top=0;
          int ans=0,num=0;

          stack[0].w=0;

          for(i=0;i<len;i++)
          {
              if(s[i]=='(')
              {
                 stack[++top].c='(';
                 stack[top].w=stack[top-1].w;
              }
              else if(s[i]==')')
              {
                 if(top>=1 && stack[top].c=='(')
                 {
                    int w=stack[top].w+2;
                    if(ans<w)
                    {
                       ans=w;
                       num=1;
                    }
                    else if(ans==w)
                    {
                       num++;
                    }
                    top--;
                    stack[top].w=w;
                 }
                 else
                 {
                     stack[++top].c=')';
                     stack[top].w=0;
                 }
              }
          }

          if(ans)printf("%d %d\n",ans,num);
          else   puts("0 1");
    }
}


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

char str[1000001];
int top, maxx, count, flag;

int main() {
    while(gets(str) ) {
        int L = strlen(str);
        top = 0;
        maxx = 0;
        count = 0;
        int temp = 0;
        flag = 0;
        for(int i = 0; i < L; i ++) {
            if(str[i] == '(' ) {
                top ++;
                flag = 1;
                if(temp < top) temp = top;
            }
            if(str[i] == ')') {
                if(top > 0) top --;
                else {
                    if(flag) count ++;
                    if(maxx < temp) maxx = temp;
                }
            }
        }
        if(count == 0) count = 1;
        printf("%d %d\n", maxx * 2, count);
    }
}


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

int main()
{
  string seq;
  cin>>seq;
  int longest = 0;
  int cnt = 0, c = 0, l = 0, p = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == ')') c--;
    else c++, l++;
    if (c < 0) l = 0, c = 0, p = 0;
    else if (l-c) {
      if (2*(l - c) + p == longest) cnt++;
      else if (2*(l-c) + p > longest) longest = 2*(l-c) + p, cnt = 1;
    }
    if (c == 0) {p = 2*(l-c) + p;l = 0;}
  }
  if (!longest) cnt = 1;
  cout<<longest<<" "<<cnt<<endl;
  return 0;
}


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

int main()
{
  string seq;
  cin>>seq;
  int stack[1000001], top = 0;
  int longest = 0, cnt = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == '(') {
      stack[++top] = 1;
      continue;
    }
    int c = 1;
    while (top) {
      c += stack[top];
      if (stack[top] == 1) break;
      top--;
    }
    if (!top) c = 0;
    else stack[top] = c;
    if (c == longest) cnt++;
    if (c > longest) longest = c, cnt = 1;
  }
  if (!longest) cnt = 1;
  cout<<longest<<" "<<cnt<<endl;
  return 0;
  }


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

int main()
{
  string seq;
  cin>>seq;
  int stack[1000001], top = 0;
  int longest = 0, cnt = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == '(') {
      stack[++top] = 1;
      continue;
    }
    int c = 1;
    int popped = 0;
    while (top) {
      c += stack[top];
      if (stack[top] == 1) break;
      popped++;
      top--;
    }
    if (!top && popped == 1) continue;
    if (c == longest) cnt++;
    if (c > longest) longest = c, cnt = 1;
    if (top) stack[top] = c;
  }
  int c = 0;
  int popped = 0;
  while (top) {
    c += stack[top];
    if (stack[top] == 1 && popped > 1) {
      c--;
      if (c == longest) cnt++;
      if (c > longest) longest = c, cnt = 1;
      c = 0;
      popped = 0;
    }
    popped++;
    top--;
  }
  if (popped > 1) {
    if (c == longest) cnt++;
    if (c > longest) longest = c, cnt = 1;
  }
  if (!longest) cnt = 1;
  cout<<longest<<" "<<cnt<<endl;
  return 0;
  }


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

int main()
{
  string seq;
  cin>>seq;
  int longest = 0;
  int cnt = 0, c = 0, l = 0, p = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == ')') c--;
    else c++, l++;
    if (c < 0) l = 0, c = 0, p = 0;
    else {
      if (2*(l - c) + p == longest) cnt++;
      else if (2*(l-c) > longest) longest = 2*(l-c) + p, cnt = 1;
    }
    if (c == 0) {p = l + p;l = 0;}
  }
  if (!longest) cnt = 1;
  cout<<longest<<" "<<cnt<<endl;
  return 0;
}


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

int main()
{
  string seq;
  cin>>seq;
  int longest = 0;
  int cnt = 0, c = 0, l = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == ')') c--;
    else c++;
    l++;
    if (c < 0) l = 0, c = 0;
    if (c == 0) {
      if (l == longest) cnt++;
      else if (l > longest) cnt = 1, longest = l;
    }
  }
  cout<<longest<<" "<<cnt<<endl;
  return 0;
}


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

int main()
{
  string seq;
  cin>>seq;
  int stack[1000001], top = 0;
  int longest = 0, cnt = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == '(') {
      stack[++top] = 1;
      continue;
    }
    int c = 1;
    while (top) {
      c += stack[top];
      if (stack[top] == 1) break;
      top--;
    }
    if (!top) c = 0;
    else stack[top] = c;
    if (c == longest) cnt++;
    if (c > longest) longest = c, cnt = 1;
  }
  int c = 0;
  while (top) {
    c += stack[top];
    if (stack[top] == 1) {
      c--;
      if (c == longest) cnt++;
      if (c > longest) longest = c, cnt = 1;
      c = 0;
    }
    top--;
  }

  if (!longest) cnt = 1;
  cout<<longest<<" "<<cnt<<endl;
  return 0;
  }


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

int main()
{
  string seq;
  cin>>seq;
  int stack[1000001], top = 0;
  int longest = 0, cnt = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == '(') {
      stack[++top] = 1;
      continue;
    }
    int c = 1;
    while (top) {
      c += stack[top];
      if (stack[top] == 1) break;
      top--;
    }
    if (c == longest) cnt++;
    if (c > longest) longest = c, cnt = 1;
    if (top) stack[top] = c;
  }
  int c = 0;
  while (top) {
    c += stack[top];
    if (stack[top] == 1) {
      if (c == longest) cnt++;
      if (c > longest) longest = c, cnt = 1;
      c = 0;
    }
    top--;
  }
   if (c == longest) cnt++;
   if (c > longest) longest = c, cnt = 1;
  if (!longest) cnt = 1;
  cout<<longest<<" "<<cnt<<endl;
  return 0;
  }


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

int main()
{
  string seq;
  cin>>seq;
  int stack[1000001], top = 0;
  int longest = 0, cnt = 0;
  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == '(') {
      stack[++top] = 1;
      continue;
    }
    int c = 1;
    while (top) {
      c += stack[top];
      if (stack[top] == 1) break;
      top--;
    }
    if (!top) c = 0;
    else stack[top] = c;
    if (c == longest) cnt++;
    if (c > longest) longest = c, cnt = 1;
  }
  int c = 0;

  while (top) {
    c += stack[top];
    if (stack[top] == 1) {
      c--;
      if (c == longest) cnt++;
      if (c > longest) longest = c, cnt = 1;
      c = 0;
    }
    top--;
  }
  if (c > longest) longest = c, cnt = 1;
  if (!longest) cnt = 1;
  cout<<longest<<" "<<cnt<<endl;
  return 0;
  }


#include<iostream>
#include<algorithm>
#define ll long long int
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }

    sort(a,a+n);
    int c=0;
    for(int i=0;i<n;i++)
    {

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

    if(c>2)
    {
        cout<<"NO"<<endl;
    }
    else
    {
        cout<<"YES"<<endl;
    }

}


int main() {
    int n;
    scanf("%d", &n);
    std::vector < int > v(n), v1(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
        v1[i] = v[i];
    }
    std::sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
        n += v[i] != v1[i];
    return puts(n - v.size() < 3 ? "YES" : "NO"), 0;
}


#include<bits/stdc++.h>
int main() {
    int n;
    scanf("%d", &n);
    std::vector < int > v(n), v1(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
        v1[i] = v[i];
    }
    std::sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
        n += v[i] != v1[i];
    return puts(n - v.size() < 3 ? "YES" : "NO"), 0;
}


#include<bits/stdc++.h>
int main() {
    int n;
    scanf("%d", &n);
    std::vector < int > v(n), v1(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &v[i]), v1[i] = v[i];
    std::sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
        n += v[i] != v1[i];
    return puts(n - v.size() < 3 ? "YES" : "NO"), 0;
}


#include<bits/stdc++.h>
int main() {
    int n;
    scanf("%d", &n);
    std::vector < int > v(n), v1(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
        v1[i] = v[i];
    }
    std::sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
        n += v[i] != v1[i];
    return puts(n - v.size() < 3 ? "YES" : "NO"), 0;
}


#include<bits/stdc++.h>
int main() {
    int n;
    scanf("%d", &n);
    std::vector < int > v(n), v1(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &v[i]), v1[i] = v[i];
    std::sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
        n += v[i] != v1[i];
    return puts(n - v.size() < 3 ? "YES" : "NO"), 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, i;
    int arr[100001];
    int arr2[100001];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &arr[i]);
        arr2[i]=arr[i];
    }
    sort(arr2, arr2+n);
    int cont=0;
    for(i=0; i<n; i++){
        if(arr[i]!=arr2[1]){
            cont++;
        }
    }
    printf("%s\n", (cont<=2 ? "YES" : "NO"));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, i;
    int arr[100001];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }
    int cont=0;
    for(i=0; i<n-1; i++){
        if(arr[i]>arr[i+1]){
            cont++;
        }
    }
    printf("%s\n", (cont==2 || cont==0 ? "YES" : "NO"));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, i;
    int arr[100001];
    int arr2[100001];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &arr[i]);
        arr2[i]=arr[i];
    }
    sort(arr2, arr2+n);
    int cont=0;
    for(i=0; i<n; i++){
        if(arr[i]!=arr2[i]){
            cont++;
        }
    }
    printf("%s\n", (cont<=2 ? "YES" : "NO"));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, i;
    int arr[100001];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }
    int cont=0;
    for(i=0; i<n; i++){
        if(arr[i]>arr2[1]){
            cont++;
        }
    }
    printf("%s\n", (cont<=2 ? "YES" : "NO"));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, i;
    int arr[100001];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }
    int cont=0;
    for(i=0; i<n-1; i++){
        if(arr[i]>arr[i+1]){
            cont++;
        }
    }
    printf("%s\n", (cont<=2 ? "YES" : "NO"));
    return 0;
}


#include<bits/stdc++.h>
#define FRL(i, n) for(i=0; i<n; i++)
#define pii pair<int, int>
int a[1000005], b[1000005];
using namespace std;
int main(){

    ios_base::sync_with_stdio(false);

	int n, i, c=0, x;

	cin>>n;
	for(i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
	}
	sort(a, a+n);
	for(i=0; i<n; i++){
        if(a[i]!=b[i]){
            c++;
        }
        if(c>2) break;
	}


#include<bits/stdc++.h>
int a[1000005], b[1000005];
using namespace std;
int main(){

    ios_base::sync_with_stdio(false);

	int n, i, c=0, x;

	cin>>n;
	for(i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
	}
	sort(a, a+n);
	for(i=0; i<n; i++){
        if(a[i]!=b[i]){
            c++;
        }
        if(c>2) break;
	}
}


#include<bits/stdc++.h>
#define FRL(i, n) for(i=0; i<n; i++)
#define pii pair<int, int>
int a[1000005], b[1000005];
using namespace std;
int main(){

    ios_base::sync_with_stdio(false);

	int n, i, c=0, x;

	cin>>n;
	for(i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
	}
	sort(a, a+n);
	for(i=0; i<n; i++){
        if(a[i]!=b[i]){
            c++;
        }
        if(c>2) break;
	}
	puts(c<3?"YES":"NO");
}


#include <iostream>
using namespace std;

int  arr[100000];

int main()
{
    int n , flag = 0, number = 0 , s , found = 0;
    cin >> n;
    cin >> arr[0];
    for (int i = 1 ; i < n ; i++){cin >> arr[i]; if (arr[i] < arr[i-1]){found = 1;}}
    for (int i = 0 ; i < n - 1 && found == 1; i++){
            if (flag == 1){number++;}
            if (number > 1){break;}
            flag = 0; long long temp = 1e11;
        for (int j = i+1 ; j < n ; j++){
            if (arr[i] > arr[j] && arr[j] <= temp){temp = arr[j];s = j; flag = 1;}
        }
        if (flag == 1){swap(arr[i] , arr[s]);}
    }
     if (flag == 1){number++;}
    if (number > 1){cout << "NO";}
    else {cout << "YES";}
    return 0;
}


#include <iostream>
using namespace std;

int  arr[100000];

int main()
{
    int n , flag = 0, number = 0 , s  ,f , found = 0;
    cin >> n;
    cin >> arr[0];
    for (int i = 1 ; i < n ; i++){cin >> arr[i]; if (arr[i] < arr[i-1] && found == 0){found = 1;f=i-1;}}
    for (int i = f ; i < n - 1 && found == 1; i++){
            if (flag == 1){number++;}
            if (number > 1){break;}
            flag = 0; long long temp = 1e11;
        for (int j = i+1 ; j < n ; j++){
            if (arr[i] > arr[j] && arr[j] <= temp){temp = arr[j];s = j; flag = 1;}
        }
        if (flag == 1){swap(arr[i] , arr[s]);}
    }
     if (flag == 1){number++;}
    if (number > 1){cout << "NO";}
    else {cout << "YES";}
    return 0;
}


#include <iostream>
using namespace std;

int  arr[100000];

int main()
{
    int n , flag = 0, number = 0 , s , found = 0;
    cin >> n;cin >> arr[0];
    for (int i = 1 ; i < n ; i++){cin >> arr[i]; if (arr[i] < arr[0]){found = 1;}}
    for (int i = 0 ; i < n - 1 && found == 1; i++){
            if (flag == 1){number++;}
            if (number > 1){break;}
            flag = 0; long long temp = 1e11;
        for (int j = i+1 ; j < n ; j++){
            if (arr[i] > arr[j] && arr[j] <= temp){temp = arr[j];s = j; flag = 1;}
        }
        if (flag == 1){swap(arr[i] , arr[s]);}
    }
     if (flag == 1){number++;}
    if (number > 1){cout << "NO";}
    else {cout << "YES";}
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define PI acos(-1.0)
#define EPS 1e-8
#define mod 1073741824
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,-1,sizeof(x))
#define max(a, b)  (a < b ? b : a)
#define min(a, b)  (a > b ? b : a)

using namespace std;

 int arr[100001] = {0};
 int sortedArr[100001] = {0};

int main()
{
    int n  ,number = 0; cin >> n;
    for (int i = 0 ; i < n ; i++){cin >> arr[i], sortedArr[i] = arr[i];}
    sort(arr , sortedArr + n);
    for (int i = 0; i < n ;i++){
        if (arr[i] != sortedArr[i]){number++;}
        if (number/2 > 1){break;}
    }
    if (number/2 > 1){cout << "NO";return 0;}
    cout << "YES";
    return 0;
}


#include <iostream>

using namespace std;

int  arr[100000];

int main()
{
    int n , flag = 0, number = 0 , s , found = 0;
    cin >> n;cin >> arr[0];
    for (int i = 1 ; i < n ; i++){cin >> arr[i]; if (arr[i] > arr[0]){found = 1;}}
    for (int i = 0 ; i < n - 1 && found == 1; i++){
            if (flag == 1){number++;}
            if (number > 1){break;}
            flag = 0; long long temp = 1e11;
        for (int j = i+1 ; j < n ; j++){
            if (arr[i] > arr[j] && arr[j] <= temp){temp = arr[j];s = j; flag = 1;}
        }
        if (flag == 1){swap(arr[i] , arr[s]);}
    }
     if (flag == 1){number++;}
    if (number > 1){cout << "NO";}
    else {cout << "YES";}
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define PI acos(-1.0)
#define EPS 1e-8
#define mod 1073741824
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,-1,sizeof(x))
#define max(a, b)  (a < b ? b : a)
#define min(a, b)  (a > b ? b : a)

using namespace std;

 int arr[100001] = {0};
 int sortedArr[100001] = {0};

int main()
{
    int n  ,number = 0; cin >> n;
    for (int i = 0 ; i < n ; i++){cin >> arr[i], sortedArr[i] = arr[i];}
    sort(sortedArr , sortedArr + n);
    for (int i = 0; i < n ;i++){
        if (arr[i] != sortedArr[i]){number++;}
        if (number/2 > 1){break;}
    }
    if (number/2 > 1){cout << "NO";return 0;}
    cout << "YES";
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define PI acos(-1.0)
#define EPS 1e-8
#define mod 1073741824
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,-1,sizeof(x))
#define max(a, b)  (a < b ? b : a)
#define min(a, b)  (a > b ? b : a)

using namespace std;

 int arr[100001] = {0};
 int sortedArr[100001] = {0};

int main()
{
    int n  ,number = 0; cin >> n;
    for (int i = 0 ; i < n ; i++){cin >> arr[i], sortedArr[i] = arr[i];}
    sort(sortedArr , sortedArr + n);
    for (int i = 0; i < n ;i++){
        if (arr[i] != sortedArr[i]){number++;}
        if (ceil(number/2.0) > 1){break;}
    }
    if (ceil(number/2.0) > 1){cout << "NO";return 0;}
    cout << "YES";
    return 0;
}


#include <iostream>
using namespace std;

int  arr[100000];

int main()
{
    int n , flag = 0, number = 0 , s , found = 0;
    cin >> n;
    cin >> arr[0];
    for (int i = 1 ; i < n ; i++){cin >> arr[i]; if (arr[i-1] < arr[i]){found = 1;}}
    for (int i = 0 ; i < n - 1 && found == 1; i++){
            if (flag == 1){number++;}
            if (number > 1){break;}
            flag = 0; long long temp = 1e11;
        for (int j = i+1 ; j < n ; j++){
            if (arr[i] > arr[j] && arr[j] <= temp){temp = arr[j];s = j; flag = 1;}
        }
        if (flag == 1){swap(arr[i] , arr[s]);}
    }
     if (flag == 1){number++;}
    if (number > 1){cout << "NO";}
    else {cout << "YES";}
    return 0;
}


#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <math.h>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>
#include <bitset>
#include <time.h>
#include <cassert>
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
const lli INF = (1e9 + 12312), MOD = 1e9 + 7; //18
const ld EPS = 0.0000000001;
#pragma comment(linker, "/STACK:64000000")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define forn(a, b) for (lli i = a; i < b; i++)
#define fore(p, a, b) for (lli p = a; p < b; p++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb(a) push_back(a)
#define sz(a) (lli)a.size()
#define mp(a, b) make_pair(a, b)
#define x first
#define y second
#define cotu cout
#define itn lli
#define pii pair<lli, lli>

using namespace std;

const int k = 350;

bool cmp(pair<pii, int> a, pair<pii, int> b){
    if (a.first.x / k == b.first.x / k){
        return a.first.y < b.first.y;
    }
    return a.first.x < b.first.x;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(time(NULL));

    int n;
    cin >> n;

    vector<int>a(n);

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

    auto b = a;

    sort(all(a));

    int kol = 0;

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

    if (kol <= 2){
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}


//In the name of Allah

#include<bits/stdc++.h>

using namespace std;

const int Maxn = 100 * 1000 + 10;
int n, cnt, a[Maxn], b[Maxn];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        cin >> 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 < 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


//In the name of Allah

#include<bits/stdc++.h>

using namespace std;

const int Maxn = 100 * 1000 + 10;
int n, cnt;
pair<int, int> arr[Maxn];

int main()
{
    cin >> n;
    int a;
    for(int i = 0; i < n; i ++)
    {
        cin >> a;
        arr[i] = make_pair(a, i);
    }
    sort(arr, arr + n);
    for(int i = 0; i < n; i ++)
        if(arr[i].second != i)
            cnt ++;
    if(cnt < 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


//Cool
#include <iostream>
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

ll a[100012], b[100012], n, cnt;

ll main(){
    cin >> n;
    lp(i, n){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b, b+n);
    lp(i, n){
        if (a[i]== b[i])
            cnt++;
    }
    cnt= n- cnt;
    cnt++;
    cnt/= 2;
    if (cnt <2){
        cout << "YES";
        return 0;
    }
    cout << "NO";
}


//Cool
#include <iostream>
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

ll a[100012], b[100012], n, cnt;

ll main(){
    cin >> n;
    lp(i, n){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b, b+n);
    lp(i, n){
        if (a[i]== b[i])
            cnt++;
    }
    cnt= n- cnt;
    cnt/= 2;
    if (cnt <2){
        cout << "YES";
        return 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
using namespace std;

long long p[100000+10];
long long c[100000+10];
int main ()
{
	int n;
	int a=0;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>p[i];
		c[i]=p[i];
	}
	sort (p,p+n);
	for (int j=0;j<n;j++)
	{
		if (p[j]!=c[j])
		{
			a++;
		}
	}
	if (a==2 || a==1 || a==0)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
}


#include <bits/stdc++.h>
using namespace std;

long long p[100000+10];
int main ()
{
	int n;
	int a=0;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>p[i];
		if (p[i]!=i+1)
		{
			a++;
		}
	}
	if (a==1 || a==2)
	{
		cout<<"YES";
	}
	else if (a==0)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

int main(){
    ios_base :: sync_with_stdio(0) ;
    cin.tie() ; cout.tie() ;
    ll n ;
    cin >> n ;
    vector <ll> s(n) , sorted(n) ;
    for(int i = 0 ; i < n ; i++){
        cin >> s[i] ;
        sorted[i] = s[i] ;
    }

    sort(sorted.begin() , sorted.end()) ;

    ll C = 0 ;
    for(int i = 0 ; i < n ; i++){
        if(sorted[i] != s[i])
            C++ ;
    }

    cout << (C <= 2 ? "YES" : "NO" ) << "\n" ;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastcin ios::sync_with_stdio(false)
#define cinl(a,b) cin.getline(a,b)
int a[1000005],b[1000005];
int main(){
    int m,n,i,j,k;
    fastcin;
    cin>>m;
    for(i=1;i<=m;i++) cin>>a[i],b[i]=a[i];
    sort(b+1,b+1+m);
    int ans=0;
    for(i=1;i<=m;i++){
        ans+=(b[i]==a[i]);
    }
    ans=m-ans;
    printf("%s",(ans==2||ans==0)?"YES":"NO");
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastcin ios::sync_with_stdio(false)
#define cinl(a,b) cin.getline(a,b)
int a[1000005],b[1000005];
int main(){
    int m,n,i,j,k;
    fastcin;
    cin>>m;
    for(i=1;i<=m;i++) cin>>a[i],b[i]=a[i];
    sort(b+1,b+1+m);
    int ans=0;
    for(i=1;i<=m;i++){
        ans+=(b[i]==a[i]);
    }
    printf("%s",ans<=1?"YES":"NO");
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastcin ios::sync_with_stdio(false)
#define cinl(a,b) cin.getline(a,b)
int a[1000005],b[1000005];
int main(){
    int m,n,i,j,k;
    fastcin;
    cin>>m;
    for(i=1;i<=m;i++) cin>>a[i],b[i]=a[i];
    sort(b+1,b+1+m);
    int ans=0;
    for(i=1;i<=m;i++){
        ans+=(b[i]==a[i]);
    }
    printf("%s",(ans==2||ans==0)?"YES":"NO");
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <map>
#include <string>
using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef vector<VI> VII;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef set<LL> SLL;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;

const int INF = 2 * (1e9);

int main(){
   int N, cnt = 0;
   cin>>N;
   VI A(N);
   for(int &i : A){cin>>i;}
   VI B = A;
   sort(B.begin(), B.end());
   for(int i = 0; i < N; i++){
      if(A[i] != B[i]){
         cnt++;
      }
   }
   if(cnt > 2){
      cout<<"NO";
   }else{
      cout<<"YES";
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,x;
	cin>>n;
	vector<long long int>p,q;
	for(long long int i=0;i<n;i++)
	{
		cin>>x;
		p.push_back(x);
	}
	q=p;
	sort(p.begin(),p.end());
	long long int count=0;
	for(int i=0;i<n;i++)
	{
		if(p[i]!=q[i])
		{
			count++;
			if(count>2)
			break;
		}
	}
	//cout<<count<<endl;
	if(count<=2)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,x,count=0;
	vector<long long int>v;
	cin>>n;
	for(long long int i=0;i<n;i++)
	{
		cin>>x;
		v.push_back(x);
	}
	for(long long int i=0;i<n-1;i++)
	{
	     	if(v[i]>v[i+1])
	     	count++;
	}
	if(count<=2)
	cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;

}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=2e9;

//scanf("%d",&);
int n,a[N],b[N],c;

int main()
{
//    freopen(".txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
            c++;
    }
    if(!c||c==2)
        puts("YES");
    else
        puts("NO");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define sp(x) fixed<<setprecision(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define die(x) return cout << x << endl, 0;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
const int MAXN = 1000 * 100 + 10;
const int MOD = 1000 * 1000 * 1000 + 7;
int n, cnt;
int a[MAXN], s[MAXN];
int main()
{
    fastio;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
        s[i] = a[i];
    }
    sort(s, s + n);
    for(int i = 0; i < n; i ++){
        if(s[i] != a[i])
            cnt++;
        if(cnt > 2)
            return cout << "NO" << endl, 0;

    }
    cout << "YES" << endl;
    return 0;
}


/*
By Tianyi Chen
*/
#include<bits/stdc++.h>

using namespace std;
int n,a[100000],bad;
int main(){
 scanf("%d",&n);for(int i=0;i<n;++i)scanf("%d",a+i);
 for(int j=0;j<n-1;++j)if (a[j]>a[j+1])++bad;
 puts(!bad||bad==2?"YES":"NO");
}


 #include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
int n,x;
bool flag;
vector<int> vc,tmp;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        //if(added.insert(x).second)
       // {
            tmp.push_back(x);
            vc.push_back(x);
       // }
    }
    sort(tmp.begin(), tmp.end());
    int cnt=0;flag=0;
    //printf("%lu\n",vc.size());
    for(int i=0;i<vc.size();i++)
    {
        if (tmp[i]!=vc[i]) {
            ++cnt;
        }
        if(cnt>2){flag=1;break;}
    }
    //printf("\n\n%d %d\n",flag,cnt);
    if(flag){puts("NO");}
    else{puts("YES");}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
map<int,bool> check;
int main(){
int a[100005];
int n; int b[100005];
long long ans=0;
cin >>n;
for(int i=0;i<n;i++){
    cin >>a[i];
    b[i]=a[i];
}

sort(b,b+n);
for(int i=0;i<n;i++){
//cout << a[i] << " " << b[i] << " ";
    if(a[i] != b[i] && !check[b[i]] ){
            ans++;
        check[b[i]]=1;
        check[a[i]]=1;
}

//cout << a[i] << " " << b[i] << " ";
}

//cout << endl << ans;

if(ans>1){
    cout << "NO";
}

else cout << "YES";

}


#include <bits/stdc++.h>

using namespace std;
map<int,bool> check;
int main(){
int a[100005];
int n; int b[100005];
long long ans=0;
cin >>n;
for(int i=0;i<n;i++){
    cin >>a[i];
    b[i]=a[i];
}

for(int i=1;i<n;i++){
    check[i]=0;
}

sort(b,b+n);
for(int i=0;i<n;i++){
//cout << a[i] << " " << b[i] << " ";
    if(a[i] != b[i] && !check[b[i]] ){
            ans++;
        check[b[i]]=1;
        check[a[i]]=1;
}

//cout << a[i] << " " << b[i] << " ";
}

//cout << endl << ans;

if(ans>1){
    cout << "NO";
}

else cout << "YES";

}


#include <bits/stdc++.h>

using namespace std;
map<int,bool> check;
int main(){
int a[100005];
int n; int b[100005];
long long ans=0;
cin >>n;
for(int i=0;i<n;i++){
    cin >>a[i];
    b[i]=a[i];
}

for(int i=1;i<n;i++){
    check[i]=0;
}

sort(b,b+n);
for(int i=0;i<n;i++){
//cout << a[i] << " " << b[i] << " ";
    if(a[i] != b[i])ans++;

//cout << a[i] << " " << b[i] << " ";
}

//cout << endl << ans;

if(ans>2){
    cout << "NO";
}

else cout << "YES";

}


#include <bits/stdc++.h>

using namespace std;
map<int,bool> check;
int main(){
int a[100005];
int n; int b[100005];
long long ans=0;
cin >>n;
for(int i=0;i<n;i++){
    cin >>a[i];
    b[i]=a[i];
}

for(int i=1;i<n;i++){
    check[i]=0;
}

sort(b,b+n);
for(int i=0;i<n;i++){
//cout << a[i] << " " << b[i] << " ";
    if(a[i] != b[i] && (!check[b[i]] or !check[a[i]] )){
            ans++;
        check[b[i]]=1;
        check[a[i]]=1;
}

//cout << a[i] << " " << b[i] << " ";
}

//cout << endl << ans;

if(ans>1){
    cout << "NO";
}

else cout << "YES";

}


#include <bits/stdc++.h>

using namespace std;
bool swapped[100005]={};
int main(){
int a[100005];
int n; int b[100005];
long long ans=0;
cin >>n;
for(int i=0;i<n;i++){
    cin >>a[i];
    b[i]=a[i];
}

sort(b,b+n);
for(int i=0;i<n;i++){
//cout << a[i] << " " << b[i] << " ";
    if(a[i] != b[i] && !swapped[i] ){
            ans++;
        swapped[a[i]-1]=true;
        swapped[b[i]-1]=true;
}

//cout << a[i] << " " << b[i] << " ";
}

//cout << endl << ans;

if(ans>1){
    cout << "NO";
}

else cout << "YES";

}


/*
PROG : milk2
LANG : C++
*/
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fi first
#define se second
#define sqr(a) ((a) * (a))
#define pi 3.1415926535897932
#define read ifstream in("input.txt")
#define write ofstream out("output.txt")
#define vii vector<int>
#define mii map<int, int>

using namespace std;

int n, m, k;
int x[100005];

int main()
{
    //ifstream in("moocast.in");
    //ofstream out("moocast.out");
    int cnt = 0, y[100005];
    cin >> n;
    for(int i = 0;i < n;i++)
        cin >> x[i], y[i] = x[i];

    sort(x, x + n);
    for(int i = 0;i < n;i++)
        if (y[i] != x[i])
        cnt++;

    if (cnt > 2)
        cout << "NO";
    else
        cout << "YES";

    return 0;
    ///dont forget about initialization array please
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,i,c=0;
    cin>>x;
    int n[x],m[x];
    for(i=0;i<x;i++)
        { cin>>n[i]; m[i]=n[i]; }
    sort(m,m+x);

    for(i=0;i<x;i++)
    {
        if(n[i]!=m[i]) c++;
    }

    if(c<=2) cout<< "YES\n";
    else cout<< "NO\n";
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
	long long n, count;
	cin>>n;
	long long a[n], b[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(a, a+n);
	count =0;
	for(int i=0; i<n; i++){
		if(a[i]!=b[i]) count++;
		if(count>=3){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}


/*  : Om Ganeshaay Namah:

~~~~~~~~~~~~~~~~~~~~~~~~~       All hail l0fty.WhizZ      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is Shreyas Iyer's code! My handle in Codechef,
Hackerrank is : shreyasiyer_14.

College: International Institute of Information Technology, Bangalore.

Oh and by the way, you can always challenge me in Counter Strike! Prepare to get rekt!
*/
#include "bits/stdc++.h"

using namespace std;

typedef int i;
typedef long int l;
typedef long long int ll;
typedef float f;
typedef long double lf;
typedef char c;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define s(x) cin >> x
#define s2(x,y) cin >> x >> y
#define p(x) cout << x << endl
#define p2(x,y) cout << x << y << endl
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define f(i,a,n) for (int i=a;i<n;i++)
#define fl(i,a,n) for (long int i=a;i<n;i++)
#define fll(i,a,n) for (long long int i=a;i<n;i++)
#define pb push_back

//Code starts Here!

int main(void) {
	FASTER;
    ll n;
    s(n);
    vector<ll> ar(n);
    fll(i,0,n)
        s(ar[i]);
    vector<ll> temp(n);
    temp = ar;
    sort(temp.begin(), temp.end());
    ll l = -1;
    ll r = -1;
    fll(i,0,ar.size()) {
        if (ar[i] != temp[i]) {
            if (l == -1)
                l = i;
            else if (r == -1) {
                r = i;
            }
            else {
                p("NO");
                return 0;
            }
        }
    }
    ll t = ar[l];
    ar[l] = ar[r];
    ar[r] = t;
    if (temp == ar) {
        p("YES");
    } else {
        p("NO");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int M = 1e5 + 5;
int n, t[M], c[M];

int main () {
  scanf ("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf ("%d", &t[i]);
    c[i] = t[i];
  }
  sort (c, c+n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (t[i] != c[i]) ans ++;
  }
  if (ans == 2 || ans == 0)
    puts( "YES" );
  else puts( "NO" );
}


using namespace std;
#include<bits/stdc++.h>
typedef long long   LL;
//typedef int   LL;
typedef long long   ll;
typedef   pair<LL,LL>  PII;
typedef   vector< PII > VPII;
typedef   vector<LL>   VI;
typedef   map<string,LL>  MSI;
typedef   map<LL,LL>  MII;
///Print
#define casep(no,val) printf("Case %lld: %lld\n",++no,val)
#define casenl(no) printf("Case %lld:\n",++no)
#define RR(n,m)       scanf("%lld%lld", &n,&m)
#define case(no) printf("Case %lld: ",++no)
#define R(n)       scanf("%lld", &n)
#define P(a)  printf("%lld\n",a)
#define NL printf("\n")
///LOOP
#define FORSTL(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
///Shortcut
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define fastinput ios_base::sync_with_stdio(false); cin.tie(false);
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define SS second
#define FF first
///Binary_search
#define LB(a,x) (lower_bound(all(a),x)-a.begin())
#define UB(a,x) (upper_bound(all(a),x)-a.begin())
///Min AND Max
#define isEq(a,b) (fabs((a)-(b))<eps)
#define MIN3(a,b,c) min(a,min(b,c))
#define MAX3(a,b,c) max(a,max(b,c))
#define PI acos(-1.0)
#define EPS (1e-9)
///DEBUG
#define DDD(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" ="<<z<<endl;
#define DD(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define D(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;

///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}///
string itos(LL n){string s;while(n){s+=(n%10+48);n/=10;}reverse(all(s));return s;}
LL stoi(string s){LL n=0;rep(i,len(s))n=n*10+(s[i]-48);return n;}
/// geometry
double DEG(double x) { return (180.0*x)/(PI);}
double RAD(double x) { return (x*(double)PI)/(180.0);}
template<typename T> T DIS(T x1,T y1,T x2, T y2){return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
template<typename T> T ANGLE(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T> LL isLeft(T a,T b,T c) { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
const  int N=5e5+5,MOD=1e9+7;

struct info{LL x,y;}arr[N];bool com(info a,info b){return (a.x<b.x) or (a.x==b.x and a.y<b.y);}
LL ar[105],br[N];LL a=0,b=0,c=0,r=0,rr=0,res=0,n,m,t=0,ks=0;
string  s;

int main()
{
   //fastinput;

     VPII  v;

     cin>>n;

     rep(i,n)
     {
         cin>>a;
         v.pb(mp(a,i));
     }

     sort(all(v));

     rep(i,n)
     {
         if(v[i].second!=i)
         {
             LL aa=v[i].FF;
             LL bb=v[i].SS;

             swap(v[i],v[bb]);

             break;

            // LL cc=v[bb].FF;
            // LL dd=v[bb].SS;

             //v[bb].FF=aa;
         }
     }

     rep(i,n)
     {
         if(v[i].SS!=i)r++;
     }

     if(r==0)  puts("YES");
     else  puts("NO");
   return 0;

}


using namespace std;
#include<bits/stdc++.h>
typedef long long   LL;
//typedef int   LL;
typedef long long   ll;
typedef   pair<LL,LL>  PII;
typedef   vector< PII > VPII;
typedef   vector<LL>   VI;
typedef   map<string,LL>  MSI;
typedef   map<LL,LL>  MII;
///Print
#define casep(no,val) printf("Case %lld: %lld\n",++no,val)
#define casenl(no) printf("Case %lld:\n",++no)
#define RR(n,m)       scanf("%lld%lld", &n,&m)
#define case(no) printf("Case %lld: ",++no)
#define R(n)       scanf("%lld", &n)
#define P(a)  printf("%lld\n",a)
#define NL printf("\n")
///LOOP
#define FORSTL(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
///Shortcut
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define fastinput ios_base::sync_with_stdio(false); cin.tie(false);
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define SS second
#define FF first
///Binary_search
#define LB(a,x) (lower_bound(all(a),x)-a.begin())
#define UB(a,x) (upper_bound(all(a),x)-a.begin())
///Min AND Max
#define isEq(a,b) (fabs((a)-(b))<eps)
#define MIN3(a,b,c) min(a,min(b,c))
#define MAX3(a,b,c) max(a,max(b,c))
#define PI acos(-1.0)
#define EPS (1e-9)
///DEBUG
#define DDD(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" ="<<z<<endl;
#define DD(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define D(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;

///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}///
string itos(LL n){string s;while(n){s+=(n%10+48);n/=10;}reverse(all(s));return s;}
LL stoi(string s){LL n=0;rep(i,len(s))n=n*10+(s[i]-48);return n;}
/// geometry
double DEG(double x) { return (180.0*x)/(PI);}
double RAD(double x) { return (x*(double)PI)/(180.0);}
template<typename T> T DIS(T x1,T y1,T x2, T y2){return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
template<typename T> T ANGLE(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T> LL isLeft(T a,T b,T c) { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
const  int N=5e5+5,MOD=1e9+7;

struct info{LL x,y;}arr[N];bool com(info a,info b){return (a.x<b.x) or (a.x==b.x and a.y<b.y);}
LL ar[105],br[N];LL a=0,b=0,c=0,r=0,rr=0,res=0,n,m,t=0,ks=0;
string  s;

int main()
{
   //fastinput;

     VPII  v;

     cin>>n;

     rep(i,n)
     {
         cin>>a;
         v.pb(mp(a,i));
     }

     sort(all(v));

     rep(i,n)
     {
         if(v[i].second!=i)c++;
     }

     if(c<=2)  puts("YES");
     else  puts("NO");
   return 0;

}


using namespace std;
#include<bits/stdc++.h>
typedef long long   LL;
//typedef int   LL;
typedef long long   ll;
typedef   pair<LL,LL>  PII;
typedef   vector< PII > VPII;
typedef   vector<LL>   VI;
typedef   map<string,LL>  MSI;
typedef   map<LL,LL>  MII;
///Print
#define casep(no,val) printf("Case %lld: %lld\n",++no,val)
#define casenl(no) printf("Case %lld:\n",++no)
#define RR(n,m)       scanf("%lld%lld", &n,&m)
#define case(no) printf("Case %lld: ",++no)
#define R(n)       scanf("%lld", &n)
#define P(a)  printf("%lld\n",a)
#define NL printf("\n")
///LOOP
#define FORSTL(x,n) for(__typeof(n.begin()) x=n.begin();x!=n.end();x++)
#define repp(x,n) for(__typeof(n) x=1;x<=(n);x++)
#define reps(i,x) for(int  i=0;i<(x.size());i++)
#define rep(x,n) for(__typeof(n) x=0;x<(n);x++)
///Shortcut
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define fastinput ios_base::sync_with_stdio(false); cin.tie(false);
#define mem(ar,value) memset(ar,value,sizeof(ar))
#define all(x) x.begin(),x.end()
#define len(s) s.size()
#define mp make_pair
#define pb push_back
#define SS second
#define FF first
///Binary_search
#define LB(a,x) (lower_bound(all(a),x)-a.begin())
#define UB(a,x) (upper_bound(all(a),x)-a.begin())
///Min AND Max
#define isEq(a,b) (fabs((a)-(b))<eps)
#define MIN3(a,b,c) min(a,min(b,c))
#define MAX3(a,b,c) max(a,max(b,c))
#define PI acos(-1.0)
#define EPS (1e-9)
///DEBUG
#define DDD(x,y,z) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<" | "#z" ="<<z<<endl;
#define DD(x,y) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<" | "#y" = "<<y<<endl;
#define D(x) cerr<<__FUNCTION__<<":"<<__LINE__<<": "#x" = "<<x<<endl;

///Gcd and Lcm
template<class T>T gcd(T a,T b){return b == 0 ? a : gcd(b, a % b);}
template<typename T>T lcm(T a, T b) {return a / gcd(a,b) * b;}
///Bigmod && Pow
template<class T>T my_pow(T n,T p){if(p==0)return 1;T x=my_pow(n,p/2);x=(x*x);if(p&1)x=(x*n);return x;} ///n to the power p
template<class T>T big_mod(T n,T p,T m){if(p==0)return (T)1;T x=big_mod(n,p/2,m);x=(x*x)%m;if(p&1)x=(x*n)%m;return x;}
///string to int
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}///
string itos(LL n){string s;while(n){s+=(n%10+48);n/=10;}reverse(all(s));return s;}
LL stoi(string s){LL n=0;rep(i,len(s))n=n*10+(s[i]-48);return n;}
/// geometry
double DEG(double x) { return (180.0*x)/(PI);}
double RAD(double x) { return (x*(double)PI)/(180.0);}
template<typename T> T DIS(T x1,T y1,T x2, T y2){return sqrt( (double)( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) );}
template<typename T> T ANGLE(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template<typename T> LL isLeft(T a,T b,T c) { return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y); }
const  int N=5e5+5,MOD=1e9+7;

struct info{LL x,y;}arr[N];bool com(info a,info b){return (a.x<b.x) or (a.x==b.x and a.y<b.y);}
LL ar[N],br[N];LL a=0,b=0,c=0,r=0,rr=0,res=0,n,m,t=0,ks=0;
string  s;

int main()
{
   //fastinput;

     VPII  v;

     cin>>n;

     rep(i,n)
     {
         cin>>a;
         v.pb(mp(a,i));

         ar[i]=a;
     }

     sort(all(v));
     LL fs=0,scnd=0;

     rep(i,n)
     {

         if(v[i].FF!=ar[i])r++;

     }

     if(r<=2)  puts("YES");
     else  puts("NO");
   return 0;

}


#pragma comment (linker, "/STACK:128000000")
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
int a[100100];
struct data{
    int num,v;
}b[100100];
int cmp(data p,data q){
    return p.v<q.v;
}
int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[i].v=a[i];
        b[i].num=i;
    }
    sort(b+1,b+1+n,cmp);
    for(int i=1;i<=n;i++){
        if(a[i]!=b[i].v){
            sum++;
            if(sum>=2) break;
            swap(a[i],a[b[i].num]);
        }
    }
    if(sum<=1)  cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#pragma comment (linker, "/STACK:128000000")
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
int a[100100];
int b[100100];
int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    for(int i=1;i<=n;i++){
        if(a[i]!=b[i]){
            sum++;
        }
    }
    if(sum<=2)  cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#pragma comment (linker, "/STACK:128000000")
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
int a[100100];
struct data{
    int num,v;
}b[100100];
int cmp(data p,data q){
    if(p.v!=q.v)
        return p.v<q.v;
    else return p.num<q.num;
}
int main()
{
    int n;
    scanf("%d",&n);
    int sum=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[i].v=a[i];
        b[i].num=i;
    }
    sort(b+1,b+1+n,cmp);
    for(int i=1;i<=n;i++){
        if(a[i]!=b[i].v){
            sum++;
            if(sum>=2) break;
            swap(a[i],a[b[i].num]);
        }
    }
    if(sum<=1)  cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((ll) (x).size())
#define clr(a,b)	memset(a,b,sizeof(a))
const double EPS = 1e-8;
const double pi = acos(-1);
ll dcmp(double a, double b) {
	return fabs(a - b) <= EPS ? 0 : a < b ? -1 : 1;
}
void debug() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "rt", stdin);
//	freopen("output.in", "wt", stdout);
#endif
}

int const N = 1e5 + 9, M = 100 + 9, OO = 1e9;

int arr[N], arr2[N];

int main() {
	cout << fixed << setprecision(0);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	debug();
	int n, a;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		arr[i] = arr2[i] = a;
	}
	sort(arr2, arr2+n);
	int res = 0;
	for (int i = 0; i < n; ++i) {
		if(arr2[i] != arr[i]) {
			++res;
			if(res > 2) {
				cout << "NO";
				return 0;
			}
		}
	}
	cout << "YES";
}


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

int main() {
	ios_base::sync_with_stdio(false);
	///hjhj
	vector <int> a, b;
	int n, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		a.push_back(c);
		b.push_back(c);
	}
	sort(a.begin(), a.end());
	int prb = 0, p1 = 0, p2 = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i]) {
			if (prb == 0)
				p1 = i;
			else if (prb == 1)
				p2 = i;
			else {
				cout << "NO";
				return 0;
			}
			prb++;
		}
	}

	if (a[p1] != b[p2] || a[p2] != b[p1])
		cout << "NO";
	else
		cout << "YES";
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);

	vector <int> a, b;
	int n, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		a.push_back(c);
		b.push_back(c);
	}
	sort(a.begin(), a.end());
	int prb = 0, p1 = 0, p2 = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i]) {
			if (prb == 0)
				p1 = i;
			else if (prb == 1)
				p2 = i;
			else {
				cout << "NO";
				return 0;
			}
			prb++;
		}
	}

	if (a[p1] != b[p2] || a[p2] != b[p1])
		cout << "NO";
	else
		cout << "YES";
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n, ct = 0;
	cin >> n;
	vector<int> nums(n), nums_copy(n);
	for (int i = 0; i < n; ++i) {
		cin >> nums[i];
		nums_copy[i] = nums[i];
	}
	sort(nums.begin(), nums.end());
	for (int i = 0; i < n; ++i) {
		if (nums_copy[i] != nums[i]) {
			++ct;
		}
	}
	if (ct <= 2) {
		cout << "YES";
	} else {
		cout << "NO";
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, ct = 0;
	cin >> n;
	vector<int> nums(n), nums_copy(n);
	for (int i = 0; i < n; ++i) {
		cin >> nums[i];
		nums_copy[i] = nums[i];
	}
	sort(nums.begin(), nums.end());
	for (int i = 0; i < n; ++i) {
		if (nums_copy[i] != nums[i]) {
			++ct;
		}
	}
	if (ct <= 2) {
		cout << "YES";
	} else {
		cout << "NO";
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define REP(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define fread(f) freopen(f, "r", stdin)
#define frite(f) freopen(f, "w", stdout)
#define SZ(x) ((int)(x).size())
#define dbs(x) cout << x << endl
#define db(x) cout << #x << " == " << x << endl
#define _ << ", " <<
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define sd(n)       scanf("%d", &n)
#define sdd(a, b)    scanf("%d %d", &a, &b)
#define sddd(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sqr(x) ((x)*(x))
#define b b_ // avoid declared "b" variable in some library
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 2e9;
const ll INFL = 2e18;
//////////////////////////////////////////////////////////////////
const int N = 1e5 + 10;
int n, a[N], b[N];
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	//fread("01.inp");
	cin >> n;
	FOR(i, 1, n){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1, b + 1 + n);
	int cnt = 0;
	FOR(i, 1, n) if (a[i] != b[i]) ++cnt;
	if (cnt <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define REP(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define fread(f) freopen(f, "r", stdin)
#define frite(f) freopen(f, "w", stdout)
#define SZ(x) ((int)(x).size())
#define dbs(x) cout << x << endl
#define db(x) cout << #x << " == " << x << endl
#define _ << ", " <<
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define sd(n)       scanf("%d", &n)
#define sdd(a, b)    scanf("%d %d", &a, &b)
#define sddd(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sqr(x) ((x)*(x))
#define b b_ // avoid declared "b" variable in some library
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 2e9;
const ll INFL = 2e18;
//////////////////////////////////////////////////////////////////
const int N = 1e5 + 10;
int n, a[N], b[N];
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	//fread("01.inp");
	cin >> n;
	FOR(i, 1, n){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1, b + 1 + n);
	int cnt = 0;
	FOR(i, 1, n) if (a[i] != b[i]) ++cnt;
	if (cnt == 2) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


//PS
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 123;
int n, a = -1, b, c, A[N], B[N];

int main ()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i], B[i] = A[i];

	sort (B, B+n);

	for (int i = 0; i < n; i++) {
		if (A[i] != B[i]) {
			if (a != -1) b = A[i];
			else a = B[i];
			c++;
		}
	}
	if (c == 0 || c == 2 && a == b)
		puts ("YES");
	else
		puts ("NO");

	return 0;
}


//PS
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 123;
int n, a = -1, b, c, A[N], B[N];

int main ()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i], B[i] = A[i];

	sort (B, B+n);

	for (int i = 0; i < n; i++) {
		if (A[i] != B[i]) {
			if (a != -1) b = A[i];
			else a = B[i];
			c++;
		}
	}
	c /= 2;
	if (c == 0 || c == 1 && a == b)
		puts ("YES");
	else
		puts ("NO");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,ch=0; cin>>n; int arr[n];
    for (int i=0;i<n;i++) cin>>arr[i];
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1; break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    ch=0; int minn=10e9,ii=-1,maxx=0,jj=-1;
    for (int i=0;i<n;i++)
    {
        if (arr[i]>arr[i+1]&&arr[i+1]<=minn) {minn=arr[i+1],ii=i+1;}
    }
    for (int i=0;i<ii;i++)
    {
        if (arr[i]>minn&&arr[i]>=maxx) {maxx=arr[i],jj=i;}
    }
    swap(arr[ii],arr[jj]);
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1;break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,ch=0; cin>>n; int arr[n];
    for (int i=0;i<n;i++) cin>>arr[i];
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1; break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    ch=0; int minn=10e9,ii=-1,maxx=0,jj=-1;
    for (int i=0;i<n;i++)
    {
        if (arr[i]>arr[i+1]&&arr[i+1]<=minn) {minn=arr[i+1],ii=i+1;}
    }
    for (int i=0;i<ii;i++)
    {
        if (arr[i]>minn&&arr[i]>maxx) {maxx=arr[i],jj=i;}
    }
    swap(arr[ii],arr[jj]);
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1;break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,ch=0; cin>>n; int arr[n],ar[n];
    for (int i=0;i<n;i++) cin>>arr[i];
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1; break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    for (int i=0;i<n;i++) ar[i]=arr[i];
    sort(ar,ar+n); ch=0; int minn=10e9,ii=-1,maxx=0,jj=-1;
    for (int i=0;i<n;i++) if (ar[i]!=arr[i]) {ii=i; break;}
    for (int i=0;i<n;i++) if (ar[n-i-1]!=arr[n-i-1]) {jj=n-i-1; break;}
    swap(arr[ii],arr[jj]);
    //cout<<arr[ii]<<" "<<arr[jj]<<endl;
    //for (int i=0;i<n;i++) cout<<arr[i]<<" ";
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1;break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,ch=0; cin>>n; int arr[n];
    for (int i=0;i<n;i++) cin>>arr[i];
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1; break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    ch=0; int minn=10e9,ii=-1,maxx=0,jj=-1;
    for (int i=0;i<n;i++)
    {
        if (arr[i]>arr[i+1]&&arr[i+1]<minn) {minn=arr[i+1],ii=i+1;}
    }
    for (int i=0;i<ii;i++)
    {
        if (arr[i]>minn&&arr[i]>maxx) {maxx=arr[i],jj=i;}
    }
    swap(arr[ii],arr[jj]);
    for (int i=0;i<n-1;i++) if (arr[i]>arr[i+1]) {ch=1;break;}
    if (!ch) {cout<<"YES"<<endl; return 0;}
    cout<<"NO"<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<unordered_map>
#include<vector>
#include<queue>
#include<numeric>
#include<cmath>
#include<set>
#include<map>

#if DEBUG && !ONLINE_JUDGE
	#include "debugger.cpp"
#else
    #define debug(args...)
	#define printMatrix(args...)
    #define printArray(args...)
#endif

#define pb push_back
#define mp make_pair

#define lli long long int
#define MOD 1000000007
using namespace std;
const int MAXN = 100000;
const int MAXR = 1;
const int MAXC = 1;
const int INF = (int)1e+9;
lli arr[MAXN];
lli arrc[MAXN];

int x4[] = {-1,0,1,0};
int y4[] = {0,1,0,-1};

int main(void){
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r+", stdin);
    #endif
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i = 0;i<n;i++){
    	cin>>arr[i];
    	arrc[i] = arr[i];
    }
    sort(arrc, arrc + n);
    int cnt = 0;
    for(int i = 0;i<n;i++){
    	if(arrc[i] != arr[i]){
    		cnt++;
    	}
    }

    if(cnt == 0 || cnt == 2){
    	cout<<"YES";
    }else{
    	cout<<"NO";
    }

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,count=0;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        if(a[i]!=i)
        count++;
    if(count>2)
        cout<<"NO";
    else
        cout<<"YES";

}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,count=0;
    cin>>n;
    long long int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    b[i]=a[i];}
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(b[i]!=a[i])
            count++;
            if(count>2){
                cout<<"NO";
        return 0;}

    }
    cout<<"YES";

}


#include <iostream>
#include <algorithm>

using namespace std;

const int mn = 100010;
int a[mn], b[mn], n,c;

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


#include <iostream>

using namespace std;

int a[100000 + 10] , cnt;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i];
		if (i && a[i] < a[i-1])
			cnt ++;
	}
	if (cnt > 2)
		cout << "NO" << endl;
	else
		cout << "YES" <<  endl;
	return 0;
}


#include <iostream>

using namespace std;

int a[100000 + 10], x, y , cnt;
bool flag;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i];
		if (i && a[i] < a[i-1])
		{
			cnt ++;
			if (!flag)
			{
				x = i - 1;
				flag = 1;
			}
			else
				y = i;
		}
	}
	if (cnt > 2)
	{
		cout << "NO" << endl;
		return 0;
	}
	if (cnt == 1)
		swap(a[n - 1], a[x]);
	else
		swap(a[y], a[x]);
	for (int i = 0 ; i < n; i ++)
	{
		//cout << a[i] << " ";
		if (i && a[i] < a[i-1])
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;

}


#include <iostream>

using namespace std;

int a[100000 + 10], x, y , cnt;
bool flag;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i];
		if (i && a[i] < a[i-1])
		{
			cnt ++;
			if (!flag)
			{
				x = i - 1;
				flag = 1;
			}
			else
				y = i;
		}
	}
	if (cnt > 2)
	{
		cout << "NO" << endl;
		return 0;
	}
	swap(a[x], a[y]);
	for (int i = 0 ; i < n; i ++)
	{
		//cout << a[i] << " ";
		if (i && a[i] < a[i-1])
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;

}


#include <iostream>

using namespace std;

int a[100000 + 10], x, y , cnt;
bool flag;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i];
		if (i && a[i] < a[i-1])
		{
			cnt ++;
			if (!flag)
			{
				x = i - 1;
				flag = 1;
			}
			else
				y = i;
		}
	}
	if (cnt > 2)
	{
		cout << "NO" << endl;
		return 0;
	}
	if (cnt == 1)
	{
		cout << "YES" << endl;
		return 0;
	}
	swap(a[x], a[y]);
	for (int i = 0 ; i < n; i ++)
	{
		//cout << a[i] << " ";
		if (i && a[i] < a[i-1])
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define lp(i,n) 	for(int i=0;i<(int)n;i++)
#define lpv(i,a,n) 	for(int i=a;i<=(int)n;i++)
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;

void YAHIA() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(8);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
int a[100074] , b[100074] ;
int main() {
	YAHIA();
	int n ;
	bool ok = 1 ;
	cin >> n ;
	lp(i,n)
		cin >> a[i] , b[i] = a[i] ;
	sort(b,b+n) ;
	lp(i,n){
		if (a[i] != b[i] && ok) {
			for (int j = i+1 ; j <n;j++){
				if (a[j] == b[i] && b[j] == a[i]){
					ok = false ;
					swap(a[i] , a[j]) ;
					break ;
				}
			}
		}else if (a[i] != b[i] && !ok ){
			return cout << "NO" , 0 ;
		}
	}
	cout << "YES" ;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define lp(i,n) 	for(int i=0;i<(int)n;i++)
#define lpv(i,a,n) 	for(int i=a;i<=(int)n;i++)
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;

void YAHIA() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(8);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
int a[100074] , b[100074] ;
int main() {
	YAHIA();
	int n , ok = 0 ;
	cin >> n ;
	lp(i,n)
		cin >> a[i] , b[i] = a[i] ;
	sort(b,b+n) ;
	lp(i,n){
		if (a[i] != b[i]) {
			for (int j = i+1 ; j <n;j++){
				if (a[j] == b[i] && b[j] == a[i]){
					++ok ;
					if (ok > 1 ) return cout << "NO" , 0 ;
					swap(a[i] , a[j]) ;
					break ;
				}
			}
		}
	}
	cout << "YES" ;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define lp(i,n) 	for(int i=0;i<(int)n;i++)
#define lpv(i,a,n) 	for(int i=a;i<=(int)n;i++)
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;

void YAHIA() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(8);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
int a[100074] , b[100074] ;
int main() {
	YAHIA();
	int n , ok = 0 ;
	cin >> n ;
	lp(i,n)
		cin >> a[i] , b[i] = a[i] ;
	sort(b,b+n) ;
	lp(i,n){
		if (a[i] != b[i]) {
			for (int j = i+1 ; j <n;j++){
				if (a[j] == b[i] && b[j] == a[i]){
					++ok ;
					swap(a[i] , a[j]) ;
					break ;
				}
			}
		}
	}
	if (ok <= 1) cout << "YES" ;
	else cout << "NO" ;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define el      	'\n'
#define ft 			first
#define sd 			second
#define mp(x,y)  	make_pair((x),(y))
#define pb(x)    	push_back((x))
#define all(v)  	((v).begin()),((v).end())
#define sz(x)  		((int) (x).size())
#define lp(i,n) 	for(int i=0;i<(int)n;i++)
#define lpv(i,a,n) 	for(int i=a;i<=(int)n;i++)
#define clr(a,b)	memset(a,b,sizeof(a))
typedef long long ll;

void YAHIA() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(8);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
int a[100074] , b[100074] ;
int main() {
	YAHIA();
	int n , ok = 0 ;
	cin >> n ;
	lp(i,n)
		cin >> a[i] , b[i] = a[i] ;
	sort(b,b+n) ;
	lp(i,n){
		if (a[i] != b[i]) {
			++ok;
		}
	}
	if (ok > 2) cout << "NO" ;
	else cout << "YES" ;
	return 0;
}


#include <iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<set>
#include<vector>
#include<string.h>
#include<stack>

using namespace std;
typedef  long long ll;

int main()
{
std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    int arr[10000];
    int arr2[10000];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr2[i]=arr[i];

    }
    int swp=0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
    {
        if(arr2[i]!=arr[i])
        {
            swp++;
        }
    }
    if(swp>2)
        cout<<"NO";
    else
        cout<<"YES";

        return 0;
    }


#include <iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<set>
#include<vector>
#include<string.h>
#include<stack>

using namespace std;
typedef  long long ll;

int main()
{
std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    int arr[100000];
    int arr2[100000];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr2[i]=arr[i];

    }
    int swp=0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
    {
        if(arr2[i]!=arr[i])
        {
            swp++;
        }
    }
    if(swp>2)
        cout<<"NO";
    else
        cout<<"YES";

        return 0;
    }


#include <iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<set>
#include<vector>
#include<string.h>
#include<stack>

using namespace std;
typedef  long long ll;

int main()
{

    int n;
    int arr[10000];
    int arr2[10000];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr2[i]=arr[i];

    }
    int swp=0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
    {
        if(arr2[i]!=arr[i])
        {
            swp++;
        }
    }
    if(swp>2)
        cout<<"NO";
    else
        cout<<"YES";

        return 0;
    }


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<bitset>
#include<cctype>
#define LL long long
#define maxn (LL)1e5
#define INF 0x3f3f3f3f
const double eps = 0.00001;
using namespace std;
int f[100005];
int t[100005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif // ONLINE_JUDGE
    LL n;
    cin>>n;
    for(int i =1;i<=n;++i)
    {
        cin>>f[i];
    }
    memcpy(t,f,sizeof(f));
    int sum = 0;
    sort(t+1,t+n+1);
    for(int i = 1;i <= n;++i)
    {
        if(f[i]!=t[i]) sum++;
    }
    if(sum==2||sum==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<bitset>
#include<cctype>
#define LL long long
#define maxn (LL)1e5
#define INF 0x3f3f3f3f
const double eps = 0.00001;
using namespace std;
int f[10005];
int t[10005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif // ONLINE_JUDGE
    LL n;
    cin>>n;
    for(int i =1;i<=n;++i)
    {
        cin>>f[i];
    }
    memcpy(t,f,sizeof(f));
    int sum = 0;
    sort(t+1,t+n+1);
    for(int i = 1;i <= n;++i)
    {
        if(f[i]!=t[i]) sum++;
    }
    if(sum==2||sum==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef string str;
#define forn(i, n) for (int i = 0; i < n; i++)
#define form(i, n, m) for (int i = n; i <= m; i++)
//
#define read(x) scanf("%d", &x)
#define write(x) printf("%d", x)
#define writeln(x) printf("%d\n", x)
#define wp(x) cout << x.first << ' ' << x.second << '\n';
#define wm(x) for (int i = 0; i < x.size(); i++) cout << x[i] << ' '; cout << LN;
#define read2(x, y) scanf("%d %d", &x, &y)
//
#define sqr(x) x*x
#define clr(a, x) memset(a, x, sizeof(a));
#define mp make_pair
#define pb push_back
#define pob pop_back
#define XX first
#define YY second
#define in insert
#define db long double
#define re return
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define y0 asdfasdf3rcdt234d5c23xd234dx43
#define sz size
#define rs resize
#define vec vector
#define all(a) a.begin(), a.end()
#define TASK "sum"   //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const str LN = "\n";
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = (int)2e9 + 7;
const ll LINF = (ll)9e18 + 7;
bool in(int k, int x1, int x2) {re (k >= x1 && k <= x2);}

const int MAXN = 60007;
const int P1 = 239017;
const int P2 = 353251;
const ll MOD = 1e9 + 7;
const ll MOD2 = 1e9 + 9;
const int l = 20;

int n;
pair<int, int> a[100007];

const bool is_testing = 0;
int main()
{
	srand(time(NULL));
	if (is_testing)
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	cin >> n;
	forn(i, n)
		cin >> a[i].XX, a[i].YY = i;
	sort(a, a + n);
	int k = 0;
	forn(i, n)
		if (i != a[i].YY)
			k++;
	if (k > 2)
		cout << "NO";
	else
		cout << "YES";

	if (is_testing){
		cout << LN << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << LN;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef string str;
#define forn(i, n) for (int i = 0; i < n; i++)
#define form(i, n, m) for (int i = n; i <= m; i++)
//
#define read(x) scanf("%d", &x)
#define write(x) printf("%d", x)
#define writeln(x) printf("%d\n", x)
#define wp(x) cout << x.first << ' ' << x.second << '\n';
#define wm(x) for (int i = 0; i < x.size(); i++) cout << x[i] << ' '; cout << LN;
#define read2(x, y) scanf("%d %d", &x, &y)
//
#define sqr(x) x*x
#define clr(a, x) memset(a, x, sizeof(a));
#define mp make_pair
#define pb push_back
#define pob pop_back
#define XX first
#define YY second
#define in insert
#define db long double
#define re return
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define y0 asdfasdf3rcdt234d5c23xd234dx43
#define sz size
#define rs resize
#define vec vector
#define all(a) a.begin(), a.end()
#define TASK "sum"   //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const str LN = "\n";
const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = (int)2e9 + 7;
const ll LINF = (ll)9e18 + 7;
bool in(int k, int x1, int x2) {re (k >= x1 && k <= x2);}

const int MAXN = 60007;
const int P1 = 239017;
const int P2 = 353251;
const ll MOD = 1e9 + 7;
const ll MOD2 = 1e9 + 9;
const int l = 20;

int n;
pair<int, int> a[100007];

const bool is_testing = 0;
int main()
{
	srand(time(NULL));
	if (is_testing)
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	cin >> n;
	forn(i, n)
		cin >> a[i].XX, a[i].YY = i;
	sort(a, a + n);
	int k = 0;
	forn(i, n)
		if (i != a[i].YY && a[a[i].YY].XX != a[i].XX)
			k++;
	if (k > 2)
		cout << "NO";
	else
		cout << "YES";

	if (is_testing){
		cout << LN << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << LN;
	}
}


#include <bits/stdc++.h>
using namespace std;

#define fastio                          ios::sync_with_stdio(false);   cin.tie(0);   cout.tie(0);
#define input(arr, n)                   for(i=1; i<=n; i++) cin >> arr[i];
#define output(arr, n)                  for(i=1; i<=n; i++) cout << arr[i] << " ";
#define print(cont)                     for(auto it : cont) cout << it << " ";
#define prefsum(arr, n)                 for(i=2; i<=n; i++) arr[i] += arr[i-1];
#define partialsum(arr, arrPS, k, n)    for(i=1; i<=n; i++) (i+k-1<=n) ? arrPS[i] = arr[i+k-1] - arr[i-1] : arrPS[i] = arr[n] - arr[i-1]; // prefsum first

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, char> pcc;
const int M = 2e5+6, MOD = 1e9+7;
int i, j, cnt;
int a[M], arr[M];

int main(){
    fastio;
    int n;
    cin >> n;
    input(a, n);
    for(i=1; i<=n; i++) arr[i] = a[i];
    sort(arr+1, arr+n+1);
    vector<pii>v;
    for(i=1; i<=n; i++){
        if(arr[i] != a[i]) v.push_back({arr[i], a[i]});
    }
    if(v.size() > 2) cout << "NO";
    else cout << "YES";

}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

bool cmp( int a , int b ) {
	return a < b ;
}

int main( ){
	ios::sync_with_stdio( 0 ) ;
	cin.tie( 0 ) ;
	int n , k ;
	ll a[100010] , b[100010] ;
	cin >> n ;
	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] , b[i] = a[i] ;
	sort( b , b + n , cmp ) ;
	k = 0 ;
	for( int i = 0; i < n; i++ )
		if( a[i] != b[i] )
			k++ ;
	if( k <= 2 )
		cout << "YES" ;
	else
		cout << "NO" ;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e3+10 ;

bool cmp( int a , int b ) {
	return a < b ;
}

int main( ){
	ios::sync_with_stdio( 0 ) ;
	cin.tie( 0 ) ;
	int n , k , a[N] , b[N] ;
	cin >> n ;
	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] , b[i] = a[i] ;
	sort( b , b + n , cmp ) ;
	k = 0 ;
	for( int i = 0; i < n; i++ )
		if( a[i] != b[i] )
			k++ ;
	if( k <= 2 )
		cout << "YES" ;
	else
		cout << "NO" ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,a[100005],b[100005],x=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]) x++;
    }
    if(x>2) cout<<"NO";
    else cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
int n,i,a[111111],b[111111],c;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(i=1;i<=n;i++)
	{
		if(a[i]!=b[i])c++;
	}
	if(c>2)cout<<"NO";
	else cout<<"YES";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sf1(a)                scanf("%d", &a)
#define sf2(a,b)              scanf("%d %d",&a, &b)
#define sf3(a,b,c)            scanf("%d %d %d", &a, &b, &c)
#define sf4(a,b,c,d)          scanf("%d %d %d %d", &a, &b, &c, &d)

#define sf1ll(a)              scanf("%I64d", &a)
#define sf2ll(a,b)            scanf("%lld %lld", &a, &b)
#define sf3ll(a,b,c)          scanf("%I64d %I64d %I64d", &a, &b, &c)
#define sf4ll(a,b,c,d)        scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d)
    map<int, int> mp;
int main()
{ cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
int n,cnt=0,tk ;
cin >> n ;
vector < int > vc , s ;
for (int i = 1 ; i<=n;i++)
   cin >> tk , vc.push_back(tk),s.push_back(tk);
   sort (s.begin(),s.end());
for (int i = 0 ; i<n;i++){
if (vc[i] != s[i]) cnt++;
}
if (cnt > 2) puts("NO");
else puts("YES");
 }


#include <iostream>
#include <algorithm>

int as[100000];
int bs[100000];
int N;

int main(){
  std::cin>>N;
  for(int i=0;i<N;i++){
    std::cin>>as[i];
  }
  std::copy(as,as+N,bs);
  std::sort(bs,bs+N);
  int wrong=0;
  for(int i=0;i<N;i++){
    wrong+=(as[i]!=bs[i]);
  }
  std::cout<<((wrong==2||wrong==0)?"YES":"NO")<<std::endl;
  return 0;
}


 // CODED BY : Super_KAZAKH(-:  >---->  Yedige Ashirbek
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <fstream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <string>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline void boost(){
    ios_base::sync_with_stdio();
    cin.tie(0);
    cout.tie(0);
}

const ll MAXN=1e5+123;
const ll inf=1e9+123;
const double pi=acos(-1);
int a[MAXN],b[MAXN];
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b+1,b+1+n);
    int s=0;
    int f=0;
    int cntr=0;
    for(int i=1;i<=n;i++){
        if(a[i]!=b[i] && cntr==0){
            s=i;
            cntr++;
        }
        else if(a[i]!=b[i]){
            f=i;
            cntr++;
        }
    }
    if(cntr!=2 && cntr!=0){
        cout<<"NO";
        return 0;
    }
    swap(a[s],a[f]);
    for(int i=1;i<=n;i++){
        if(a[i]!=b[i]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    exit(0);
}


//God & me
//I have agreed about this: "God can do anything" :-"
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
//#define int long long
using namespace std;
template<class T,class L>bool smax(T&x,L y){return x<y?(x=y,1):0;}template<class T,class L>bool smin(T&x,L y){return x>y?(x=y,1):0;}
typedef pair<int,int> pii;
const int maxn=1e5+17;
int n,a[maxn];
main(){
  ios::sync_with_stdio(0),cin.tie();
  cin>>n;
  vector<int>p;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]!=i+1)
      p.pb(i);
  }
  if(p.size()>2 || p.size()==1)
    return cout<<"NO\n",0;
  if(p.empty())
    return cout<<"YES\n",0;
  swap(a[p[0]],a[p[1]]);
  for(int i=0;i<n;i++){
    if(a[i]!=i+1)
    return cout<<"NO\n",0;
  }
  cout<<"YES\n";
  return 0;
}


//God & me
//I have agreed about this: "God can do anything" :-"
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
//#define int long long
using namespace std;
template<class T,class L>bool smax(T&x,L y){return x<y?(x=y,1):0;}template<class T,class L>bool smin(T&x,L y){return x>y?(x=y,1):0;}
typedef pair<int,int> pii;
const int maxn=1e5+17;
int n,a[maxn];
main(){
  ios::sync_with_stdio(0),cin.tie();
  cin>>n;
  vector<int>p;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]!=i+1)
      p.pb(i);
  }
  if(p.size()>2)
    return cout<<"NO\n",0;
  swap(a[p[0]],a[p[1]]);
  for(int i=0;i<n;i++){
    if(a[i]!=i+1)
    return cout<<"NO\n",0;
  }
  cout<<"YES\n";
  return 0;
}


t=int(input())
while t:
    t=t-1
    s=input()
    flag=0
    l=[]
    if '1' not in s:
        print(0)
        continue
    elif '2' not in s:
        print(0)
        continue
    elif '3' not in s:
        print(0)
        continue
    else:
        k=[]
        ans=0
        for w in range(len(s)):
            if k==[]:
                k.append(s[w])
                ans=1
            elif s[w] not in k:
                k.append(s[w])
                ans+=1
            elif s[w] in k and len(k)!=1:
                if k[-1]==s[w]:
                    ans+=1
                else:
                    ans=2
                    temp=k[-1]
                    k=[temp,s[w]]
            if len(k)==3:
                print(ans)
                flag=1
                break
    if flag==0:
        print(0)