import java.io.FileNotFoundException;
import java.util.Scanner;

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

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		}
		if(cnt<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		}
		if(cnt<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		}
		if(cnt<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} main {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		}
		if(cnt<=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 cnt = 0; cnt 0 for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		} {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		} int p = sc.nextInt(); p sc.nextInt() sc.nextInt sc if(i+1!=p) {
				cnt++;
			} i+1!=p i+1 i 1 p {
				cnt++;
			} cnt++ cnt if(cnt<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		} cnt<=2 cnt 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) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		}
		if(cnt<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		}
		if(cnt<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main
import java.io.FileNotFoundException;
import java.util.Scanner;

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

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int cnt = 0;
		for(int i=0;i<N;i++) {
			int p = sc.nextInt();
			if(i+1!=p) {
				cnt++;
			}
		}
		if(cnt<=2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}
