import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int i, number, count = 0;
    number = Integer.parseInt(sc.next());
    int[] num_array = new int[number];
    for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number; i++) {
      if(i + 1 != num_array[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 i, number, count = 0;
    number = Integer.parseInt(sc.next());
    int[] num_array = new int[number];
    for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number; i++) {
      if(i + 1 != num_array[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 i, number, count = 0;
    number = Integer.parseInt(sc.next());
    int[] num_array = new int[number];
    for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number; i++) {
      if(i + 1 != num_array[i]) count++;
    }
    if(count == 0 || count == 2) System.out.println("YES");
    else System.out.println("NO");
  } main {
    Scanner sc = new Scanner(System.in);
    int i, number, count = 0;
    number = Integer.parseInt(sc.next());
    int[] num_array = new int[number];
    for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number; i++) {
      if(i + 1 != num_array[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 i i number number count = 0; count 0 number = Integer.parseInt(sc.next()) number Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] num_array = new int[number]; num_array new int[number] number for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next()); i = 0; i = 0 i 0 i < number i number i++ i++ i num_array[i] = Integer.parseInt(sc.next()); num_array[i] = Integer.parseInt(sc.next()) num_array[i] num_array i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(i = 0; i < number; i++) {
      if(i + 1 != num_array[i]) count++;
    } i = 0; i = 0 i 0 i < number i number i++ i++ i {
      if(i + 1 != num_array[i]) count++;
    } {
      if(i + 1 != num_array[i]) count++;
    } if(i + 1 != num_array[i]) count++; i + 1 != num_array[i] i + 1 i 1 num_array[i] num_array i 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 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 sc = new Scanner(System.in);
    int i, number, count = 0;
    number = Integer.parseInt(sc.next());
    int[] num_array = new int[number];
    for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number; i++) {
      if(i + 1 != num_array[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 i, number, count = 0;
    number = Integer.parseInt(sc.next());
    int[] num_array = new int[number];
    for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number; i++) {
      if(i + 1 != num_array[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 i, number, count = 0;
    number = Integer.parseInt(sc.next());
    int[] num_array = new int[number];
    for(i = 0; i < number; i++) num_array[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number; i++) {
      if(i + 1 != num_array[i]) count++;
    }
    if(count == 0 || count == 2) System.out.println("YES");
    else System.out.println("NO");
  }
}
