package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	var sum int
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	sort.Ints(a)
	var total int
	for i := n - 1; i >= 0; i-- {
		total += a[i]
		if total > sum/2 {
			fmt.Print(n - i)
			return
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	var N, res, sum, sum2 int
	fmt.Scanln(&N)
	a := make([]int, N)

	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &a[i])
		sum += a[i]
	}
	sort.Sort(sort.IntSlice(a))

	for i := N - 1; i >= 0; i-- {
		sum2 += a[i]
		if sum2 > (sum - sum2) {
			res = N - i
			break
		}
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var num int
	_, _ = fmt.Scan(&num)
	var oned = make([]int,num)
	sum := 0
	for i:=0; i<num; i++ {
		fmt.Scan(&oned[i])
		sum = sum + oned[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(oned)))
	temp :=0
	count := 0
	for i:=0; i<len(oned); i++ {
		if temp > sum {
			break
		}
		temp = temp+oned[i]
		count++
		sum = sum - oned[i]
	}
	fmt.Println(count)

}

package main

import "fmt"
import "sort"

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	sort.Ints(a)
	l, r := 0, sum
	nr := len(a)
	for _, v := range a {
		if l + v < r - v {
			l += v
			r -= v
			nr--
		}
	}
	fmt.Println(nr)
}

package main

import "fmt"
import "sort"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	curr := 0
	for i := 0; i < n; i++ {
		curr += a[i]
		if 2*curr > sum {
			fmt.Println(i + 1)
			return
		}
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"log"
	"strings"
	"fmt"
	"sort"
)

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	first := scanner.Text()

	scanner.Scan()
	second := scanner.Text()

	n, err := strconv.Atoi(first)
	if err != nil {
		log.Fatal(err)
	}

	tmpList := strings.Split(second, " ")
	total := 0
	mList := make([]int, n);
	for i, value := range tmpList {
		intVal, err := strconv.Atoi(value)
		if err != nil {
			log.Fatal(err)
		}

		total += intVal
		mList[i] = intVal
	}

	sort.Sort(sort.Reverse(sort.IntSlice(mList)))

	sum := 0;
	min := 0;
	for i, v := range mList {
		sum += v;

		if (sum > (total/2)) {
			min = i+1
			break;
		}

	}
	fmt.Println(min)
}

package main

import "fmt"

func main() {

    var n int
    fmt.Scan(&n)
    // var a []int
    a := make([]int,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    var sum int = 0
    var sum2 int = 0
    var count [101]int
    for i := 0; i < n; i++ {
        count[a[i]]++
        sum += a[i]
    }
    // fmt.Println("summa", sum)
    // var result []int
    b := 0
    for i := 100; i >= 0; i--{
        for j := 0; j < count[i]; j++{
            a[b] = i
            b++
        }
    }
    var counter int
    for i := 0; i < len(a); i++ {
        if sum2 > sum {
            counter = i
            break
        } else {
            sum2 += a[i]
            sum -= a[i]
        }
    }
    if counter == 0 {
        counter = len(a)
    }
    fmt.Println(counter)
}

package main
import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scanf("%d\n",&t)
	num := make([]int, t)
	sum,total,ans := 0,0,0
	for  i:=0;i<t;i++{
		fmt.Scan(&num[i])
		sum += num[i]
	}

	sum /=2
	j := (t-1)
	sort.Ints(num)
	for j=j;j>=0;j-- {
			if  total<=sum {
			total += num[j]
			ans++
			}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

func sum(coins []int) int {
	var sum int
	for _, coin := range coins {
		sum += coin
	}
	return sum
}
func main() {
	var n int
	var coin int

	fmt.Scan(&n)
	coins := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&coin)
		coins[i] = coin
	}
	sort.Ints(coins)
	for i := 1; i <= n; i++ {
		me := sum(coins[n-i : n])
		twin := sum(coins[0 : n-i])
		if me > twin {
			fmt.Println(i)
			break
		}
	}

}

package main

import (
	"fmt"
	"os"
	"sort"
)

//import "strings"

//import "math"
//import "strconv"
//import "sort"

func main() {

	var n int

	fmt.Scan(&n)

	var a []int

	sum := 0
	cur := 0
	res := 0

	for i := 0; i < n; i++ {
		x := 0
		fmt.Scan(&x)
		a = append(a, x)
		sum += x

	}

	sort.Ints(a)
	for i := n - 1; i >= 0; i-- {
		if cur <= sum-cur {
			cur += a[i]
			res++
		} else {
			fmt.Println(res)
			os.Exit(0)
		}

	}

	fmt.Println(res)

	os.Exit(0)

}

package main

import (
  "fmt"
  "sort"
)

func sumarr(x []int) int  {
  var sum int
  for _,val := range x {
    sum+=val
  }
  return sum
}

func main() {
  var n, a, b int
  fmt.Scan(&n)
  arr := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&arr[i])
  }
  sort.Ints(arr)
  if len(arr) == 1 {
    fmt.Print("1")
  } else {
    i := 1
    a = sumarr(arr[0:len(arr)-i])
    b = sumarr(arr[len(arr)-i:len(arr)])
    for a >= b && i <= len(arr){
      i++
      a = sumarr(arr[0:len(arr)-i])
      b = sumarr(arr[len(arr)-i:len(arr)])
    }

    fmt.Print(len(arr[len(arr)-i:len(arr)]))
  }
}

package main

import (
	"fmt"
)

func sort(a []int) {
	pivot := a[0]
	i := 0
	j := len(a) - 1

	for i <= j {
		if a[i] <= pivot {
			i++
		} else {
			a[i], a[j] = a[j], a[i]
			j--
		}
	}

	if j < i {
		i = j
	}
	a[0], a[i] = a[i], a[0]

	if i > 1 {
		sort(a[:i])
	}
	if len(a)-i > 2 {
		sort(a[i+1:])
	}
}

func main() {
	var n int
	fmt.Scan(&n)

	coins := make([]int, n)
	var sum int
	for i := 0; i < n; i++ {
		fmt.Scan(&coins[i])
		sum += coins[i]
	}

	sort(coins)
	var part int
	i := len(coins) - 1
	for ; part <= sum; i-- {
		part += coins[i]
		sum -= coins[i]
	}

	fmt.Print(len(coins) - i - 1)

}

package main

import (
	"fmt"
	"sort"
)

func sum(a []int) (sum int) {
	for _, v := range a {
		sum += v
	}
	return
}

