import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			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) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} Main public static void main(String[] args) {
		(new Main()).execute();
	} main {
		(new Main()).execute();
	} (new Main()).execute() (new Main()).execute (new Main()) String[] args args public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	} execute {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			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 p[] = new int[N+1] ; p new int[N+1] N+1 N 1 int ngPos = 0 ; ngPos 0 int ngNum = 0 ; ngNum 0 int changeCount = 0 ; changeCount 0 boolean ok = true ; ok true for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		} int i = 1 ; int i = 1 ; i 1 i <= N i N i ++ i ++ i {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		} {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			} p[i] != i p[i] p i i {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			} if(0 < changeCount) {
					ok = false ;
					break ;
				} 0 < changeCount 0 changeCount {
					ok = false ;
					break ;
				} ok = false ok false break ; if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				} 0 == ngPos 0 ngPos {
					ngPos = i ;
					ngNum = p[i];
				} ngPos = i ngPos i ngNum = p[i] ngNum p[i] p i {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				} if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					} ngPos == p[i] && ngNum == i ngPos == p[i] ngPos p[i] p i ngNum == i ngNum i {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					} changeCount ++ changeCount ngPos = 0 ngPos 0 ngNum = 0 ngNum 0 {
						ok = false ;
						break ;
					} ok = false ok false break ; if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		} ok {
			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" public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
} Main
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int  N = sc.nextInt();
		int p[] = new int[N+1] ;

		int ngPos = 0 ;
		int ngNum = 0 ;
		int changeCount = 0 ;
		boolean ok = true ;
		for( int i = 1 ; i <= N; i ++ ) {
			p[i] = sc.nextInt();
			if(p[i] != i ) {
				if(0 < changeCount) {
					ok = false ;
					break ;
				}
				if(0 == ngPos) {
					ngPos = i ;
					ngNum = p[i];
				}else {
					if(ngPos == p[i] && ngNum == i) {
						changeCount ++ ;
						ngPos = 0 ;
						ngNum = 0 ;
					}else {
						ok = false ;
						break ;
					}
				}
			}
		}
		if(ok) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}
