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

public class A {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    class Pointd implements Comparable<Pointd>{
        int x, in;

        @Override
        public int compareTo(Pointd o) {
            if(x > o.x) return 1;
            if(x < o.x) return -1;
            if(in < o.in) return -1;
            if(in > o.in) return 1;
            return 0;
        }

        public Pointd(int x, int in) {
            super();
            this.x = x;
            this.in = in;
        }
    }

    void solve() throws IOException {
        int n = readInt();
        Pointd[] a = new Pointd[n];
        for(int i = 0; i < n; i++){
            a[i] = new Pointd(readInt(), i);
        }
        Arrays.sort(a);

        int count = 0;
        for(int i = 0; i < n; i++){
            if(a[i].x != a[a[i].in].x) count++;
        }
        if(count == 0 || count == 2) out.println("YES");
        else out.println("NO");
    }

    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()) {
            tok = new StringTokenizer(in.readLine());
        }
        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());
    }

    int[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

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

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}


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.util.*;
public class r220a {
	public static void main(String args[]) {
		Scanner in =new Scanner(System.in);
		int N = in.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> sort = new ArrayList<Integer>();
		for(int i = 0; i < N; i++) {
			int k = in.nextInt();
			list.add(k);
			sort.add(k);
		}

		Collections.sort(sort);

		int count = 0;
		for(int i = 0; i < N; i++) {
			if(sort.get(i).intValue() != list.get(i).intValue())
				count++;
		}
		if(count != 2 && count != 0)
			System.out.println("NO");
		else
			System.out.println("YES");
	}
}


import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Random;
import java.util.TreeSet;

/**
 * Actual solution is at the top, in class Solver
 */
public class Main implements Runnable {
	private static String[] args;

	public static void main(String[] args) {
		Main.args = args;
		new Thread(null, new Main(), "MyRunThread", 1 << 26).start();
	}

	@Override
	public void run() {
		long time_beg = -1;
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		if (args.length > 0 && args[0].equals("outside")) {
			time_beg = System.currentTimeMillis();
			try {
				inputStream = new FileInputStream("IO/in.txt");
//				outputStream = new FileOutputStream("IO/out.txt");
			} catch (Exception e) {
				System.err.println(e);
				System.exit(1);
			}
		} else {
			try {
//				inputStream = new FileInputStream("file_name");
//				outputStream = new FileOutputStream("file_name");
			} catch (Exception e) {
				System.err.println(e);
				System.exit(1);
			}
		}

		Solver s = new Solver();
		s.in = new InputReader(inputStream);
		s.out = new OutputWriter(outputStream);
		if (args.length > 0 && args[0].equals("outside")) {
			s.debug = new DebugWriter(s.out);
		}

		s.solve();
		s.out.close();

		if (args.length > 0 && args[0].equals("outside")) {
			s.debug.close();
			System.err.printf("*** Total time: %.3f ***\n", (System.currentTimeMillis() - time_beg) / 1000.0);
		}
	}
}

final class Solver {
	InputReader in;
	OutputWriter out;
	DebugWriter debug;

	public void solve() {
		int n = in.readInt();
		int[] mas = new int[n];
		int[] sorted = new int[n];

		for (int i = 0; i < n; ++i)
			sorted[i] = mas[i] = in.readInt();

		Random rnd = new Random(System.nanoTime());
		for (int i = 1; i < n; ++i) {
			int j = rnd.nextInt(i);
			int tmp = sorted[j];
			sorted[j] = sorted[i];
			sorted[i] = tmp;
		}

		Arrays.sort(sorted);

		int id1 = -1;

		for (int i = 0; i < n; ++i)
			if (mas[i] != sorted[i]) {
				id1 = i;
				break;
			}

		int id2 = -1;

		for (int i = n - 1; i >= 0; --i)
			if (mas[i] != sorted[i]) {
				id2 = i;
				break;
			}

		if (id1 != -1 && id2 != -1 && id1 != id2) {
			int tmp = mas[id1];
			mas[id1] = mas[id2];
			mas[id2] = tmp;
		}

		for (int i = 0; i < n; ++i)
			if (mas[i] != sorted[i]) {
				out.printLine("NO");
				return;
			}
		out.printLine("YES");
	}
}
class InputReader {
	private boolean finished = false;

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

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

	private 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 peek() {
		if (numChars == -1)
			return -1;
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				return -1;
			}
			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 long readLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long 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();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

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

	private String readLine0() {
		StringBuilder buf = new StringBuilder();
		int c = read();
		while (c != '\n' && c != -1) {
			if (c != '\r')
				buf.appendCodePoint(c);
			c = read();
		}
		return buf.toString();
	}

	public String readLine() {
		String s = readLine0();
		while (s.trim().length() == 0)
			s = readLine0();
		return s;
	}

	public String readLine(boolean ignoreEmptyLines) {
		if (ignoreEmptyLines)
			return readLine();
		else
			return readLine0();
	}

	public BigInteger readBigInteger() {
		try {
			return new BigInteger(readString());
		} catch (NumberFormatException e) {
			throw new InputMismatchException();
		}
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	public double readDouble() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		double res = 0;
		while (!isSpaceChar(c) && c != '.') {
			if (c == 'e' || c == 'E')
				return res * Math.pow(10, readInt());
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		}
		if (c == '.') {
			c = read();
			double m = 1;
			while (!isSpaceChar(c)) {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				m /= 10;
				res += (c - '0') * m;
				c = read();
			}
		}
		return res * sgn;
	}

