import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line; line int n = 0; n 0 try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		} catch (IOException e) {
			e.getStackTrace();
		} IOException e {
			e.getStackTrace();
		} e.getStackTrace() e.getStackTrace e {
			line = br.readLine();
			n = Integer.parseInt(line);
		} line = br.readLine() line br.readLine() br.readLine br n = Integer.parseInt(line) n Integer.parseInt(line) Integer.parseInt Integer line int p[] = new int [n]; p new int [n] n String in[] = new String [n]; in new String [n] n try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		} catch (IOException e) {
			e.getStackTrace();
		} IOException e {
			e.getStackTrace();
		} e.getStackTrace() e.getStackTrace e {
			line = br.readLine();
			in = line.split(" ");
		} line = br.readLine() line br.readLine() br.readLine br in = line.split(" ") in line.split(" ") line.split line " " int count = 0; count 0 for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		} {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		} p[i] =  Integer.parseInt(in[i]) p[i] p i Integer.parseInt(in[i]) Integer.parseInt Integer in[i] in i if(p[i] != i+1) count++; p[i] != i+1 p[i] p i i+1 i 1 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("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) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} public class Main{
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}