func main() {
	var n int
	fmt.Scan(&n)
	var money = make([]int, n)
	for i := range money {
		fmt.Scan(&money[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(money)))
	var i = 1
	for badBroMoney := money[0]; badBroMoney <= sum(money[i:]); i++ {
		badBroMoney += money[i]
	}
	fmt.Println(i)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, sum, myCoins int
	var coins [100]int
	fmt.Scan(&n)
	for i := range coins[:n] {
		fmt.Scan(&coins[i])
		sum += coins[i]
	}
	sort.Ints(coins[:n])
	for i := n - 1; i >= 0; i-- {
		myCoins += coins[i]
		sum -= coins[i]
		if myCoins > sum {
			fmt.Print(n - i)
			break
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	a160()
}

func a160() {
	var n int
	fmt.Scan(&n)
	coins := make([]int, n)
	var sum int
	for i := 0; i < n; i++ {
		fmt.Scan(&coins[i])
		sum += coins[i]
	}

	sort.Slice(coins, func(i, j int) bool { return coins[j] < coins[i] })

	half := sum / 2
	cur := 0
	for i := 0; i < len(coins); i++ {
		cur += coins[i]
		if cur > half {
			fmt.Println(i + 1)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Compfun func(a, b int32) bool

func InvSort(x []int32, less Compfun) {
	var (
		i, j, nx int32
		xi       int32
	)
	nx = int32(len(x))
	for i = 1; i < nx; i++ {
		xi = x[i]
		for j = i; j > 0 && less(xi, x[j-1]); j-- {
			x[j] = x[j-1]
		}
		x[j] = xi
	}
}

func main() {

	var (
		i, xi, nx, sum int32
		x              []int32
	)

	fmt.Scan(&nx)
	x = make([]int32, nx, nx)
	for i = 0; i < nx; i++ {
		fmt.Scan(&xi)
		sum += xi
		x[i] = xi
	}

	//	fmt.Println(x, sum)
	InvSort(x, func(a, b int32) bool { return a > b })
	//	fmt.Println(x, sum)

	sum /= 2
	for i = 0; i < nx && sum >= 0; i++ {
		sum -= x[i]
	}

	fmt.Println(i)

}

package main

import "fmt"

func main() {
    var n int
    var a [105]int
    total := 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
        total += a[i]
    }
    for i := n-1; i > 0; i-- {
        k := i
        for j := 0; j < i; j++ {
            if a[j] < a[k] { k = j }
        }
        a[k], a[i] = a[i], a[k]
    }
    cnt := 0
    for i := 0; i < n; i++ {
        cnt += a[i]
        total -= a[i]
        if cnt > total {
            fmt.Println(i+1)
            break
        }
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	var scanner *bufio.Scanner
	var n, allSum, minimumCoins int
	var sum int
	var line []string
	var numbers []int

	minimumCoins, sum = 0, 0
	scanner = bufio.NewScanner(os.Stdin)
	fmt.Scanln(&n)

	if scanner.Scan() {
		line = strings.Fields(scanner.Text())
		for _, word := range line {
			number, _ := strconv.Atoi(word)
			numbers = append(numbers, number)
		}

		allSum = getSum(numbers)

		sort.Slice(numbers, func(i, j int) bool {
			return numbers[i] > numbers[j]
		})

		for sum <= (allSum - sum) {
			sum += numbers[minimumCoins]
			minimumCoins++
		}

		fmt.Println(minimumCoins)
	}
}

func getSum(numbers []int) int {
	var result int
	for _, number := range numbers {
		result += number
	}

	return result
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a []int
	sum := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		a = append(a, x)
		sum += x
	}
	tot := 0
	coins := 0
	sort.Ints(a)
	for i := n-1; i >= 0; i-- {
		tot += a[i]
		coins++
		if tot > sum - tot {
			break
		}
	}
	fmt.Println(coins)
}

package main

import "fmt"

func main(){
	var n int
	fmt.Scan(&n)
	a := make([]int,n)
	var i int
	var sum int
	for ;n>0;n--{
		fmt.Scan(&a[i])
		sum+=a[i]
		i++
	}
	heapsort(a)
	var out int
	var outsum int
	for i = 0;i<len(a);i++{
		if 2*outsum>sum{
			break
		} else {
			outsum+=a[i]
			out++
		}
	}
	fmt.Println(out)
}

func heapify(a []int,i int,hsize int){
	l := (i<<1)+1
	r := (i+1)<<1
	var smallest int
	if l < hsize && a[l]<a[i]{
		smallest=l
	}else{
		smallest=i
	}
	if r < hsize && a[r]<a[smallest]{
		smallest=r
	}
	if smallest!=i{
		a[i],a[smallest]=a[smallest],a[i]
		heapify(a,smallest,hsize)
	}
}

func heapsort(a []int){
	n:= len(a)
	for i:=n/2;i>=0;i--{
		heapify(a,i,n)
	}
	for i:=n-1;i>=0;i--{
		a[0],a[i]=a[i],a[0]
		heapify(a,0,i)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	a := make([]int, n)
	tot := 0
	for i := range a {
		a[i] = nextInt(sc)
		tot += a[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	var sum, mine int
	for i := 0; i < n; i++ {
		sum += a[i]
		mine++
		if sum > tot-sum {
			break
		}
	}
	fmt.Println(mine)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, sum int
	fmt.Scan(&n)
	var cs []int
	for i := 0; i < n; i++ {
		var c int
		fmt.Scan(&c)
		cs = append(cs, c)
		sum += c
	}
	sort.Sort(sort.Reverse(sort.IntSlice(cs)))
	var t int
	for i, v := range cs {
		t += v
		sum -= v
		if t > sum {
			fmt.Println(i + 1)
			return
		}
	}
	fmt.Println(n)
}

package main
import(
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	set(n)
}

func set(n int) {
	var  sum, total, tmp, tmp1, k, p int
	sum = 0
	a := make([]int, n)
	for i := 0; i < n; i++ {
	fmt.Scan(&a[i])
	}
	sort.Ints(a)
	//fmt.Println(a)

	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
	a[i], a[j] = a[j], a[i]
	}
	//fmt.Println(a)
	//new_a = a[1:]
	//fmt.Println(len(a))

	for _,k = range(a){
		sum = sum + k
	}

	total = (sum/2) + 1
	//fmt.Println(total)
	tmp = 0; tmp1 = 0
	for _,p = range(a) {
		tmp = tmp + p
		tmp1 = tmp1 + 1
		if tmp >= total{
			break
		}
	}
	fmt.Println(tmp1)
}

/* https://codeforces.com/problemset/problem/160/A
A. Twins
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.

Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1, a2, ..., an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.

As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.

Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the coins' values. All numbers are separated with spaces.

Output
In the single line print the single number — the minimum needed number of coins.

Examples
inputCopy
2
3 3
outputCopy
2
inputCopy
3
2 1 2
outputCopy
2
Note
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.

In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
*/

package main

import (
	"fmt"
	"sort"
)

func main() {
	var num_coins, coin_total, tabulating int
	fmt.Scanln(&num_coins)

	coin_values := make([]int, num_coins)
	for i := 0; i < num_coins; i++ {
		fmt.Scan(&coin_values[i])
	}

	for _, coin_value := range coin_values {
		coin_total += coin_value
	}

	sort.Sort(sort.Reverse(sort.IntSlice(coin_values)))
	for keepers, coin := range coin_values {

		tabulating += coin

		if tabulating > coin_total/2 {
			fmt.Println(keepers + 1)
			return
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

// TakeCoins calculates the minimum number of coins.
func TakeCoins(s string) int {
	ss := strings.Split(s, " ")
	c := make([]int, len(ss))
	total := 0
	for i, v := range ss {
		if val, err := strconv.Atoi(v); err == nil {
			c[i] = val
			total += val
		}
	}
	sort.Sort(sort.IntSlice(c))
	sum := 0
	for i := len(c) - 1; i >= 0; i-- {
		sum += c[i]
		if sum > total-sum {
			return len(c) - i
		}
	}

	return 0
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// Skip first line.
	scanner.Scan()
	scanner.Scan()
	fmt.Println(TakeCoins(scanner.Text()))
}

package main

import "fmt"
import "sort"

type IntSlice []int

func (p IntSlice) Len() int {
	return len(p)
}

func (p IntSlice) Less(i, j int) bool {
	return p[i] > p[j]
}

func (v IntSlice) Swap(i, j int) {
	v[i], v[j] = v[j], v[i]
}

func main() {
	var n int
	sum, yours := 0, 0
	fmt.Scanf("%d\n", &n)
	var v IntSlice
	v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &v[i])
		sum += v[i]
		// fmt.Printf("%d %d %d %d\n", n, i, v[i], sum)
	}
	sort.Sort(v)
	// fmt.Printf("%d %d\n", sum, yours)
	for i, vi := range v {
		yours += vi
		sum -= vi
		// fmt.Printf("%d %d\n", i, vi)
		if yours > sum {
			fmt.Printf("%d\n", i+1)
			break
		}
	}
}

/*
Twins
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.

Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1, a2, ..., an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.

As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.

Input
The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the coins' values. All numbers are separated with spaces.

Output
In the single line print the single number — the minimum needed number of coins.

Sample test(s)
input
2
3 3
output
2
input
3
2 1 2
output
2
Note
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.

In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.
*/
package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n int
		coin int
		sum int
		takeCoin int
		coins = make([]int, 0, 10)
	)
	fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &coin)
		sum += coin
		coins = append(coins, coin)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(coins)))

	for i := 0; i < n; i++ {
		takeCoin += coins[i]
		if takeCoin > sum/2 {
			fmt.Println(i+1)
			return
		}
	}
}

package main

import (
	"fmt"
)

func BubbleSort(data []int) []int {
	result := make([]int, len(data))
	copy(result, data)
	for offset := 0; offset < len(result); offset++ {
		for j := 0; j < offset; j++ {
			if result[j] < result[offset] {
				result[offset], result[j] = result[j], result[offset]
			}
		}
	}
	return result
}

func main() {
	var coinNum int
	fmt.Scan(&coinNum)
	coins := make([]int, coinNum)
	var total int
	for offset := 0; offset < coinNum; offset++ {
		fmt.Scan(&coins[offset])
		total += coins[offset]
	}
	coins = BubbleSort(coins)
	var myCount int
	var myCoinNum int
	for _, coin := range coins {
		myCount += coin
		myCoinNum += 1
		if myCount > total / 2 {
			break
		}
	}
	fmt.Print(myCoinNum)
}

package main

import "fmt"

func main() {
	var n int
	var coins [101]int
	fmt.Scan(&n)

	var v int
	total := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&v)
		coins[v] += 1
		total += v
	}

	num := 0
	left := total/2 + 1
	for i := 100; i > 0; i-- {
		if coins[i] == 0 {
			continue
		}
		if coins[i]*i < left {
			left -= coins[i] * i
			num += coins[i]
		} else {
			for j := 1; j <= coins[i]; j++ {
				left -= i
				num += 1
				if left <= 0 {
					fmt.Print(num)
					return
				}
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var n int
var a []int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1<<20)
	fmt.Fscanf(reader, "%d\n", &n)
	a = make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
		sum += a[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	pre := 0
	for i := 0; i < n; i++ {
		pre += a[i]
		if pre*2 > sum {
			fmt.Println(i + 1)
			return
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func sum(a []int) int {
	var i, sum int
	for i = 0; i < len(a); i++ {
		sum += a[i]
	}
	return sum
}

func main() {
	var n, i int
	fmt.Scan(&n)
	s := make([]int, n)
	for i = 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(s)))
	suml := s[0]
	sumr := sum(s) - s[0]
	if suml > sumr {
		fmt.Println(1)
	} else {
		for i = 1; i < n; i++ {
			suml += s[i]
			sumr -= s[i]
			if suml > sumr {
				fmt.Println(i + 1)
				break
			}
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, sum int
	fmt.Scan(&n)
	c := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
		sum += c[i]
	}

	sort.Ints(c)

	count := 0
	for h := n - 1; h >= 0; h-- {
		count += c[h]
		sum -= c[h]
		if count > sum {
			fmt.Println(n - h)
			return
		}
	}
	fmt.Println(n)
}

package main
import ("fmt"
		"sort")

func main(){
	var n int;
	fmt.Scan(&n);
	var a [100]int
	t:=0
	for i:=0 ;i <n;i++{
		fmt.Scan(&a[i])
		t+=a[i]
	}
	//sort.Ints(a)
	b := a[0:n]
	sort.Ints(b)
   // aa := []a

	/*for i:=0 ;i <n;i++{
		fmt.Print(b[i])
	}*/
	s:=0;
	c:=0;
	for i:= n-1 ; i>=0;i--{
		s+=b[i]
		c++
		if(2*s>t){
			break
		}

	}
	fmt.Print(c)

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	inputData := make([]string, 0)
	for scanner.Scan() {
		inputData = append(inputData, scanner.Text())
	}
	arrayStrings := strings.Fields(inputData[1])
	coins := make([]int, len(arrayStrings))
	for index, item := range arrayStrings {
		coins[index], _ = strconv.Atoi(item)
	}
	heap := make([]int, 0)
	for sum(coins) >= sum(heap) {
		coin := findMaxCoin(coins)
		heap = append(heap, coin)
		for index := range coins {
			if coins[index] == coin {
				coins[index] = 0
				break
			}
		}
	}
	fmt.Println(len(heap))
}

func findMaxCoin(coins []int) int {
	max := coins[0]
	for _, item := range coins {
		if item > max {
			max = item
		}
	}
	return max
}

func sum(coins []int) int {
	sum := 0
	for _, item := range coins {
		sum += item
	}
	return sum
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d\n", &n)

    var coin, sum int
    sum = 0
    var count = [101]int{0:101}
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &coin)
        sum += coin
        count[coin]++
    }

    cur := 0
    num := 0
    find := false
    for i := 100; i >= 0 && !find; i-- {
        for j := 0; j < count[i]; j++ {
            cur += i
            num++
            if (cur > sum - cur) {
                find = true
                break
            }
        }
    }

    fmt.Println(num)
}

//  URL: http://codeforces.com/problemset/problem/160/A
//  ~ Basic Implementation Problem

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func sum(arr []int) int {
	sum := 0
	for i := 0; i < len(arr); i++ {
		sum += arr[i]
	}
	return sum
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	totalSum := sum(a)
	myCoins := 0
	for i := 0; i < n; i++ {
		myCoins += a[i]
		if myCoins > totalSum-myCoins {
			fmt.Fprintf(writer, "%d\n", i+1)
			return
		}
	}
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var n int
    fmt.Scan(&n)

    var cs []int
    var tot  = 0
    for i := 0 ; i  < n ; i++ {
        var c int
        fmt.Scan(&c)

        cs = append(cs, c)
        tot += c
    }
    tot = tot/2

    sort.Ints(cs)

    ctot := 0
    i := n - 1
    for  ; i >=  0; i-- {
        ctot += cs[i]
        if ctot > tot  {
            break
        }
    }
    fmt.Println(n-i)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, a, b, i, j int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	arrOfValues := make([]int, n)
	for index := 0; index < n; index++ {
		fmt.Fscan(reader, &arrOfValues[index])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if arrOfValues[j] > arrOfValues[j+1] {
				arrOfValues[j], arrOfValues[j+1] = arrOfValues[j+1], arrOfValues[j]
			}
		}
	}
	i = 0
	j = n - 1
	for i != j {
		if a+arrOfValues[i] < b+arrOfValues[j] {
			a += arrOfValues[i]
			i++
		} else {
			b += arrOfValues[j]
			if j != 0 {
				j--
			}
		}
	}
	if a == b && i != j {
		j--
	}
	fmt.Println(n - j)

}

package main

import (
	"fmt"
	"os"
	"sort"
)

func main() {
	var n int
	scanf("%d\n", &n)

	var sum int
	a := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d", &a[i])
		sum += a[i]
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	var my int
	for i := 0; i < n; i++ {
		my += a[i]
		sum -= a[i]
		if my > sum {
			printf("%d\n", i+1)
			break
		}
	}
}

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

func scanf(format string, x ...interface{}) {
	if _, err := fmt.Fscanf(os.Stdin, format, x...); err != nil {
		panic(err)
	}
}

package main

import ("fmt";
		"sort")

type set map[int]bool
type long int64

func main(){
	var n, sum int
	scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++{
		scan(&a[i])
		sum += a[i]
	}
	sort.Slice(a, func(i, j int)bool{return a[i] > a[j]})
	pref := 0
	for i := 0; i < n; i++{
		pref += a[i]
		if pref * 2 > sum{
			sout(i + 1)
			return
		}
	}
}

func scan(in ... interface{}){
	for _,k := range in{
		fmt.Scan(k)
	}
}

func sout(obj ... interface{}){
	for _, k := range obj{
		fmt.Print(k)
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	var sum = 0
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
		sum += arr[i]
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if arr[j] < arr[j+1] {
				temp := arr[j]
				arr[j] = arr[j+1]
				arr[j+1] = temp
			}
		}
	}
	tempSum := 0
	count := 0
	for tempSum < sum/2+1 {

		tempSum += arr[count]
		count++
	}
	fmt.Print(count)
}

package main

import (
	"fmt"
	"sort"
)

func tryTake(n int, coins []int) bool {
	var sum1, sum2 int
	for i, val := range coins {
		if i < n {
			sum1 += val
		} else {
			sum2 += val
		}
	}

	return sum1 > sum2
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	coins := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &coins[i])
	}
	sort.Ints(coins)
	sort.Sort(sort.Reverse(sort.IntSlice(coins)))

	take := 1
	for !tryTake(take, coins) {
		take++
	}

	fmt.Println(take)
}

