import java.util.*;
class Main{
	static Scanner input = new Scanner(System.in);
	
	public static void main(String[] args){
		int n;
		n = input.nextInt();
		int A[] = new int[n+1];
		int cnt = 0;
		for(int i = 1 ;i <= n ; i++)
			A[i] = input.nextInt();
		for(int i = 1 ;i <= n ; i++){
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		}
		if(cnt <= 1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}	
} import java.util.*; util.* java class Main{
	static Scanner input = new Scanner(System.in);
	
	public static void main(String[] args){
		int n;
		n = input.nextInt();
		int A[] = new int[n+1];
		int cnt = 0;
		for(int i = 1 ;i <= n ; i++)
			A[i] = input.nextInt();
		for(int i = 1 ;i <= n ; i++){
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		}
		if(cnt <= 1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}	
} Main static Scanner input = new Scanner(System.in); input new Scanner(System.in) public static void main(String[] args){
		int n;
		n = input.nextInt();
		int A[] = new int[n+1];
		int cnt = 0;
		for(int i = 1 ;i <= n ; i++)
			A[i] = input.nextInt();
		for(int i = 1 ;i <= n ; i++){
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		}
		if(cnt <= 1)
			System.out.println("YES");
		else
			System.out.println("NO");
	} main {
		int n;
		n = input.nextInt();
		int A[] = new int[n+1];
		int cnt = 0;
		for(int i = 1 ;i <= n ; i++)
			A[i] = input.nextInt();
		for(int i = 1 ;i <= n ; i++){
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		}
		if(cnt <= 1)
			System.out.println("YES");
		else
			System.out.println("NO");
	} int n; n n = input.nextInt() n input.nextInt() input.nextInt input int A[] = new int[n+1]; A new int[n+1] n+1 n 1 int cnt = 0; cnt 0 for(int i = 1 ;i <= n ; i++)
			A[i] = input.nextInt(); int i = 1 ; int i = 1 ; i 1 i <= n i n i++ i++ i A[i] = input.nextInt(); A[i] = input.nextInt() A[i] A i input.nextInt() input.nextInt input for(int i = 1 ;i <= n ; i++){
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		} int i = 1 ; int i = 1 ; i 1 i <= n i n i++ i++ i {
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		} {
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		} for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			} int j = i+1 ; int j = i+1 ; j i+1 i 1 j <= n j n j++ j++ j {
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			} {
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			} if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				} A[i] != i && A[j] == i A[i] != i A[i] A i i A[j] == i A[j] A j i {
					A[j] = A[i];
					A[i] = i;
					cnt++;
				} A[j] = A[i] A[j] A j A[i] A i A[i] = i A[i] A i i cnt++ cnt if(cnt <= 1)
			System.out.println("YES");
		else
			System.out.println("NO"); cnt <= 1 cnt 1 System.out.println("YES") System.out.println System.out System System.out "YES" System.out.println("NO") System.out.println System.out System System.out "NO" String[] args args
import java.util.*;
class Main{
	static Scanner input = new Scanner(System.in);
	
	public static void main(String[] args){
		int n;
		n = input.nextInt();
		int A[] = new int[n+1];
		int cnt = 0;
		for(int i = 1 ;i <= n ; i++)
			A[i] = input.nextInt();
		for(int i = 1 ;i <= n ; i++){
			for(int j = i+1 ;j <= n ; j++){
				if(A[i] != i && A[j] == i){
					A[j] = A[i];
					A[i] = i;
					cnt++;
				}
			}
		}
		if(cnt <= 1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}	
}