import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] array = new int[n];
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      
      int count1 = 0;
      for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      }
      
      if(count1 == 0 || count1 == 2 ) System.out.print("YES");
      else System.out.println("NO");
    }
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] array = new int[n];
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      
      int count1 = 0;
      for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      }
      
      if(count1 == 0 || count1 == 2 ) System.out.print("YES");
      else System.out.println("NO");
    }
} Main public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] array = new int[n];
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      
      int count1 = 0;
      for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      }
      
      if(count1 == 0 || count1 == 2 ) System.out.print("YES");
      else System.out.println("NO");
    } main {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] array = new int[n];
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      
      int count1 = 0;
      for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      }
      
      if(count1 == 0 || count1 == 2 ) System.out.print("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[] array = new int[n]; array new int[n] n for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      } int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
      	array[i] = sc.nextInt();
      } {
      	array[i] = sc.nextInt();
      } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int count1 = 0; count1 0 for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      } int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
      	if(array[i] != i+1) count1++;
      } {
      	if(array[i] != i+1) count1++;
      } if(array[i] != i+1) count1++; array[i] != i+1 array[i] array i i+1 i 1 count1++ count1 if(count1 == 0 || count1 == 2 ) System.out.print("YES");
      else System.out.println("NO"); count1 == 0 || count1 == 2 count1 == 0 count1 0 count1 == 2 count1 2 System.out.print("YES") System.out.print System.out System System.out "YES" 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 sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] array = new int[n];
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      
      int count1 = 0;
      for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      }
      
      if(count1 == 0 || count1 == 2 ) System.out.print("YES");
      else System.out.println("NO");
    }
} public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] array = new int[n];
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      
      int count1 = 0;
      for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      }
      
      if(count1 == 0 || count1 == 2 ) System.out.print("YES");
      else System.out.println("NO");
    }
} Main
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] array = new int[n];
      for(int i = 0;i < array.length;i++){
      	array[i] = sc.nextInt();
      }
      
      int count1 = 0;
      for(int i = 0;i < array.length;i++){
      	if(array[i] != i+1) count1++;
      }
      
      if(count1 == 0 || count1 == 2 ) System.out.print("YES");
      else System.out.println("NO");
    }
}
