import java.lang.reflect.Array;
import java.util.*;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();
	int array[] = new int [X];
	int count = 0;
	
	//int array2[] = new int[X];
	
	for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	}
	
	for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	}
	if(count==2||count==0) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	
}
} import java.lang.reflect.Array; Array java.lang.reflect import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();
	int array[] = new int [X];
	int count = 0;
	
	//int array2[] = new int[X];
	
	for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	}
	
	for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	}
	if(count==2||count==0) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	
}
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();
	int array[] = new int [X];
	int count = 0;
	
	//int array2[] = new int[X];
	
	for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	}
	
	for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	}
	if(count==2||count==0) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	
} main {
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();
	int array[] = new int [X];
	int count = 0;
	
	//int array2[] = new int[X];
	
	for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	}
	
	for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	}
	if(count==2||count==0) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int X = sc.nextInt(); X sc.nextInt() sc.nextInt sc int array[] = new int [X]; array new int [X] X int count = 0; count 0 for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	} int j=0; int j=0; j 0 j<X j X j++ j++ j {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	} {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	} array[j] = sc.nextInt() array[j] array j sc.nextInt() sc.nextInt sc for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	} int i=0; int i=0; i 0 i<X i X i++ i++ i {
		if(array[i]!=i+1)
		count = count+1;
	} {
		if(array[i]!=i+1)
		count = count+1;
	} if(array[i]!=i+1)
		count = count+1; array[i]!=i+1 array[i] array i i+1 i 1 count = count+1 count count+1 count 1 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("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 sc = new Scanner(System.in);
	int X = sc.nextInt();
	int array[] = new int [X];
	int count = 0;
	
	//int array2[] = new int[X];
	
	for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	}
	
	for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	}
	if(count==2||count==0) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	
}
} public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();
	int array[] = new int [X];
	int count = 0;
	
	//int array2[] = new int[X];
	
	for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	}
	
	for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	}
	if(count==2||count==0) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	
}
} Main
import java.lang.reflect.Array;
import java.util.*;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int X = sc.nextInt();
	int array[] = new int [X];
	int count = 0;
	
	//int array2[] = new int[X];
	
	for(int j=0;j<X;j++) {
		array[j] = sc.nextInt();
		//array2[j] = sc2.nextInt();
		//System.out.println(array[j]);
	}
	
	for(int i=0;i<X;i++) {
		if(array[i]!=i+1)
		count = count+1;
	}
	if(count==2||count==0) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	
}
}
