import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class C {

	public static final long MAX = 1000000000L;

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer tok1 = new StringTokenizer(br.readLine());
		final int n = Integer.parseInt(tok1.nextToken());
		final long k = Integer.parseInt(tok1.nextToken());

		StringTokenizer tok2 = new StringTokenizer(br.readLine());
		int[] array = new int[n];
		for(int i = 0; i < n; i++){
			array[i] = Integer.parseInt(tok2.nextToken());
		}

		int size = n;

		Arrays.sort(array);

		boolean[] skip = new boolean[n];
		for(int i = 0; i < n; i++){
			if(skip[i]){
				size--;
				continue;
			}

			long input = array[i];
			input *= k;
			if(input > MAX){
				continue;
			}

			final int pos = Arrays.binarySearch(array, (int)(input));
			if(pos >= 0 && !skip[pos]){
				skip[pos] = true;
			}
		}

		System.out.println(size);
	}
}


import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.Arrays;

public class Main {
    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        long k = input.nextInt();
        long[] nums = new long[n];
        for (int i = 0; i < n; i++) {
            nums[i] = input.nextInt();
        }
        Arrays.sort(nums);
        Set<Long> wrong = new TreeSet<Long>();
        long ans = 0;
        for (int i = 0; i < n; i++) {
            if (!wrong.contains(nums[i])) {
                try {
                    wrong.add(nums[i] * k);
                } catch (Exception e) {
                }
                ans++;
            }
        }
        System.out.println(ans);
    }
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class A implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(null, new A(), "", 64*1024*1024).start();
	}

	public void run() {
		try {
			long t1 = 0, t2 = 0, m1 = 0, m2 = 0;
			if (LOCAL) {
				t1 = System.currentTimeMillis();
				m1 = Runtime.getRuntime().freeMemory();
			}
			Locale.setDefault(Locale.US);
			if (LOCAL) {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			} else {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			}
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			if (LOCAL) {
				t2 = System.currentTimeMillis();
				m2 = Runtime.getRuntime().freeMemory();
				System.err.println("Time = " + (t2 - t1) + " ms.");
				System.err.println("Memory = " + ((m1 - m2) / 1024) + " KB.");
			}
		} catch (Throwable e) {
			e.printStackTrace(System.err);
			throw new RuntimeException();
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) return null;
			tok = new StringTokenizer(line);
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	static class Mergesort {

		private Mergesort() {}

		public static void sort(int[] a) {
			mergesort(a, 0, a.length - 1);
		}

		public static void sort(long[] a) {
			mergesort(a, 0, a.length - 1);
		}

		public static void sort(double[] a) {
			mergesort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 42;

		private static void mergesort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergesort(a, leftIndex, middleIndex);
					mergesort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void mergesort(long[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergesort(a, leftIndex, middleIndex);
					mergesort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void mergesort(double[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergesort(a, leftIndex, middleIndex);
					mergesort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void merge(long[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			long[] leftArray = new long[length1];
			long[] rightArray = new long[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void merge(double[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			double[] leftArray = new double[length1];
			double[] rightArray = new double[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

		private static void insertionSort(long[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				long current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

		private static void insertionSort(double[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				double current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}

	void debug(Object... o) {
		if (LOCAL) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	final static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;

//------------------------------------------------------------------------------

	void solve() throws IOException {
		int n = readInt();
		long k = readLong();
		if (k == 1) {
			out.println(n);
			return;
		}
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = readLong();
		}
		Mergesort.sort(a);
		int ans = 0;
		boolean[] processed = new boolean[n];
		debug(a);
		for (int i = 0; i < n; i++) {
			if (processed[i]) {
				continue;
			}
			processed[i] = true;
			long cur = a[i];
			ans++;
			int index = Arrays.binarySearch(a, cur * k);
			if (index >= 0) {
				processed[index] = true;
			}
		}
		out.println(ans);
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	public void solve () throws Exception {
		int n = sc.nextInt();
		int k = sc.nextInt();

		TreeSet<Integer> bad = new TreeSet<>();
		int a [] = new int [n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();

		Random rnd = new Random();
		for (int i = 1; i < n; i++) {
			int j = rnd.nextInt(i + 1);
			int t = a[i];
			a[i] = a[j];
			a[j] = t;
		}

		Arrays.sort(a);

		int result = 0;
		for (int i = 0; i < n; i++) {
			if (!bad.contains(a[i])) {
				result++;
				long next = (long) a[i] * k;
				if (next <= 1000000000)
					bad.add((int) next);
			}
		}
		out.println(result);
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Solution.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Solution(), "", (1 << 26));
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}

	public String nextToken() throws IOException {
		while (strTok == null || !strTok.hasMoreTokens()) {
			strTok = new StringTokenizer(reader.readLine());
		}
		return strTok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

//basically tried to understand ping's greedy alg
public class kMultRedo {
	static int n;
	static int k;
	public static void main(String[] args){
		Set<Integer> set = new TreeSet<Integer>();
		FastScanner s = new FastScanner();
		n = s.nextInt();
		k = s.nextInt();

		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = s.nextInt();
		}
		Arrays.sort(a);

		for(int i=0; i<n; i++){
			if(a[i]%k !=0){
				set.add(a[i]);
			}else{
				if(!set.contains(a[i]/k)){
					set.add(a[i]);
				}
			}
		}

		System.out.println(set.size());
	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author ocelopilli
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long k = in.nextLong();
        long[] a = new long[n];
        for (int i=0; i<n; i++) a[i] = in.nextInt();
        Arrays.sort( a );
        boolean[] ok = new boolean[ n ];
        Arrays.fill( ok, true );
        if (k > 1) for (int i=0; i<n; i++)
        {
            if ( ok[i] == false ) continue;
            int pos = Arrays.binarySearch( a, a[i]*k );
            if ( pos >= 0 )
            {
                //out.println( a[i]+" "+a[pos] );
                ok[ pos ] = false;
            }
        }
        int ans = 0;
        for (boolean x : ok) if ( x ) ans++;
        out.println( ans );
    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

    public InputReader(InputStream in)
    {
        br = new BufferedReader(new InputStreamReader(in));
        st = null;
    }

    public String next()
    {
        while (st==null || !st.hasMoreTokens())
        {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public int nextInt()
    {
        return Integer.parseInt(next());
    }

    public long nextLong()
    {
        return Long.parseLong(next());
    }
}


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

public class A274 {

    /**
     * @param args
     */
    public static void main(String[] args) {

        Scanner in= new Scanner(System.in);
        int n=in.nextInt();
        int k=in.nextInt();

        Long a[] =new Long[n];
        Hashtable<Long, Boolean> hash= new Hashtable<Long, Boolean>();

        for (int i=0;i< n;i++){
            a[i]=in.nextLong();

        }
        Arrays.sort(a);

        for (int i=0;i<n;i++){
            if (!hash.containsKey(a[i]) ){
                hash.put(a[i]*k, true);
            }

        }
        System.out.println(hash.size());

    }

}


import static java.math.BigInteger.*;
import static java.util.Arrays.*;

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

public class A {

	final int MOD = (int)1e9 + 7;
	final double eps = 1e-12;
	final int INF = (int)1e9;

	public A () {
		int N = sc.nextInt();
		int K = sc.nextInt();
		Long [] A = sc.nextLongs();

		sort(A);
		Set<Long> S = new HashSet<Long>();

		for (long a : A) {
			if (a % K == 0 && S.contains(P * (a/K)))
				continue;
			S.add(P*a);
		}

		int res = S.size();
		exit(res);
	}

	long P = probablePrime(50, new Random()).longValue();

	////////////////////////////////////////////////////////////////////////////////////

	/* Dear hacker, don't bother reading below this line, unless you want to help me debug my I/O routines :-) */

	static MyScanner sc = new MyScanner();

	static class MyScanner {
		public String next() {
			newLine();
			return line[index++];
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			line = null;
			return readLine();
		}

		public String [] nextStrings() {
			line = null;
			return readLine().split(" ");
		}

		public char [] nextChars() {
			return next().toCharArray();
		}

		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}

		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}

		public Double [] nextDoubles() {
			String [] L = nextStrings();
			Double [] res = new Double [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Double.parseDouble(L[i]);
			return res;
		}

		public String [] next (int N) {
			String [] res = new String [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.next();
			return res;
		}

		public Integer [] nextInt (int N) {
			Integer [] res = new Integer [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInt();
			return res;
		}

		public Long [] nextLong (int N) {
			Long [] res = new Long [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLong();
			return res;
		}

		public Double [] nextDouble (int N) {
			Double [] res = new Double [N];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDouble();
			return res;
		}

		public String [][] nextStrings (int N) {
			String [][] res = new String [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextStrings();
			return res;
		}

		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextInts();
			return res;
		}

		public Long [][] nextLongs (int N) {
			Long [][] res = new Long [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextLongs();
			return res;
		}

		public Double [][] nextDoubles (int N) {
			Double [][] res = new Double [N][];
			for (int i = 0; i < N; ++i)
				res[i] = sc.nextDoubles();
			return res;
		}

		//////////////////////////////////////////////

		private boolean eol() {
			return index == line.length;
		}

		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private final BufferedReader r;

		MyScanner () {
			this(new BufferedReader(new InputStreamReader(System.in)));
		}

		MyScanner(BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}

		private String [] line;
		private int index;

		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}

	static void print(Object o, Object... a) {
		printDelim(" ", o, a);
	}

	static void cprint(Object o, Object... a) {
		printDelim("", o, a);
	}

	static void printDelim (String delim, Object o, Object... a) {
		pw.println(build(delim, o, a));
	}

	static void exit (Object o, Object... a) {
		print(o, a);
		exit();
	}

	static void exit () {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}

	void NO() {
		throw new Error("NO!");
	}

	////////////////////////////////////////////////////////////////////////////////////

	static String build(String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.toString().trim();
	}

	static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>) {
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		} else
			b.append(delim).append(o);
	}

	////////////////////////////////////////////////////////////////////////////////////

	public static void main(String[] args) {
		new A();
		exit();
	}

	static void start() {
		t = millis();
	}

	static PrintWriter pw = new PrintWriter(System.out);

	static long t;

	static long millis() {
		return System.currentTimeMillis();
	}
}


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

public class P220A
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        List<Integer> b = new ArrayList<Integer>(n);
        for (int i = 0; i < n; i++)
        {
            a[i] = sc.nextInt();
            b.add(a[i]);
        }
        Collections.sort(b);
        int c = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] != b.get(i)) c++;
        }
        if (c == 0 || c == 2)
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }
}


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

import static java.lang.Math.*;

public class Main implements Runnable {

	void randomShuffle(int[] arr) {
		Random rnd = new Random();
		for (int i = arr.length - 1; i >= 0; i--) {
			int pos = rnd.nextInt(i + 1);
			int temp = arr[pos];
			arr[pos] = arr[i];
			arr[i] = temp;
		}
	}

	void solve() throws Exception {
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] ac = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = ac[i] = sc.nextInt();
		}
		randomShuffle(ac);
		Arrays.sort(ac);
		int diff = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != ac[i]) {
				diff++;
			}
		}
		if (diff <= 2) {
			out.println("YES");
		} else {
			out.println("NO");
		}
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Main.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Main(), "", 128 * 1024 * 1024);
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}

	public String nextToken() throws IOException {
		while (strTok == null || !strTok.hasMoreTokens()) {
			strTok = new StringTokenizer(reader.readLine());
		}
		return strTok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Locale;
import java.io.OutputStream;
import java.util.RandomAccess;
import java.io.PrintWriter;
import java.util.AbstractList;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        int[] b = a.clone();
        Collections.sort(ArrayUtils.asList(b));
        int diff = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] != b[i])
                diff++;
        }
        out.println(diff <= 2 ? "YES" : "NO");
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int[] nextIntArray(int count) {
        int[] result = new int[count];
        for (int i = 0; i < count; i++) {
            result[i] = nextInt();
        }
        return result;
    }

    }

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void println(String x) {
        writer.println(x);
    }

    public void close() {
        writer.close();
    }

    }

class ArrayUtils {

    public static List<Integer> asList(int[] array) {
        return new IntList(array);
    }

    private static class IntList extends AbstractList<Integer> implements RandomAccess {

        int[] array;

        private IntList(int[] array) {
            this.array = array;
        }

        public Integer get(int index) {
            return array[index];
        }

        public Integer set(int index, Integer element) {
            int result = array[index];
            array[index] = element;
            return result;
        }

        public int size() {
            return array.length;
        }
    }

    }


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

public class Solution {

	private StringTokenizer st;
	private BufferedReader in;
	private PrintWriter out;

	public void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = nextInt();
		}
		int[] b = a.clone();
		Arrays.sort(b);
		int diff = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] != b[i]) {
				diff++;
			}
		}
		out.println(diff <= 2 ? "YES" : "NO");
	}

	public void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		eat("");

		solve();

		out.close();
	}

	void eat(String s) {
		st = new StringTokenizer(s);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		new Solution().run();
	}

}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.*;

public class A implements Runnable{

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws FileNotFoundException{
		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(in.readLine());
			}catch (Exception e){
				return null;
			}
		}
		return tok.nextToken();
	}

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException{
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException{
		return Double.parseDouble(readString());
	}

	public static void main(String[] args){
		new Thread(null, new A(), "", 128 * (1L << 20)).start();
	}

	long timeBegin, timeEnd;

	void time(){
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	long memoryTotal, memoryFree;

	void memory(){
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
	}

	void debug(Object... objects){
		if (DEBUG){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}

	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			memoryTotal = Runtime.getRuntime().freeMemory();
			init();
			solve();
			out.close();
			time();
			memory();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	boolean DEBUG = false;

	void solve() throws IOException{
		int n = readInt();

		int[] a = new int[n];
		Integer[] b = new Integer[n];
		for (int i = 0; i < n; ++i){
			a[i] = readInt();
			b[i] = a[i];
		}

		Arrays.sort(b);
		int count = 0;
		for (int i = 0; i < n; ++i){
			if (a[i] != b[i]){
				count++;
			}
		}

		if (count == 2 || count == 0){
			out.println("YES");
		}else{
			out.println("NO");
		}
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        int testCount = 1;
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }
}

class Task {
    int n;
    int[] a;
    int[] b;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.readInt();
        a = new int[n];
        b = new int[n];
        for (int i = 0; i < n; ++i)
            a[i] = b[i] = in.readInt();
        sort(0, n - 1);
        int different = 0;
        for (int i = 0; i < n; ++i)
            if (a[i] != b[i])
                ++different;
        out.println(different <= 2 ? "YES" : "NO");
    }

    public void sort(int lo, int hi) {
        if (lo < hi) {
            int mid = (lo + hi) / 2;
            sort(lo, mid);
            sort(mid + 1, hi);
            merge(lo, mid, hi);
        }
    }

    public void merge(int lo, int mid, int hi) {
        int n1 = mid - lo + 1;
        int n2 = hi - (mid + 1) + 1;
        int[] x = new int[n1 + 1];
        int[] y = new int[n2 + 1];
        for (int i = 0; i < n1; ++i)
            x[i] = b[lo + i];
        for (int j = 0; j < n2; ++j)
            y[j] = b[mid + 1 + j];
        x[n1] = y[n2] = Integer.MAX_VALUE;
        for (int k = lo, i = 0, j = 0; k <= hi; ++k)
            b[k] = x[i] < y[j] ? x[i++] : y[j++];
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public Long readLong() {
        return Long.parseLong(readString());
    }

    public Double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
}


import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.Scanner;
import java.util.Vector;

public class Main {

    public static void main(String[] args) {
        Scanner in=new Scanner(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        Vector<Integer> mas=new Vector<Integer>();
        Vector<Integer> mas2=new Vector<Integer>();
        int index=-1;
        boolean res=false;
        for(int i=0; i<n; i++){
            mas.add(in.nextInt());
            if(i!=0 && mas.get(i)<mas.get(i-1)){
                index=i-1;
                break;
            }
        }
        if(index==-1) res=true;
        else{
            int min=mas.get(index+1);
            int minIndex=index+1;
            for(int i=index+2; i<n; i++){
                mas.add(in.nextInt());
                if(mas.get(i)<=min){
                    min=mas.get(i);
                    minIndex=i;

                }
            }

            mas2.addAll(mas);
            mas.set(minIndex, mas.get(index));
            mas.set(index, min);
            int o=mas.hashCode();
            Collections.sort(mas);
            int nw=mas.hashCode();
            res=nw==o;
        }
        if(!res){
            mas=mas2;
            for(int i=n-1; i>=0; i--){
                if(i!=n-1 && mas.get(i)>mas.get(i+1)){
                    index=i+1;
                    break;
                }
            }
            if(index==-1) res=true;
            else{
                int max=mas.get(index-1);
                int maxIndex=index-1;
                for(int i=index-1; i>=0; i--){
                    if(mas.get(i)>=max){
                        max=mas.get(i);
                        maxIndex=i;
                    }
                }
                mas.set(maxIndex, mas.get(index));
                mas.set(index, max);
                int o=mas.hashCode();
                Collections.sort(mas);
                int nw=mas.hashCode();
                res=res||nw==o;
            }
        }
        if(res) out.println("YES");
        else out.println("NO");
        out.close();
    }

}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main{

    public static void main(String[] args) throws Exception {
        Parserdoubt12 s = new Parserdoubt12(System.in);

        int n = s.nextInt();

        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = s.nextInt();
        }

        int copy[] = a.clone();
        Arrays.sort(a);
        int count = 0;
        for (int i = 0; i < copy.length; i++) {
            if(a[i] != copy[i]) count++;
        }
        if(count <= 2) System.out.println("YES");
        else System.out.println("NO");
    }

}

class Parserdoubt12
{
   final private int BUFFER_SIZE = 1 << 17;

   private DataInputStream din;
   private byte[] buffer;
   private int bufferPointer, bytesRead;

   public Parserdoubt12(InputStream in)
   {
      din = new DataInputStream(in);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
   }
   public String nextString() throws Exception
   {
       StringBuffer sb=new StringBuffer("");
       byte c = read();
       while (c <= ' ') c = read();
       do
       {
           sb.append((char)c);
           c=read();
       }while(c>' ');
       return sb.toString();
   }
   public char nextChar() throws Exception
   {
       byte c=read();
       while(c<=' ') c= read();
       return (char)c;
   }
   public int nextInt() throws Exception
   {
      int ret = 0;
      byte c = read();
      while (c <= ' ') c = read();
      boolean neg = c == '-';
      if (neg) c = read();
      do
      {
          ret = ret * 10 + c - '0';
         c = read();
      } while (c > ' ');
      if (neg) return -ret;
      return ret;
   }
   public long nextLong() throws Exception
   {
      long ret = 0;
      byte c = read();
      while (c <= ' ') c = read();
      boolean neg = c == '-';
      if (neg) c = read();
      do
      {
          ret = ret * 10 + c - '0';
         c = read();
      } while (c > ' ');
      if (neg) return -ret;
      return ret;
   }
   private void fillBuffer() throws Exception
   {
      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      if (bytesRead == -1) buffer[0] = -1;
   }

   private byte read() throws Exception
   {
      if (bufferPointer == bytesRead) fillBuffer();
      return buffer[bufferPointer++];
   }
}


import java.util.*;

public class Main {

	public static void main(String[] args) {

		// long start = System.currentTimeMillis();
		// long end = System.currentTimeMillis();
		// System.out.println(" Execution time was "+(end-start)+" ms.");

		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt();
		int a[] = new int[n];
		int b[] = new int[n];
		for(int i = 0;i<n;i++){
			a[i]=kb.nextInt();
			b[i]=a[i];
		}
		Arrays.sort(a);
		int count = 0;
		for(int i=0;i<n;i++){
			if(a[i]!=b[i])count++;
		}
		if(count<=2)
			System.out.println("YES");
		else
			System.out.println("NO");

	}

}


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

public class A {
	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer st;
	static Random  rnd;

	void solve() throws IOException {
		int n = nextInt();

		int[] arr = new int[n];
		Integer[] arrCopy = new Integer[n];

		for (int i = 0; i < n; i++)
			arr[i] = arrCopy[i] = nextInt();

		Arrays.sort(arrCopy);

		int bad = 0;

		for (int i = 0; i < n; i++)
			if (arr[i] != arrCopy[i])
				++bad;

		boolean fail = bad > 2;

		out.println(!fail ? "YES" : "NO");
	}

	public static void main(String[] args) {
		new A().run();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(42);
		}
	}

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null)
				return null;

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
public class A {

    public A() throws Exception {
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = in.nextInt();
        int[] arr2 = arr.clone();
        Arrays.sort(arr2);
        int diff = 0;
        for (int i=0; i<n; i++) {
            if (arr2[i]!=arr[i]) diff++;
        }
        if (diff<=2) System.out.println("YES");
        else System.out.println("NO");
    }

    Scanner in = new Scanner(System.in);
    StringBuilder buf = new StringBuilder();
    public static void main(String[] args) throws Exception { // {{{
        new A();
    } // }}}
    public static void debug(Object... arr) { // {{{
        System.err.println(Arrays.deepToString(arr));
    } // }}}
    public static class Scanner { // {{{
        BufferedReader br;
        String line;
        StringTokenizer st;
        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        public boolean hasNext() throws IOException {
            while ((st==null||!st.hasMoreTokens())&&(line=br.readLine())!=null)
                st = new StringTokenizer(line);
            return st.hasMoreTokens();
        }
        public String next() throws IOException {
            if (hasNext()) return st.nextToken();
            throw new NoSuchElementException();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    } // }}}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Solution implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

	int fu(int[] a, int l) {
		for (int i = l; i < a.length - 1; i++) {
			if (a[i] > a[i + 1]) return i;
		}
		return a.length;
	}

	void swap(int[] a, int q, int w) {
		int t = a[q]; a[q] = a[w]; a[w] = t;
	}

	void solve() throws Exception {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) a[i] = nextInt();
		int q = fu(a, 0);
		if (q == n) out.println("YES"); else {
			int w = fu(a, q + 1);
			if (w < n) {
				boolean ans = false;
				swap(a, q, w);
				ans |= fu(a, 0) == n;
				swap(a, q, w);
				if (q < n - 1) {
					swap(a, q + 1, w);
					ans |= fu(a, 0) == n;
					swap(a, q + 1, w);
				}
				if (w < n - 1) {
					swap(a, q, w + 1);
					ans |= fu(a, 0) == n;
					swap(a, q, w + 1);
				}
				if (q < n - 1 && w < n - 1) {
					swap(a, q + 1, w + 1);
					ans |= fu(a, 0) == n;
					swap(a, q + 1, w + 1);
				}
				if (ans) out.println("YES"); else out.println("NO");
			} else {
				int j = q + 1;
				while (j < n && a[j] == a[q + 1]) j++;
				j--;
				swap(a, q, j);
				if (fu(a, 0) == n) out.println("YES"); else {
					swap(a, q, j);
					q++;
					j = q - 1;
					while (j >= 0 && a[j] == a[q - 1]) j--;
					j++;
					swap(a, q, j);
					if (fu(a, 0) == n) out.println("YES"); else out.println("NO");
				}
			}
		}
	}

	public void run() {
		try {
			Locale.setDefault(Locale.UK);
			in = new BufferedReader(new InputStreamReader(System.in));
			// in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(System.out);
			// out = new PrintWriter("output.txt");
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		// new Thread(null, new Solution(), "1", 1 << 28).start();
		(new Solution()).run();
	}

}


import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author niyaznigmatul
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, FastScanner in, FastPrinter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int[] b = a.clone();
        ArrayUtils.sort(b);
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] != b[i]) {
                ++count;
            }
        }
        out.println(count <= 2 ? "YES" : "NO");
	}
}

