import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N=sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] nums = new int[N]; nums new int[N] N int[] nums2= new int[N]; nums2 new int[N] N int cnt=0; cnt 0 for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		} {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		} nums[i]=sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc nums2[i]=nums[i] nums2[i] nums2 i nums[i] nums i Arrays.sort(nums2) Arrays.sort Arrays nums2 for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		} {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		} if(nums[i]!=nums2[i]) {
				cnt++;
			} nums[i]!=nums2[i] nums[i] nums i nums2[i] nums2 i {
				cnt++;
			} cnt++ cnt System.out.println(cnt<=2?"YES":"NO") System.out.println System.out System System.out cnt<=2?"YES":"NO" cnt<=2 cnt 2 "YES" "NO" sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	}
}