import java.util.*;
import java.io.*;

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();
    }
    int d = 0;
    Integer q[] = new Integer[n];
    for(int i=0;i<n;i++){
      q[i] = i+1;
    }



    for(int i=0;i < n ;i++){
      if(p[i] != q[i]){
        d ++;
      }
    }
    if(d == 2 || d == 0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }

    }

  } import java.util.*; util.* java import java.io.*; io.* java 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();
    }
    int d = 0;
    Integer q[] = new Integer[n];
    for(int i=0;i<n;i++){
      q[i] = i+1;
    }



    for(int i=0;i < n ;i++){
      if(p[i] != q[i]){
        d ++;
      }
    }
    if(d == 2 || d == 0){
      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();
    }
    int d = 0;
    Integer q[] = new Integer[n];
    for(int i=0;i<n;i++){
      q[i] = i+1;
    }



    for(int i=0;i < n ;i++){
      if(p[i] != q[i]){
        d ++;
      }
    }
    if(d == 2 || d == 0){
      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();
    }
    int d = 0;
    Integer q[] = new Integer[n];
    for(int i=0;i<n;i++){
      q[i] = i+1;
    }



    for(int i=0;i < n ;i++){
      if(p[i] != q[i]){
        d ++;
      }
    }
    if(d == 2 || d == 0){
      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 int d = 0; d 0 Integer q[] = new Integer[n]; q new Integer[n] n for(int i=0;i<n;i++){
      q[i] = i+1;
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      q[i] = i+1;
    } {
      q[i] = i+1;
    } q[i] = i+1 q[i] q i i+1 i 1 for(int i=0;i < n ;i++){
      if(p[i] != q[i]){
        d ++;
      }
    } int i=0; int i=0; i 0 i < n i n i++ i++ i {
      if(p[i] != q[i]){
        d ++;
      }
    } {
      if(p[i] != q[i]){
        d ++;
      }
    } if(p[i] != q[i]){
        d ++;
      } p[i] != q[i] p[i] p i q[i] q i {
        d ++;
      } d ++ d if(d == 2 || d == 0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    } d == 2 || d == 0 d == 2 d 2 d == 0 d 0 {
      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
import java.util.*;
import java.io.*;

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();
    }
    int d = 0;
    Integer q[] = new Integer[n];
    for(int i=0;i<n;i++){
      q[i] = i+1;
    }



    for(int i=0;i < n ;i++){
      if(p[i] != q[i]){
        d ++;
      }
    }
    if(d == 2 || d == 0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }

    }

  }