class FastScanner extends BufferedReader {

    boolean isEOF;

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
            if (isEOF && ret < 0) {
                throw new InputMismatchException();
            }
            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= -1 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (!isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    }

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}

class ArrayUtils {

    public static void sort(int[] a) {
        Random rand = new Random(System.nanoTime());
        for (int i = 0; i < a.length; i++) {
            int j = rand.nextInt(i + 1);
            int t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
        Arrays.sort(a);
    }

    }


import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.Line2D;
import java.awt.Point;
import static java.lang.reflect.Array.*;

public class LittleElephantAndProblem {

    boolean DEBUG = true;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder out = new StringBuilder();
    StringTokenizer st = null;

    String s() throws IOException {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    int i() throws IOException {
        return Integer.parseInt(s());
    }

    int i(String s) throws IOException {
        return Integer.parseInt(s);
    }

    long l() throws IOException {
        return Long.parseLong(s());
    }

    long l(String s) throws IOException {
        return Long.parseLong(s);
    }

    double d() throws IOException {
        return Double.parseDouble(s());
    }

    double d(String s) throws IOException {
        return Double.parseDouble(s);
    }

    void D(Object a) {
        if (DEBUG) {
            int len = getLength(a);
            for (int i = 0; i < len; ++i) {
                System.out.print(get(a, i) + " ");
            }
            System.out.println();
        }
    }

    void D(Object[] a) {
        if (DEBUG) {
            int R = getLength(a), C = getLength(get(a, 0));
            for (int i = 0; i < R; ++i) {
                for (int j = 0; j < C; ++j) {
                    System.out.print(get(get(a, i), j) + " ");
                }
                System.out.println();
            }
        }
    }

    void D(String args) {
        if (DEBUG) {
            System.out.print(args);
        }
    }

    void D(String format, Object... args) {
        if (DEBUG) {
            System.out.printf(format, args);
        }
    }

    void fl() {
        System.out.print(out);
    }
    int n = i();

    public LittleElephantAndProblem() throws IOException {
        List<Integer> a = new ArrayList<Integer>();
        List<Integer> b = new ArrayList<Integer>();
        for (int i = 0; i < n; ++i) {
            int x = i();
            a.add(x);
            b.add(x);
        }
        sort(b);
        int d = 0;
        for (int i = 0; i < n; ++i) {
            if ((int)a.get(i) != (int)b.get(i)) {
                ++d;
            }
        }
        if (d > 2) {
            out.append("NO\n");
        } else {
            out.append("YES\n");
        }
        fl();
    }

    public static void main(String[] args) throws IOException {
        new LittleElephantAndProblem();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class A {

	private void solve() throws IOException {
		int n = nextInt();
		Integer[] a = new Integer[n];
		Integer[] b = new Integer[n];

		for (int i = 0; i < n; i++) {
			a[i] = b[i] = nextInt();
		}

		Arrays.sort(a);
		int k = 0;
		for (int i = 0; i < n; i++) {
			if (!a[i].equals(b[i])) {
				k++;
			}
		}

		if (k <= 2) {
			println("YES");
		} else {
			println("NO");
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new A().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Solution implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

	void solve() throws Exception {
		int n = nextInt();
		Integer[] a = new Integer[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		Integer[] b = a.clone();
		Arrays.sort(b);
		int d = 0;
		for (int i = 0; i < n; i++) {
			if (!a[i].equals(b[i])) d++;
		}
		out.println(d > 2? "NO" : "YES");
	}

	public void run() {
		try {
			Locale.setDefault(Locale.UK);
			in = new BufferedReader(new InputStreamReader(System.in));
			// in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(System.out);
			// out = new PrintWriter("output.txt");
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		// new Thread(null, new Solution(), "1", 1 << 28).start();
		(new Solution()).run();
	}

}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int count = in.readInt();
        int[] array = IOUtils.readIntArray(in, count);
        int[] sorted = array.clone();
        ArrayUtils.sort(sorted, IntComparator.DEFAULT);
        int differs = 0;
        for (int i = 0; i < count; i++) {
            if (array[i] != sorted[i])
                differs++;
        }
        if (differs <= 2)
            out.printLine("YES");
        else
            out.printLine("NO");
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    }

class IOUtils {

    public static int[] readIntArray(InputReader in, int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++)
            array[i] = in.readInt();
        return array;
    }

    }

class ArrayUtils {
    private static int[] tempInt = new int[0];

    public static int[] sort(int[] array, IntComparator comparator) {
        return sort(array, 0, array.length, comparator);
    }

    public static int[] sort(int[] array, int from, int to, IntComparator comparator) {
        ensureCapacityInt(to - from);
        System.arraycopy(array, from, tempInt, 0, to - from);
        sortImpl(array, from, to, tempInt, 0, to - from, comparator);
        return array;
    }

    private static void ensureCapacityInt(int size) {
        if (tempInt.length >= size)
            return;
        size = Math.max(size, tempInt.length << 1);
        tempInt = new int[size];
    }

    private static void sortImpl(int[] array, int from, int to, int[] temp, int fromTemp, int toTemp, IntComparator comparator) {
        if (to - from <= 1)
            return;
        int middle = (to - from) >> 1;
        int tempMiddle = fromTemp + middle;
        sortImpl(temp, fromTemp, tempMiddle, array, from, from + middle, comparator);
        sortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);
        int index = from;
        int index1 = fromTemp;
        int index2 = tempMiddle;
        while (index1 < tempMiddle && index2 < toTemp) {
            if (comparator.compare(temp[index1], temp[index2]) <= 0)
                array[index++] = temp[index1++];
            else
                array[index++] = temp[index2++];
        }
        if (index1 != tempMiddle)
            System.arraycopy(temp, index1, array, index, tempMiddle - index1);
        if (index2 != toTemp)
            System.arraycopy(temp, index2, array, index, toTemp - index2);
    }

    }

interface IntComparator {
    public static final IntComparator DEFAULT = new IntComparator() {
        public int compare(int first, int second) {
            if (first < second)
                return -1;
            if (first > second)
                return 1;
            return 0;
        }
    };

    public int compare(int first, int second);
}


import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class A implements Runnable
{
    String file = "input";

    boolean TEST = System.getProperty("ONLINE_JUDGE") == null;

    void solve() throws IOException
    {
        int n = nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        int[] b = a.clone();
        sortInt(b);
        int count = 0;
        for(int i = 0; i < a.length; i++)
            if(a[i] != b[i]) count++;
        if(count == 0 || count == 2) out.println("YES");
        else out.println("NO");
    }

    Random rnd = new Random();

    void sortInt(int[] a)
    {
        sortInt(a, 0, a.length - 1);
    }

    void sortInt(int[] a, int from, int to)
    {
        if(from >= to) return;
        int i = from - 1;
        int p = rnd.nextInt(to - from + 1) + from;
        int t = a[p]; a[p] = a[to]; a[to] = t;
        for(int j = from; j < to; j++)
            if(a[j] <= a[to])
            {
                i++;
                t = a[i]; a[i] = a[j]; a[j] = t;
            }
        t = a[i + 1]; a[i + 1] = a[to]; a[to] = t;
        sortInt(a, i + 2, to);
        while(i >= 0 && a[i] == a[i + 1]) i--;
        sortInt(a, from, i);

    }

    String next() throws IOException
    {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }

    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }

    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

    public static void main(String[] args) throws IOException
    {
        new Thread(null, new A(), "", 1 << 22).start();
    }

    public void run()
    {
        try
        {
            init();
            if(TEST)
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


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

public class A {
	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer st;
	static Random rnd;

	void solve() throws IOException {
		int n = nextInt();

		int[] arr = new int[n];
		Integer[] arrCopy = new Integer[n];

		for (int i = 0; i < n; i++)
			arr[i] = arrCopy[i] = nextInt();

		Arrays.sort(arrCopy);

		int bad = 0;

		for (int i = 0; i < n; i++)
			if (arr[i] != arrCopy[i])
				++bad;

		boolean fail = bad > 2;

		out.println(!fail ? "YES" : "NO");
	}

	public static void main(String[] args) {
		new A().run();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(42);
		}
	}

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null)
				return null;

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class A implements Runnable
{
    String file = "input";

    boolean TEST = System.getProperty("ONLINE_JUDGE") == null;

    void solve() throws IOException
    {
        int n = nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        int[] b = a.clone();
        qsort(b);
        //sortInt(b);
        int count = 0;
        for(int i = 0; i < a.length; i++)
            if(a[i] != b[i]) count++;
        if(count == 0 || count == 2) out.println("YES");
        else out.println("NO");
    }

    void qsort(int[] a)
    {
        List<Integer> as = new ArrayList<Integer>();
        for(int x : a) as.add(x);
        Collections.shuffle(as);
        for(int i = 0; i < a.length; i++) a[i] = as.get(i);
        sort(a);
    }

    Random rnd = new Random();

    void sortInt(int[] a)
    {
        sortInt(a, 0, a.length - 1);
    }

    void sortInt(int[] a, int from, int to)
    {
        if(from >= to) return;
        int i = from - 1;
        int p = rnd.nextInt(to - from + 1) + from;
        int t = a[p]; a[p] = a[to]; a[to] = t;
        for(int j = from; j < to; j++)
            if(a[j] <= a[to])
            {
                i++;
                t = a[i]; a[i] = a[j]; a[j] = t;
            }
        t = a[i + 1]; a[i + 1] = a[to]; a[to] = t;
        sortInt(a, i + 2, to);
        while(i >= 0 && a[i] == a[i + 1]) i--;
        sortInt(a, from, i);

    }

    String next() throws IOException
    {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }

    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }

    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

    public static void main(String[] args) throws IOException
    {
        new Thread(null, new A(), "", 1 << 22).start();
    }

    public void run()
    {
        try
        {
            init();
            if(TEST)
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class A {

    static StreamTokenizer st;
    static class Sort implements Comparable<Sort> {
        int val;
        public int compareTo(Sort o) {
            return this.val-o.val;
        }
    }
    public static void main(String[] args) throws IOException{
        st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        Sort[]a = new Sort[n+1];
        int[]b = new int[n+1];
        for (int i = 1; i <= n; i++) {
            a[i] = new Sort();
            a[i].val = nextInt();
            b[i] = a[i].val;
        }
        Arrays.sort(a, 1, n+1);
        int k1 = 0, k2 = 0;
        for (int i = 1; i <= n; i++) {
            if (b[i] != a[i].val) {
                if (k1==0)
                    k1 = i;
                else if (k2==0)
                    k2 = i;
                else {
                    System.out.println("NO");
                    return;
                }
            }
        }
        if (k1==0)
            System.out.println("YES");
        else if (k2==0)
            System.out.println("NO");
        else {
            if (b[k1]==a[k2].val && b[k2]==a[k1].val)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
        pw.close();
    }

    private static int nextInt() throws IOException{
        st.nextToken();
        return (int) st.nval;
    }

}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class A {
    public void run() throws IOException {
        final int n = IOFast.nextInt();
        int[] xs = new int[n];
        for(int i = 0; i < n; i++) {
            xs[i] = IOFast.nextInt();
        }
        int[] ys = xs.clone();
        Random random = new Random();
        for(int i = 0; i < n; i++) {
            final int j = random.nextInt(i + 1);
            final int t = ys[j]; ys[j] = ys[i]; ys[i] = t;
        }
        Arrays.sort(ys);

        int diff = 0;
        for(int i = 0; i < ys.length; i++) {
            if(xs[i] != ys[i]) {
                diff++;
            }
        }

        IOFast.out.println(diff > 2 ? "NO" : "YES");
    }

    public static void main(String[] args) throws IOException {
        new A().run();
        IOFast.out.flush();
    }

    static public class IOFast {
        private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        private static PrintWriter out = new PrintWriter(System.out);

//      private static final int BUFFER_SIZE = 50 * 200000;
        private static int pos, readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static final StringBuilder buf = new StringBuilder();
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];

        static {
            for(int i = 0; i < 10; i++) {
                isDigit['0' + i] = true;
            }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
        }

        static boolean endInput;

        private static int read() throws IOException {
            if(readLen == -1) {
                return -1;
            }

            if(pos >= readLen) {
                readLen = in.read(buffer);
                pos = 0;

                if(readLen <= 0) {
                    return -1;
                }
            }

            return buffer[pos++];
        }

        private static int nextInt() throws IOException {
            boolean plus = false;
            int ret = 0;
            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return Integer.MIN_VALUE;
                }

                if(isDigit[c]) {
                    if(c != '-') {
                        plus = true;
                        ret = c - '0';
                    }
                    break;
                }
            }

            while(true) {
                final int c = read();
                if(c == -1 || !isDigit[c]) {
                    break;
                }
                ret = ret * 10 + c - '0';
            }

            return plus ? ret : -ret;
        }

        private static long nextLong() throws IOException {
            boolean plus = false;
            long ret = 0;
            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return Integer.MIN_VALUE;
                }

                if(isDigit[c]) {
                    if(c != '-') {
                        plus = true;
                        ret = c - '0';
                    }
                    break;
                }
            }

            while(true) {
                final int c = read();
                if(c == -1 || !isDigit[c]) {
                    break;
                }
                ret = ret * 10 + c - '0';
            }

            return plus ? ret : -ret;
        }

        private static char nextChar() throws IOException {
            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return '\0';
                }

                if(!isSpace[c]) {
                    return (char)c;
                }
            }
        }

        private static int next(char[] cs) throws IOException {
            int n = 0;
            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return n;
                }

                if(!isSpace[c]) {
                    cs[n++] = (char)c;
                    break;
                }
            }

            while(true) {
                final int c = read();

                if(c == -1 || isSpace[c]) {
                    break;
                }
                cs[n++] = (char)c;
            }

            return n;
        }

