import java.util.Scanner;

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

	int N = sc.nextInt();
	int p[] = new int[N];
	for (int i = 0; i < N; i++)
	    p[i] = sc.nextInt();

	int count = 0;
	for (int i = 0; i < N - 1; i++) {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	}

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

	int N = sc.nextInt();
	int p[] = new int[N];
	for (int i = 0; i < N; i++)
	    p[i] = sc.nextInt();

	int count = 0;
	for (int i = 0; i < N - 1; i++) {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	}

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

	int N = sc.nextInt();
	int p[] = new int[N];
	for (int i = 0; i < N; i++)
	    p[i] = sc.nextInt();

	int count = 0;
	for (int i = 0; i < N - 1; i++) {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	}

	if (count < 2)
	    System.out.println("YES");
	else
	    System.out.println("NO");
    } main {
	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();
	int p[] = new int[N];
	for (int i = 0; i < N; i++)
	    p[i] = sc.nextInt();

	int count = 0;
	for (int i = 0; i < N - 1; i++) {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	}

	if (count < 2)
	    System.out.println("YES");
	else
	    System.out.println("NO");
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int p[] = new int[N]; p new int[N] N for (int i = 0; i < N; i++)
	    p[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i p[i] = sc.nextInt(); p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int i = 0; i < N - 1; i++) {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	} int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 i++ i++ i {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	} {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	} int key = i; key i for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    } int j = i + 1; int j = i + 1; j i + 1 i 1 j < N j N j++ j++ j {
		if (p[key] > p[j])
		    key = j;
	    } {
		if (p[key] > p[j])
		    key = j;
	    } if (p[key] > p[j])
		    key = j; p[key] > p[j] p[key] p key p[j] p j key = j key j if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    } key != i key i {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    } int tmp = p[i]; tmp p[i] p i p[i] = p[key] p[i] p i p[key] p key p[key] = tmp p[key] p key tmp count++ count if (count < 2)
	    System.out.println("YES");
	else
	    System.out.println("NO"); count < 2 count 2 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[] args args
import java.util.Scanner;

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

	int N = sc.nextInt();
	int p[] = new int[N];
	for (int i = 0; i < N; i++)
	    p[i] = sc.nextInt();

	int count = 0;
	for (int i = 0; i < N - 1; i++) {
	    int key = i;
	    for (int j = i + 1; j < N; j++) {
		if (p[key] > p[j])
		    key = j;
	    }
	    
	    if (key != i) {
		int tmp = p[i];
		p[i] = p[key];
		p[key] = tmp;
		count++;
	    }
	}

	if (count < 2)
	    System.out.println("YES");
	else
	    System.out.println("NO");
    }
}