codeparrot/codecomplex huggingface dataset:
// Problem: 903_D. Almost Difference
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class D {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	
	
	public void solve() {
		int n = in.nextInt();
		HashMap<Long, Integer> map = new HashMap();
		BigInteger sum = BigInteger.ZERO;
		BigInteger ans = BigInteger.valueOf(0);
		for (int i = 0; i < n; i++) {
			long x = in.nextLong();
			ans = ans.add(BigInteger.valueOf(i * x));
			if (map.containsKey(x + 1)) {
				ans = ans.add(BigInteger.valueOf(map.get(x + 1)));
			}
			if (map.containsKey(x - 1)) {
				ans = ans.subtract(BigInteger.valueOf(map.get(x - 1)));
			}
			if (map.containsKey(x)) {
				map.put(x, map.get(x) + 1);
			} else {
				map.put(x, 1);
			}
			ans = ans.subtract(sum);
			sum = sum.add(BigInteger.valueOf(x));
		}
		out.print(ans.toString());
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("segments.in"));
				out = new PrintWriter(new File("segments.out"));
			}
			solve();

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

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				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());
		}

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	public static void main(String[] arg) {
		new D().run();
	}
}
// Problem: 903_D. Almost Difference
// Time complexity: nlogn
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

    static Map<BigInteger, BigInteger> mp = new HashMap<BigInteger, BigInteger>();

    public static void main(String[] args) {
        mp.clear();
        Scanner cin = new Scanner(new BufferedInputStream(System.in));
        BigInteger n = cin.nextBigInteger();
        BigInteger x = cin.nextBigInteger();
        mp.put(x, BigInteger.ONE);
        BigInteger sum = x;
        BigInteger ans = BigInteger.ZERO;
        for (int i = 2;i <= n.intValue(); i++) {
            x=cin.nextBigInteger();
            BigInteger tmp = x.multiply(BigInteger.valueOf(i-1)).subtract(sum);
            if (mp.containsKey(x.subtract(BigInteger.ONE))) tmp = tmp.subtract(mp.get(x.subtract(BigInteger.ONE)));
            if (mp.containsKey(x.add(BigInteger.ONE))) tmp = tmp.add(mp.get(x.add(BigInteger.ONE)));
            ans = ans.add(tmp);
            sum = sum.add(x);
            BigInteger xx;
            if (mp.containsKey(x)) xx = mp.get(x);
            else xx = BigInteger.ZERO;
            mp.put(x, xx.add(BigInteger.ONE));
        }
        System.out.println(ans);
    }
}
// Problem: 903_D. Almost Difference
// Time complexity: nlogn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.math.BigInteger;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];

            BigInteger sum = new BigInteger("0");
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                long tmp = ((long) (2 * i + 1 - n)) * a[i];
                sum = sum.add(BigInteger.valueOf(tmp));
            }

            Map<Integer, Integer> cnt = new HashMap<>();

            for (int i = n - 1; i >= 0; --i) {
                if (cnt.containsKey(a[i] + 1)) {
                    sum = sum.subtract(BigInteger.valueOf(cnt.get(a[i] + 1)));
                }
                if (cnt.containsKey(a[i] - 1)) {
                    sum = sum.add(BigInteger.valueOf(cnt.get(a[i] - 1)));
                }
                if (cnt.containsKey(a[i])) {
                    cnt.put(a[i], cnt.get(a[i]) + 1);
                } else {
                    cnt.put(a[i], 1);
                }
            }

            out.println(sum);
        }

    }
}
// Problem: 903_D. Almost Difference
// Time complexity: nlogn
import java.math.BigInteger;
import java.util.*;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class D {
  public static void main(String[] args) {
    init();

    int n = in.nextInt();

    long total = 0L;



    int arr[] = new int[n+5];

    Map<Integer, Integer> freq = new HashMap<>();
    Map<Integer, Integer> kiri = new HashMap<>();

    for (int i = 1; i <= n; ++i){
     arr[i] = in.nextInt();
      if (freq.containsKey(arr[i])) {
        freq.put(arr[i], freq.get(arr[i])+1);
      } else {
        freq.put(arr[i], 1);
        kiri.put(arr[i], 0);
      }
      total += (long)arr[i];
    }

    BigInteger ans = BigInteger.valueOf(0L);

    for (int i = 1; i <= n - 1; ++i) {
      kiri.put(arr[i], kiri.get(arr[i])+1);
      total -= arr[i];

      int cnt_kanan = n - i;
      long temp = total;
      int cnt_sama = freq.get(arr[i]) - kiri.get(arr[i]);
      temp -= (cnt_sama)*(long)arr[i];
      cnt_kanan -= (cnt_sama);
      if (freq.containsKey(arr[i]-1)) {
        int cnt_kurang = freq.get(arr[i]-1) - kiri.get(arr[i]-1);
        cnt_kanan -= cnt_kurang;
        temp -= (long) cnt_kurang * (long)(arr[i]-1);
      }
      if (freq.containsKey(arr[i]+1)) {
        int cnt_lebih = freq.get(arr[i]+1) - kiri.get(arr[i]+1);
        cnt_kanan -= cnt_lebih;
        temp -= (long)(cnt_lebih) * (long)(arr[i]+1);
      }
      temp -= (long)cnt_kanan * (long)arr[i];
      ans = ans.add(BigInteger.valueOf(temp));
    }

    out.println(ans.toString());
    out.close();
  }

  /* PrintWriter and BufferedReader Template from Codeforces */
  public static MyScanner in;
  public static PrintWriter out;

  public static void init() {
    in = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));
  }

  public static class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(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 nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }

}
// Problem: 903_D. Almost Difference
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.StringTokenizer;

