codeparrot/codecomplex huggingface dataset:
// Problem: 160_A. Twins
// Time complexity: nlogn
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class nA {

    Scanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int a[] = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            sum+=a[i];
        }
        Arrays.sort(a);
        int nowsum = 0;
        int kol = 0;
        for(int i = n - 1; i >= 0; i--){
            if(nowsum <= sum / 2){
                nowsum+=a[i];
                kol++;
            }else{
                break;
            }
        }
        out.println(kol);
    }

    void run() {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);
        try {
            solve();
        } finally {
            out.close();
        }
    }

    public static void main(String[] args) {
        new nA().run();
    }
}
// Problem: 160_A. Twins
// Time complexity: nlogn

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

/**
 * @author Andrew Porokhin, andrew.porokhin@gmail.com
 */
public class Problem111A implements Runnable {
    void solve() throws NumberFormatException, IOException {
        // TODO: Write your code here ...
        final int n = nextInt();
        final int[] a = new int[n];
        
        long sum = 0;
        for (int i = 0; i < n; i++) {
            final int nextInt = nextInt();
            sum += nextInt;
            a[i] = nextInt;
        }

        Arrays.sort(a);
        int currSum = 0;
        int maxCoins = 0;
        for (int j = a.length - 1; j >= 0; j--) {
            currSum += a[j];
            maxCoins++;
            if (sum - currSum < currSum) {
                break;
            }
        }
        System.out.println(maxCoins);
    }

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) {
        // Introduce thread in order to increase stack size
        new Problem111A().run();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
        } catch (Exception e) {
            System.exit(9000);
        } finally {
            out.flush();
            out.close();
        }
    }

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

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

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

    double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        team[] t = new team[n];
        for (int i = 0; i < n; i++)
            t[i] = new team(in.nextInt(), in.nextInt());
        Arrays.sort(t);
        int cnt = 0;
        team tm = t[t.length - k];
        for (int i = t.length - 1; i >= 0; i--)
            if (tm.equal(t[i]))
                cnt++;
        System.out.println(cnt);
    }

    static class team implements Comparable<team> {
        int p, t;

        public team(int pp, int tt) {
            p = pp;
            t = tt;
        }

        @Override
        public int compareTo(team o) {
            if (p == o.p)
                return o.t - t;
            return p - o.p;
        }

        public boolean equal(team a) {
            return a.p == p && a.t == t;
        }
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn

import java.awt.Point;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt() - 1;
        Point[] A = new Point[n];
        for (int i = 0; i < n; i++)
            A[i] = new Point(in.nextInt(), in.nextInt());
        Arrays.sort(A, new Comparator<Point>() {
            public int compare(Point o1, Point o2) {
                if (o1.x != o2.x)
                    return o2.x - o1.x;
                if (o1.y != o2.y)
                    return o1.y - o2.y;
                return 0;
            }
        });
        int i = k;
        int j = k;
        while (i >= 0 && A[i].x == A[k].x && A[i].y == A[k].y)
            i--;
        while (j < n && A[j].x == A[k].x && A[j].y == A[k].y)
            j++;
        System.out.println(j - i - 1);
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.Scanner;


public class R113A {

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = in.nextInt();
        int[] ind = new int[n];
        int[] p = new int[n];
        int[] t = new int[n];
        for (int i = 0; i < n; i++){
            ind[i] = i;
            p[i] = in.nextInt();
            t[i] = in.nextInt();
        }
        //System.out.println("erwer");
        for (int i = 0; i < n - 1; i++)
         for (int j = i + 1; j < n; j++){
             if (p[i] < p[j] || (p[i] == p[j] && t[i] > t[j])){
                 int tmp = p[i];
                 p[i] = p[j];
                 p[j] = tmp;
                 tmp = t[i];
                 t[i] = t[j];
                 t[j] = tmp;
             }
         }
        
        int i = k - 1;
//      System.out.println(i+" "+p[i]);
        while (i > 0 && p[i] == p[i - 1] && t[i] == t[i - 1]) i--;
    //  System.out.println(i);
        int j = 0;
        while (i < n - 1 && p[i] == p[i + 1] && t[i] == t[i + 1]) {
            i++;
            j++;
        }
//      System.out.println(i);
        System.out.println(j + 1);
        
        
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.*;
import java.util.*;
import java.math.*;


public class Solution
{
    public static void main(String[] args) throws IOException
    {
        new Solution().run();
    }
    StreamTokenizer in; 
    Scanner ins;
    PrintWriter out;
    
    int nextInt() throws IOException
    {
        in.nextToken();      
        return (int)in.nval;
    }

    
    void run() throws IOException
    {

        if(System.getProperty("ONLINE_JUDGE")!=null)
        {
            in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
            ins = new Scanner(System.in);
            out = new PrintWriter(System.out);
        }
        else
        {           
            in = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));             
            ins = new Scanner(new FileReader("input.txt"));
            out = new PrintWriter(new FileWriter("output.txt"));
        }
        int n = nextInt(),k = nextInt();
        Team[] A = new Team[n];
        for(int i = 0; i < n; i++)
        {
            A[i] = new Team();
            A[i].p = nextInt(); A[i].t = nextInt();
        }
        Arrays.sort(A);
        
        
        k--;
        int sum = 0;
        for(int i = 0; i < n; i++)
            if(A[k].compareTo(A[i])==0)
                sum++;
        
        out.print(sum);
        out.close();
    }
    
    
    class Team implements Comparable
    {
        public int p,t;
        public int compareTo(Object obj)
        {
            Team a = (Team) obj;
            if(p>a.p || p==a.p && t<a.t)                          
                return -1;
            else                
                if(p==a.p && t==a.t)
                    return 0;
                else
                    return 1;
        }
        
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ProblemA {

    private final BufferedReader in;
    private final PrintStream out;
    private StringTokenizer tok = new StringTokenizer("");
    private String nextLine = null;

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

    private ProblemA() throws Exception {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = System.out;
        start();
        end();
    }

    private int nextInt() {
        return Integer.parseInt(nextWord());
    }

    private String nextWord() {
        if (tok.hasMoreTokens()) {
            return tok.nextToken();
        } else {
            while (!tok.hasMoreTokens()) {
                try {
                    nextLine = in.readLine();
                    if (nextLine == null) {
                        return null;
                    } else {
                        tok = new StringTokenizer(nextLine);
                    }
                } catch (IOException ex) {
                    Logger.getLogger(ProblemA.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            return tok.nextToken();
        }
    }

    private void start() {
        int n = nextInt();
        int k = nextInt();
        T[] ts = new T[n];
        for (int i = 0; i < n; i++) {
            ts[i] = new T(nextInt(), nextInt());
        }
        Arrays.sort(ts, new Comparator<T>() {

            @Override
            public int compare(T o1, T o2) {
                if (o1.p > o2.p) {
                    return -1;
                }
                if (o1.p < o2.p) {
                    return 1;
                }
                if (o1.t < o2.t) {
                    return -1;
                }
                if (o1.t > o2.t) {
                    return 1;
                }
                return 0;
            }
        });
        int t = ts[k - 1].t;
        int p = ts[k - 1].p;
        int res = 0;
        for (int i = 0; i < n; i++) {
            if (ts[i].p == p && ts[i].t == t) {
                res++;
            }
        }
        out.println(res);
    }

    class T {

        int p;
        int t;

        public T(int p, int t) {
            this.p = p;
            this.t = t;
        }
    }

    private void end() {
        out.close();
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;
	
	public static void main(String[] args) throws IOException
	{
		new Main().execute();
	}
	
	void debug(Object...os)
	{
		System.out.println(Arrays.deepToString(os));
	}
	
	int ni() throws IOException
	{
		return Integer.parseInt(ns());
	}
	
	long nl() throws IOException 
	{
		return Long.parseLong(ns());
	}
	
	double nd() throws IOException 
	{
		return Double.parseDouble(ns());
	}
		
	String ns() throws IOException 
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens()) 
			tokenizer = new StringTokenizer(br.readLine());
		return tokenizer.nextToken();
	}
	
	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}
		
	
	//Main Code starts Here
	int totalCases, testNum;	
	int k,n;
	
	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			input();
			solve();
		}
	}

	void solve()
	{
		int a = arr[k-1].a;
		int b = arr[k-1].b;
		//debug(a,b);
		int count = 0;
		for(int i = 0;i<n;i++)
		{
			if(arr[i].a == a && arr[i].b == b)
				count++;
		}
		System.out.println(count);
	}
	
	void printarr(int [] a,int b)
	{
		for(int i = 0;i<=b;i++)
		{
			if(i==0)
				System.out.print(a[i]);
			else
				System.out.print(" "+a[i]);
		}
		System.out.println();
	}
	
	class Pair implements Comparable<Pair>
{	
	int a,b;
	Pair(int _a,int _b)
	{
		a=_a;
		b=_b;
	}
	
	public int compareTo(Pair x)
	{
		if(a == x.a) return b-x.b;
		return -(a-x.a);
	}
		
	public boolean equals(Pair x)
	{
		return a==x.a && b==x.b;
	}
}

	Pair[] arr;
	boolean input() throws IOException
	{
		n = ni();
		k = ni();
		arr = new Pair[n];
		for(int i = 0 ;i<n;i++)
		{
			Pair p =new Pair(ni(),ni());
			arr[i]  = p;
		}
		Arrays.sort(arr);
		//debug(arr);
		return true;
	}
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.*;

import java.io.*;
public class C{
		public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt(),key=in.nextInt(),ans=0;
		int[] a = new int[101], b = new int[101];
		for (int i=1;i<=n;i++) {a[i]=in.nextInt();b[i]=in.nextInt();}
		for (int i=1;i<n;i++)
			for (int j=i+1;j<=n;j++)
				if (a[i]<a[j] || (a[i]==a[j] && b[i]>b[j])) {
		int yed = a[i];a[i]=a[j];			a[j]=yed;
		yed = b[i];b[i]=b[j];b[j]=yed;
				}
		int k=0;
		
		
		for (int i=1;i<=n;i++) {
			if (a[i]==a[i-1] && b[i]==b[i-1]) k++; else 
				{if (i>key && ans==0) ans = k;k=1;}
			
		}
		if (ans == 0) ans = k;
		System.out.println(ans);
		
		}
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);
        int N = r.nextInt();
        int K = r.nextInt() - 1;
        
        T[] a = new T[N];
        for(int i = 0; i < N; i++)
            a[i] = new T(r.nextInt(), r.nextInt());
        
        Arrays.sort(a, new Comparator<T>() {

            @Override
            public int compare(T x, T y) {
                if(x.p > y.p)return -1;
                else if(x.p == y.p){
                    if(x.t < y.t)return -1;
                    else if(x.t == y.t)return 0;
                    else return 1;
                }else return 1;
            }
        });
        
        int ret = 0;
        for(int i = 0; i < N; i++)
            if(a[i].p == a[K].p && a[i].t == a[K].t)ret++;
        
        System.out.println(ret);
    }
}