        private static String next() throws IOException {
            buf.setLength(0);

            while(true) {
                final int c = read();

                if(c == -1) {
                    endInput = true;
                    return "-1";
                }

                if(!isSpace[c]) {
                    buf.append((char)c);
                    break;
                }
            }

            while(true) {
                final int c = read();

                if(c == -1 || isSpace[c]) {
                    break;
                }
                buf.append((char)c);
            }

            return buf.toString();
        }

        private static double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

    }

}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int count = in.readInt();
		int[] array = IOUtils.readIntArray(in, count);
		int[] sorted = array.clone();
		ArrayUtils.sort(sorted, IntComparator.DEFAULT);
		int differs = 0;
		for (int i = 0; i < count; i++) {
			if (array[i] != sorted[i])
				differs++;
		}
		if (differs <= 2)
			out.printLine("YES");
		else
			out.printLine("NO");
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	}

class ArrayUtils {
    private static int[] tempInt = new int[0];

	public static int[] sort(int[] array, IntComparator comparator) {
        return sort(array, 0, array.length, comparator);
    }

    public static int[] sort(int[] array, int from, int to, IntComparator comparator) {
        ensureCapacityInt(to - from);
        System.arraycopy(array, from, tempInt, 0, to - from);
        sortImpl(array, from, to, tempInt, 0, to - from, comparator);
        return array;
    }

