import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
} Main public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  } main {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    } in.hasNext() in.hasNext in {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    } int N = in.nextInt(); N in.nextInt() in.nextInt in int[] p = new int[N + 1]; p new int[N + 1] N + 1 N 1 int countWrongPos = 0; countWrongPos 0 for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      } int i = 1; int i = 1; i 1 i < p.length i p.length p p.length ++i ++i i {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      } {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      } p[i] = in.nextInt() p[i] p i in.nextInt() in.nextInt in if (i != p[i]) {
          ++countWrongPos;
        } i != p[i] i p[i] p i {
          ++countWrongPos;
        } ++countWrongPos countWrongPos if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      } countWrongPos == 0 || countWrongPos == 2 countWrongPos == 0 countWrongPos 0 countWrongPos == 2 countWrongPos 2 {
        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 {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
} public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      int N = in.nextInt();
      int[] p = new int[N + 1];
      int countWrongPos = 0;

      for (int i = 1; i < p.length; ++i) {
        p[i] = in.nextInt();
        if (i != p[i]) {
          ++countWrongPos;
        }
      }

      if (countWrongPos == 0 || countWrongPos == 2) {
        System.out.println("YES");
      } else {
        System.out.println("NO");
      }
    }
  }
}