/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	static String sorting(int[] arr){
			int n = arr.length;
			int count = 0;
			for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			}
			return((count==2||count==0)?"YES":"NO");
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		System.out.println(sorting(arr));

	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main
{
	static String sorting(int[] arr){
			int n = arr.length;
			int count = 0;
			for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			}
			return((count==2||count==0)?"YES":"NO");
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		System.out.println(sorting(arr));

	}
} Main static String sorting(int[] arr){
			int n = arr.length;
			int count = 0;
			for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			}
			return((count==2||count==0)?"YES":"NO");
	} sorting {
			int n = arr.length;
			int count = 0;
			for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			}
			return((count==2||count==0)?"YES":"NO");
	} int n = arr.length; n arr.length arr arr.length int count = 0; count 0 for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			} int i=0; int i=0; i 0 i<n i n i++ i++ i {
				if(arr[i]!=i+1){
					count++;
				}
			} {
				if(arr[i]!=i+1){
					count++;
				}
			} if(arr[i]!=i+1){
					count++;
				} arr[i]!=i+1 arr[i] arr i i+1 i 1 {
					count++;
				} count++ count return((count==2||count==0)?"YES":"NO"); ((count==2||count==0)?"YES":"NO") (count==2||count==0) count==2 count 2 count==0 count 0 "YES" "NO" int[] arr arr public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		System.out.println(sorting(arr));

	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		System.out.println(sorting(arr));

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] arr = new int[n]; arr new int[n] n for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i] = scan.nextInt();
		} {
			arr[i] = scan.nextInt();
		} arr[i] = scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan System.out.println(sorting(arr)) System.out.println System.out System System.out sorting(arr) sorting arr String[] args args public class Main
{
	static String sorting(int[] arr){
			int n = arr.length;
			int count = 0;
			for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			}
			return((count==2||count==0)?"YES":"NO");
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		System.out.println(sorting(arr));

	}
} public class Main
{
	static String sorting(int[] arr){
			int n = arr.length;
			int count = 0;
			for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			}
			return((count==2||count==0)?"YES":"NO");
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		System.out.println(sorting(arr));

	}
} Main
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	static String sorting(int[] arr){
			int n = arr.length;
			int count = 0;
			for(int i=0;i<n;i++){
				if(arr[i]!=i+1){
					count++;
				}
			}
			return((count==2||count==0)?"YES":"NO");
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i] = scan.nextInt();
		}
		System.out.println(sorting(arr));

	}
}
