import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int[] p_sort = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(p_sort);
    for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    }
    System.out.println(count<=2?"YES":"NO");
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io import java.util.Arrays; Arrays java.util public class Main {
  public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int[] p_sort = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(p_sort);
    for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    }
    System.out.println(count<=2?"YES":"NO");
  }
} Main public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int[] p_sort = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(p_sort);
    for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    }
    System.out.println(count<=2?"YES":"NO");
  } main {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int[] p_sort = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(p_sort);
    for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    }
    System.out.println(count<=2?"YES":"NO");
  } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(in.readLine()); n Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in int[] p = new int[n]; p new int[n] n int[] p_sort = new int[n]; p_sort new int[n] n int count = 0; count 0 String[] str = in.readLine().split(" "); str in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    } {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    } p[i] = Integer.parseInt(str[i]) p[i] p i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i p_sort[i] = Integer.parseInt(str[i]) p_sort[i] p_sort i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i Arrays.sort(p_sort) Arrays.sort Arrays p_sort for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
       if(p_sort[i] != p[i])
        count += 1;
    } {
       if(p_sort[i] != p[i])
        count += 1;
    } if(p_sort[i] != p[i])
        count += 1; p_sort[i] != p[i] p_sort[i] p_sort i p[i] p i count += 1 count 1 System.out.println(count<=2?"YES":"NO") System.out.println System.out System System.out count<=2?"YES":"NO" count<=2 count 2 "YES" "NO" String[] args args public class Main {
  public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int[] p_sort = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(p_sort);
    for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    }
    System.out.println(count<=2?"YES":"NO");
  }
} public class Main {
  public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int[] p_sort = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(p_sort);
    for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    }
    System.out.println(count<=2?"YES":"NO");
  }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args)throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] p = new int[n];
    int[] p_sort = new int[n];
    int count = 0;
    String[] str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      p[i] = Integer.parseInt(str[i]);
      p_sort[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(p_sort);
    for(int i=0; i<n; i++) {
       if(p_sort[i] != p[i])
        count += 1;
    }
    System.out.println(count<=2?"YES":"NO");
  }
}