codeparrot/codecomplex huggingface dataset:
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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();
    }








}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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");
    }
    
 
}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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");
        }
    }
}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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");
		}
	}
}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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();
    }








}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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());
    }
}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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);
    }
}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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++;
            }
        }
    }
    
    }
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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());
	}
}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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();
    }








}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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();
	}

}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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");
    }
}
// Problem: 220_A. Little Elephant and Problem
// Time complexity: nlogn
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();
    }

}
// Problem: 169_A. Chores
// Time complexity: nlogn
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]);
	}	
}
// Problem: 169_A. Chores
// Time complexity: nlogn
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]);
        
        
    }
}