    private static void ensureCapacityInt(int size) {
        if (tempInt.length >= size)
            return;
        size = Math.max(size, tempInt.length << 1);
        tempInt = new int[size];
    }

    private static void sortImpl(int[] array, int from, int to, int[] temp, int fromTemp, int toTemp, IntComparator comparator) {
        if (to - from <= 1)
            return;
        int middle = (to - from) >> 1;
        int tempMiddle = fromTemp + middle;
        sortImpl(temp, fromTemp, tempMiddle, array, from, from + middle, comparator);
        sortImpl(temp, tempMiddle, toTemp, array, from + middle, to, comparator);
        int index = from;
        int index1 = fromTemp;
        int index2 = tempMiddle;
        while (index1 < tempMiddle && index2 < toTemp) {
            if (comparator.compare(temp[index1], temp[index2]) <= 0)
                array[index++] = temp[index1++];
            else
                array[index++] = temp[index2++];
        }
        if (index1 != tempMiddle)
            System.arraycopy(temp, index1, array, index, tempMiddle - index1);
        if (index2 != toTemp)
            System.arraycopy(temp, index2, array, index, toTemp - index2);
    }

    }

interface IntComparator {
    public static final IntComparator DEFAULT = new IntComparator() {
        public int compare(int first, int second) {
            if (first < second)
                return -1;
            if (first > second)
                return 1;
            return 0;
        }
    };

