import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	}

} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	}

} Main public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	} main {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	} Scanner stdin = new Scanner(System.in); stdin new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int N = Integer.parseInt(stdin.next()); N Integer.parseInt(stdin.next()) Integer.parseInt Integer stdin.next() stdin.next stdin int Nlist[] = new int[N]; Nlist new int[N] N int list[] = new int[N]; list new int[N] N int p[] = new int[N]; p new int[N] N int cnt = 0; cnt 0 for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		} {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		} p[i] = Integer.parseInt(stdin.next()) p[i] p i Integer.parseInt(stdin.next()) Integer.parseInt Integer stdin.next() stdin.next stdin list[i] = i+1 list[i] list i i+1 i 1 for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		} {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		} if(list[i] != p[i]) {
				cnt += 1;
			} list[i] != p[i] list[i] list i p[i] p i {
				cnt += 1;
			} cnt += 1 cnt 1 if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		} cnt > 2 cnt 2 {
			out.print("NO");
		} out.print("NO") out.print out "NO" {
			out.print("YES");
		} out.print("YES") out.print out "YES" out.flush() out.flush out String[] args args public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	}

} public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	}

} Main
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = Integer.parseInt(stdin.next());
		int Nlist[] = new int[N];
		int list[] = new int[N];
		int p[] = new int[N];
		int cnt = 0;

		for(int i=0;i<N;i++) {
			p[i] = Integer.parseInt(stdin.next());
			list[i] = i+1;
		}
		
		for(int i=0;i<N;i++) {
			if(list[i] != p[i]) {
				cnt += 1;
			}
		}
		
		if(cnt > 2) {
			out.print("NO");
		}
		else {
			out.print("YES");
		}

		out.flush();
	}

}