package main
import (
    "fmt"
    "sort"
)

func main() {
    var i,n,tmp int
    var vals[] int
    fmt.Scan(&n)
    sum:=0
    for i=0;i<n;i++ {
    	fmt.Scan(&tmp)
    	vals=append(vals,tmp)
    	sum+=tmp
    }
    sort.Sort(sort.Reverse(sort.IntSlice(vals)))
    tmp=0
    for i=0;i<n;i++ {
    	tmp+=vals[i]
    	if tmp>sum/2 {
    		break
    	}
    }
    fmt.Println(i+1)
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math/rand"
	"os"
)

const INF  = 1000000001

type Pair struct {
	first, second int
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] > arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func solution(reader io.Reader, writer io.Writer) {
	var n, s, s1 int
	fmt.Fscanf(reader, "%d\n", &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
		s += a[i]
	}

	a = sort(a)

	for i := 0; i < n; i++ {
		s1 += a[i]
		if s1 * 2 > s {
			fmt.Fprintf(writer, "%d\n", i + 1)
			return
		}
	}
	fmt.Fprintf(writer, "%d\n", n)
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var numberOfCoin int
	fmt.Scan(&numberOfCoin)

	coins := []int{}

	for i := 0; i < numberOfCoin; i++ {
		var coinValue int
		fmt.Scan(&coinValue)
		coins = append(coins, coinValue)
	}

	sort.Ints(coins)
	coins = reverse(coins)
	tmpCoins := coins

	value := 0
	count := 0

	for i, v := range coins {
		value += v
		count++
		tmpCoins = coins[i+1 : len(coins)]
		if value > sumCoinsValue(tmpCoins) {
			break
		}
	}

	fmt.Println(count)

}

func reverse(coins []int) (reversedCoins []int) {
	for i := len(coins) - 1; i >= 0; i-- {
		reversedCoins = append(reversedCoins, coins[i])
	}
	return
}

func sumCoinsValue(coins []int) (value int) {
	value = 0
	for _, v := range coins {
		value += v
	}
	return
}

package main

import "fmt"

func main() {
    var n int
    var a [105]int
    total := 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
        total += a[i]
    }
    for i := n-1; i > 0; i-- {
        k := i
        for j := 0; j < i; j++ {
            if a[j] < a[k] { k = j }
        }
        a[k], a[i] = a[i], a[k]
    }
    cnt := 0
    for i := 0; i < n; i++ {
        cnt += a[i]
        total -= a[i]
        if cnt > total {
            fmt.Println(i+1)
            break
        }
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

// https://codeforces.com/problemset/problem/160/A
// A. Twins
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.

// Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1, a2, ..., an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.

// As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
// Input

// The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the coins' values. All numbers are separated with spaces.
// Output

// In the single line print the single number — the minimum needed number of coins.

func main() {
	bufStdin := bufio.NewReader(os.Stdin)

	var n int
	_, _ = fmt.Fscan(bufStdin, &n)

	coins := make([]int, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscan(bufStdin, &coins[i])
	}

	sort.Ints(coins)

	var leftSum int
	for i := 0; i < len(coins)-1; i++ {
		leftSum += coins[i]
	}

	rightSum := coins[len(coins)-1]

	nCoins := 1

	for rightSum <= leftSum {
		exchange := coins[len(coins)-nCoins-1]

		leftSum -= exchange
		rightSum += exchange

		nCoins++
	}

	_, _ = fmt.Print(nCoins)

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	var coins []int
	total := 0
	for i:= 0; i < n; i++ {
		scanner.Scan()
		v, _ := strconv.Atoi(scanner.Text())
		coins = append(coins, v)
		total+= v
	}
	mid := total /2
	sort.Sort(sort.Reverse(sort.IntSlice(coins)))

	count := 0;
	twin1 := 0
	for _, v := range coins {
		twin1 += v
		count++
		if twin1 > mid {
			break
		}
	}
	fmt.Println(count)

}

package main

import (
	"fmt"
	"sort"
)

func summ(arr []int) int {
	var summ int
	for i := range arr {
		summ += arr[i]
	}
	return summ
}

func main() {
	var testcount, a int
	var arr []int
	fmt.Scanf("%d\n", &testcount)
	for i := 0; i < testcount; i++ {
		fmt.Scanf("%d", &a)
		arr = append(arr, a)
	}
	sort.Ints(arr)
	if testcount == 1 {
		fmt.Println("1")
	} else {
		for i := testcount; i >= 0; i-- {
			if summ(arr[:i]) < summ(arr[i:]) {
				fmt.Println(len(arr[i:]))
				break
			}
		}
	}
}

package main

import (
	"fmt"
	"sort"

)
func reverseInts(input []int) []int {
	if len(input) == 0 {
		return input
	}
	return append(reverseInts(input[1:]), input[0])
}
	func main() {
	var n int
	fmt.Scan(&n)
	var a []int
	for i:=0;i<n;i++{
		var n int
		fmt.Scan(&n)
		a=append(a,n )
	}
		var lim int
	for i:=0;i<len(a);i++{
			lim+=a[i]
		}
	lim=lim/2+1

		sort.Ints(a)
		for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
			a[i], a[j] = a[j], a[i]
		}
		sum:=0
		k:=0
		for i:=0;i<len(a);i++{
			if lim>sum{
				sum+=a[i]
				k+=1
			}else{
				break
			}
		}

	fmt.Println(k)

}

