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[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	}
} 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[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] p = new int[N]; p new int[N] N int[] s = new int[N]; s new int[N] N for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			p[i] = sc.nextInt();
			s[i] = p[i];
		} {
			p[i] = sc.nextInt();
			s[i] = p[i];
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc s[i] = p[i] s[i] s i p[i] p i sc.close() sc.close sc Arrays.sort(s) Arrays.sort Arrays s int r = 0; r 0 for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(p[i] != s[i]) r++;
		} {
			if(p[i] != s[i]) r++;
		} if(p[i] != s[i]) r++; p[i] != s[i] p[i] p i s[i] s i r++ r System.out.println(r == 0 || r == 2 ? "YES" : "NO") System.out.println System.out System System.out r == 0 || r == 2 ? "YES" : "NO" r == 0 || r == 2 r == 0 r 0 r == 2 r 2 "YES" "NO" String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	}
} 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[] p = new int[N];
		int[] s = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			s[i] = p[i];
		}
		sc.close();
		Arrays.sort(s);
		// System.out.println(Arrays.toString(p));
		// System.out.println(Arrays.toString(s));
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != s[i]) r++;
		}
		// System.out.println(r);
		System.out.println(r == 0 || r == 2 ? "YES" : "NO");
	}
}