public class D
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		BigInteger ans = BigInteger.ZERO;
		int n = sc.nextInt();
		int arr[] = new int[n];
		long cum[] = new long[n];
		
		for (int i = 0; i < n; i++)
			arr[i] = sc.nextInt();
		
//		int n=(int)2e5;
//		for(int i=0;i<n;i++){
//			arr[i]=1;
//			if(i>n/2)
//				arr[i]=(int)1e9;
//		}
		
		for (int i = 0; i < cum.length; i++)
		{
			cum[i] = arr[i];
			if(i > 0)
				cum[i] += cum[i-1];
		}
		
		for (int i = 0; i < n; i++)
			ans = ans.add(BigInteger.valueOf((1l*(i+1)*arr[i] - cum[i])));
		
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 0; i < n; i++)
		{
			ans =  ans.subtract(BigInteger.valueOf(map.getOrDefault(arr[i]-1, 0)));
			ans = ans.add(BigInteger.valueOf(map.getOrDefault(arr[i]+1, 0)));
			map.put(arr[i], map.getOrDefault(arr[i], 0)+1);
		}
		
		pw.println(ans);
		pw.flush();
		pw.close();
	}
	
		
	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(String s) throws FileNotFoundException
		{
			br = new BufferedReader(new FileReader(new File((s))));
		}

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

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

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

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

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else
				{
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException
		{
			return br.ready();
		}
	}
}
// Problem: 903_D. Almost Difference
// Time complexity: nlogn
import java.math.BigDecimal;
import java.util.*;
import java.math.BigInteger;
public class Main {
    static Long[] a = new Long[205000];
    static Long[] postfix=new Long[205000];
    static HashMap<Long,Long> check=new HashMap<Long,Long>();
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        long k, j, p,sum,equal,bigone,lessone,cnt;
        BigInteger ans;
        int i,n;
        while (cin.hasNext()) {
            n=cin.nextInt();
            check.clear();
            for(i=1;i<=n;i++)
            {
                a[i]=cin.nextLong();
            }
            postfix[n+1]=0L;
            for(i=n;i>=1;i--) {
                postfix[i] = postfix[i + 1] + a[i];
                if (check.containsKey(a[i]) == true) {
                    Long v = check.get(a[i]);
                    v += 1;
                    check.put(a[i], v);
                }
                else
                    check.put(a[i],1L);
            }
            ans=BigInteger.ZERO;
            for(i=1;i<n;i++){
                Long v=check.get(a[i]);
                v--;
                check.put(a[i],v);
                equal=check.get(a[i]);
                bigone=0L;
                lessone=0L;
                if(check.containsKey(a[i]+1L)==true)
                bigone=check.get(a[i]+1L);
                if(check.containsKey(a[i]-1L)==true)
                lessone=check.get(a[i]-1L);
                sum=postfix[i]-bigone*(a[i]+1L)-lessone*(a[i]-1L)-equal*a[i]-a[i];
                cnt=n-i-bigone-lessone-equal;
                ans=ans.add(BigInteger.valueOf(a[i]*cnt).subtract(BigInteger.valueOf(sum)));
            }
            System.out.println(ans.multiply(BigInteger.valueOf(-1)));
        }
    }
}
// Problem: 160_A. Twins
// Time complexity: nlogn
import java.io.PrintWriter;
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 = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }

        for (int i = 0; i < n; i++)
            a[i] *= -1;
        Arrays.sort(a);
        for (int i = 0; i < n; i++)
            a[i] *= -1;

        int ans = 0;
        int sum1 = 0;
        for (int i = 0; i < n; i++) {
            sum1 += a[i];
            sum -= a[i];
            ans++;
            if (sum1 > sum)
                break;
        }

        pw.print(ans);
        pw.close();
    }
}
// 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.math.BigInteger;
import java.util.*;