    public int compare(int first, int second);
}


import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class A implements Runnable
{
    String file = "input";

    boolean TEST = System.getProperty("ONLINE_JUDGE") == null;

    void solve() throws IOException
    {
        int n = nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = nextInt();
        int[] b = a.clone();
        qsort(b);
        //sortInt(b);
        int count = 0;
        for(int i = 0; i < a.length; i++)
            if(a[i] != b[i]) count++;
        if(count == 0 || count == 2) out.println("YES");
        else out.println("NO");
    }

    void qsort(int[] a)
    {
        List<Integer> as = new ArrayList<Integer>();
        for(int x : a) as.add(x);
        Collections.shuffle(as);
        int j = 0;
        for(int x : as) a[j++] = x;
        sort(a);
    }

    Random rnd = new Random();

    void sortInt(int[] a)
    {
        sortInt(a, 0, a.length - 1);
    }

    void sortInt(int[] a, int from, int to)
    {
        if(from >= to) return;
        int i = from - 1;
        int p = rnd.nextInt(to - from + 1) + from;
        int t = a[p]; a[p] = a[to]; a[to] = t;
        for(int j = from; j < to; j++)
            if(a[j] <= a[to])
            {
                i++;
                t = a[i]; a[i] = a[j]; a[j] = t;
            }
        t = a[i + 1]; a[i + 1] = a[to]; a[to] = t;
        sortInt(a, i + 2, to);
        while(i >= 0 && a[i] == a[i + 1]) i--;
        sortInt(a, from, i);

    }

    String next() throws IOException
    {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }

    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }

    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

    public static void main(String[] args) throws IOException
    {
        new Thread(null, new A(), "", 1 << 22).start();
    }

    public void run()
    {
        try
        {
            init();
            if(TEST)
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class C {
	BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st = null;
	PrintWriter out;

	public void solution() throws IOException {
		int n = nextInt();
		int a[] = new int[n];
		int b[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
			b[i] = a[i];
		}
		Arrays.sort(a);
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[i]) {
				ans++;
			}
		}

		if (ans == 2 || ans == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	public String nextToken() throws IOException {
		if (st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(bf.readLine());
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void print(int a[]) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + " ");
		}
	}

	public static void main(String args[]) throws IOException {
		new C().solution();
	}
}


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

public class A {

	final String filename = new String("C").toLowerCase();

	void solve() throws Exception {
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		if (isSorted(a)) {
			out.println("YES");
			return;
		}
		int pos1 = -1;
		for (int i = 0; i < n - 1; i++) {
			if (a[i] > a[i + 1]) {
				int j = i;
				while (j >= 0 && a[j] == a[i]) {
					j--;
				}
				pos1 = j + 1;
				break;
			}

		}
		int pos2 = -1;
		for (int i = n - 2; i >= 0; i--) {
			if (a[i] > a[i + 1]) {
				int j = i + 1;
				while (j < n && a[j] == a[i + 1]) {
					j++;
				}
				pos2 = j - 1;
				break;
			}
		}
		int tmp = a[pos1];
		a[pos1] = a[pos2];
		a[pos2] = tmp;
		if (isSorted(a)) {
			out.println("YES");
		} else {
			out.println("NO");
		}
	}

	boolean isSorted(int[] a) {
		for (int i = 0; i < a.length - 1; i++) {
			if (a[i] > a[i + 1]) {
				return false;
			}
		}
		return true;
	}

	void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			// in = new BufferedReader(new FileReader("input.txt"));
			// out = new PrintWriter("output.txt");

			solve();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

	public static void main(String[] args) {
		new A().run();
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class c {
    class IO {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st;
        Random rnd = new Random();;
        String nextToken() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String line = in.readLine();
                if (line == null)
                    return null;
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }
        int nextInt() throws IOException {
            return Integer.parseInt(nextToken());
        }
        long nextLong() throws IOException {
            return Long.parseLong(nextToken());
        }
        double nextDouble() throws IOException {
            return Double.parseDouble(nextToken());
        }
    }

    void run() throws IOException{
        IO read=new IO();
        int n=read.nextInt();
        int a[]=new int[n],b[]=new int[n];
        for(int i=0;i<n;i++)
            a[i]=b[i]=read.nextInt();
        Arrays.sort(b);
        int cnt=0;
        for(int i=0;i<n;i++)
            if(a[i]!=b[i])
                cnt++;
        if(cnt==0||cnt==2)
            read.out.println("YES");
        else
            read.out.println("NO");
        read.out.close();
    }
    public static void main(String[] args) throws IOException {
        new c().run();
    }
}


//package round136;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class A {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i = 0;i < n;i++)b[i] = a[i] = ni();

		Arrays.sort(b);
		int ct = 0;
		for(int i = 0;i < n;i++){
			if(a[i] != b[i])ct++;
		}
		if(ct <= 2){
			out.println("YES");
		}else{
			out.println("NO");
		}
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new A().run();
	}

	public int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public String ns()
	{
		try{
			int b = 0;
			StringBuilder sb = new StringBuilder();
			while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = 0, p = 0;
			while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	double nd() { return Double.parseDouble(ns()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {

        int n = in.nextInt();
        int a[] = in.nextIntArray(n);
        int i,j,k;

        int b[] = a.clone();
        ArrayUtils.randomShuffle(a);
        Arrays.sort(a);

        int c[] = new int[n];
        k=0;
        for(i=0;i<n;++i) if(a[i]!=b[i]) c[k++] = i;

        String res = "NO";
        if(k==0){
            res = "YES";
        }else
        if(k==1){

        }else
        if(k==2){
            i = c[0]; j = c[1];
            if(a[i]==b[j] && a[j]==b[i]) res = "YES";
        }

        out.writeln(res);
	}
}

class InputReader{
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next(){
        while(tokenizer==null || !tokenizer.hasMoreTokens()){
            try{
                tokenizer = new StringTokenizer(reader.readLine());
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt(){
        return Integer.parseInt(next());
    }

    public int[] nextIntArray(int size){
        int array[] = new int[size];
        for(int i=0; i<size; ++i) array[i] = nextInt();
        return array;
    }
}

class OutputWriter{
    private PrintWriter out;

    public OutputWriter(Writer out){
        this.out = new PrintWriter(out);
    }

    public OutputWriter(OutputStream out){
        this.out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));
    }

    public void close(){
        out.flush();
        out.close();
    }

    public void writeln(Object ... o){
        for(Object x : o) out.print(x);
        out.println();
    }
}

class ArrayUtils{
    private final static Random random = new Random(System.nanoTime());

    public static void randomShuffle(int a[]){
        int n = a.length;
        for(int i=0;i<n;++i){
            int j = random.nextInt(n-i);
            int t = a[i]; a[i] = a[j]; a[j] = t;
        }
    }
}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Locale;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.RandomAccess;
import java.util.AbstractList;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);
        int[] b = a.clone();
        ArrayUtils.safeSort(b);
        int diff = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] != b[i])
                diff++;
        }
        out.println(diff <= 2 ? "YES" : "NO");
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int[] nextIntArray(int count) {
        int[] result = new int[count];
        for (int i = 0; i < count; i++) {
            result[i] = nextInt();
        }
        return result;
    }

    }

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void println(String x) {
        writer.println(x);
    }

    public void close() {
        writer.close();
    }

    }

class ArrayUtils {

    public static List<Integer> asList(int[] array) {
        return new IntList(array);
    }

    private static class IntList extends AbstractList<Integer> implements RandomAccess {

        int[] array;

        private IntList(int[] array) {
            this.array = array;
        }

        public Integer get(int index) {
            return array[index];
        }

        public Integer set(int index, Integer element) {
            int result = array[index];
            array[index] = element;
            return result;
        }

        public int size() {
            return array.length;
        }
    }

    public static void safeSort(int[] array) {
        Collections.shuffle(asList(array));
        Arrays.sort(array);
    }

    }