package main

import (
	"fmt"
	"os"
	"sort"
)

func main() {
	var n int

	total := 0
	scanf("%d\n",&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d",&a[i])
		total += a[i]
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	mine := 0

	for i, v := range a {
		mine += v
		total -= v

		if mine > total {
			fmt.Println(i+1)
			break
		}
	}
}

func scanf(format string, x ...interface{}) {
	if _, err := fmt.Fscanf(os.Stdin, format, x...); err != nil {
		panic(err)
	}
}

package main

import (
	"fmt"
)

func Qsort(a []int, l int, r int) (err error) {
	x, i, j:= a[l], l, r
	for i < j {
		for (i < j) && (a[j] <= x) {
			j--
		}
		a[i] = a[j]
		for (i < j) && (a[i] >= x) {
			i++
		}
		a[j] = a[i]
	}
	a[i] = x
	if l < i-1 {
		Qsort(a, l, i-1)
	}
	if j+1 < r {
		Qsort(a, j+1, r)
	}
	return nil
}

//func vent(a *[4]int) (err error) {
//	(*a)[0] = 555
//	return nil
//}

func main() {
	var n, all, res, i int

	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		//fmt.Printf("%d: %d ", i, a[i])
		all += a[i]
	}
	Qsort(a, 0, len(a) - 1)
	for {
		res += a[i]
		if res > (all - res) {
			i = i + 1
			//fmt.Printf("all=%d res=%d i=%d\n", all, res, i)
			fmt.Println(i)
			break
		} else {
			i++
		}
	}
}

package main

import (
	"fmt"
	//"math"
	"sort"
)

func summ(arr []int) (sum int) {
	for _, v := range arr {
		sum += v
	}
	return
}

func main() {
	var n byte
	fmt.Scan(&n)

	var arr = make([]int, n)
	for ; n > 0; n-- {
		var val byte
		fmt.Scan(&val)
		arr[n-1] = int(val)
	}

	sort.Sort(sort.Reverse(sort.IntSlice(arr)))

	for i, _ := range arr {
		if summ(arr[:i+1]) > summ(arr[i+1:]) {
			fmt.Println(i + 1)
			break
		}
	}
}

package main

import (
  "fmt"
  "os"
  "bufio"
  "log"
  "strings"
  "sort"
)

