//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      
      int count = 0;
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      }
      
      if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      }

      
      
      
      
      out.close();
   }
   
      
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      
      int count = 0;
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      }
      
      if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      }

      
      
      
      
      out.close();
   }
   
      
} Main public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      
      int count = 0;
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      }
      
      if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      }

      
      
      
      
      out.close();
   } main {
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      
      int count = 0;
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      }
      
      if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      }

      
      
      
      
      out.close();
   } BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); f new BufferedReader(new InputStreamReader(System.in)) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int n = Integer.parseInt(f.readLine()); n Integer.parseInt(f.readLine()) Integer.parseInt Integer f.readLine() f.readLine f StringTokenizer st = new StringTokenizer(f.readLine()); st new StringTokenizer(f.readLine()) int[] array = new int[n+1]; array new int[n+1] n+1 n 1 int count = 0; count 0 for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      } int k = 1; int k = 1; k 1 k <= n k n k++ k++ k {
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      } {
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      } array[k] = Integer.parseInt(st.nextToken()) array[k] array k Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st if(array[k] != k){
            count++;
         } array[k] != k array[k] array k k {
            count++;
         } count++ count if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      } count <= 2 count 2 {
         out.println("YES");
      } out.println("YES") out.println out "YES" {
         out.println("NO");
      } out.println("NO") out.println out "NO" out.close() out.close out String[] args args public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      
      int count = 0;
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      }
      
      if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      }

      
      
      
      
      out.close();
   }
   
      
} public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      
      int count = 0;
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      }
      
      if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      }

      
      
      
      
      out.close();
   }
   
      
} Main
//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      StringTokenizer st = new StringTokenizer(f.readLine());
      
      int[] array = new int[n+1];
      
      int count = 0;
      for(int k = 1; k <= n; k++){
         array[k] = Integer.parseInt(st.nextToken());
         if(array[k] != k){
            count++;
         }
      }
      
      if(count <= 2){
         out.println("YES");
      } else {
         out.println("NO");
      }

      
      
      
      
      out.close();
   }
   
      
}