import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


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

} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


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

} Main public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


    if (count <= 2) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  } main {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


    if (count <= 2) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int count = 0; count 0 for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    } {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    } int tmp = scan.nextInt(); tmp scan.nextInt() scan.nextInt scan if (tmp != i) {
        count++;
      } tmp != i tmp i {
        count++;
      } count++ count if (count <= 2) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    } 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 scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


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

} public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


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

} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


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

}