func fastGetInt(b[]byte) int{
  neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func solveFromFile() int{
    file, err := os.Open(os.Args[1])
    if err != nil {
      log.Fatalf("failed opening file: %s", err)
    }
    scanner := bufio.NewScanner(file)
    scanner.Scan()
    scanner.Scan()
  //  fmt.Println(byts)

    defer file.Close()

    return solution(strings.Fields(scanner.Text()))
}

//========== Implement Algorithm =======================
func solution(str []string) int{
  var num []int
  count :=0
  for x := 0; x < len(str); x++ {
    i := fastGetInt([]byte(str[x]))
    num = append(num,i)
    count +=i
  }

  tempCount := 0
  totNum := 0
  sort.Ints(num)
  for x := len(num)-1; x >= 0; x-- {
    if tempCount<= (count/2){
      tempCount+= num[x]
      totNum++
    }
  }
  return totNum
}

func main() {

//================== Variables used ====================
  var ret int
//======================================================

  if len(os.Args) >=2{
//============== Get return value from File ============
    ret = solveFromFile()

  }else{
//============== Get return value from STDIN ===========
    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    scanner.Scan()
    ret = solution(strings.Fields(scanner.Text()))
  }

//================== OUTPUT ============================
  fmt.Println(ret)
}

package main

// https://codeforces.com/problemset/problem/160/A

import (
	"fmt"
	"sort"
)

func task_solution(a []int) (ans int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sum := 0
	for _, e := range a {
		sum += e
	}
	for value := 0; ans < len(a) && (value <= sum-value); ans += 1 {
		value += a[ans]
	}
	return ans
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	in := []int{}
	for i := 0; i < n; i += 1 {
		var a int
		if _, err := fmt.Scan(&a); err != nil {
			panic(err)
		}
		in = append(in, a)
	}

	fmt.Println(task_solution(in))
}

package main

import (
	"fmt"
	"sort"
)

func task_solution(a []int) (ans int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sum := 0
	for _, e := range a {
		sum += e
	}
	for value := 0; ans < len(a) && (value <= sum-value); ans += 1 {
		value += a[ans]
	}
	return ans
}

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		panic(err)
	}
	in := []int{}
	for i := 0; i < n; i += 1 {
		var a int
		_, err := fmt.Scan(&a)
		if err != nil {
			panic(err)
		}
		in = append(in, a)
	}

	fmt.Println(task_solution(in))
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/160/A

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func Solve(n int, a []int) int {
	sort.Ints(a)
	sum := 0
	for _, elem := range a {
		sum += elem
	}
	minSum := 0
	minCount := 0
	for i := n - 1; i >= 0; i-- {
		minSum += a[i]
		minCount += 1
		if minSum > sum-minSum {
			return minCount
		}
	}
	return minCount
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, i int
	fmt.Scanln(&n)

	coins := make([]int, n)
	sum := 0
	for i = 0; i < n; i++ {
		fmt.Scan(&coins[i])
		sum += coins[i]
	}

	average := sum / 2
	sum = 0
	sort.Sort(sort.Reverse(sort.IntSlice(coins)))
	for i, value := range coins {
		sum += value
		if sum > average {
			fmt.Println(i + 1)
			break
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a = make([]int, n)
	var sum = 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	sum >>= 1
	sort.Ints(a)
	var ans = 0
	for i := len(a) - 1; i >= 0; i-- {
		sum -= a[i]
		ans++
		if sum < 0 {
			break
		}
	}
	fmt.Println(ans)
}

package main

import (
  "fmt"
  "os"
  "bufio"
  "log"
  "sort"
)

func fastGetInt(b[]byte) int{
  neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func solveFromFile() int{
    var num int
    file, err := os.Open(os.Args[1])
    if err != nil {
      log.Fatalf("failed opening file: %s", err)
    }
    scanner := bufio.NewScanner(file)
    scanner.Scan()
    num = fastGetInt(scanner.Bytes())

    var inlist []int
    scanner.Scan()
    byts := scanner.Bytes()
  //  fmt.Println(byts)
    tempnum:=0
    tempnum = num *2-1
    count :=0
    for x := 0; x < tempnum; x++ {
      if byts[x]>='0'&&byts[x]<='9' {
        //fmt.Println([]byte{byts[x],'a'})
        i:= fastGetInt([]byte{byts[x]})
        //fmt.Println(i)
        inlist = append(inlist,i)
        count += i
      }

    }

    defer file.Close()

    return solution(inlist,count)
}

//========== Implement Algorithm =======================
func solution(num []int,count int) int{
  tempCount := 0
  totNum := 0
  sort.Ints(num)
  for x := len(num)-1; x >= 0; x-- {
    if tempCount<= (count/2){
      tempCount+= num[x]
      totNum++
    }
  }
  return totNum
}

func main() {

//================== Variables used ====================
  var num, ret int
  var inlist []int
//======================================================

  if len(os.Args) >=2{
//============== Get return value from File ============
    ret = solveFromFile()

  }else{
//============== Get return value from STDIN ===========
    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    num = fastGetInt(scanner.Bytes())
    scanner.Scan()
    byts := scanner.Bytes()
    count:= 0
    for x := 0; x < num; x=x+2 {
      i:= fastGetInt(byts[x:x+1])
      inlist = append(inlist,i)
      count += i
    }
    fmt.Println()
    ret = solution(inlist,count)
  }

//================== OUTPUT ============================
  fmt.Println(ret)
}

package main

import (
  "fmt"
  "os"
  "bufio"
  "log"
  "sort"
)

func fastGetInt(b[]byte) int{
  neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func solveFromFile() int{
    var num int
    file, err := os.Open(os.Args[1])
    if err != nil {
      log.Fatalf("failed opening file: %s", err)
    }
    scanner := bufio.NewScanner(file)
    scanner.Scan()
    num = fastGetInt(scanner.Bytes())

    var inlist []int
    scanner.Scan()
    byts := scanner.Bytes()
  //  fmt.Println(byts)
    tempnum:=0
    tempnum = num *2-1
    count :=0
    for x := 0; x < tempnum; x++ {
      if byts[x]>='0'&&byts[x]<='9' {
        //fmt.Println([]byte{byts[x],'a'})
        i:= fastGetInt([]byte{byts[x]})
        //fmt.Println(i)
        inlist = append(inlist,i)
        count += i
      }

    }

    defer file.Close()

    return solution(inlist,count)
}

//========== Implement Algorithm =======================
func solution(num []int,count int) int{
  tempCount := 0
  totNum := 0
  sort.Ints(num)
  for x := len(num)-1; x >= 0; x-- {
    if tempCount<= (count/2){
      tempCount+= num[x]
      totNum++
    }
  }
  return totNum
}

func main() {

//================== Variables used ====================
  var num, ret int
  var inlist []int
//======================================================

  if len(os.Args) >=2{
//============== Get return value from File ============
    ret = solveFromFile()

  }else{
//============== Get return value from STDIN ===========
    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    num = fastGetInt(scanner.Bytes())
    scanner.Scan()
    byts := scanner.Bytes()
    count:= 0
    tempnum := num *2-1
    for x := 0; x < tempnum; x=x+2 {
      i:= fastGetInt(byts[x:x+1])
      inlist = append(inlist,i)
      count += i
    }
    ret = solution(inlist,count)
  }

//================== OUTPUT ============================
  fmt.Println(ret)
}

package main

import (
	"fmt"
)

func Qsort(a []int, l int, r int) (err error) {
	x, i, j:= a[l], l, r
	for i < j {
		for (i < j) && (a[j] <= x) {
			j--
		}
		a[i] = a[j]
		for (i < j) && (a[i] >= x) {
			i++
		}
		a[j] = a[i]
	}
	a[i] = x
	if l < i-1 {
		Qsort(a, l, i-1)
	}
	if j+1 < r {
		Qsort(a, j+1, r)
	}
	return nil
}

//func vent(a *[4]int) (err error) {
//	(*a)[0] = 555
//	return nil
//}

func main() {
	var n, all, res, i int

	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		fmt.Printf("%d: %d ", i, a[i])
		all += a[i]
	}
	Qsort(a, 0, len(a) - 1)
	for {
		res += a[i]
		if res > (all - res) {
			i = i + 1
			fmt.Printf("all=%d res=%d i=%d\n", all, res, i)
			break
		} else {
			i++
		}
	}
}

package main

import (
	"fmt"
)

func Qsort(a []int, l int, r int) (err error) {
	x, i, j:= a[l], l, r
	for i < j {
		for (i < j) && (a[j] <= x) {
			j--
		}
		a[i] = a[j]
		for (i < j) && (a[i] >= x) {
			i++
		}
		a[j] = a[i]
	}
	a[i] = x
	if l < i-1 {
		Qsort(a, l, i-1)
	}
	if j+1 < r {
		Qsort(a, j+1, r)
	}
	return nil
}

//func vent(a *[4]int) (err error) {
//	(*a)[0] = 555
//	return nil
//}

func main() {
	var n, all, res, i int

	fmt.Scanf("%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		all += a[i]
	}
	Qsort(a, 0, len(a) - 1)
	for {
		res += a[i]
		if res > (all - res) {
			i = i + 1
			fmt.Printf("%d\n", i)
			break
		} else {
			i++
		}
	}
}

package main

import (
	"fmt"
)

func Qsort(a []int, l int, r int) (err error) {
	x, i, j:= a[l], l, r
	for i < j {
		for (i < j) && (a[j] <= x) {
			j--
		}
		a[i] = a[j]
		for (i < j) && (a[i] >= x) {
			i++
		}
		a[j] = a[i]
	}
	a[i] = x
	if l < i-1 {
		Qsort(a, l, i-1)
	}
	if j+1 < r {
		Qsort(a, j+1, r)
	}
	return nil
}

//func vent(a *[4]int) (err error) {
//	(*a)[0] = 555
//	return nil
//}

func main() {
	var n, all, res, i int

	fmt.Scanf("%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		all += a[i]
	}
	Qsort(a, 0, len(a) - 1)
	for {
		res += a[i]
		if res > (all - res) {
			fmt.Println(i + 1)
			break
		} else {
			i++
		}
	}
}

package main

import (
	"fmt"
)

func Qsort(a []int, l int, r int) (err error) {
	x, i, j:= a[l], l, r
	for i < j {
		for (i < j) && (a[j] <= x) {
			j--
		}
		a[i] = a[j]
		for (i < j) && (a[i] >= x) {
			i++
		}
		a[j] = a[i]
	}
	a[i] = x
	if l < i-1 {
		Qsort(a, l, i-1)
	}
	if j+1 < r {
		Qsort(a, j+1, r)
	}
	return nil
}

//func vent(a *[4]int) (err error) {
//	(*a)[0] = 555
//	return nil
//}

func main() {
	var n, all, res, i int

	fmt.Scanf("%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		all += a[i]
	}
	Qsort(a, 0, len(a) - 1)
	for {
		res += a[i]
		if res > (all - res) {
			i = i + 1
			fmt.Printf("all=%d res=%d i=%d\n", all, res, i)
			break
		} else {
			i++
		}
	}
}

package main

import (
	"fmt"
)

func Qsort(a []int, l int, r int) (err error) {
	x, i, j:= a[l], l, r
	for i < j {
		for (i < j) && (a[j] <= x) {
			j--
		}
		a[i] = a[j]
		for (i < j) && (a[i] >= x) {
			i++
		}
		a[j] = a[i]
	}
	a[i] = x
	if l < i-1 {
		Qsort(a, l, i-1)
	}
	if j+1 < r {
		Qsort(a, j+1, r)
	}
	return nil
}

//func vent(a *[4]int) (err error) {
//	(*a)[0] = 555
//	return nil
//}

func main() {
	var n, all, res, i int

	fmt.Scanf("%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		fmt.Printf("%d: %d ", i, a[i])
		all += a[i]
	}
	Qsort(a, 0, len(a) - 1)
	for {
		res += a[i]
		if res > (all - res) {
			i = i + 1
			fmt.Printf("all=%d res=%d i=%d\n", all, res, i)
			break
		} else {
			i++
		}
	}
}

package main

import (
	"fmt"
)

func Qsort(a []int, l int, r int) (err error) {
	x, i, j:= a[l], l, r
	for i < j {
		for (i < j) && (a[j] <= x) {
			j--
		}
		a[i] = a[j]
		for (i < j) && (a[i] >= x) {
			i++
		}
		a[j] = a[i]
	}
	a[i] = x
	if l < i-1 {
		Qsort(a, l, i-1)
	}
	if j+1 < r {
		Qsort(a, j+1, r)
	}
	return nil
}

//func vent(a *[4]int) (err error) {
//	(*a)[0] = 555
//	return nil
//}

func main() {
	var n, all, res, i int

	fmt.Scanf("%d", &n)
	a := make([]int, n)
	//a := [4]int {}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		all += a[i]
	}
	Qsort(a, 0, len(a) - 1)

	for {
		res += a[i]
		if res > (all - res) {
			fmt.Println(i + 1)
			break
		} else {
			i++
		}
	}
}

package main

import "fmt"
import "sort"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	sort.Ints(a)
	curr := 0
	for i := 0; i < n; i++ {
		curr += a[i]
		if 2*curr > sum {
			fmt.Println(i + 1)
			return
		}
	}
}

package main
import (
	"fmt"
)

func main() {
	var t int
	var num [101]int
	fmt.Scanf("%d\n",&t)
	sum,total,ans := 0,0,0
	for  i:=0;i<t;i++{
		fmt.Scan(&num[i])
		sum += num[i]
	}
	bubblesort(num)
	for i:=(t-1);;i-- {
		if i>=0 && total<=sum/2 {
			total += num[i]
			ans++
		} else {break}
	}
	fmt.Println(ans)
}

func bubblesort(a [101]int) { //fungsi bubblesort
    for itemCount := len(a) - 1; ; itemCount-- { //for yang dimulai dengan pemberian nilai pada itemCount yaitu, banyak jumlah elemen array list dikurang satu, tanpa batas, dimana setiap loop terjadi pengurangan nilai itemCount sebanyak 1
        hasChanged := false //bool hasChanged yang berisi false
        for index := 0; index < itemCount; index++ { //for yang dimulai dengan index bernilai 0, syaratnya index harus selalu lebih kecil dari itemCount,dimana setiap loop terjadi peningkatan nilai index sebanyak 1
            if a[index] > a[index+1] { //jika nilai a[index] lebih besar dari a[index+1] menandakan array list tadi nilainya tidak berurutan
                a[index], a[index+1] = a[index+1], a[index] //swap dimana a[index] berisi nilai a[index+1] dan a[index+1] berisi nilai a[index]
                hasChanged = true //hasChanged berisi true agar loop berikutnya dapat dijalankan
            }
        }
        if hasChanged == false { //if agar dapat keluar dari loop yaitu ketika hasChanged berisi false
            break
        }
    }
}

package main

import (
  "fmt"
  "sort"
)

func sumarr(x []int) int  {
  var sum int
  for _,val := range x {
    sum+=val
  }
  return sum
}

func main() {
  var n, a, b int
  fmt.Scan(&n)
  arr := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&arr[i])
  }
  sort.Ints(arr)
  if len(arr) == 1 {
    fmt.Print("1")
  } else {
    i := 1
    a = sumarr(arr[0:len(arr)-i])
    b = sumarr(arr[len(arr)-i:len(arr)])
    for a > b && i <= len(arr){
      i++
      a = sumarr(arr[0:len(arr)-i])
      b = sumarr(arr[len(arr)-i:len(arr)])
    }

    fmt.Print(len(arr[len(arr)-i:len(arr)]))
  }
}

package main

import (
  "fmt"
  "sort"
)

func sumarr(x []int) int  {
  var sum int
  for _,val := range x {
    sum+=val
  }
  return sum
}

func main() {
  var n, sum, b int
  fmt.Scan(&n)
  arr := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&arr[i])
  }
  sort.Ints(arr)
  if len(arr) == 1 {
    fmt.Print("1")
  } else {
    i := 1
    sum = sumarr(arr[0:i])
    b = sumarr(arr[i:len(arr)])
    i++
    for sum < b && i <= len(arr){
      sum = sumarr(arr[0:i])
      b = sumarr(arr[i:len(arr)])
      if sum < b {
        i++
      }
    }
    fmt.Print(len(arr[0:i]))
  }
}

package main

import (
	"fmt"
)

func InvSort(x []int32) {
	var (
		i, j, nx int32
		xi       int32
	)
	nx = int32(len(x))
	for i = 1; i < nx; i++ {
		xi = x[i]
		for j = i; j > 0 && xi < x[j-1]; j-- {
			x[j] = x[j-1]
		}
		x[j] = xi
	}
}

func main() {

	var (
		i, xi, nx, sum int32
		x              []int32
	)

	fmt.Scan(&nx)
	x = make([]int32, nx, nx)
	for i = 0; i < nx; i++ {
		fmt.Scan(&xi)
		sum += xi
		x[i] = xi
	}

	//	fmt.Println(x, sum)
	InvSort(x)
	//	fmt.Println(x, sum)

	sum /= 2
	for i = 0; i < nx && sum >= 0; i++ {
		sum -= x[i]
	}

	fmt.Println(i)

}

package main

import "fmt"