	public boolean isExhausted() {
		int value;
		while (isSpaceChar(value = peek()) && value != -1)
			read();
		return value == -1;
	}
}

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 printFormat(String format, Object... objects) {
		writer.printf(format, objects);
	}

	public void print(char[] objects) {
		writer.print(objects);
	}

	public void printLine(char[] objects) {
		writer.println(objects);
	}

	public void printLine(char[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

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

	public void printLine(int[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(int[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

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

	public void printLine(long[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(long[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

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

	public void printLine(double[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(double[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

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

	public void printLine(byte[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(byte[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

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

	public void printLine(boolean[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(boolean[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

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

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

class DebugWriter {
	private final OutputWriter writer;

	public DebugWriter(OutputWriter writer) {
		this.writer = writer;
	}

	private void printDebugMessage() {
		writer.print("debug:\t");
	}

	public void printLine(Object... objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printFormat(String format, Object... objects) {
		flush();
		printDebugMessage();
		writer.printFormat(format, objects);
		flush();
	}

	public void printLine(char[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(char[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(double[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(double[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(int[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(int[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(long[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(long[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(byte[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(byte[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(boolean[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(boolean[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

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

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


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

public class Solution{

    void solve()throws Exception
    {

        int n=nextInt();

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

        ArrayList<Integer>list=new ArrayList<Integer>();
        for(int i=0;i<n;i++)
            list.add(a[i]);
        Collections.shuffle(list);
        int[]b=new int[n];
        for(int i=0;i<n;i++)
            b[i]=list.get(i);
        Arrays.sort(b);
        int cnt=0;
        for(int i=0;i<n;i++)
            if(a[i]!=b[i])
                cnt++;
        if(cnt<=2)
            System.out.println("YES");
        else
            System.out.println("NO");

    }

    private void mySort(int[] a) {
        if(a.length<=1)
            return;
        int n=a.length;
        int[]left=new int[n/2];
        int[]right=new int[n-n/2];
        for(int i=0;i<n;i++)
            if(i<left.length)
                left[i]=a[i];
            else
                right[i-left.length]=a[i];
        mySort(left);
        mySort(right);
        int i=0;
        int j=0;
        while (i<left.length || j<right.length)
        {
            if(i==left.length)
                a[i+j]=right[j++];
            else if(j==right.length)
                a[i+j]=left[i++];
            else if(left[i]<right[j])
                a[i+j]=left[i++];
            else
                a[i+j]=right[j++];
        }

    }

    ////////////
    BufferedReader reader;
    PrintWriter writer;
    StringTokenizer stk;
    void run()throws Exception
    {

        reader=new BufferedReader(new InputStreamReader(System.in));
        // reader=new BufferedReader(new FileReader("input.txt"));
        stk=null;
        //writer=new PrintWriter(new PrintWriter(System.out));
        //writer=new PrintWriter(new FileWriter("output.txt"));
        solve();
        reader.close();
        //writer.close();
    }
    int nextInt()throws Exception
    {
        return Integer.parseInt(nextToken());
    }

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

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

    }

    String nextString()throws Exception
    {
        return nextToken();
    }
    String nextLine()throws Exception
    {
        return reader.readLine();
    }
    String nextToken()throws Exception
    {
        if(stk==null || !stk.hasMoreTokens())
        {
            stk=new StringTokenizer(nextLine());
            return nextToken();

        }
        return stk.nextToken();
    }

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

}


import java.util.Arrays;
import java.util.Scanner;

public class test1
{

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[]=new int[n];
        int b[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=in.nextInt();
            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)
            System.out.println("YES");
        else
            System.out.println("NO");
    }

}


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

public class Problem220A {
    static int[] numbers;
    static int[] numbersCopy;

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int i = Integer.parseInt(in.readLine());
        numbers = new int[i];
        numbersCopy = new int[i];
        StringTokenizer stringTokenizer = new StringTokenizer(in.readLine());
        int numOutOfPlace = 0;
        for (int j = 0; j < i; j++) {
            numbers[j] = Integer.parseInt(stringTokenizer.nextToken());
            numbersCopy[j] = numbers[j];
        }
        Arrays.sort(numbers);
        for (int j = 0; j < i; j++) {
            if (numbers[j] != numbersCopy[j]) {
                numOutOfPlace++;
                if (numOutOfPlace > 2) {
                    break;
                }
            }
        }
        if (numOutOfPlace == 0 || numOutOfPlace == 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class LittleElephant {
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int temp;
		ArrayList<Integer> a2 = new ArrayList<Integer>();
		ArrayList<Integer> a1 = new ArrayList<Integer>();
		int count = 0;
		int temp1,temp2;

		for(int i= 0; i < n ; i++){
			temp = input.nextInt();
			a2.add(temp);
			a1.add(temp);
		}
		Collections.sort(a2);
		input.close();
		for(int i = 0; i < n; i++){
			temp1 = a2.get(i);
			temp2 = a1.get(i);
			if(temp1 != temp2){
				count++;
			}
		}
		if(count==2 || count==0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}


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

import java.util.*;

public class Solution{

    void solve()throws Exception
    {

        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 cnt=0;
        for(int i=0;i<n;i++)
            if(a[i]!=b[i])
                cnt++;
        if(cnt<=2)
            System.out.println("YES");
        else
            System.out.println("NO");

    }

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

    ////////////
    BufferedReader reader;
    PrintWriter writer;
    StringTokenizer stk;
    void run()throws Exception
    {

        reader=new BufferedReader(new InputStreamReader(System.in));
        // reader=new BufferedReader(new FileReader("input.txt"));
        stk=null;
        writer=new PrintWriter(new PrintWriter(System.out));
        //writer=new PrintWriter(new FileWriter("output.txt"));
        solve();
        reader.close();
        writer.close();
    }
    int nextInt()throws Exception
    {
        return Integer.parseInt(nextToken());
    }

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

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

    }

    String nextString()throws Exception
    {
        return nextToken();
    }
    String nextLine()throws Exception
    {
        return reader.readLine();
    }
    String nextToken()throws Exception
    {
        if(stk==null || !stk.hasMoreTokens())
        {
            stk=new StringTokenizer(nextLine());
            return nextToken();

        }
        return stk.nextToken();
    }

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

}


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

public class Main {

   static class Scanner {
      StreamTokenizer in;
      boolean forceMode = false;

      Scanner(InputStream is, String codePage, boolean forceMode) {
         in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
         if (!forceMode) {
            in.resetSyntax();
            in.wordChars(33, 255);
            in.whitespaceChars(0, 32);
         }
      }

      Scanner(InputStream is, String codePage) {
         in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
         if (!forceMode) {
            in.resetSyntax();
            in.wordChars(33, 255);
            in.whitespaceChars(0, 32);
         }
      }

      String next() {
         try {
            in.nextToken();
            return in.sval;
         } catch (Exception e) {
            throw new Error();
         }
      }

      int nextInt() {
         if (forceMode) {
            try {
               in.nextToken();
               return (int) in.nval;
            } catch (Exception e) {
               throw new Error();
            }
         } else {
            return Integer.parseInt(next());
         }
      }

      long nextLong() {
         if (forceMode) {
            throw new Error("No long at force mod!");
         } else {
            return Long.parseLong(next());
         }

      }

      double nextDouble() {
         if (forceMode) {
            try {
               in.nextToken();
               return in.nval;
            } catch (Exception e) {
               throw new Error();
            }
         } else {
            return Double.parseDouble(next());
         }
      }
   }

   static class Assertion {
      static void checkRE(boolean e) {
         if (!e) {
            throw new Error();
         }
      }

      static void checkTL(boolean e) {
         if (!e) {
            int idx = 1;
            while (idx > 0) {
               idx++;
            }
         }
      }
   }

   Scanner in;
   PrintWriter out;

   class Int implements Comparable<Int> {
      int value;
      int pos;

      public Int(int value, int pos) {
         this.value = value;
         this.pos = pos;
      }

      @Override
      public int compareTo(Int second) {
         if (this.value == second.value) {
            return this.pos - second.pos;
         } else {
            return this.value - second.value;
         }
      }
   }

   void solve() {
      int n = in.nextInt();
      Int ar[] = new Int[n];
      for (int i = 0; i < ar.length; i++) {
         ar[i] = new Int(in.nextInt(), i);
      }
      Arrays.sort(ar);
      int cnt = 0;
      for (int i = 0; i < ar.length; i++) {
         if (ar[i].value!=ar[ar[i].pos].value) {
            cnt++;
         }
      }
      if (cnt == 2 || cnt == 0) {
         out.println("YES");
      } else {
         out.println("NO");
      }

   }

   final static String fileName = "";

   void run() {
      // try {
      // in = new Scanner(new FileInputStream(fileName + ".in"), "ISO-8859-1");
      // out = new PrintWriter(fileName + ".out", "ISO-8859-1");
      // } catch (FileNotFoundException e) {
      // throw new Error(e);
      //
      // } catch (UnsupportedEncodingException e) {
      // throw new Error(e);
      // }
      in = new Scanner(System.in, "");
      out = new PrintWriter(System.out);
      try {
         solve();
      } catch (Exception e) {
         throw new Error(e);
      } finally {
         out.close();
      }
   }

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


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.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/*
 * @author Ivan Pryvalov (ivan.pryvalov@gmail.com)
 */
public class Codeforces_R136_Div1_A implements Runnable{

	private void solve() throws IOException {
		int n = scanner.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = scanner.nextInt();
		}

		boolean sorted = true;
		for (int i = 0; i < a.length; i++) {
			if (!isOk(a, i)){
				sorted = false;
			}
		}
		if (sorted){
			out.println("YES");
			return;
		}

		List<Integer> idx = new ArrayList<Integer>();
		for(int i=0; i<n; i++){
			if (!isOk(a, i)){
				idx.add(i);
			}
		}

		if (idx.size() > 6){
			out.println("NO");
			return;
		}

		for(int i=0; i<idx.size(); i++){
			for(int j=0; j<n; j++){
				swap(a, idx.get(i), j);
				if (isOk(a, idx) && isOk(a, j)){
					out.println("YES");
					return;
				}
				swap(a, idx.get(i), j);
			}
		}
		out.println("NO");
	}

	private boolean isOk(int[] a, int i) {
		boolean ordered = true;
		if (i>0 && !(a[i-1] <= a[i])){
			ordered = false;
		}
		if (i<a.length-1 && !(a[i]<=a[i+1])){
			ordered = false;
		}
		return ordered;
	}

	private boolean isOk(int[] a, List<Integer> idx) {
		for(int i : idx){
			if (!isOk(a, i))
				return false;
		}
		return true;
	}

	private void swap(int[] a, int i, int j) {
		int tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}

	/////////////////////////////////////////////////
	final int BUF_SIZE = 1024 * 1024 * 8;//important to read long-string tokens properly
	final int INPUT_BUFFER_SIZE = 1024 * 1024 * 8 ;
	final int BUF_SIZE_INPUT = 1024;

	final int BUF_SIZE_OUT = 1024;

	boolean inputFromFile = false;
	String filenamePrefix = "A-small-attempt0";
	String inSuffix = ".in";
	String outSuffix = ".out";

	//InputStream bis;
	//OutputStream bos;
	PrintStream out;
	ByteScanner scanner;
	ByteWriter writer;

//	@Override
	public void run() {
		try{
			InputStream bis = null;
			OutputStream bos = null;
			//PrintStream out = null;
			if (inputFromFile){
				File baseFile = new File(getClass().getResource("/").getFile());
				bis = new BufferedInputStream(
						new FileInputStream(new File(
								baseFile, filenamePrefix+inSuffix)),
								INPUT_BUFFER_SIZE);
				bos = new BufferedOutputStream(
						new FileOutputStream(
								new File(baseFile, filenamePrefix+outSuffix)));
				out = new PrintStream(bos);
			}else{
				bis = new BufferedInputStream(System.in, INPUT_BUFFER_SIZE);
				bos = new BufferedOutputStream(System.out);
				out = new PrintStream(bos);
			}
			scanner = new ByteScanner(bis, BUF_SIZE_INPUT, BUF_SIZE);
			writer = new ByteWriter(bos, BUF_SIZE_OUT);

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

	public interface Constants{
		final static byte ZERO = '0';//48 or 0x30
		final static byte NINE = '9';
		final static byte SPACEBAR = ' '; //32 or 0x20
		final static byte MINUS = '-'; //45 or 0x2d

		final static char FLOAT_POINT = '.';
	}

	public static class EofException extends IOException{
	}

	public static class ByteWriter implements Constants {

		int bufSize = 1024;
		byte[] byteBuf = new byte[bufSize];
		OutputStream os;

		public ByteWriter(OutputStream os, int bufSize){
			this.os = os;
			this.bufSize = bufSize;
		}

		public void writeInt(int num) throws IOException{
	         int byteWriteOffset = byteBuf.length;
	         if (num==0){
	        	 byteBuf[--byteWriteOffset] = ZERO;
	         }else{
	        	 int numAbs = Math.abs(num);
	        	 while (numAbs>0){
	        		 byteBuf[--byteWriteOffset] = (byte)((numAbs % 10) + ZERO);
	        		 numAbs /= 10;
	        	 }
	        	 if (num<0)
	        		 byteBuf[--byteWriteOffset] = MINUS;
	         }
	         os.write(byteBuf, byteWriteOffset, byteBuf.length - byteWriteOffset);
		}

		/**
		 * Please ensure ar.length <= byteBuf.length!
		 *
		 * @param ar
		 * @throws IOException
		 */
		public void writeByteAr(byte[] ar) throws IOException{
			for (int i = 0; i < ar.length; i++) {
				byteBuf[i] = ar[i];
			}
			os.write(byteBuf,0,ar.length);
		}

		public void writeSpaceBar() throws IOException{
			byteBuf[0] = SPACEBAR;
			os.write(byteBuf,0,1);
		}

	}

	public static class ByteScanner implements Constants{

		InputStream is;

		public ByteScanner(InputStream is, int bufSizeInput, int bufSize){
			this.is = is;
			this.bufSizeInput = bufSizeInput;
			this.bufSize = bufSize;

			byteBufInput = new byte[this.bufSizeInput];
			byteBuf = new byte[this.bufSize];
		}

		public ByteScanner(byte[] data){
			byteBufInput = data;
			bufSizeInput = data.length;
			bufSize = data.length;
			byteBuf = new byte[bufSize];
			byteRead = data.length;
			bytePos = 0;
		}

		private int bufSizeInput;
		private int bufSize;

		byte[] byteBufInput;
		byte by=-1;
		int byteRead=-1;
		int bytePos=-1;

		byte[] byteBuf;
		int totalBytes;

		boolean eofMet = false;

		private byte nextByte() throws IOException{

			if (bytePos<0 || bytePos>=byteRead){
				byteRead = is==null? -1: is.read(byteBufInput);
				bytePos=0;
				if (byteRead<0){
					byteBufInput[bytePos]=-1;//!!!
					if (eofMet)
						throw new EofException();
					eofMet = true;
				}
			}
			return byteBufInput[bytePos++];
		}

		/**
		 * Returns next meaningful character as a byte.

		 *
		 * @return
		 * @throws IOException
		 */
		public byte nextChar() throws IOException{
			while ((by=nextByte())<=0x20);
			return by;
		}

		/**
		 * Returns next meaningful character OR space as a byte.

		 *
		 * @return
		 * @throws IOException
		 */
		public byte nextCharOrSpacebar() throws IOException{
			while ((by=nextByte())<0x20);
			return by;
		}

	    /**
	     * Reads line.
	     *
	     * @return
	     * @throws IOException
	     */
	    public String nextLine() throws IOException {
            readToken((byte)0x20);
            return new String(byteBuf,0,totalBytes);
	    }

	    public byte[] nextLineAsArray() throws IOException {
            readToken((byte)0x20);
            byte[] out = new byte[totalBytes];
            System.arraycopy(byteBuf, 0, out, 0, totalBytes);
            return out;
	    }

	    /**
	     * Reads token. Spacebar is separator char.
	     *
	     * @return
	     * @throws IOException
	     */
	    public String nextToken() throws IOException {
            readToken((byte)0x21);
            return new String(byteBuf,0,totalBytes);
	    }

	    /**
	     * Spacebar is included as separator char
	     *
	     * @throws IOException
	     */
	    private void readToken() throws IOException {
            readToken((byte)0x21);
	    }

	    private void readToken(byte acceptFrom) throws IOException {
            totalBytes = 0;
            while ((by=nextByte())<acceptFrom);
            byteBuf[totalBytes++] = by;
            while ((by=nextByte())>=acceptFrom){
                byteBuf[totalBytes++] = by;
            }
	    }

	    public int nextInt() throws IOException{
			readToken();
			int num=0, i=0;
			boolean sign=false;
			if (byteBuf[i]==MINUS){
				sign = true;
				i++;
			}
			for (; i<totalBytes; i++){
				num*=10;
				num+=byteBuf[i]-ZERO;
			}
			return sign?-num:num;
		}

		public long nextLong() throws IOException{
			readToken();
			long num=0;
			int i=0;
			boolean sign=false;
			if (byteBuf[i]==MINUS){
				sign = true;
				i++;
			}
			for (; i<totalBytes; i++){
				num*=10;
				num+=byteBuf[i]-ZERO;
			}
			return sign?-num:num;
		}

		/*
		//TODO test Unix/Windows formats
		public void toNextLine() throws IOException{
			while ((ch=nextChar())!='\n');
		}
		*/

		public double nextDouble() throws IOException{
			readToken();
			char[] token = new char[totalBytes];
			for (int i = 0; i < totalBytes; i++) {
				token[i] = (char)byteBuf[i];
			}
			return Double.parseDouble(new String(token));
		}

	}

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

}


import java.io.IOException;
import java.util.Arrays;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.util.NoSuchElementException;
import java.util.TreeSet;
import java.util.Collection;
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;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskA {
    public void solve(int testNumber, MyScanner in, PrintWriter out) {
        int n = in.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) as[i] = in.nextInt();
        int[] sorted = as.clone();
        ArrayUtils.sort(sorted);
        int diff = 0;
        for (int i = 0; i < n; i++)if(as[i]!=sorted[i])diff++;
        if(diff<=2)out.println("YES");
        else out.println("NO");
    }
}

class MyScanner {
    private final InputStream in;
    public MyScanner(InputStream in){
        this.in = in;
    }

    public int nextInt(){
        try{
            int c=in.read();
            if(c==-1) return c;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=in.read();
                if(c==-1) return c;
            }
            if(c=='-') return -nextInt();
            int res=0;
            do{
                res*=10;
                res+=c-'0';
                c=in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    }

class ArrayUtils {

    public static void swap(int[] is, int i, int j) {
        int t = is[i];
        is[i] = is[j];
        is[j] = t;
    }

    public static void shuffle(int[] S) {
        Random rnd = r == null ? (r = new Random()) : r;
        shuffle(S, rnd);
    }

    private static Random r;
    private static void shuffle(int[] S, Random rnd) {
        for (int i = S.length; i > 1; i--)
            swap(S, i - 1, rnd.nextInt(i));
    }

    public static void sort(int[] a) {
        shuffle(a);
        Arrays.sort(a);
    }
}


import java.io.InputStreamReader;
import java.io.IOException;
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 Sunits789
 */
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();
        int arr[]=new int[n];
        in.getArray(arr);
        int arrc[]=new int[n];
        for(int i=0;i<n;i++){
            arrc[i]=arr[i];
        }
        Library.sort(arrc);
        int c=0;
        for(int i=0;i<n;i++){
            if(arrc[i]!=arr[i]){
                c++;
            }
        }
        if(c>2){
            out.println("NO");
        }
        else{
            out.println("YES");
        }
	}
}

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 (IOException e){
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

    public void getArray(int arr[]){
        for(int i=0;i<arr.length;i++){
            arr[i]=nextInt();
        }
    }

    }

class Library{
    public static void sort(int n[]){
        int len=n.length;
        int l1=len/2;
        int l2=len-l1;
        int n1[]=new int[l1];
        int n2[]=new int[l2];
        for(int i=0;i<l1;i++){
            n1[i]=n[i];
        }
        for(int i=0;i<l2;i++){
            n2[i]=n[i+l1];
        }
        if(l1!=0){
            sort(n1);
            sort(n2);
        }
        int ind1=0;
        int ind2=0;
        int ind=0;
        for(int i=0;i<len&&ind1<l1&&ind2<l2;i++){
            if(n1[ind1]<n2[ind2]){
                n[i]=n1[ind1];
                ind1++;
            }
            else{
                n[i]=n2[ind2];
                ind2++;
            }
            ind++;
        }
        if(ind1<l1){
            for(int i=ind1;i<l1;i++){
                n[ind]=n1[i];
                ind++;
            }
        }
        if(ind2<l2){
            for(int i=ind2;i<l2;i++){
                n[ind]=n2[i];
                ind++;
            }
        }
    }

    }


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

public class A {
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	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 k = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[i]) {
				k++;
			}
		}
		if (k <= 2) {
			out.println("YES");
		} else {
			out.println("NO");
		}
	}

	void run() {
		try {
			// br = new BufferedReader(new FileReader("G.in"));
			// out = new PrintWriter("G.out");

			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			solve();

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

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

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

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

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

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


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

public class Solution{

    void solve()throws Exception
    {

        int n=nextInt();

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

        int[]b=a.clone();
        mySort(b);
        int cnt=0;
        for(int i=0;i<n;i++)
            if(a[i]!=b[i])
                cnt++;
        if(cnt<=2)
            System.out.println("YES");
        else
            System.out.println("NO");

    }

    private void mySort(int[] a) {
        if(a.length<=1)
            return;
        int n=a.length;
        int[]left=new int[n/2];
        int[]right=new int[n-n/2];
        for(int i=0;i<n;i++)
            if(i<left.length)
                left[i]=a[i];
            else
                right[i-left.length]=a[i];
        mySort(left);
        mySort(right);
        int i=0;
        int j=0;
        while (i<left.length || j<right.length)
        {
            if(i==left.length)
                a[i+j]=right[j++];
            else if(j==right.length)
                a[i+j]=left[i++];
            else if(left[i]<right[j])
                a[i+j]=left[i++];
            else
                a[i+j]=right[j++];
        }

    }

    ////////////
    BufferedReader reader;
    PrintWriter writer;
    StringTokenizer stk;
    void run()throws Exception
    {

        reader=new BufferedReader(new InputStreamReader(System.in));
        // reader=new BufferedReader(new FileReader("input.txt"));
        stk=null;
        //writer=new PrintWriter(new PrintWriter(System.out));
        //writer=new PrintWriter(new FileWriter("output.txt"));
        solve();
        reader.close();
        //writer.close();
    }
    int nextInt()throws Exception
    {
        return Integer.parseInt(nextToken());
    }

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

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

    }

    String nextString()throws Exception
    {
        return nextToken();
    }
    String nextLine()throws Exception
    {
        return reader.readLine();
    }
    String nextToken()throws Exception
    {
        if(stk==null || !stk.hasMoreTokens())
        {
            stk=new StringTokenizer(nextLine());
            return nextToken();

        }
        return stk.nextToken();
    }

    public static void main(String[]args) throws Exception
    {
        new Solution().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 A2 {
	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();

		b = radixSort(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");
		}
	}

	public static int[] radixSort(int[] f)
	{
		int[] to = new int[f.length];
		{
			int[] b = new int[65537];
			for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		return f;
	}

	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 A2().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.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	Scanner in;
	static PrintWriter out;

	static class Scanner {
		StreamTokenizer in;

		Scanner(InputStream is) {
			in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
			  in.resetSyntax();
		         in.whitespaceChars(0, 32);
		         in.wordChars(33, 255);

		}

		int nextInt() {
			try {
				in.nextToken();
				return Integer.parseInt(in.sval);
			} catch (IOException e) {
				throw new Error();
			}
		}

		String next() {
			try {
				in.nextToken();
				return in.sval;
			} catch (IOException e) {
				throw new Error();
			}
		}
	}

	static class Value implements Comparable <Value> {
		int x;
		int pos;

		Value(int x, int pos) {
			this.x = x;
			this.pos = pos;
		}

		public int compareTo(Value second) {
			if (this.x == second.x) {
				return this.pos - second.pos;
			} else {
				return this.x - second.x;
			}
		}
	}

	void solve() {
		int n = in.nextInt();

		Value ar[] = new Value[n];

		for (int i = 0; i < n; i++) {
			ar[i] = new Value(in.nextInt(), i);
		}
		Arrays.sort(ar);
		int cnt = 0;
		//LinkedList <Integer> gavno = new LinkedList<Integer>();
		for (int i = 0; i < n; i++) {
			if (ar[i].pos != i && ar[ar[i].pos].x != ar[i].x) {
				cnt++;
				//gavno.add(i);
			}
		}
		if (cnt > 2) {
			out.println("NO");
		} else {
			out.println("YES");
		}
	}

	static void asserT(boolean e) {
		if (!e) {
			throw new Error();
		}
	}

	public void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		try {
			solve();
		} finally {
			out.close();
		}
	}

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

}


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

public class CF220A {
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[] A = new int[n];
        Integer[] B = new Integer[n];
        for(int i=0; i<n; i++) {
            A[i] = Integer.parseInt(st.nextToken());
            B[i] = A[i];
        }
        Collections.sort(Arrays.asList(B));

        int cnt = 0;
        for(int i=0; i<n; i++)
            if(A[i] != B[i])
                cnt++;
        System.out.println(cnt <= 2 ? "YES" : "NO");
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

/**
 * User: serparamon
 */
public class Codeforces_2012_08_31_A {

    public static void main(String[] args) throws IOException {
        //Scanner in = new Scanner(System.in);
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(System.out);
        in.nextToken();
        int n = (int) in.nval;
        int[] a = new int[n];
        for (int i=0; i<n; i++) {
            in.nextToken();
            a[i] = (int) in.nval;
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(a);
        int k = 0;
        for (int i=0; i<n; i++) {
            if (a[i] != b[i]) k++;
        }
        if (k==0 || k==2)
            out.println("YES");
        else
            out.println("NO");
        out.flush();
        out.close();
    }

}


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

import static java.lang.Math.*;

public class Main {
    static int n;
     static long TotalTime;
    static Problem[] problems;
    static StringBuilder sb;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        sb = new StringBuilder();
        n = sc.nextInt();
        TotalTime = sc.nextLong();
        problems = new Problem[n];
        for (int i = 0; i < n; i++) {
            problems[i] = new Problem (sc.nextInt(), sc.nextLong(), i);
        }
        Arrays.sort(problems);
        long num = -1;
        long high = n;
        long low = 0;
        int iter = 0;
        while (high - low > 1) {
            num = (high + low) / 2;
            if (test(num, false)) {
                low = num;
            }
            else {
                high = num;
            }
        }
        if (test(high, false))
            num = high;
        else
            num = low;
        test(num, true);
        System.out.print(sb);
    }

    public static boolean test (long num, boolean print) {
        int count = 0;
        long sum = 0L;
        if (print) sb.append(num + "\n" + num + "\n");
        for (int i = 0; i < n && count < num; i++) {
            if (problems[i].a >= num) {
                count++;
                sum += problems[i].t;
                if (print) sb.append((problems[i].index + 1) + " ");
            }
        }
        return (count == num) && (sum <= TotalTime);
    }

    public static class Problem implements Comparable<Problem>  {
        int a;
        long t;
        int index;

        public int compareTo(Problem o) {
          return Long.compare(t, o.t);
        }
        public Problem (int a, long t, int index) {
            this.a = a;
            this.t = t;
            this.index = index;
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

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

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

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

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

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }

        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextLong();
            }
            return a;
        }
    }
}


import java.math.BigInteger;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p1096f {
    static long MOD = 998244353;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        BIT invert = new BIT(n+5);
        BIT neg = new BIT(n+5);
        long res = 0;
        int[] arr = new int[n];
        boolean[] has = new boolean[n+1];
        long num1 = 0;
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            if(arr[i] != -1) {
                res += invert.read(n+5)-invert.read(arr[i]);
                res %= MOD;
                invert.update(arr[i], 1);
                has[arr[i]] = true;
            } else num1++;
        }
        if(num1 == 0) {
            System.out.println(res);
            return;
        }
        for(int i = 1; i <= n; i++) if(!has[i]) neg.update(i, 1);
        long invertNum1 = modInv(num1, MOD);
        res += ((num1*(num1-1))%MOD)*modInv(4, MOD);
        res %= MOD;
        long cnt = 0;
        for(int i = 0; i < n; i++) {
            if(arr[i] == -1) {
                cnt++;
                continue;
            }
            res += (((neg.read(n+5)-neg.read(arr[i]))*cnt)%MOD)*invertNum1;
            res %= MOD;
        }
        cnt = 0;
        for(int i = n-1; i >= 0; i--) {
            if(arr[i] == -1) {
                cnt++;
                continue;
            }
            res += (((neg.read(arr[i]))*cnt)%MOD)*invertNum1;
            res %= MOD;
        }
        System.out.println(res);
    }

    //@
    static class BIT {
            int n;
            int[] tree;
            public BIT(int n) {
                    this.n = n;
                    tree = new int[n + 1];
            }

            int read(int i) {
                    int sum = 0;
                    while (i > 0) {
                            sum += tree[i];
                            i -= i & -i;
                    }
                    return sum;
            }

            void update(int i, int val) {
                    while (i <= n) {
                            tree[i] += val;
                            i += i & -i;
                    }
            }
            //$
    }

    //@
    // Computes the modular inverse of x
    // Returns 0 if the GCD of x and mod is not 1
    // O(log n)  :  Can be converted to use BigIntegers
    static long modInv(long x, long mod) {
        return (BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod))).longValue();
    }

    static long modInv(long a, long b, long y0, long y1, long q0, long q1) {
            long y2 = y0 - y1*q0;
            return b == 0 ? y2 : modInv(b, a % b, y1, y2, q1, a / b);
    }

    //@
    static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

}


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

public class Main{
    public static void main(String[] args){
        try {
            new Main().solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    ArrayList<Edge>[]edge;
    int n,m,cnt=0;
    int ord;
    int[]order;int[]vis;
    Edge[] e;
    private void solve() throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        n=in.nextInt();m=in.nextInt();
        edge=new ArrayList[n+1];
        e=new Edge[m];
        vis=new int[n+1];
        order=new int[n+1];
        for(int i=1;i<=n;i++){
            edge[i]=new ArrayList<>();
        }
        for(int i=1;i<=m;i++){
            int s=in.nextInt(),t=in.nextInt(),c=in.nextInt();
            edge[s].add(new Edge(s,t,c,i));
        }
        int l=0,r=1000000000;
        while (l<r){
            int mid=(l+r)>>>1;
            if(judge(mid,false))r=mid;
            else l=mid+1;
        }
        out.print(l+" ");
        judge(l,true);
        Arrays.sort(e,0,cnt,Comparator.comparingInt(x->x.id));
        int ans=0;
        int[]a=new int[m];
        for(int i=0;i<cnt;i++){
            if(order[e[i].s]<order[e[i].t])a[ans++]=e[i].id;
        }
        out.println(ans);
        for(int i=0;i<ans;i++){
            out.print(a[i]+" ");
        }
        out.println();
        out.flush();
    }
    boolean judge(int min,boolean mod){
        Arrays.fill(vis,0);
        cycle=false;
        for(int i=1;i<=n;i++){
            if(vis[i]==0){
                dfs(i,min,mod);
                if(cycle)return false;
            }
        }
        return true;
    }
    boolean cycle=false;
    void dfs(int cur,int min,boolean mod){
        if(cycle)return;
        vis[cur]=1;
        for(Edge e:edge[cur]){
            if(e.c<=min){
                if(mod)this.e[cnt++]=e;
                continue;
            }
            if(vis[e.t]==1){
                cycle=true;return;
            }
            else if(vis[e.t]==0)dfs(e.t,min,mod);
        }
        vis[cur]=2;
        if(mod)order[cur]=ord++;
    }
}
class Edge{
    int s,t,c,id;
    Edge(int a,int b,int c,int d){
        s=a;t=b;this.c=c;id=d;
    }
}
class InputReader{
    StreamTokenizer tokenizer;
    public InputReader(InputStream stream){
        tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));
        tokenizer.ordinaryChars(33,126);
        tokenizer.wordChars(33,126);
    }
    public String next() throws IOException {
        tokenizer.nextToken();
        return tokenizer.sval;
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public boolean hasNext() throws IOException {
        int res=tokenizer.nextToken();
        tokenizer.pushBack();
        return res!=tokenizer.TT_EOF;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
        ReaderFastIO in = new ReaderFastIO(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DConcatenatedMultiples solver = new DConcatenatedMultiples();
        solver.solve(1, in, out);
        out.close();
    }

    static class DConcatenatedMultiples {
        public void solve(int testNumber, ReaderFastIO in, PrintWriter out) {

            Map<Integer, Integer>[] mapMods = new HashMap[11];

            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = in.readArrayInt(n);

            for (int i = 0; i < 11; i++) {
                mapMods[i] = new HashMap<>();
            }

            for (int i = 0; i < n; i++) {
                int pot = getPot(a[i]);
                mapMods[pot].put(a[i] % k, mapMods[pot].getOrDefault(a[i] % k, 0) + 1);
            }

            long ct = 0;

            for (int i = 0; i < n; i++) {

                int ownPot = getPot(a[i]);
                long suffix = a[i] * 10L;
                for (int j = 1; j <= 10; j++) {

                    int mod = (int) (suffix % k);
                    int comMod = (k - mod) % k;
                    int qt = mapMods[j].getOrDefault(comMod, 0);

                    if (j == ownPot && (a[i] % k) == comMod) {
                        qt--;
                    }

                    ct += qt;

                    suffix = (suffix * 10L) % k;
                }

            }

            out.println(ct);
        }

        public int getPot(int x) {

            int ct = 0;

            while (x != 0) {
                x /= 10;
                ct++;
            }

            return ct;
        }

    }

    static class ReaderFastIO {
        BufferedReader br;
        StringTokenizer st;

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

        public ReaderFastIO(InputStream input) {
            br = new BufferedReader(new InputStreamReader(input));
        }

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

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

        public int[] readArrayInt(int n) {

            int[] array = new int[n];

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

            return array;
        }

    }
}


import java.io.*;
import java.util.StringTokenizer;
public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int N = sc.nextInt();
        long dest = sc.nextLong();
        long max = (long)N * ((long)N + 1L) / 2L;
        if (dest < 2 * N - 1 || dest > max) {
            out.println("No");
            out.close();
            return;
        }
        int[] d = new int[N + 1];
        int[] f = new int[N + 1];
        int K = 1;
        for (; K <= N; K++) {
            long dep = 1L, cnt = 1L, c = 1L;
            long t = 1L;
            while (cnt < N) {
                c = c * K;
                dep++;
                t += (dep * Math.min(c, N - cnt));
                cnt += c;
            }
            if (t <= dest) break;
        }
        out.println("Yes");
        int dep = 1; long cnt = 1L, c = 1L;
        long t = 1L;
        d[1] = 1;
        while (cnt < N) {
            dep++; c = c * K;
            long x = (long)N - cnt;
            int min;
            if (c >= x) min = (int)x;
            else min = (int)c;
            d[dep] = min;
            t += (dep * Math.min(c, (long)N - cnt)); cnt += c;
        }
        dest -= t;
        int curDep = dep; int nextDep = dep + 1;
        while (dest > 0) {
            if (d[curDep] <= 1) curDep--;
            d[curDep]--;
            long next = Math.min(nextDep++, dest + curDep);
            dest -= ((int)next - curDep);
            d[(int)next]++;
        }
        int first = 1;
        for (int i = 2; i < nextDep; i++) {
            int p = 0, fn = first - d[i - 1] + 1;
            for (int j = first + 1; j <= first + d[i]; j++) {
                if (p == K) {
                    fn++; p = 0;
                }
                p++; f[j] = fn;
            }
            first += d[i];
        }
        for (int i = 2; i <= N; i++)
            out.format("%d ", f[i]);
        out.close();
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

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

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

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

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

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextLong();
            }
            return a;
        }*/
    }
}


import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        HashMap<Integer, Integer> map = new HashMap<>();
        StringTokenizer st = new StringTokenizer(br.readLine());
        for (int i = 0; i < n; i++) {
            int x = Integer.parseInt(st.nextToken());
            arr[i] = x;
            if (!map.containsKey(x)) {
                map.put(x, 1);
            } else {
                map.replace(x, map.get(x) + 1);
            }
        }
        int[] power = new int[31];
        for (int i = 0; i < 31; i++) {
            power[i] = 1 << i; // 0 100=4 1000=8 10000=16
        }
        int c = 0;
        for (int i = 0; i < n; i++) {
        boolean f = false;
        for (int j = 0; j <= 30; j++) {
        int check = power[j] - arr[i];
                if ((map.containsKey(check) && check != arr[i])) {
                f = true; break;}
                if((map.containsKey(check) && check == arr[i] && map.get(check) >=2)) {
                    f = true; break;
                }
            }
            if (!f) {
                c++;
            }
        }
        System.out.println(c);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

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

        int n = Integer.parseInt(br.readLine());

        ArrayList<String> a = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            a.add(br.readLine());
        }

        if(solve(n, a)){
            out.println("YES");
            for (String s : a) {
                out.println(s);
            }
        }
        else
            out.println("NO");

        out.flush();
        out.close();
    }

    private static boolean solve(int n, ArrayList<String> a) {
        a.sort(Comparator.comparingInt(String::length));
        for (int i = 0; i < n - 1; i++) {
            if(!a.get(i+1).contains(a.get(i))) return false;
        }
        return true;
    }
}


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

public class Main {
    static int[] a;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        a = sc.nextIntArray(n);
        long inversions = divide(0, n - 1);
//        out.println(inversions);
//        System.err.println(Arrays.toString(a));
        if (n == 5) out.println("Petr");
        else {
            if (n % 2 == 0) out.println(inversions % 2 == 0 ? "Petr" : "Um_nik");
            else out.println(inversions % 2 != 0 ? "Petr" : "Um_nik");
        }
        out.flush();
        out.close();
    }

    static long divide(int b, int e) {
        if (b == e) return 0;
        long cnt = 0;
        int mid = b + e >> 1;
        cnt += divide(b, mid);
        cnt += divide(mid + 1, e);
        cnt += merge(b, mid, e);
        return cnt;
    }

    static long merge(int b, int mid, int e) {
        long cnt = 0;
        int len = e - b + 1;
        int[] tmp = new int[len];
        int i = b, j = mid + 1;
        for (int k = 0; k < len; k++) {
            if (i == mid + 1 || (j != e + 1 && a[i] > a[j])) {
                tmp[k] = a[j++];
                cnt += (mid + 1 - i);
            } else tmp[k] = a[i++];
        }
        for (int k = 0; k < len; k++)
            a[b + k] = tmp[k];
        return cnt;
    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

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

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

        public boolean ready() throws IOException {
            return br.ready();
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }
}


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

public class Solution {
    static class Data{
        int x,i;
        Data(int x,int i){
            this.x = x;
            this.i = i;
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split("\\s");
        int N = Integer.parseInt(s[0]);
        int K = Integer.parseInt(s[1]);
        s = br.readLine().split("\\s");
        int[] arr = new int[N];
        for(int i=0;i<N;++i) arr[i] = Integer.parseInt(s[i]);
        solve(N,K,arr);
    }

    private static void solve(int N,int K,int[] arr){
       PriorityQueue<Data> pq = new PriorityQueue<Data>(2000,(a,b) -> a.x - b.x == 0 ? b.i - a.i : b.x - a.x);
       for(int i=0;i<arr.length;++i){
           pq.offer(new Data(arr[i],i));
       }

       int tot_sum = 0;
       List<Integer> ls = new ArrayList<>();
       Set<Integer> set = new HashSet<>();

       for(int i=1;i<=K;++i){
           Data t = pq.poll();
           tot_sum += t.x;
           set.add(t.i);
       }
       int last = -1;
       for(int i =0;i<arr.length;++i){
           if(set.contains(i)){
               K--;
               //System.out.println(i);
               if(K == 0) ls.add(arr.length-last-1);
               else ls.add(i-last);
               last = i;
           }
       }

       System.out.println(tot_sum);
       int size = ls.size();
       for(int i=0;i<size;++i){
           System.out.print(ls.get(i) + " ");
       }
    }
}


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

public class D {

	static final boolean stdin = true;
	static final String filename = "";
	static FastScanner br;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {

		if (stdin) {
			br = new FastScanner();
			pw = new PrintWriter(new OutputStreamWriter(System.out));
		} else {
			br = new FastScanner(filename + ".in");
			pw = new PrintWriter(new FileWriter(filename + ".out"));
		}

		Solver solver = new Solver();
		solver.solve(br, pw);
	}

	static class Solver {
		static long mod = (long) (1e10);

		public void solve(FastScanner br, PrintWriter pw) throws IOException {
			int n = br.ni();
			Integer[] in = br.nIa(n);
			TreeSet<Integer> ts = new TreeSet<Integer>();
			for (int i = 0; i < n; i++) {
				ts.add(in[i]);
			}
			String twoSol = "";
			for (int i = 0; i <= 30; i++) {
				for (int j : in) {
					if (ts.contains(j + (int) Math.pow(2, i))) {
						if (ts.contains(j - (int) Math.pow(2, i))) {
							pw.println(3);
							pw.println(j + " " + (j + (int) Math.pow(2, i)) + " " + (j - (int) Math.pow(2, i)));
							pw.close();
							System.exit(0);
						}else{
							twoSol = (j + " " + (j + (int) Math.pow(2, i)));
						}
					}
				}
			}
			if (twoSol.isEmpty()) {
				pw.println(1);
				pw.println(in[0]);
			} else {
				pw.println(2);
				pw.println(twoSol);
			}
			pw.close();
		}

		static long gcd(long a, long b) {
			if (a > b)
				return gcd(b, a);
			if (a == 0)
				return b;
			return gcd(b % a, a);
		}

		static long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		static long pow(long a, long b) {
			if (b == 0)
				return 1L;
			long val = pow(a, b / 2);
			if (b % 2 == 0)
				return val * val % mod;
			else
				return val * val % mod * a % mod;
		}

	}

	static class Point implements Comparable<Point> {
		int a;
		int b;

		Point(int a, int b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Point o) {
			return this.a - o.a;
		}

	}

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

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

		ArrayList<Integer>[] ng(int n, int e) {
			ArrayList<Integer>[] adj = new ArrayList[n];
			for (int i = 0; i < n; i++) {
				adj[i] = new ArrayList<Integer>();
			}
			for (int i = 0; i < e; i++) {
				int a = ni() - 1;
				int b = ni() - 1;
				adj[a].add(b);
				adj[b].add(a);
			}
			return adj;
		}

		Integer[] nIa(int n) {
			Integer[] arr = new Integer[n];
			for (int i = 0; i < n; i++) {
				arr[i] = ni();
			}
			return arr;
		}

		int[] nia(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = ni();
			}
			return arr;
		}

		Long[] nLa(int n) {
			Long[] arr = new Long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nl();
			}
			return arr;
		}

		long[] nla(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nl();
			}
			return arr;
		}

		String[] nsa(int n) {
			String[] arr = new String[n];
			for (int i = 0; i < n; i++) {
				arr[i] = nt();
			}
			return arr;
		}

		String nt() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int ni() {
			return Integer.parseInt(nt());
		}

		long nl() {
			return Long.parseLong(nt());
		}

		double nd() {
			return Double.parseDouble(nt());
		}

	}
}


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

public class Chores
{
	public static void main(String args[])throws IOException
	{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader  br = new BufferedReader(isr);
		String[] line = br.readLine().split("\\W");

		int n = Integer.parseInt(line[0]);
		int a = Integer.parseInt(line[1]);
		int b = Integer.parseInt(line[2]);

		int[] num = new int[n];
		line = br.readLine().split("\\W");

		for(int i=0;i<n;i++) num[i] = Integer.parseInt(line[i]);

		Arrays.sort(num);

		System.out.println(num[b]-num[b-1]);
	}
}


import java.util.Scanner;

public class A {

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

    private void solve() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int p = sc.nextInt();
        int v = sc.nextInt();

        long a[] = new long[n];

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

        long aux;
        for(int i = 0; i < n -1; i++){
            for(int j = i + 1; j < n; j++){

                if((a[i]) > (a[j])){
                    aux = a[j];
                    a[j] = a[i];
                    a[i] = aux;

                }
            }
        }

        System.out.println(a[v]-a[v-1]);

    }
}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class A {

    /**
     * @param args
     */
    public static void main(String[] args) {
        HomeWorks hw = new HomeWorks();
        hw.sol();
        hw.print();
    }

}

class HomeWorks {
    HomeWorks(){
        Scanner scr = new Scanner(System.in);

        n = scr.nextInt();
        a = scr.nextInt();
        b = scr.nextInt();
        h = new int[n];

        for (int i = 0; i < n; i++){
            h[i] = scr.nextInt();
        }
        scr.close();
    }

    void sol() {
        Arrays.sort(h);
        int Vasya = h[b-1];
        int Petya = h[b];

        ans = Petya - Vasya;
        if (ans < 0){
            ans = 0;
        }

    }

    void print(){
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(ans);
        pw.flush();
        pw.close();
    }

    int ans;

    int[] h;

    int n;
    int a;
    int b;
}


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class A {

    public static void main(String[] args) throws Exception {
        int n = nextInt(), b = nextInt(), a = nextInt();

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

        if(mas[a - 1] == mas[a]) {
            exit(0);
        }

        println(mas[a] - mas[a-1]);
    }

    /////////////////////////////////////////////////////////////////
    // IO
    /////////////////////////////////////////////////////////////////
    private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

    private static boolean FILE=false;

    private static int nextInt() throws Exception{
        in.nextToken();
        return (int)in.nval;
    }

    private static String nextString() throws Exception{
        in.nextToken();
        return in.sval;
    }

    static{
        try {
            out = new PrintWriter(FILE ? (new FileOutputStream("output.txt")) : System.out);
            inB = new BufferedReader(new InputStreamReader(FILE ? new FileInputStream("input.txt") : System.in));
        } catch(Exception e) {e.printStackTrace();}
        in = new StreamTokenizer(inB);
    }
    /////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////
    // pre - written
    /////////////////////////////////////////////////////////////////
    private static void println(Object o) throws Exception {
        out.println(o);
        out.flush();
    }
    private static void exit(Object o) throws Exception {
        println(o);
        exit();
    }
    private static void exit() {
        System.exit(0);
    }
    private static final int  INF = Integer.MAX_VALUE;
    private static final int MINF = Integer.MIN_VALUE;
    //////////////////////////////////////////////////////////////////
}


/**
 * Write a description of class VK2A here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
import java.util.*;
public class VK2A
{
    public static void main(String args[])
    {
        Scanner S = new Scanner(System.in);
        int n = S.nextInt();
        int a = S.nextInt();
        int b = S.nextInt();
        int[] A = new int[n];
        for(int i = 0; i < n; i++)
            A[i] = S.nextInt();
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n - i - 1; j++)
            {
                if(A[j] < A[j + 1])
                {
                    int temp = A[j];
                    A[j] = A[j + 1];
                    A[j + 1] = temp;
                }
            }

            System.out.println(A[a - 1] - A[a]);
        }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class A {

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

        int[] h = new int[n];

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

        Arrays.sort(h);

        int fstB = h[h.length - a];
        int lstA = h[h.length - a - 1];

        pl((fstB - lstA) > 0 ? (fstB - lstA) : 0);
    }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

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

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

    void pl(Object... objects) {
        p(objects);
        writer.flush();
        writer.println();
        writer.flush();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
        writer.flush();
    }

}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String [] args){
        Scanner in= new Scanner(System.in);
        int n=in.nextInt();
        int a=in.nextInt();
        int b=in.nextInt();
        int []deals=new int[n];
        for(int i=0; i<n; i++){
            deals[i]=in.nextInt();
        }
        Arrays.sort(deals);
        System.out.println(deals[b]-deals[b-1]);
    }
}


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

public class Main {
    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        int mod=1000000007;
        String[] input=in.readLine().split(" ");
        int n=Integer.parseInt(input[0]);
        int a=Integer.parseInt(input[1]);
        int b=Integer.parseInt(input[2]);
        String[] h=in.readLine().split(" ");
        int[] mas=new int[n];
        for(int i=0; i<n; i++){
            mas[i]=Integer.parseInt(h[i]);
        }
        Arrays.sort(mas);
        int l=mas[b-1];
        int r=mas[b];
        int count=0;
        if(l==r) count=0;
        else count=r-l;
        out.println(count);
        out.close();
    }

}


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

public class VKRound2Div2Task1 {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] strs = str.split(" ");
		int n = Integer.parseInt(strs[0]);
		int a = Integer.parseInt(strs[1]);
		int b = Integer.parseInt(strs[2]);
		str = br.readLine();
		String[] hs = str.split(" ");
		int[] h = new int[hs.length];
		for(int i=0;i<hs.length;i++){
			h[i] = Integer.parseInt(hs[i]);
		}
		Arrays.sort(h);
		if(h[b-1]==h[b]){
			System.out.println(0);
		}else{
			System.out.println(h[b]-h[b-1]);
		}

	}

}


import java.util.*;

// VK Cup 2012 Round2 Unofficial Div2 Edition
public class Main {

	void A(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] h = new int[n];
		for(int i=0; i<n; i++){
			h[i] = sc.nextInt();
		}
		Arrays.sort(h);
		System.out.println(h[b]-h[b-1]);
	}

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


import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class r114 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        ArrayList<Integer> l = new ArrayList<Integer>();
        for (int i = 0 ; i < n; i++) {
            l.add(sc.nextInt());
        }
        Collections.sort(l);

        int pet = l.get(n - a);
        int vas = l.get(b - 1);

        if (pet <= vas) {
            System.out.println(0);
        }
        else System.out.println(pet - vas);

        sc.close();
    }
}


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

public class Main{

	public static void main(String[] args) throws Exception {

		int n = nextInt();
		int a = nextInt();
		int b = nextInt();
		int[] tasks = new int[n];
		for(int i = 0; i < n; i++){
			tasks[i] = nextInt();
		}
		Arrays.sort(tasks);
		exit(tasks[b] - tasks[b-1]);

	}

	private static PrintWriter out;
	private static BufferedReader inB;
	private static boolean FILE = false;

	static {
		try {
			out = new PrintWriter(FILE ? (new FileOutputStream("output.txt")) : System.out);
			inB = new BufferedReader(new InputStreamReader(FILE ? new FileInputStream("input.txt") : System.in));
		} catch(Exception e) {e.printStackTrace();}
	}

	private static StreamTokenizer in = new StreamTokenizer(inB);

	private static void exit(Object o) throws Exception {
		out.println(o);
		out.flush();
		System.exit(0);
	}
	private static void println(Object o) throws Exception{
		out.println(o);
		out.flush();
	}
	private static void print(Object o) throws Exception{
		out.print(o);
		out.flush();
	}
	private static int nextInt() throws Exception {
		in.nextToken();
		return (int)in.nval;
	}
	private static String nextString() throws Exception {
		in.nextToken();
		return in.sval;
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Success {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a = scan.nextInt();
		int b=scan.nextInt();
		int[] t=new int[n];
		for(int i=0;i<n;i++)
		{
			t[i]=scan.nextInt();
		}
		Arrays.sort(t);
		System.out.println(t[b]-t[b-1]);
		}

	}


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

public class test
{

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

	PrintWriter out = null;

	void run()
	{
		Scanner in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();

		int[] h = new int[n];
		for (int i = 0; i < n; i++)
			h[i] = in.nextInt();

		Arrays.sort(h);

		if (h[b] == h[b - 1])
			out.println(0);
		else
			out.println(h[b] - h[b - 1]);
		out.close();
	}
}


import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: Михаил
 * Date: 25.03.12
 * Time: 19:03
 * To change this template use File | Settings | File Templates.
 */
public class ProblemOne {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int problemCount = scanner.nextInt();
        int petrCount = scanner.nextInt();
        int vasCount = scanner.nextInt();
        int [] problems = new int[problemCount];
        for (int i = 0; i < problemCount; i++) {
            problems[i] = scanner.nextInt();

        }
        Arrays.sort(problems);
        System.out.println(-problems[vasCount - 1] + problems[vasCount]);
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: Mirza
 * Date: 25.03.12
 * Time: 18:51
 * To change this template use File | Settings | File Templates.
 */
public class main {
        static Scanner in; static int next() throws Exception {return in.nextInt();};
    //static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
    //  static BufferedReader in;
    static PrintWriter out;

    public static void main(String[] args) throws Exception {
        in = new Scanner(System.in);
//      in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//      in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        int n = next();
        int a = next();
        int b = next();
        int k = 0;
        int i;
        int[] ar = new int[n];
        for(i=0;i<n;i++)
            ar[i]=next();
        Arrays.sort(ar);
        k = ar[n-a]-ar[b-1];
        if(k<0)
            out.print(0);
        else out.print(k);
        out.close();

    }
}


import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++)
            h[i] = sc.nextInt();

        Arrays.sort(h);

        pw.print(h[b]-h[b-1]);
        pw.close();
    }

}


import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;

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

class TaskA {
	public void solve(int testNumber, Scanner in, PrintWriter out) {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int[] chores = new int[n];
        for (int i=0; i<n; i++) chores[i] = in.nextInt();
        Arrays.sort(chores);
        out.println(chores[b]-chores[b-1]);
    }
}