import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = input.nextInt();
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      if(array[i] != i + 1)
        count++;
    }
    if (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 input = new Scanner(System.in);
    int n = input.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = input.nextInt();
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      if(array[i] != i + 1)
        count++;
    }
    if (count <= 2)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
} Main public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = input.nextInt();
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      if(array[i] != i + 1)
        count++;
    }
    if (count <= 2)
      System.out.println("YES");
    else
      System.out.println("NO");
  } main {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = input.nextInt();
    }

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

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      if(array[i] != i + 1)
        count++;
    }
    if (count <= 2)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
} public class Main {

  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = input.nextInt();
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      if(array[i] != i + 1)
        count++;
    }
    if (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 input = new Scanner(System.in);
    int n = input.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = input.nextInt();
    }

    int count = 0;
    for (int i = 0; i < n - 1; i++) {
      if(array[i] != i + 1)
        count++;
    }
    if (count <= 2)
      System.out.println("YES");
    else
      System.out.println("NO");
  }
}