func main(){
	var n int
	fmt.Scan(&n)
	a := make([]int,n)
	var i int
	var sum int
	for ;n>0;n--{
		fmt.Scan(&a[i])
		sum+=a[i]
		i++
	}
	heapsort(a)
	var outsum int
	for i = 0;i<len(a);i++{
		if 2*outsum>sum{
			break
		}
		outsum+=a[i]
	}
	fmt.Println(i)
}

func heapify(a []int,i int,hsize int){
	l := (i<<1)+1
	r := (i+1)<<1
	var smallest int
	if l < hsize && a[l]<a[i]{
		smallest=l
	}else{
		smallest=i
	}
	if r < hsize && a[r]<a[i]{
		smallest=r
	}
	if smallest!=i{
		a[i],a[smallest]=a[smallest],a[i]
		heapify(a,smallest,hsize)
	}
}

func heapsort(a []int){
	n:= len(a)
	for i:=n/2;i>=0;i--{
		heapify(a,i,n)
	}
	for i:=n-1;i>=0;i--{
		a[0],a[i]=a[i],a[0]
		heapify(a,0,i)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

// TakeCoins calculates the minimum number of coins.
func TakeCoins(s string) int {
	ss := strings.Split(s, " ")
	c := make([]int, len(ss))
	total := 0
	for i, v := range ss {
		if val, err := strconv.Atoi(v); err == nil {
			c[i] = val
			total += val
		}
	}
	c = sort.IntSlice(c)
	sum := 0
	for i := len(c) - 1; i >= 0; i-- {
		sum += c[i]
		if sum > total-sum {
			return len(c) - i
		}
	}

	return 0
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// Skip first line.
	scanner.Scan()
	scanner.Scan()
	fmt.Println(TakeCoins(scanner.Text()))
}

package main

import "fmt"
import "sort"

type IntSlice []int

func (p IntSlice) Len() int {
	return len(p)
}

func (p IntSlice) Less(i, j int) bool {
	return p[i] > p[j]
}

func (v IntSlice) Swap(i, j int) {
	v[i], v[j] = v[j], v[i]
}

func main() {
	var n, sum, yours int
	fmt.Scanf("%d", &n)
	var v IntSlice
	v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &v[i])
		sum += v[i]
	}
	sort.Sort(v)
	for i, vi := range v {
		yours += vi
		sum -= vi
		if yours > sum {
			fmt.Printf("%d\n", i+1)
			break
		}
	}
}

package main

import "fmt"
import "sort"

type IntSlice []int

func (p IntSlice) Len() int {
	return len(p)
}

func (p IntSlice) Less(i, j int) bool {
	return p[i] > p[j]
}

func (v IntSlice) Swap(i, j int) {
	v[i], v[j] = v[j], v[i]
}

func main() {
	var n int
	sum, yours := 0, 0
	fmt.Scanf("%d", &n)
	var v IntSlice
	v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &v[i])
		sum += v[i]
	}
	sort.Sort(v)
	for i, vi := range v {
		yours += vi
		sum -= vi
		if yours > sum {
			fmt.Printf("%d\n", i+1)
			break
		}
	}
}

package main

import "fmt"
import "sort"

type IntSlice []int

func (p IntSlice) Len() int {
	return len(p)
}

func (p IntSlice) Less(i, j int) bool {
	return p[i] > p[j]
}

func (v IntSlice) Swap(i, j int) {
	v[i], v[j] = v[j], v[i]
}

func main() {
	var n int
	sum, yours := 0, 0
	fmt.Scanf("%d", &n)
	var v IntSlice
	v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &v[i])
		sum += v[i]
	}
	sort.Sort(v)
	fmt.Printf("%d %d\n", sum, yours)
	for i, vi := range v {
		yours += vi
		sum -= vi
		fmt.Printf("%d %d\n", i, vi)
		if yours > sum {
			fmt.Printf("%d\n", i+1)
			break
		}
	}
}

package main

import "fmt"
import "sort"

type IntSlice []int

func (p IntSlice) Len() int {
	return len(p)
}

func (p IntSlice) Less(i, j int) bool {
	return p[i] > p[j]
}

func (v IntSlice) Swap(i, j int) {
	v[i], v[j] = v[j], v[i]
}

func main() {
	var n int
	sum, yours := 0, 0
	fmt.Scanf("%d", &n)
	var v IntSlice
	v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &v[i])
		sum += v[i]
		fmt.Printf("%d %d %d %d\n", n, i, v[i], sum)
	}
	sort.Sort(v)
	fmt.Printf("%d %d\n", sum, yours)
	for i, vi := range v {
		yours += vi
		sum -= vi
		fmt.Printf("%d %d\n", i, vi)
		if yours > sum {
			fmt.Printf("%d\n", i+1)
			break
		}
	}
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)

    var coin, sum int
    sum = 0
    var count = [101]int{0:101}
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &coin)
        sum += coin
        count[coin]++
    }

    cur := 0
    num := 0
    find := false
    for i := 100; i >= 0 && !find; i-- {
        for j := 0; j < count[i]; j++ {
            cur += i
            num++
            if (cur > sum - cur) {
                find = true
                break
            }
        }
    }

    fmt.Println(num)
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)

    var coin, sum int
    sum = 0
    var count = [101]int{0:101}
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &coin)
        sum += coin
        count[coin]++
    }

    cur := 0
    num := 0
    find := false
    for i := 100; i >= 0; i-- {
        for j := 0; j < count[i] && !find; j++ {
            cur += i
            num++
            if (cur > sum - cur) {
                find = true
                break
            }
        }
    }

    fmt.Println(num)
}

//  URL: http://codeforces.com/problemset/problem/160/A
//  ~ Basic Implementation Problem

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func sum(arr []int) int {
	sum := 0
	for i := 0; i < len(arr); i++ {
		sum += arr[i]
	}
	return sum
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}
	sort.Ints(a)
	totalSum := sum(a)
	myCoins := 0
	for i := 0; i < n; i++ {
		myCoins += a[i]
		if myCoins > totalSum - myCoins {
			fmt.Fprintf(writer, "%d\n", i+1)
			return
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, a, b, result int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	arrOfValues := make([]int, n)
	for index := 0; index < n; index++ {
		fmt.Fscan(reader, &arrOfValues[index])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if arrOfValues[j] > arrOfValues[j+1] {
				arrOfValues[j], arrOfValues[j+1] = arrOfValues[j+1], arrOfValues[j]
			}
		}
	}
	for index := n - 1; index >= n/2; index-- {
		a += arrOfValues[index]
		b += arrOfValues[n-index-1]
		result++

	}
	if a == b {
		result++
	}
	fmt.Println(result)

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n, a, b, result int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	arrOfValues := make([]int, n)
	for index := 0; index < n; index++ {
		fmt.Fscan(reader, &arrOfValues[index])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if arrOfValues[j] > arrOfValues[j+1] {
				arrOfValues[j], arrOfValues[j+1] = arrOfValues[j+1], arrOfValues[j]
			}
		}
	}
	for index := n - 1; index >= n/2 && index != 0; index-- {
		a += arrOfValues[index]
		b += arrOfValues[n-index-1]
		result++

	}
	if a == b {
		result++
	}
	fmt.Println(result)

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	var coins []int
	total := 0
	for i:= 0; i < n; i++ {
		scanner.Scan()
		v, _ := strconv.Atoi(scanner.Text())
		coins = append(coins, v)
		total+= v
	}
	mid := total /2
	sort.Sort(sort.Reverse(sort.IntSlice(coins)))

	count := 0;
	twin1 := 0
	for _, v := range coins {
		if v > mid {
			continue
		}
		twin1 += v
		count++
		if twin1 > mid {
			break
		}
	}
	fmt.Println(count)

}

package main

import (
	"fmt"
	"sort"
)

func main() {
	mine := 0
	total := 0
	a := []int{}
	var n int

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		var num int
		fmt.Scan(&num)
		a = append(a,num)
		total = total + num
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	for _, v := range a {
		if total > mine {
			total -= v
			mine++
		}
	}

	fmt.Println(mine)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	mine := 0
	total := 0
	a := []int{}
	var n int

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		var num int
		fmt.Scan(&num)
		a = append(a,num)
		total = total + num
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	for _, v := range a {
		if total > mine && mine <= (len(a)/2){
			total -= v
			mine++
		}
	}

	fmt.Println(mine)
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n byte
	var sum uint
	fmt.Scan(&n)
	var arr = make([]int, n)
	for ; n > 0; n-- {
		var val byte
		fmt.Scan(&val)
		arr[n-1] = int(val)
		sum += uint(val)
	}

	var half = uint(math.Ceil(float64(sum / 2)))
	sort.Sort(sort.Reverse(sort.IntSlice(arr)))

	for _, v := range arr {
		if (sum - uint(v)) >= half {
			sum -= uint(v)
			n++
		} else {
			n++
			break
		}
	}
	fmt.Println(n)
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n byte
	var sum uint
	fmt.Scan(&n)
	var arr = make([]int, n)
	for ; n > 0; n-- {
		var val byte
		fmt.Scan(&val)
		arr[n-1] = int(val)
		sum += uint(val)
	}

	var half = uint(math.Ceil(float64(sum / 2)))
	sort.Sort(sort.Reverse(sort.IntSlice(arr)))

	fmt.Println(sum, half)
	for _, v := range arr {
		if (sum - uint(v)) >= half {
			sum -= uint(v)
			n++
		} else {
			n++
			break
		}
	}
	fmt.Println(n)
}

package main

import (
  "fmt"
  "os"
  "bufio"
  "log"
  "strings"
  "sort"
)

