import java.io.*;
import java.util.*;

public class Main
{
  public static void main(String[] args) { new Main(); }
  Scanner in = new Scanner(System.in);
  PrintWriter out = new PrintWriter(System.out);
  
  int n, cnt = 0;
  
  Main()
  {
   	n = in.nextInt();
    for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++;
    if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO");
    out.close();
  }
} import java.io.*; io.* java import java.util.*; util.* java public class Main
{
  public static void main(String[] args) { new Main(); }
  Scanner in = new Scanner(System.in);
  PrintWriter out = new PrintWriter(System.out);
  
  int n, cnt = 0;
  
  Main()
  {
   	n = in.nextInt();
    for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++;
    if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO");
    out.close();
  }
} Main Scanner in = new Scanner(System.in); in new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int n n cnt = 0; cnt 0 public static void main(String[] args) { new Main(); } main { new Main(); } new Main() String[] args args Main()
  {
   	n = in.nextInt();
    for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++;
    if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO");
    out.close();
  } Main {
   	n = in.nextInt();
    for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++;
    if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO");
    out.close();
  } n = in.nextInt() n in.nextInt() in.nextInt in for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++; int i = 1; int i = 1; i 1 i <= n i n i++ i++ i if (in.nextInt() != i) cnt++; if (in.nextInt() != i) cnt++; in.nextInt() != i in.nextInt() in.nextInt in i cnt++ cnt if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO"); cnt == 0 || cnt == 2 cnt == 0 cnt 0 cnt == 2 cnt 2 out.println("YES") out.println out "YES" out.println("NO") out.println out "NO" out.close() out.close out public class Main
{
  public static void main(String[] args) { new Main(); }
  Scanner in = new Scanner(System.in);
  PrintWriter out = new PrintWriter(System.out);
  
  int n, cnt = 0;
  
  Main()
  {
   	n = in.nextInt();
    for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++;
    if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO");
    out.close();
  }
} public class Main
{
  public static void main(String[] args) { new Main(); }
  Scanner in = new Scanner(System.in);
  PrintWriter out = new PrintWriter(System.out);
  
  int n, cnt = 0;
  
  Main()
  {
   	n = in.nextInt();
    for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++;
    if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO");
    out.close();
  }
} Main
import java.io.*;
import java.util.*;

public class Main
{
  public static void main(String[] args) { new Main(); }
  Scanner in = new Scanner(System.in);
  PrintWriter out = new PrintWriter(System.out);
  
  int n, cnt = 0;
  
  Main()
  {
   	n = in.nextInt();
    for (int i = 1; i <= n; i++)
      	if (in.nextInt() != i) cnt++;
    if (cnt == 0 || cnt == 2) out.println("YES");
    else out.println("NO");
    out.close();
  }
}
