import java.util.Scanner;

/**
 * https://atcoder.jp/contests/abc135/tasks/abc135_b
 */
public class Main {

  private static boolean answer(long[] ps) {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  }

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

    if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {

  private static boolean answer(long[] ps) {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  }

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

    if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
} Main private static boolean answer(long[] ps) {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  } answer {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  } int count = 0; count 0 for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    } int i = 0; int i = 0; i 0 i < ps.length i ps.length ps ps.length i++ i++ i {
      if (ps[i] != i + 1) {
        count++;
      }
    } {
      if (ps[i] != i + 1) {
        count++;
      }
    } if (ps[i] != i + 1) {
        count++;
      } ps[i] != i + 1 ps[i] ps i i + 1 i 1 {
        count++;
      } count++ count return count == 2 || count == 0; count == 2 || count == 0 count == 2 count 2 count == 0 count 0 long[] ps ps public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long[] ps = new long[n];
    for (int i = 0; i < n; i++) {
      ps[i] = scan.nextInt();
    }
    scan.close();

    if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  } main {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long[] ps = new long[n];
    for (int i = 0; i < n; i++) {
      ps[i] = scan.nextInt();
    }
    scan.close();

    if (answer(ps)) {
      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 long[] ps = new long[n]; ps new long[n] n for (int i = 0; i < n; i++) {
      ps[i] = scan.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      ps[i] = scan.nextInt();
    } {
      ps[i] = scan.nextInt();
    } ps[i] = scan.nextInt() ps[i] ps i scan.nextInt() scan.nextInt scan scan.close() scan.close scan if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    } answer(ps) answer ps {
      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 {

  private static boolean answer(long[] ps) {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  }

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

    if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
} public class Main {

  private static boolean answer(long[] ps) {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  }

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

    if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
} Main
import java.util.Scanner;

/**
 * https://atcoder.jp/contests/abc135/tasks/abc135_b
 */
public class Main {

  private static boolean answer(long[] ps) {
    int count = 0;
    for (int i = 0; i < ps.length; i++) {
      if (ps[i] != i + 1) {
        count++;
      }
    }

    return count == 2 || count == 0;
  }

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

    if (answer(ps)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}
