import java.util.Scanner;

public class Main {
	static boolean memo[];
	static boolean ok;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a, cnt = 0;
		for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static boolean memo[];
	static boolean ok;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a, cnt = 0;
		for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} Main static boolean memo[]; memo static boolean ok; ok public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a, cnt = 0;
		for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a, cnt = 0;
		for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a a cnt = 0; cnt 0 for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		} {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		} a = sc.nextInt() a sc.nextInt() sc.nextInt sc if (i != a) {
				cnt++;
			} i != a i a {
				cnt++;
			} cnt++ cnt if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		} cnt == 2 || cnt == 0 cnt == 2 cnt 2 cnt == 0 cnt 0 {
			System.out.println("YES");
		} System.out.println("YES") System.out.println System.out System System.out "YES" {
			System.out.println("NO");
		} System.out.println("NO") System.out.println System.out System System.out "NO" String[] args args public class Main {
	static boolean memo[];
	static boolean ok;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a, cnt = 0;
		for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} public class Main {
	static boolean memo[];
	static boolean ok;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a, cnt = 0;
		for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} Main
import java.util.Scanner;

public class Main {
	static boolean memo[];
	static boolean ok;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a, cnt = 0;
		for (int i = 1; i <= n; i++) {
			a = sc.nextInt();
			if (i != a) {
				cnt++;
			}
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}