public class A {

    private void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        int sum = 0;
        for (int i = a.length - 1; i >= 0; i--) {
            sum += a[i];
            int k = 0;
            for (int j = 0; j < i; j++)
                k += a[j];
            if (sum > k) {
                pl(a.length - i);
                return;
            }
        }
    }

    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();
    }

}
// 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;

public class Test {
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

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

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

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

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

	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
		int n = nextInt();
		int[] mas = new int[n];
		int sum=0;
		for(int i=0;i<n;i++)
		{
			mas[i]=nextInt();
			sum+=mas[i];
		}
		Arrays.sort(mas);
		int cs=0;
		int res=0;
		for(int i=n-1;i>=0;i--)
		{
			cs+=mas[i];
			sum-=mas[i];
			res++;
			if(cs>sum)
				break;
		}
		writer.println(res);		
	}
}
// Problem: 160_A. Twins
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(), sum = 0;
		
		Integer[] A = new Integer[n];
		
		for (int i = 0 ; i < n ; i++) {
			A[i] = sc.nextInt();
			sum += A[i];
		}
		
		Arrays.sort(A, Collections.reverseOrder());
		
		int c = 0, ans = 0;
		
		while (ans <= sum) {
			ans += A[c];
			sum -= A[c];
			c++;
		}
		
		System.out.println(c);
	}
}
// Problem: 160_A. Twins
// Time complexity: nlogn
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;

public class a111 {
    public static void debug(Object... obs) {
        System.out.println(Arrays.deepToString(obs));
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n=sc.nextInt();
        int[]a=new int[n];
        
        int su=0;
        for(int i=0;i<n;i++)
        {
            a[i]=-sc.nextInt();
            su+=-1*a[i];
        }
        Arrays.sort(a);
        
        
        int ss=0;
        for(int i=0;i<n;i++)
        {
            ss+=-1*a[i];
            su-=-1*a[i];
            if(ss > su)
            {
                System.out.println(i+1);
                return;
            }
        }
        
    }
}
// Problem: 160_A. Twins
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

/**
 * Works good for CF
 * 
 * @author cykeltillsalu
 */
public class A111_div2 {

	// some local config
	static boolean test = false;
	static String testDataFile = "testdata.txt";
	static String feedFile = "feed.txt";
	CompetitionType type = CompetitionType.CF;
	private static String ENDL = "\n";

	// solution
	private void solve() throws Throwable {

		int n = iread();
		
		int[] vals = new int[n];
		double tot = 0;
		for (int i = 0; i < n; i++) {
			int value = iread();
			vals[i] = value;
			tot += value;
		}
		
		Arrays.sort(vals);
		int pick = 0;
		int worth = 0;
		for (int i = vals.length - 1; i >= 0; i--) {
			worth += vals[i];
			pick ++;
			if(worth > tot/2.0d){
				break;
			}
		}
		
		out.write(pick + ENDL);
		out.flush();
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

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

		if (test) { // run all cases from testfile:
			BufferedReader testdataReader = new BufferedReader(new FileReader(testDataFile));
			String readLine = testdataReader.readLine();
			int casenr = 0;
			out: while (true) {
				BufferedWriter w = new BufferedWriter(new FileWriter(feedFile));
				if (!readLine.equals("input")) {
					break;
				}
				while (true) {
					readLine = testdataReader.readLine();
					if (readLine.equals("output")) {
						break;
					}
					w.write(readLine + "\n");
				}
				w.close();
				System.out.println("Answer on case " + (++casenr) + ": ");

				new A111_div2().solve();
				System.out.println("Expected answer: ");

				while (true) {
					readLine = testdataReader.readLine();

					if (readLine == null) {
						break out;
					}
					if (readLine.equals("input")) {
						break;
					}
					System.out.println(readLine);
				}
				System.out.println("----------------");
			}
			testdataReader.close();
		} else { // run on server
			new A111_div2().solve();
		}
		out.close();
	}

	public A111_div2() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(feedFile)));
		}
	}

	InputStreamReader inp = new InputStreamReader(System.in);
	BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

	enum CompetitionType {
		CF, OTHER
	};
}
// Problem: 160_A. Twins
// Time complexity: nlogn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class AAA {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
			sum += array[i];
		}

		int counter = 0;
		Arrays.sort(array);
		int first = 0;
		for (int j = n - 1; j >= 0; j--) {
			first += array[j];
			sum -= array[j];
			counter++;
			if (first > sum) {
				break;
			}
		}
		System.out.println(counter);
	}
}