func fastGetInt(b[]byte) int{
  neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

func solveFromFile() int{
    file, err := os.Open(os.Args[1])
    if err != nil {
      log.Fatalf("failed opening file: %s", err)
    }
    scanner := bufio.NewScanner(file)
    scanner.Scan()
    scanner.Scan()
  //  fmt.Println(byts)

    defer file.Close()

    return solution(strings.Fields(scanner.Text()))
}

//========== Implement Algorithm =======================
func solution(str []string) int{
  var num []int
  count :=0
  for x := 0; x < len(str); x++ {
    i := fastGetInt([]byte(str[x]))
    num = append(num,i)
    count +=i
  }

  tempCount := 0
  totNum := 0
  sort.Ints(num)
  fmt.Println(num)
  for x := len(num)-1; x >= 0; x-- {
    if tempCount<= (count/2){
      tempCount+= num[x]
      totNum++
    }
  }
  return totNum
}

func main() {

//================== Variables used ====================
  var ret int
//======================================================

  if len(os.Args) >=2{
//============== Get return value from File ============
    ret = solveFromFile()

  }else{
//============== Get return value from STDIN ===========
    scanner := bufio.NewScanner(os.Stdin)

    scanner.Scan()
    scanner.Scan()
    ret = solution(strings.Fields(scanner.Text()))
  }

//================== OUTPUT ============================
  fmt.Println(ret)
}


package main

import (
	"bufio"
	"os"
	"strconv"
	"math"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func ReadString() string {
	scanner.Scan()
	return scanner.Text()
}

func PrintInts(ints ...int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}
func PrintStrings(strs ...string) {
	for _, value := range strs {
		writer.WriteString(value)
		writer.WriteByte(' ')
	}
}

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	x1,y1,x2,y2 := ReadInt32(),ReadInt32(),ReadInt32(),ReadInt32()
	var x3,x4,y3,y4 int
	if y1 == y2  {
		x3 = x1
		x4 = x2
		y3 = y1 + (x1-x2)
		y4 = y3
		PrintInts(x3,y3,x4,y4)
	} else if x1 == x2 {
		x3 = x1 + (y1 - y2)
		x4 = x3
		y3 = y1
		y4 = y2
		PrintInts(x3,y3,x4,y4)
	} else  if math.Abs(float64(x1-x2)) == math.Abs(float64(y1-y2)) {
		x3= x1
		x4 = x2
		y3 = y2
		y4 = y1
		PrintInts(x3,y3,x4,y4)
	} else {
		PrintInts(-1)
	}

}

package main

import (
    "fmt"
    "math"
)

func main() {
    var x1, y1, x2, y2 int
    fmt.Scanf("%d%d%d%d", &x1, &y1, &x2, &y2)
    dx := int(math.Abs(float64(x1 - x2)))
    dy := int(math.Abs(float64(y1 - y2)))
    switch {
    case dx == 0 && dy == 0:
        fmt.Println(-1)
    case dx != dy && dx != 0 && dy != 0:
        fmt.Println(-1)
    case dx == 0:
        fmt.Println(x1+dy, y1, x2+dy, y2)
    case dy == 0:
        fmt.Println(x1, y1+dx, x2, y2+dx)
    default:
        fmt.Println(x1, y2, x2, y1)
    }
}

package main

import (
	"fmt"
)

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1, &y1, &x2, &y2)
	baseX, baseY := x1, y1
	x1, y1 = 0, 0
	x2, y2 = x2-baseX, y2-baseY
	var x3, x4, y3, y4 int
	poss := true
	if x1 == x2 {
		y := y1 - y2
		if y < 0 {
			y = -y
		}
		x3, y3 = y, y2
		x4, y4 = y, y1
	} else if y1 == y2 {
		x := x1 - x2
		if x < 0 {
			x = -x
		}
		x3, y3 = x1, x
		x4, y4 = x2, x
	} else if x2 == y2 || x2 == -y2 {
		x := x2
		if x < 0 {
			x = -x2
		}
		x3, y3 = x2, 0
		x4, y4 = 0, y2
	} else {
		poss = false
	}
	if poss {

		fmt.Println(x3+baseX, y3+baseY, x4+baseX, y4+baseY)
	} else {
		fmt.Println("-1")
	}
}

package main

import (
	"fmt"
	logger "log"
	"os"
)

var log *logger.Logger

func init() {
	log = logger.New(os.Stderr, "", 0)
}

