import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				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 s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	}

} Main public static void main(String[] args) {
			Scanner s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	} main {
			Scanner s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int numN = s.nextInt(); numN s.nextInt() s.nextInt s int[] nums = new int[numN]; nums new int[numN] numN for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			} int i = 0; int i = 0; i 0 i < numN i numN i++ i++ i {
				nums[i] = s.nextInt();
			} {
				nums[i] = s.nextInt();
			} nums[i] = s.nextInt() nums[i] nums i s.nextInt() s.nextInt s s.close() s.close s int count = 0; count 0 for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			} int i = 0; int i = 0; i 0 i < numN i numN i++ i++ i {
				if(nums[i] != i +1 ) {
					count++;
				}
			} {
				if(nums[i] != i +1 ) {
					count++;
				}
			} if(nums[i] != i +1 ) {
					count++;
				} nums[i] != i +1 nums[i] nums i i +1 i 1 {
					count++;
				} count++ count if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			} count == 2 ||count ==0 count == 2 count 2 count ==0 count 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 {

	public static void main(String[] args) {
			Scanner s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	}

} public class Main {

	public static void main(String[] args) {
			Scanner s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
			Scanner s = new Scanner(System.in);
			int numN = s.nextInt();
			int[] nums = new int[numN];

			for(int i = 0; i < numN; i++) {
				nums[i] = s.nextInt();
			}
			s.close();
			int count = 0;
			for(int i = 0; i < numN ; i++) {
				if(nums[i] != i +1 ) {
					count++;
				}
			}
			if(count == 2 ||count ==0) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}

	}

}
