import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[] numbers = new int[N];
		for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		}
		
		int count = 0;
		for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		}
		
		if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[] numbers = new int[N];
		for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		}
		
		int count = 0;
		for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		}
		
		if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	}
} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[] numbers = new int[N];
		for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		}
		
		int count = 0;
		for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		}
		
		if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	} main {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[] numbers = new int[N];
		for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		}
		
		int count = 0;
		for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		}
		
		if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] numbers = new int[N]; numbers new int[N] N for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			numbers[i] = scan.nextInt();
		} {
			numbers[i] = scan.nextInt();
		} numbers[i] = scan.nextInt() numbers[i] numbers i scan.nextInt() scan.nextInt scan int count = 0; count 0 for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		} int i = 1; int i = 1; i 1 i <= numbers.length i numbers.length numbers numbers.length i++ i++ i {
			if (numbers[i - 1] == i) {
				count++;
			}
		} {
			if (numbers[i - 1] == i) {
				count++;
			}
		} if (numbers[i - 1] == i) {
				count++;
			} numbers[i - 1] == i numbers[i - 1] numbers i - 1 i 1 i {
				count++;
			} count++ count if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		} count >= (N - 2) count (N - 2) N 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" String[] args args public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[] numbers = new int[N];
		for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		}
		
		int count = 0;
		for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		}
		
		if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	}
} public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[] numbers = new int[N];
		for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		}
		
		int count = 0;
		for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		}
		
		if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		int[] numbers = new int[N];
		for (int i = 0; i < N; i++) {
			numbers[i] = scan.nextInt();
		}
		
		int count = 0;
		for (int i = 1; i <= numbers.length; i++) {
			if (numbers[i - 1] == i) {
				count++;
			}
		}
		
		if (count >= (N - 2)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
		
	}
}