func AbsInt(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func Solve(x1, y1, x2, y2 int) {
	var dx = x2 - x1
	var dy = y2 - y1
	var adx = AbsInt(dx)
	var ady = AbsInt(dy)
	if adx > 0 && ady > 0 {
		if adx != ady {
			fmt.Printf("-1\n")
			return
		}

		fmt.Printf("%d %d ", x1+dx, y1)
		fmt.Printf("%d %d\n", x1, y1+dy)
	} else if adx > 0 {
		fmt.Printf("%d %d ", x1, y1+adx)
		fmt.Printf("%d %d\n", x2, y2+adx)
	} else {
		fmt.Printf("%d %d ", x1+ady, y1)
		fmt.Printf("%d %d\n", x2+ady, y2)
	}
}

func main() {
	var x1, y1, x2, y2 int
	if _, err := fmt.Scanf("%d %d %d %d", &x1, &y1, &x2, &y2); err != nil {
		log.Printf("Failed to read input: %s", err)
		os.Exit(0)
	}
	Solve(x1, y1, x2, y2)
}

package main

import (
	"math"
	"fmt"
)

func main() {
	var x1, y1, x2, y2, xsize float64

	fmt.Scan(&x1, &y1, &x2, &y2)

	if x1 == x2 {
		if y1 == y2 {
			fmt.Println(-1)
		} else {
			xsize = math.Abs(y1-y2)
			fmt.Println(x1+xsize, y1, x2+xsize, y2)
		}
	} else {
		if y1 == y2 {
			xsize = math.Abs(x1-x2)
			fmt.Println(x1, y1+xsize, x2, y2+xsize)
		} else {
			if math.Abs(x1-x2) == math.Abs(y1-y2) {
				fmt.Println(x1, y2, x2, y1)
			} else {
				fmt.Println(-1)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	x1, y1 := nextInt(), nextInt()
	x2, y2 := nextInt(), nextInt()

	if x1 == x2 {
		dis := abs(y1 - y2)
		println(x1 + dis, y1, x2 + dis, y2)
		return
	}

	if y1 == y2 {
		dis := abs(x1 - x2)
		println(x1, y1 + dis, x2, y2 + dis)
		return
	}

	if abs(x1 - x2) != abs(y1 - y2) {
		println(-1)
		return
	}

	println(x2, y1, x1, y2)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func i(s *bufio.Scanner) int  {
	s.Scan()
	v,_ := strconv.Atoi(s.Text())
	return v
}

func abs(i int) int  {
	if i<0 {
		return i*-1
	} else {
		return i
	}
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	x1,y1,x2,y2 := i(s), i(s), i(s), i(s)

	var d, x3, y3, x4, y4 int
	if x1==x2 {
		d = y1 - y2
		x3,y3,x4,y4 = x1+d,y1, x2+d, y2
	} else if y1==y2 {
		d = x1 - x2
		x3,y3,x4,y4 = x1,y1+d, x2, y2+d
	} else if abs(x1 - x2) == abs(y1 - y2) {
		x3,y3,x4,y4 = x1,y2,x2,y1
 	} else {
 		fmt.Println(-1)
		return
	}

	fmt.Printf("%d %d %d %d", x3, y3, x4, y4)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')

	var x1, y1, x2, y2, size int

	fmt.Sscanf(line, "%d %d %d %d", &x1, &y1, &x2, &y2)

	if x1 == x2 {
		size = y1 - y2
		if size != 0 {
			fmt.Printf("%d %d %d %d", x1+size, y1, x2+size, y2)
		} else {
			fmt.Println("-1")
		}
	} else if y1 == y2 {
		size = x1 - x2
		if size != 0 {
			fmt.Printf("%d %d %d %d", x1, y1+size, x2, y2+size)
		} else {
			fmt.Println("-1")
		}
	} else {
		sizeX := x1 - x2
		sizeY := y1 - y2
		if sizeX == sizeY || sizeX == 0-sizeY {
			fmt.Printf("%d %d %d %d", x1, y2, x2, y1)
		} else {
			fmt.Println("-1")
		}
	}

}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"time"
	"unicode/utf8"
)

// ******************************** CODE STARTS ********************************

var ()

func solve() {
	x1 := readInt()
	y1 := readInt()
	x2 := readInt()
	y2 := readInt()

	if x1 != x2 && y1 != y2 {
		if absInt(x1 - x2) != absInt(y1 - y2) {
			printInt(-1)
			printLine()
		} else {
			printInt(x1)
			printString(" ")
			printInt(y2)
			printString(" ")
			printInt(x2)
			printString(" ")
			printInt(y1)
			printLine()
		}
	} else {
		l := absInt(x1 - x2) + absInt(y1 - y2)
		if x1 == x2 {
			printInt(x1 + l)
			printString(" ")
			printInt(y1)
			printString(" ")
			printInt(x2 + l)
			printString(" ")
			printInt(y2)
			printLine()
		} else {
			printInt(x1)
			printString(" ")
			printInt(y1 + l)
			printString(" ")
			printInt(x2)
			printString(" ")
			printInt(y2 + l)
			printLine()
		}
	}
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	dbg := flag.Bool("dbg", false, "Equals true, if run is in debug mode.")
	opt := flag.Bool("opt", false, "Equals true, if run is in optimized mode.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *opt || *dbg {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
		if *dbg {
			cpuprofile, _ := os.Create("/home/outside/coding/workspace/go/io/cpuprofile.txt")
			pprof.StartCPUProfile(cpuprofile)
			defer cpuprofile.Close()
			defer pprof.StopCPUProfile()
		}
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFLoat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	return p[j].a < p[i].a
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Point struct {
	x, y int
}

var invalid_point = Point{x: -1, y: -1}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func square(p1, p2 Point) (bool, Point, Point) {
	if p1.x == p2.x {
		diff := abs(p1.y - p2.y)
		if diff == 0 {
			return false, invalid_point, invalid_point
		}
		return true, Point{x: p1.x + diff, y: p1.y},
			Point{x: p2.x + diff, y: p2.y}
	}
	if p1.y == p2.y {
		diff := abs(p1.x - p2.x)
		if diff == 0 {
			return false, invalid_point, invalid_point
		}
		return true, Point{x: p1.x, y: p1.y + diff},
			Point{x: p2.x, y: p2.y + diff}
	}
	// We are dealing with diagonal points here
	if abs(p1.x-p2.x) != abs(p1.y-p2.y) {
		return false, invalid_point, invalid_point
	}
	return true, Point{x: p1.x, y: p2.y}, Point{x: p2.x, y: p1.y}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var p1, p2 Point
	fmt.Fscanln(reader, &p1.x, &p1.y, &p2.x, &p2.y)
	ok, p3, p4 := square(p1, p2)
	if !ok {
		fmt.Fprintln(writer, -1)
		return
	}
	fmt.Fprintln(writer, p3.x, p3.y, p4.x, p4.y)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	var x0, y0, x1, y1 int
	fmt.Fscan(reader, &x0, &y0, &x1, &y1)
	if x0 == x1 && y0-y1 != 0 {
		var length int = y0 - y1
		fmt.Println(x0+length, y0, x1+length, y1)
	} else if x0-x1 != 0 && y0 == y1 {
		var length int = x0 - x1
		fmt.Println(x0, y0+length, x1, y1+length)
	} else if x0 != x1 && y0 != y1 && (x0-x1 == y0-y1 || x0-x1 == y1-y0) {
		fmt.Println(x0, y1, x1, y0)
	} else {
		fmt.Println(-1)
	}
}

package main

import (
	"fmt"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1)
	fmt.Scan(&y1)
	fmt.Scan(&x2)
	fmt.Scan(&y2)
	switch {
	case x1 == x2:
		l := y1 - y2
		fmt.Println(x1+l, y1, x2+l, y2)
	case y1 == y2:
		l := x1 - x2
		fmt.Println(x1, y1+l, x2, y2+l)
	case abs(x1-x2) == abs(y1-y2):
		fmt.Println(x1, y2, x2, y1)
	default:
		fmt.Println(-1)
	}
}

package main

import "fmt"

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1, &y1, &x2, &y2)

	r := abs(x2 - x1)
	tmp := abs(y2 - y1)

	if r == 0 {
		r = abs(y2 - y1)
	} else if tmp != 0 && tmp != r {
		fmt.Println(-1)
		return
	}

	if y1 == y2 {
		fmt.Println(x1, y1+r, x2, y1+r)
	} else if x1 == x2 {
		fmt.Println(x1+r, y1, x1+r, y2)
	} else {
		fmt.Println(x1, y2, x2, y1)
	}
}

func abs(x int) int {
	if x < 0 {
		return -1 * x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	x1, y1 := nextInt(), nextInt()
	x2, y2 := nextInt(), nextInt()

	if x1 == x2 {
		dis := abs(y1 - y2)
		println(x1 + dis, y1, x2 + dis, y2)
	}

	if y1 == y2 {
		dis := abs(x1 - x2)
		println(x1, y1 + dis, x2, y2 + dis)
	}

	if abs(x1 - x2) != abs(y1 - y2) {
		println(-1)
		return
	}

	println(x2, y1, x1, y2)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func i(s *bufio.Scanner) int  {
	s.Scan()
	v,_ := strconv.Atoi(s.Text())
	return v
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	x1,y1,x2,y2 := i(s), i(s), i(s), i(s)

	var d, x3, y3, x4, y4 int
	if x1==x2 {
		d = y1 - y2
		x3,y3,x4,y4 = x1+d,y1, x2+d, y2
	} else if y1==y2 {
		d = x1 - x2
		x3,y3,x4,y4 = x1,y1+d, x2, y2+d
	} else {
		x3,y3,x4,y4 = x1,y2,x2,y1
 	}

	fmt.Printf("%d %d %d %d", x3, y3, x4, y4)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Point struct {
	x, y int
}

var invalid_point = Point{x: -1, y: -1}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func square(p1, p2 Point) (bool, Point, Point) {
	if p1.x == p2.x {
		if p1.y == p2.y {
			return false, invalid_point, invalid_point
		}
		return true, Point{x: p1.x + 1, y: p1.y},
			Point{x: p2.x + 1, y: p2.y}
	}
	if p1.y == p2.y {
		if p1.x == p2.x {
			return false, invalid_point, invalid_point
		}
		return true, Point{x: p1.x, y: p1.y + 1},
			Point{x: p2.x, y: p2.y + 1}
	}
	// We are dealing with diagonal points here
	if abs(p1.x-p2.x) != abs(p1.y-p2.y) {
		return false, invalid_point, invalid_point
	}
	return true, Point{x: p1.x, y: p2.y}, Point{x: p2.x, y: p1.y}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var p1, p2 Point
	fmt.Fscanln(reader, &p1.x, &p1.y, &p2.x, &p2.y)
	ok, p3, p4 := square(p1, p2)
	if !ok {
		fmt.Fprintln(writer, -1)
		return
	}
	fmt.Fprintln(writer, p3.x, p3.y, p4.x, p4.y)
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Point struct {
	x, y int
}

var invalid_point = Point{x: -1, y: -1}
const max_coord = 1000

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func square(p1, p2 Point) (bool, Point, Point) {
	if p1.x == p2.x {
		if p1.y == p2.y {
			return false, invalid_point, invalid_point
		}
		var a, b Point
		if p1.y > p2.y {
			a, b = p1, p2
		} else {
			b, a = p1, p2
		}
		if a.x == max_coord {
			return true, Point{x: -max_coord, y: a.y},
				Point{x: -max_coord, y: b.y}
		}
		return true, Point{x: max_coord, y: b.y},
			Point{x: max_coord, y: a.y}
	}
	if p1.y == p2.y {
		if p1.x == p2.x {
			return false, invalid_point, invalid_point
		}
		var a, d Point
		if p1.x > p2.x {
			d, a = p1, p2
		} else {
			a, d = p1, p2
		}
		if a.y == max_coord {
			return true, Point{x: a.x, y: -max_coord},
				Point{x: d.x, y: -max_coord}
		}
		return true, Point{x: a.x, y: max_coord},
			Point{x: d.x, y: max_coord}
	}
	// We are dealing with diagonal points here
	if abs(p1.x - p2.x) != abs(p1.y - p2.y) {
		return false, invalid_point, invalid_point
	}
	var a, c Point
	if p1.x > p2.x {
		c, a = p1, p2
	} else {
		c, a = p2, p1
	}
	return true, Point{x: a.x, y: c.y}, Point{x: c.x, y: a.y}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var p1, p2 Point
	fmt.Fscanln(reader, &p1.x, &p1.y, &p2.x, &p2.y)
	ok, p3, p4 := square(p1, p2)
	if !ok {
		fmt.Fprintln(writer, -1)
		return
	}
	fmt.Fprintln(writer, p3.x, p3.y, p4.x, p4.y)
}

package main

import (
	"fmt"
)

func main() {
	var x1, y1, x2, y2 int
	fmt.Scan(&x1, &y1, &x2, &y2)
	baseX, baseY := x1, y1
	x1, y1 = 0, 0
	x2, y2 = x2-baseX, y2-baseY
	var x3, x4, y3, y4 int
	poss := true
	if x1 == x2 {
		y := y1 - y2
		if y < 0 {
			y = -y
		}
		x3, y3 = y, y2
		x4, y4 = y, y1
	} else if y1 == y2 {
		x := x1 - x2
		if x < 0 {
			x = -x
		}
		x3, y3 = x1, x
		x4, y4 = x2, x
	} else if x2 == y2 {
		x3, y3 = x1, x2
		x4, y4 = x2, y1
	} else {
		poss = false
	}
	if poss {

		fmt.Println(x3+baseX, y3+baseY, x4+baseX, y4+baseY)
	} else {
		fmt.Println("-1")
	}
}


package main

import (
	"fmt"
	"bufio"
	"os"
)

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func abs(a int64) int64 {
    if a >= 0 { return a}
    return -a
}

func min(a, b int64) int64{
    if a < b { return a}
    return b
}
func max(a, b int64) int64{
    if a > b { return a}
    return b
}
func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
    }

    if check(a) {
        fmt.Fprintln(output, "YES")
    } else {
        fmt.Fprintln(output, "NO")
    }
}

func check(a []int) bool {
    if len(a) <= 1 { return true }

    last := len(a) -1
    if a[0] == a[last] { return check(a[1:last]) }

    if checkWithout(a[1:], a[0]) { return true }
    return checkWithout(a[:last], a[last])
}

func checkWithout(a []int, w int) bool {
    l, r := 0, len(a) -1
    for l < r {
        if a[l] == w {
            l++
            continue
        }
        if a[r] == w {
            r--
            continue
        }
        if a[l] != a[r] { return false }
        l++; r--
    }
    return true
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		l, r := 0, n-1
		isValid := true
		d := -1
		// go from left-right
		for l < r {
			if arr[l] == arr[r] {
				l++
				r--
			} else if d < 0 {
				d = arr[r]
				r--
			} else if arr[l] == d && arr[r] == d {
				l++
				r--
			} else if arr[r] == d {
				r--
			} else if arr[l] == d {
				l++
			} else {
				isValid = false
				break
			}
		}

		if !isValid {
			l, r := 0, n-1
			isValid = true
			d := -1
			// go from left-right
			for l < r {
				if arr[l] == arr[r] {
					l++
					r--
				} else if d < 0 {
					d = arr[l]
					l++
				} else if arr[l] == d && arr[r] == d {
					l++
					r--
				} else if arr[r] == d {
					r--
				} else if arr[l] == d {
					l++
				} else {
					isValid = false
					break
				}
			}
		}

		if !isValid {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}