import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    boolean ok = true;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    }

    System.out.println("YES");

  }
} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    boolean ok = true;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    }

    System.out.println("YES");

  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    boolean ok = true;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    }

    System.out.println("YES");

  } main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    boolean ok = true;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    }

    System.out.println("YES");

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n boolean ok = true; ok true 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 for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    } {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    } if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      } p[i] != (i + 1) p[i] p i (i + 1) i 1 {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      } if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        } ok {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } int index = 0; index 0 for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          } {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          } if (p[j] == (i + 1)) {
              index = j;
              break;
            } p[j] == (i + 1) p[j] p j (i + 1) i 1 {
              index = j;
              break;
            } index = j index j break; int tmp = p[i]; tmp p[i] p i p[i] = p[index] p[i] p i p[index] p index p[index] = tmp p[index] p index tmp ok = false ok false {
          System.out.println("NO");
          return;
        } System.out.println("NO") System.out.println System.out System System.out "NO" return; System.out.println("YES") System.out.println System.out System System.out "YES" String[] args args public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    boolean ok = true;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    }

    System.out.println("YES");

  }
} public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    boolean ok = true;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    }

    System.out.println("YES");

  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    boolean ok = true;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      if (p[i] != (i + 1)) {
        if (ok) {
          int index = 0;
          for (int j = i + 1; j < n; j++) {
            if (p[j] == (i + 1)) {
              index = j;
              break;
            }
          }
          int tmp = p[i];
          p[i] = p[index];
          p[index] = tmp;
          ok = false;
        } else {
          System.out.println("NO");
          return;
        }
      }
    }

    System.out.println("YES");

  }
}