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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}
	 import java.util.*; util.* java import java.io.*; io.* java public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
} Main public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	} main {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n=in.nextInt(); n in.nextInt() in.nextInt in int prev=0; prev 0 int ans=1; ans 1 int it=0; it 0 for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		} {
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		} int t=in.nextInt(); t in.nextInt() in.nextInt in if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			} t!=i&&prev==0 t!=i t i prev==0 prev 0 {
				it=t;
				prev=i;
			} it=t it t prev=i prev i if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			} t!=i&&(it!=i||prev!=t) t!=i t i (it!=i||prev!=t) it!=i it i prev!=t prev t {
				ans=0;
			} ans=0 ans 0 if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO"); ans==1 ans 1 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 public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
} public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
} Main
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int prev=0;
		int ans=1;
		int it=0;
		for(int i=1;i<=n;i++)
		{
			int t=in.nextInt();
			if(t!=i&&prev==0)
			{
				it=t;
				prev=i;
			}
			else if(t!=i&&(it!=i||prev!=t))
			{
				ans=0;
			}
		}
		if(ans==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}
	