class T{
    int p, t;
    public T(int pi, int ti){
        p = pi;
        t = ti;
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class ProblemA {
    public static class Team {
        int solved;
        int penalty;
        Team(int s, int p) {
            solved = s;
            penalty = p;
        }
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        String[] data = s.readLine().split(" ");
        int n =  Integer.valueOf(data[0]);
        int k =  Integer.valueOf(data[1]);

        
        Team[] t = new Team[n];
        for (int i = 0 ; i < n ; i++) {
            String[] line = s.readLine().split(" ");
            t[i] = new Team(Integer.valueOf(line[0]), Integer.valueOf(line[1]));
        }
        Arrays.sort(t, new Comparator<Team>(){
            public int compare(Team arg0, Team arg1) {
                if (arg0.solved != arg1.solved) {
                    return arg1.solved - arg0.solved;
                }
                return arg0.penalty - arg1.penalty;
            }
        });
        
        
        int idx = k - 1;
        int ksol = t[idx].solved;
        int kpen = t[idx].penalty;
        int count = 0;
        for (int i = 0 ; i < n ; i++) {
            if (t[i].solved == ksol && t[i].penalty == kpen) {
                count++;
            }
        }
        System.out.println(count);
    }
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class AA {
	static class O implements Comparable<O> {
		int problems;
		int penalty;

		public O(int p, int pp) {
			problems = p;
			penalty = pp;
		}

		public int compareTo(O arg0) {
			if (problems == arg0.problems) {
				return penalty - arg0.penalty;
			}
			return -(problems - arg0.problems);
		}

	}

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		String[] sp = s.split("[ ]+");
		int n = new Integer(sp[0]), k = new Integer(sp[1]) - 1;
		O[] arr = new O[n];
		for (int i = 0; i < arr.length; i++) {
			s = r.readLine();
			sp = s.split("[ ]+");
			arr[i] = new O(new Integer(sp[0]), new Integer(sp[1]));
		}
		Arrays.sort(arr);

		int res = 1;

		int i = k + 1;
		while (i < arr.length && arr[i].problems == arr[k].problems
				&& arr[i].penalty == arr[k].penalty) {
			i++;
			res++;
		}

		i = k - 1;
		while (i >= 0 && arr[i].problems == arr[k].problems
				&& arr[i].penalty == arr[k].penalty) {
			i--;
			res++;
		}
		System.out.println(res);

	}
}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class A
{
	String line;
	StringTokenizer inputParser;
	BufferedReader is;
	FileInputStream fstream;
	DataInputStream in;
	String FInput="";
	
	void openInput(String file)
	{

		if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
		else
		{
			try{
		
				
			fstream = new FileInputStream(file);
			in = new DataInputStream(fstream);
			is = new BufferedReader(new InputStreamReader(in));
			}catch(Exception e)
			{
				System.err.println(e);
			}
		}

	}
	
	void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}	
		catch (NullPointerException e)
		{
			line=null;
			
		}
		
	}
	
