import java.util.Scanner;

public class Main {

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

    int N = Integer.parseInt(sc.next());

    int[] p = new int[N];
    for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    }

    System.out.println(cnt <= 2 ? "YES" : "NO");
  }
} import java.util.Scanner; Scanner java.util public class Main {

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

    int N = Integer.parseInt(sc.next());

    int[] p = new int[N];
    for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    }

    System.out.println(cnt <= 2 ? "YES" : "NO");
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int[] p = new int[N];
    for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    }

    System.out.println(cnt <= 2 ? "YES" : "NO");
  } main {
    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int[] p = new int[N];
    for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    }

    System.out.println(cnt <= 2 ? "YES" : "NO");
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] p = new int[N]; p new int[N] N for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      p[i] = Integer.parseInt(sc.next());
    } {
      p[i] = Integer.parseInt(sc.next());
    } p[i] = Integer.parseInt(sc.next()) p[i] p i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if (p[i] != i+1) {
        cnt++;
      }
    } {
      if (p[i] != i+1) {
        cnt++;
      }
    } if (p[i] != i+1) {
        cnt++;
      } p[i] != i+1 p[i] p i i+1 i 1 {
        cnt++;
      } cnt++ cnt System.out.println(cnt <= 2 ? "YES" : "NO") System.out.println System.out System System.out cnt <= 2 ? "YES" : "NO" cnt <= 2 cnt 2 "YES" "NO" String[] args args public class Main {

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

    int N = Integer.parseInt(sc.next());

    int[] p = new int[N];
    for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    }

    System.out.println(cnt <= 2 ? "YES" : "NO");
  }
} public class Main {

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

    int N = Integer.parseInt(sc.next());

    int[] p = new int[N];
    for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    }

    System.out.println(cnt <= 2 ? "YES" : "NO");
  }
} Main
import java.util.Scanner;

public class Main {

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

    int N = Integer.parseInt(sc.next());

    int[] p = new int[N];
    for (int i = 0; i < N; i++) {
      p[i] = Integer.parseInt(sc.next());
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (p[i] != i+1) {
        cnt++;
      }
    }

    System.out.println(cnt <= 2 ? "YES" : "NO");
  }
}