import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt();
		scanner.close();

		int cnt = 0;
		for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++;

		switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt();
		scanner.close();

		int cnt = 0;
		for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++;

		switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		}
	}
} Main public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt();
		scanner.close();

		int cnt = 0;
		for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++;

		switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt();
		scanner.close();

		int cnt = 0;
		for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++;

		switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] p = new int[N]; p new int[N] N for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i p[i] = scanner.nextInt(); p[i] = scanner.nextInt() p[i] p i scanner.nextInt() scanner.nextInt scanner scanner.close() scanner.close scanner int cnt = 0; cnt 0 for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++; int i = 0; int i = 0; i 0 i < N i N i++ i++ i if (p[i] != i + 1)
				cnt++; if (p[i] != i + 1)
				cnt++; p[i] != i + 1 p[i] p i i + 1 i 1 cnt++ cnt switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		} cnt case 0: 0 case 0: case 2: 2 case 2: System.out.println("YES") System.out.println System.out System System.out "YES" break; default: default: System.out.println("NO") System.out.println System.out System System.out "NO" break; String args[] args public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt();
		scanner.close();

		int cnt = 0;
		for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++;

		switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		}
	}
} public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt();
		scanner.close();

		int cnt = 0;
		for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++;

		switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = scanner.nextInt();
		scanner.close();

		int cnt = 0;
		for (int i = 0; i < N; i++)
			if (p[i] != i + 1)
				cnt++;

		switch (cnt) {
		case 0:
		case 2:
			System.out.println("YES");
			break;
		default:
			System.out.println("NO");
			break;
		}
	}
}