	int NextInt()
	{
		String n = inputParser.nextToken();
		int val = Integer.parseInt(n);
		
		//System.out.println("I read this number: " + val);
		return val;
	}
	
	long NextLong()
	{
		String n = inputParser.nextToken();
		long val = Long.parseLong(n);
		
		//System.out.println("I read this number: " + val);
		return val;
	}
	
	String NextString()
	{
		String n = inputParser.nextToken();
		return n;
	}
	
	void closeInput()
	{
		try {
			is.close();
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
			
	}
	
	
	public static void main(String [] argv)
	{
		String filePath=null;
		if(argv.length>0)filePath=argv[0];
		new A(filePath);
	}
	
	public void readFInput()
	{
		for(;;)
		{
			try
			{
				readNextLine();
				FInput+=line+" ";
			}
			catch(Exception e)
			{
				break;
			}
		}
		inputParser = new StringTokenizer(FInput, " ");
	}
	 
	public A(String inputFile)
	{
		openInput(inputFile);
		
		readNextLine();
		int n=NextInt();
    	int k=NextInt()-1;
		int ret=0;
		Team [] t = new Team[n];
		for(int i=0; i<n; i++)
		{
			readNextLine();
			t[i]=new Team(NextInt(), NextInt());
		}
		Arrays.sort(t);
		int ti=t[k].t, p=t[k].p;
		
		for(int i=0; i<n; i++)
			if(t[i].t==ti&&t[i].p==p)ret++;
		
		
		
		
		System.out.print(ret);
        closeInput();		
	}
	
	private class Team implements Comparable<Team>
	{
		int p,t;
		Team(int p, int t)
		{
			this.p=p;
			this.t=t;
		}
		
		public int compareTo(Team d)
		{
			return 10000*(d.p-p)+t-d.t;
		}
	}

}
// Problem: 166_A. Rank List
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class C113A{
    static BufferedReader br;
    public static void main(String args[])throws Exception{
        br=new BufferedReader(new InputStreamReader(System.in));
        int nm[]=toIntArray();
        int n=nm[0];
        int k=nm[1];
        Pai p[]=new Pai[n];
        for(int i=0;i<n;i++){
            nm=toIntArray();
            p[i]=new Pai(nm[0],nm[1]);
        }
        Arrays.sort(p);
        int count=0;
        for(int i=0;i<n;i++){
            if(p[k-1].first==p[i].first && p[k-1].second==p[i].second){
                count++;
            }
        }
        System.out.println(count);

    }


    /****************************************************************/
    public static int[] toIntArray()throws Exception{
       String str[]=br.readLine().split(" ");
       int k[]=new int[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Integer.parseInt(str[i]);
       }
       return k;
    }
    public static int toInt()throws Exception{
       return Integer.parseInt(br.readLine());
    }
    public static long[] toLongArray()throws Exception{
       String str[]=br.readLine().split(" ");
       long k[]=new long[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Long.parseLong(str[i]);
       }
       return k;
    }
    public static long toLong()throws Exception{
       return Long.parseLong(br.readLine());
    }
    public static double[] toDoubleArray()throws Exception{
       String str[]=br.readLine().split(" ");
       double k[]=new double[str.length];
       for(int i=0;i<str.length;i++){
            k[i]=Double.parseDouble(str[i]);
       }
       return k;
    }
    public static double toDouble()throws Exception{
       return Double.parseDouble(br.readLine());
    }
    public static String toStr()throws Exception{
       return br.readLine();
    }
    public static String[] toStrArray()throws Exception{
       String str[]=br.readLine().split(" ");
       return str;
    }
    /****************************************************************/

}
class Pai implements Comparable<Pai> {

    int first;
    int second;

    public Pai(int f, int s) {
        first = f;
        second = s;
    }

    public int compareTo(Pai p) {
        int ret = 0;
        if (first < p.first) {
            ret = 1;

        } else if (first > p.first) {
            ret = -1;

        } else {
            if(second<p.second){
                ret=-1;
            }
            else if(second>p.second){
                ret=1;
            }
            else ret=0;
        }
        return ret;
    }
}