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[] arr = new int[n];
		int[] compare = new int[n];
		for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		}
		int count = 0;
		Arrays.sort(compare);
		for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		}
		System.out.println(count>2?"NO":"YES");

	}

} 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[] arr = new int[n];
		int[] compare = new int[n];
		for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		}
		int count = 0;
		Arrays.sort(compare);
		for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		}
		System.out.println(count>2?"NO":"YES");

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		int[] compare = new int[n];
		for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		}
		int count = 0;
		Arrays.sort(compare);
		for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		}
		System.out.println(count>2?"NO":"YES");

	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		int[] compare = new int[n];
		for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		}
		int count = 0;
		Arrays.sort(compare);
		for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		}
		System.out.println(count>2?"NO":"YES");

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n int[] compare = new int[n]; compare new int[n] n for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		} int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		} {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		} int temp = sc.nextInt(); temp sc.nextInt() sc.nextInt sc arr[i]=temp arr[i] arr i temp compare[i] = temp compare[i] compare i temp int count = 0; count 0 Arrays.sort(compare) Arrays.sort Arrays compare for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		} int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
			if(arr[i]!=compare[i])count++;
		} {
			if(arr[i]!=compare[i])count++;
		} if(arr[i]!=compare[i])count++; arr[i]!=compare[i] arr[i] arr i compare[i] compare i count++ count System.out.println(count>2?"NO":"YES") System.out.println System.out System System.out count>2?"NO":"YES" count>2 count 2 "NO" "YES" String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		int[] compare = new int[n];
		for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		}
		int count = 0;
		Arrays.sort(compare);
		for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		}
		System.out.println(count>2?"NO":"YES");

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		int[] compare = new int[n];
		for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		}
		int count = 0;
		Arrays.sort(compare);
		for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		}
		System.out.println(count>2?"NO":"YES");

	}

} 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[] arr = new int[n];
		int[] compare = new int[n];
		for(int i = 0;i<n;i++) {
			int temp = sc.nextInt();
			arr[i]=temp;
			compare[i] = temp;
		}
		int count = 0;
		Arrays.sort(compare);
		for(int i = 0;i<n;i++) {
			if(arr[i]!=compare[i])count++;
		}
		System.out.println(count>2?"NO":"YES");

	}

}
