import java.io.*;

public class Main {

  public static void main(String[] args){

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  }

  public static void func(int a, int b){
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  }

  public static void ffunc(String[] ss){

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

  }
} import java.io.*; io.* java public class Main {

  public static void main(String[] args){

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  }

  public static void func(int a, int b){
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  }

  public static void ffunc(String[] ss){

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

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

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  } main {

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  } try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    } catch(IOException e){
      e.printStackTrace();
    } IOException e {
      e.printStackTrace();
    } e.printStackTrace() e.printStackTrace e {
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } String str; str BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); br new BufferedReader(new InputStreamReader(System.in, "UTF-8")) str = br.readLine() str br.readLine() br.readLine br str=br.readLine() str br.readLine() br.readLine br String[] ss = str.split(" "); ss str.split(" ") str.split str " " ffunc(ss) ffunc ss String[] args args public static void func(int a, int b){
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  } func {
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  } if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE"); (a+b)%2 == 0 (a+b)%2 (a+b) a b 2 0 {
      System.out.println(Math.abs((a+b)/2));
    } System.out.println(Math.abs((a+b)/2)) System.out.println System.out System System.out Math.abs((a+b)/2) Math.abs Math (a+b)/2 (a+b) a b 2 System.out.println("IMPOSSIBLE") System.out.println System.out System System.out "IMPOSSIBLE" int a a int b b public static void ffunc(String[] ss){

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

  } ffunc {

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

  } int ints[] = new int[ss.length]; ints new int[ss.length] ss.length ss ss.length int count = 0; count 0 for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    } int i = 0; int i = 0; i 0 i < ss.length i ss.length ss ss.length i++ i++ i {
      ints[i] = Integer.parseInt(ss[i]);
    } {
      ints[i] = Integer.parseInt(ss[i]);
    } ints[i] = Integer.parseInt(ss[i]) ints[i] ints i Integer.parseInt(ss[i]) Integer.parseInt Integer ss[i] ss i for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
} int i = 0; int i = 0; i 0 i < ss.length i ss.length ss ss.length i++ i++ i {
      if(ints[i] != i+1)count++;
} {
      if(ints[i] != i+1)count++;
} if(ints[i] != i+1)count++; ints[i] != i+1 ints[i] ints i i+1 i 1 count++ count if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO"); count == 2 || count == 0 count == 2 count 2 count == 0 count 0 System.out.println("YES") System.out.println System.out System System.out "YES" System.out.println("NO") System.out.println System.out System System.out "NO" String[] ss ss public class Main {

  public static void main(String[] args){

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  }

  public static void func(int a, int b){
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  }

  public static void ffunc(String[] ss){

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

  }
} public class Main {

  public static void main(String[] args){

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  }

  public static void func(int a, int b){
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  }

  public static void ffunc(String[] ss){

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

  }
} Main
import java.io.*;

public class Main {

  public static void main(String[] args){

    try{
      String str;
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
      str = br.readLine();
str=br.readLine();
      String[] ss = str.split(" ");
      //int sample = Integer.parseInt(str);
      //func(Integer.parseInt(ss[0]),Integer.parseInt(ss[1]));
ffunc(ss);
    } catch(IOException e){
      e.printStackTrace();
    }
  }

  public static void func(int a, int b){
    if((a+b)%2 == 0){
      System.out.println(Math.abs((a+b)/2));
    } else System.out.println("IMPOSSIBLE");
  }

  public static void ffunc(String[] ss){

    int ints[] = new int[ss.length];

int count = 0;

    for(int i = 0; i < ss.length; i++){
      ints[i] = Integer.parseInt(ss[i]);
    }

    for (int i = 0; i < ss.length; i++){
      if(ints[i] != i+1)count++;
}
if(count == 2 || count == 0) System.out.println("YES");
else System.out.println("NO");

  }
}
