import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int result = 0;

		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		}

		if(result == 0 || result == 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) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int result = 0;

		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		}

		if(result == 0 || result == 2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}

} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int result = 0;

		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		}

		if(result == 0 || result == 2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int result = 0;

		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		}

		if(result == 0 || result == 2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int result = 0; result 0 for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		} {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		} int val = sc.nextInt(); val sc.nextInt() sc.nextInt sc if (val != (i + 1)) {
				result++;
			} val != (i + 1) val (i + 1) i 1 {
				result++;
			} result++ result if(result == 0 || result == 2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		} result == 0 || result == 2 result == 0 result 0 result == 2 result 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) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int result = 0;

		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		}

		if(result == 0 || result == 2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}

} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int result = 0;

		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		}

		if(result == 0 || result == 2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int result = 0;

		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val != (i + 1)) {
				result++;
			}
		}

		if(result == 0 || result == 2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}

}
