import java.util.*;
import java.io.*;
class Main
{

	public static void main(String args[])throws IOException
	{
		int n,count=0 ;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int p[]=new int[n];
		int p1[]=new int[n];
      	for(int i=0;i<n;i++)
      	{
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	}
      	for (int i = 0; i < n-1; i++) 
            for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } 
		for(int i=0;i<n;i++)
		{
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		}
		if(count<=2)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
} import java.util.*; util.* java import java.io.*; io.* java class Main
{

	public static void main(String args[])throws IOException
	{
		int n,count=0 ;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int p[]=new int[n];
		int p1[]=new int[n];
      	for(int i=0;i<n;i++)
      	{
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	}
      	for (int i = 0; i < n-1; i++) 
            for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } 
		for(int i=0;i<n;i++)
		{
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		}
		if(count<=2)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
} Main public static void main(String args[])throws IOException
	{
		int n,count=0 ;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int p[]=new int[n];
		int p1[]=new int[n];
      	for(int i=0;i<n;i++)
      	{
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	}
      	for (int i = 0; i < n-1; i++) 
            for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } 
		for(int i=0;i<n;i++)
		{
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		}
		if(count<=2)
			System.out.println("YES");
		else
			System.out.println("NO");
	} main {
		int n,count=0 ;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int p[]=new int[n];
		int p1[]=new int[n];
      	for(int i=0;i<n;i++)
      	{
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	}
      	for (int i = 0; i < n-1; i++) 
            for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } 
		for(int i=0;i<n;i++)
		{
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		}
		if(count<=2)
			System.out.println("YES");
		else
			System.out.println("NO");
	} int n n count=0 ; count 0 Scanner sc=new Scanner(System.in); sc new Scanner(System.in) n=sc.nextInt() n sc.nextInt() sc.nextInt sc int p[]=new int[n]; p new int[n] n int p1[]=new int[n]; p1 new int[n] n for(int i=0;i<n;i++)
      	{
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	} {
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	} p[i]=sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc p1[i]=p[i] p1[i] p1 i p[i] p i for (int i = 0; i < n-1; i++) 
            for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } int j = 0; int j = 0; j 0 j < n-i-1 j n-i-1 n-i-1 n i 1 j++ j++ j if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } p1[j] > p1[j+1] p1[j] p1 j p1[j+1] p1 j+1 j 1 { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } int temp = p1[j]; temp p1[j] p1 j p1[j] = p1[j+1] p1[j] p1 j p1[j+1] p1 j+1 j 1 p1[j+1] = temp p1[j+1] p1 j+1 j 1 temp for(int i=0;i<n;i++)
		{
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		} {
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		} if(p1[i]!=p[i])
				count++; p1[i]!=p[i] p1[i] p1 i p[i] p i count++ count if(count>=3)
				break; count>=3 count 3 break; if(count<=2)
			System.out.println("YES");
		else
			System.out.println("NO"); count<=2 count 2 System.out.println("YES") System.out.println System.out System System.out "YES" System.out.println("NO") System.out.println System.out System System.out "NO" String args[] args
import java.util.*;
import java.io.*;
class Main
{

	public static void main(String args[])throws IOException
	{
		int n,count=0 ;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		int p[]=new int[n];
		int p1[]=new int[n];
      	for(int i=0;i<n;i++)
      	{
      		p[i]=sc.nextInt();
      		p1[i]=p[i];
      	}
      	for (int i = 0; i < n-1; i++) 
            for (int j = 0; j < n-i-1; j++) 
                if (p1[j] > p1[j+1]) 
                { 
                    int temp = p1[j]; 
                    p1[j] = p1[j+1]; 
                    p1[j+1] = temp; 
                } 
		for(int i=0;i<n;i++)
		{
			if(p1[i]!=p[i])
				count++;
			if(count>=3)
				break;
		}
		if(count<=2)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}