import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		int count = 0;
		for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		}
		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		int count = 0;
		for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		}
		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		int count = 0;
		for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		}
		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		int count = 0;
		for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		}
		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] p = new int[n]; p new int[n] n for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		} int i = 0; int i = 0; i 0 i < p.length i p.length p p.length i++ i++ i {
			p[i] = Integer.parseInt(sc.next());
		} {
			p[i] = Integer.parseInt(sc.next());
		} p[i] = Integer.parseInt(sc.next()) p[i] p i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int count = 0; count 0 for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		} int i = 0; int i = 0; i 0 i < p.length i p.length p p.length i++ i++ i {
			if (i + 1 != p[i]) {
				count++;
			}
		} {
			if (i + 1 != p[i]) {
				count++;
			}
		} if (i + 1 != p[i]) {
				count++;
			} i + 1 != p[i] i + 1 i 1 p[i] p i {
				count++;
			} count++ count if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		} count == 0 || count == 2 count == 0 count 0 count == 2 count 2 {
			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" sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		int count = 0;
		for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		}
		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}
} public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		int count = 0;
		for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		}
		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		int count = 0;
		for (int i = 0; i < p.length; i++) {
			if (i + 1 != p[i]) {
				count++;
			}
		}
		if (count == 0 || count == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		sc.close();
	}
}