import java.util.*;
public class Main {

  public static void main (String[] args) {
	
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    Integer[] p = new Integer[N];
    
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    Integer[] p_ = p.clone();

    Arrays.sort(p);

    int count = 0;

    for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    }

    if (count == 0 || count == 2){
      System.out.println("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();
    
    Integer[] p = new Integer[N];
    
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    Integer[] p_ = p.clone();

    Arrays.sort(p);

    int count = 0;

    for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    }

    if (count == 0 || count == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
    
  }

} Main public static void main (String[] args) {
	
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    Integer[] p = new Integer[N];
    
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    Integer[] p_ = p.clone();

    Arrays.sort(p);

    int count = 0;

    for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    }

    if (count == 0 || count == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
    
  } main {
	
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    Integer[] p = new Integer[N];
    
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    Integer[] p_ = p.clone();

    Arrays.sort(p);

    int count = 0;

    for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    }

    if (count == 0 || count == 2){
      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 Integer[] p = new Integer[N]; p new Integer[N] N for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      p[i] = sc.nextInt();
    } {
      p[i] = sc.nextInt();
    } p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc sc.close() sc.close sc Integer[] p_ = p.clone(); p_ p.clone() p.clone p Arrays.sort(p) Arrays.sort Arrays p int count = 0; count 0 for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if (p[i] != p_[i]){
        count++;
      }
    } {
      if (p[i] != p_[i]){
        count++;
      }
    } if (p[i] != p_[i]){
        count++;
      } p[i] != p_[i] p[i] p i p_[i] p_ i {
        count++;
      } count++ count if (count == 0 || count == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    } count == 0 || count == 2 count == 0 count 0 count == 2 count 2 {
      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" String[] args args public class Main {

  public static void main (String[] args) {
	
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    Integer[] p = new Integer[N];
    
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    Integer[] p_ = p.clone();

    Arrays.sort(p);

    int count = 0;

    for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    }

    if (count == 0 || count == 2){
      System.out.println("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();
    
    Integer[] p = new Integer[N];
    
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    Integer[] p_ = p.clone();

    Arrays.sort(p);

    int count = 0;

    for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    }

    if (count == 0 || count == 2){
      System.out.println("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();
    
    Integer[] p = new Integer[N];
    
    for (int i = 0; i < N; i++) {
      p[i] = sc.nextInt();
    }

    sc.close();

    Integer[] p_ = p.clone();

    Arrays.sort(p);

    int count = 0;

    for (int i = 0; i < N; i++){
      if (p[i] != p_[i]){
        count++;
      }
    }

    if (count == 0 || count == 2){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
    
  }

}