package main

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

const (
    N_MAX = 5000
)

func Init() {
}

func Solve(io *FastIO) {
    N := io.NextInt()
    A := io.NextIntArray(N)

    all := NewFreqMap()
    for _, v := range A {
        all.Increment(v)
    }

    best := make([]int, N)
    prev := 0
    for i := range A {
        best[i] = Max(best[i], prev)
        out := all.Clone()
        has := NewFreqMap()
        for j := i; j < N; j++ {
            out.Decrement(A[j])
            has.Increment(A[j])
            if out.Size + has.Size == all.Size {
                best[j] = Max(best[j], prev + has.XorScore)
            }
        }
        prev = best[i]
    }
    fmt.Println(best[N - 1])
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

type FreqMap struct {
    Freq [N_MAX + 1]int
    Size int
    XorScore int
}

func NewFreqMap() *FreqMap {
    return &FreqMap{}
}

func (this *FreqMap) Increment(k int) {
    if (this.Freq[k] == 0) {
        this.XorScore ^= k
        this.Size++
    }
    this.Freq[k]++
}

func (this *FreqMap) Decrement(k int) {
    if this.Freq[k] == 1 {
        this.XorScore ^= k
        this.Size--
    }
    this.Freq[k]--
}

func (this FreqMap) Clone() *FreqMap {
    freq := NewFreqMap()
    for k, v := range this.Freq {
        freq.Freq[k] = v
    }
    freq.Size = this.Size
    freq.XorScore = this.XorScore
    return freq
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

const (
  N_MAX = 5001
  INF = 123456789
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextIntArrayOffset(N, 1)

	L := make([]int, N_MAX)
	R := make([]int, N_MAX)

	for i := 1; i <= N; i++ {
	  R[A[i]] = i
	}
	for i := N; i > 0; i-- {
	  L[A[i]] = i
	}

	cost := make([]int, N + 1)
	end := make([]int, N + 1)

	for i := 1; i <= N; i++ {
	  if L[A[i]] != i {
	    cost[i] = -INF
	    continue
	  }
	  far := R[A[i]]
	  idx := i
	  xor := A[i]
	  seen := make(map[int]bool)
	  seen[A[i]] = true
	  for idx < far {
	    if L[A[idx]] < i {
	      xor = -INF
	      break
	    }
	    if !seen[A[idx]] {
	      seen[A[idx]] = true
	      xor ^= A[idx]
	      far = Max(far, R[A[idx]])
	    }
	    idx++
	  }
	  cost[i] = xor
	  end[i] = far
	}

// 	fmt.Println(end)
// 	fmt.Println(cost)

	best := make([]int, N + 1)
	bestSoFar := 0
	for i := 1; i <= N; i++ {
	  best[end[i]] = Max(best[end[i]], bestSoFar, bestSoFar + cost[i])
	  bestSoFar = Max(bestSoFar, best[i])
	}
// 	fmt.Println(best)
	io.Println(bestSoFar)
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

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

func main() {
	b1688(os.Stdin, os.Stdout)
}

func b1688(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var x int

	loop:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		oc := 0
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a[i] = x
			if x%2 == 0 {
				oc++
			}
		}
		if oc == 0 {
			Fprintln(out, 0)
			continue loop
		}
		if oc < n {
			Fprintln(out, oc)
			continue loop
		}

		sort.Ints(a)
		mi := 32
		for _, v := range a {
			t := 0
			for v%2 == 0 {
				v /= 2
				t++
				if t > mi {
					break
				}
			}
			if t < mi {
				mi = t
			}
		}

		Fprintln(out, oc + mi-1)
	}
}

package main

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

type CF1688B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1688B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1688B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1688B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1688B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1688B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1688B
Date: 9/1/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1688/B
Problem: CF1688B
**/
func (in *CF1688B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		odd := 0
		even := 0
		evenIndex := -1
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i]%2 == 0 {
				if evenIndex == -1 {
					evenIndex = i
				}
				if arr[evenIndex] > arr[i] {
					evenIndex = i
				}
				even++
			} else {
				odd++
			}
		}

		ans := 0
		if odd > 0 {
			ans = even
		} else {
			count := -1
			for i := 0; i < n; i++ {
				if arr[i]%2 == 0 {
					aux := 0
					for arr[i]%2 == 0 {
						arr[i] /= 2
						aux++
					}
					if count == -1 {
						count = aux
					}
					if aux < count {
						count = aux
					}
				}

			}
			ans = count + n - 1
		}
		fmt.Println(ans)
	}
}

func NewCF1688B(r *bufio.Reader) *CF1688B {
	return &CF1688B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1688B(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for e := 0; e < t; e++ {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		f1, f2 := false, true
		kn := 0
		pos := 0
		km := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			if a[i]%2 != 0 {
				f1 = true
			}

			if a[i]%2 == 0 {
				p := a[i]
				kl := 0
				for u := 0; ; u++ {
					kl++
					p /= 2
					if p%2 != 0 {
						break
					}
				}
				if f2 || (kl < km) {
					pos = i
					km = kl
				}
				f2 = false
				kn++
			}
			//fmt.Println(km, "////*")
		}
		if f1 && f2 {
			fmt.Println(0)
		} else {
			if f1 {
				fmt.Println(kn)
			} else {
				k := 0
				for {
					a[pos] /= 2
					k++
					//fmt.Println(pos, "//")
					if a[pos]%2 != 0 {
						fmt.Println(k + kn - 1)
						break
					}
				}
			}
		}

	}
}

package main

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

/*
6
1
2
1
3
2
4 6
3
8 12 13
4
12 8 4 10
4
10 20 30 4
---
1
0
2
2
4
4

1
5
16 16 16 16 1
---
4

*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	oddCnt := 0

	minRed := maxInt

	for i := range a {
		scanf("%d", &a[i])

		if a[i]%2 != 0 {
			oddCnt++
			minRed = 1
		} else {
			num := a[i]

			red := 0

			for num%2 == 0 {
				num /= 2
				red++
			}

			minRed = min(minRed, red)
		}
	}
	scanf("\n")

	ans := 0

	evenCnt := n - oddCnt

	if evenCnt > 0 {
		ans = evenCnt - 1 + minRed
	}

	fmt.Fprintln(writer, ans)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"math/bits"
	"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)
		var e int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			if arr[i]%2 == 0 {
				e++
			}
		}

		if e != n {
			fmt.Fprintln(out, e)
		} else {
			g := math.MaxInt32
			for _, v := range arr {
				x := bits.TrailingZeros(uint(v))
				if x < g {
					g = x
				}
			}
			fmt.Fprintln(out, g+n-1)
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		free := 0
		odd := 10000
		for i := 0; i < n; i++ {
			var tmp uint
			fmt.Fscan(scanner, &tmp)
			co := 0
			if tmp%2 == 0 {
				for tmp%2 == 0 {
					co++
					tmp >>= 1
				}
				if co < odd {
					odd = co
				}
			} else {
				odd = 0
				free++
			}
		}
		if free != 0 {
			fmt.Fprintln(writer, n-free)
		} else {
			fmt.Fprintln(writer, n-1+odd)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); A := gis(N)
		ocnt,ecnt,mintz := 0,0,999
		for _,a := range A { mintz = min(mintz,bits.TrailingZeros(uint(a))); if a & 1 == 0 { ecnt++ } else { ocnt++ } }
		ans := 0; if ocnt > 0 { ans = ecnt } else { ans = ecnt - 1 + mintz }
		fmt.Fprintln(wrtr,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = (x << 1) + (x << 3) + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = (x << 1) + (x << 3) + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() {
	n := ri()
	var ev, mb int = 0, 1024
	for i := 0; i < n; i++ {
		z := ri()
		if (z & 1) == 0 {
			ev++
			zz := z & -z
			mt := 0
			for ; zz != 1; zz >>= 1 {
				mt++
			}
			if mb > mt {
				mb = mt
			}
		}
	}
	if ev < n {
		myio.Println(ev)
	} else if ev > 0 {
		myio.Println(mb + ev - 1)
	} else {
		myio.Println(0)
	}
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

// This example demonstrates an integer heap built using the heap interface.

// An IntHeap is a min-heap of ints.
/* type IntHeap []int64

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int64))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}
*/

// // This example inserts several ints into an Int, checks the minimum,
// // and removes them in order of priority.
// func main() {
// 	h := &IntHeap{2, 1, 5}
// 	heap.Init(h)
// 	heap.Push(h, 3)
// 	fmt.Printf("minimum: %d\n", (*h)[0])
// 	for h.Len() > 0 {
// 		fmt.Printf("%d ", heap.Pop(h))
// 	}
// }

func A2() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		ans := int(1e9 + 7)
		var e int
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		for i := 0; i < n; i++ {
			if a[i]%2 == 0 {
				e++
				var cnt int
				for a[i]%2 == 0 {
					cnt++
					a[i] /= 2
				}
				if cnt < ans {
					ans = cnt
				}
			} else {

			}
		}
		if e != n {
			Fprintln(out, e)
		} else {
			Fprintln(out, ans+(e-1))
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A2() }

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	cnt := 0
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		if nums[i] % 2 == 0 {
			cnt++
		}
	}
	if cnt != n {
		fmt.Fprintln(w, cnt)
	} else {
		m := 32
		for i := range nums {
			for j:=0;j<32;j++ {
				if nums[i] & (1 << j) != 0 {
					m = min(m, j)
					break
				}
			}
		}
		fmt.Fprintln(w, m + n - 1)
	}

}

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

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var tc int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		var n int
		fmt.Fscan(in, &n)
		var evencnt, minpow int
		minpow = 999
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(in, &a)
			if a%2 == 0 {
				evencnt++
			}
			p := bits.TrailingZeros(uint(a))
			if p < minpow {
				minpow = p
			}
		}
		if minpow == 0 {
			fmt.Fprintln(out, evencnt)
		} else {
			fmt.Fprintln(out, minpow+evencnt-1)
		}
	}
}

package main

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

type CF1688B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1688B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1688B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1688B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1688B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1688B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1688B
Date: 9/1/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1688/B
Problem: CF1688B
**/
func (in *CF1688B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		odd := 0
		even := 0
		evenIndex := -1
		count := 20000000000
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i] > count {
				count = arr[i] + 1
			}
			if arr[i]%2 == 0 {
				if evenIndex == -1 {
					evenIndex = i
				}
				if arr[evenIndex] > arr[i] {
					evenIndex = i
				}
				even++
			} else {
				odd++
			}
		}

		ans := 0
		if odd > 0 {
			ans = n - odd
		} else {

			for i := evenIndex; i < n; i++ {
				if arr[i]%2 == 0 {
					aux := 0
					for arr[i]%2 == 0 {
						arr[i] /= 2
						aux++
					}
					if aux < count {
						count = aux
					}
				}

			}
			ans += count + n - 1
		}
		fmt.Println(ans)
	}
}

func NewCF1688B(r *bufio.Reader) *CF1688B {
	return &CF1688B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1688B(bufio.NewReader(os.Stdin)).Run()
}

package main

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

type CF1688B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1688B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1688B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1688B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1688B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1688B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1688B
Date: 9/1/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1688/B
Problem: CF1688B
**/
func (in *CF1688B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		odd := 0
		even := 0
		evenIndex := -1
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i]%2 == 0 {
				if evenIndex == -1 {
					evenIndex = i
				}
				if arr[evenIndex] > arr[i] {
					evenIndex = i
				}
				even++
			} else {
				odd++
			}
		}

		ans := 0
		if odd > 0 {
			ans = n - odd
		} else {
			for arr[evenIndex]%2 == 0 {
				arr[evenIndex] /= 2
				ans++
			}
			ans += n - 1
		}
		fmt.Println(ans)
	}
}

func NewCF1688B(r *bufio.Reader) *CF1688B {
	return &CF1688B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1688B(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for e := 0; e < t; e++ {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		f1, f2 := false, true
		kn := 0
		pos := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			if a[i]%2 != 0 {
				f1 = true
			}
			if a[i]%2 == 0 {
				if f2 || a[i] < a[pos] {
					pos = i
				}
				f2 = false
				kn++
			}
		}
		if f1 && f2 {
			fmt.Println(0)
		} else {
			if f1 {
				fmt.Println(kn)
			} else {
				k := 0
				for {
					a[pos] /= 2
					k++
					if a[pos]%2 != 0 {
						fmt.Println(k + kn - 1)
						break
					}
				}
			}
		}

	}
}

package main

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

/*
6
1
2
1
3
2
4 6
3
8 12 13
4
12 8 4 10
4
10 20 30 4
---
1
0
2
3
4
4

4 6 -> 10 -> 5
8 12 13 -> 20 -> 10 -> 5

8 -> 4 -> 2 -> 1

12 8 4 10 -> 34 -> 17

8 16 32 64 -> 100 -> 50 -> 25

2 2 2 2 2 -> 10 -> 5 == 5ops
4 4 4 4 4 -> 20 -> 10 -> 5 == 6ops

10 20 30 4 -3> 64 -> 32 -> 16 -> 8 -> 4 -> 2 -> 1 == 9ops
5  10 15 2
    5    1

*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	a := make([]int, n)

	oddCnt := 0

	minRed := maxInt

	for i := range a {
		scanf("%d", &a[i])

		if a[i]%2 != 0 {
			oddCnt++
		} else {
			num := a[i]

			red := 0

			for num%2 == 0 {
				num /= 2
				red++
			}

			minRed = min(minRed, red)
		}
	}
	scanf("\n")

	ans := 0

	evenCnt := n - oddCnt

	if evenCnt > 0 {
		ans = evenCnt - 1 + minRed
	}

	fmt.Fprintln(writer, ans)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"sort"
)

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)
		var e int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			if arr[i]%2 == 0 {
				e++
			}
		}

		if e != n {
			fmt.Fprintln(out, e)
		} else {
			sort.Ints(arr)
			g := bits.TrailingZeros(uint(arr[0]))
			fmt.Fprintln(out, g+n-1)
		}
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF294B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	b := [3][]int{}
	var n, t, w, all, s int
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		Fscan(in, &t, &w)
		b[t] = append(b[t], w)
		all += w
	}
	for i := 1; i < 3; i++ {
		sort.Sort(sort.Reverse(sort.IntSlice(b[i])))
		b[i] = append(b[i], 0)
	}
	ans := int(1e9)
	for i, v := range b[1] {
		ss := s
		for j, w := range b[2] {
			b := i + j*2
			top := all - ss
			if top <= b && b < ans {
				ans = b
			}
			ss += w
		}
		s += v
	}
	Fprint(out, ans)
}

func main() { CF294B(os.Stdin, os.Stdout) }

package main

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

// github.com/EndlessCheng/codeforces-go
func CF294B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	b := [3][]int{}
	var n, t, w, all, s int
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		Fscan(in, &t, &w)
		b[t] = append(b[t], w)
		all += w
	}
	for i := 1; i < 3; i++ {
		sort.Sort(sort.Reverse(sort.IntSlice(b[i])))
		b[i] = append(b[i], 0)
	}
	ans := int(1e9)
	for i, v := range b[1] {
		ss := s
		for j, w := range b[2] {
			if t := i + j*2; t >= all-ss && t < ans {
				ans = t
			}
			ss += w
		}
		s += v
	}
	Fprint(out, ans)
}

func main() { CF294B(os.Stdin, os.Stdout) }


package main

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

func A0() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		var x int
		Fscan(in, &n, &x)
		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		for i := n; i < 2*n; i++ {
			if a[i]-a[i-n] < x {
				Fprintln(out, "No")
				return
			}
		}

		Fprintln(out, "Yes")
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A0() }

package main

import (
	"fmt"
	"sort"
)

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

	for tt := 0; tt < T; tt++ {
		var N, X int
		fmt.Scanf("%d %d\n", &N, &X)

		var arr []int
		var lim int = N << 1

		for i := 0; i < lim; i++ {
			var c int

			if i != lim - 1 {
				fmt.Scanf("%d", &c)
			} else {
				fmt.Scanf("%d\n", &c)
			}

			arr = append(arr, c)
		}

		sort.Ints(arr)

        var done bool = false

		for i := 0; i < N; i++ {
			if arr[i + N] - arr[i] < X {
				fmt.Println("NO")
                done = true
                break
			}
		}

        if done {
            continue
        }

		fmt.Println("YES")
	}
}
//

package main

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

func solve() {
	n := get()
	x := get()
	var arr []int
	for i := 0; i < 2*n; i++ {
		arr = append(arr, get())
	}
	sort.Ints(arr)
	for i := 0; i < n; i++ {
		if arr[i+n]-arr[i] < x {
			puts("NO")
			line()
			return
		}
	}
	puts("YES")
	line()
}

const (
	maxBufSize = 10000000
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)
	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := get()
	for i := 0; i < t; i++ {
		solve()
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func gets() string {
	in.Scan()
	return in.Text()
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func puts(s string) {
	out.WriteString(s)
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES")
	line()
}

func no() {
	puts("NO")
	line()
}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

package main

import (
	"fmt"
	"sort"
)

func solve() {
	var n int
	var x int
	fmt.Scan(&n)
	fmt.Scan(&x)
	var arr []int
	for i := 0; i < 2*n; i++ {
		var a int
		fmt.Scan(&a)
		arr = append(arr, a)
	}
	sort.Ints(arr)
	for i := 0; i < n; i++ {
		if arr[i+n]-arr[i] < x {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

const N = 1000

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var t, n, x int
var check bool

func main() {
	defer out.Flush()
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &x)
		arr := make([]int, n*2)
		check = false
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(in, &arr[j])
		}
		sort.Ints(arr)

		for j := 0; j < n; j++ {
			if arr[j+n]-arr[j] < x {
				check = true
				break
			}
		}
		if check {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

const N = 1000

var t, n, x int
var check bool

func main() {
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		fmt.Scan(&x)
		arr := make([]int, n*2)
		check = false
		for j := 0; j < 2*n; j++ {
			fmt.Scan(&arr[j])
		}
		sort.Ints(arr)

		for j := 0; j < n; j++ {
			if arr[j+n]-arr[j] < x {
				check = true
				break
			}
		}
		if check {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

func main() {
	CF1043A(os.Stdin, os.Stdout)
}

func CF1043A(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n, diff int64
		fmt.Fscan(r, &n, &diff)
		arr := make([]int, n*2)
		for i := int64(0); i < 2*n; i++ {
			fmt.Fscan(r, &arr[i])
		}
		sort.Ints(arr)
		can := true
		for i := int64(0); i < n; i++ {
			if int64(arr[i+n]-arr[i]) < diff {
				can = false
				break
			}
		}
		if can {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}

	}

}

package main
import "fmt"
import "sort"

func main() {

    var testCase int
    fmt.Scan(&testCase)
    for testCase > 0 {

        var n, x int
        var nums []int

        fmt.Scan(&n)
        fmt.Scan(&x)
        for i:=0; i<n*2; i++ {
            var v int
            fmt.Scan(&v)
            nums = append(nums, v)
        }
        sort.Ints(nums)
        res := "YES"
        for i:=0; i<n; i++ {
            if nums[i+n] - nums[i] < x {
                res = "NO"
                break
            }
        }

        fmt.Println(res)

        testCase--
    }
}

// 1705A. Mark the Photographer
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, x int
		fmt.Fscan(reader, &n, &x)
		h := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			fmt.Fscan(reader, &h[i])
		}
		sort.Ints(h)
		possible := true
		for i := 0; i < n; i++ {
			if h[n+i]-h[i] < x {
				possible = false
				break
			}
		}
		if possible {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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, x int
		fmt.Fscan(in, &n, &x)
		aa := make([]int, n*2)
		for i := 0; i < n*2; i++ {
			fmt.Fscan(in, &aa[i])
		}

		sort.Ints(aa)
		f := true
		for i := 0; i < n; i++ {
			if aa[i+n]-aa[i] < x {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "sort"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,c int
		fmt.Fscan(in,&n,&c)
		list:= make([]int,n*2)
		for j:=0;j<n*2;j++{
			fmt.Fscan(in,&list[j])
		}
		sort.Ints(list)
		for j:=0;j<n;j++{
			if list[j+n]-list[j] < c {
				fmt.Fprintln(out,"NO")
				goto out
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, x := readTwoNums(reader)
		heights := readNNums(reader, 2*n)
		res := solve(heights, x)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(heights []int, x int) bool {
	sort.Ints(heights)
	n := len(heights) / 2
	for i := 0; i < n; i++ {
		if heights[i+n]-heights[i] < x {
			return false
		}
	}
	return true
}

package main

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

const MOD int64 = 1000000007

var n, x int

var h[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &x)

		h = make([]int, 2 * n)

		for j := 0; j < 2 * n; j++ {
			fmt.Fscan(read, &h[j])
		}

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() string {
	sort.Ints(h)

	for i := 0; i < n; i++ {
		if h[i] + x > h[i + n] {
			return "NO"
		}
	}
	return "YES"
}

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()

	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		if solve() {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

func solve() bool {
	var n, x int
	fmt.Fscan(in, &n, &x)
	a := make([]int, n*2)
	for i := 0; i < n*2; i++ {
		fmt.Fscan(in, &a[i])
	}
	sort.Ints(a)
	for i := 0; i < n; i++ {
		if a[n+i] - a[i] < x {
			return false
		}
	}
	return true
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()
	var t, n, x int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &n, &x)
		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Ints(a)
		flag := true
		for i := 0; i < n; i++ {
			if a[i]+x > a[i+n] {
				flag = false
				break
			}
		}
		if flag {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, x int
	h       []int
)

func solve(n, x int, h []int) string {
	sort.Slice(h, func(i, j int) bool {
		return h[i] < h[j]
	})
	for i := 0; i < n; i++ {
		if h[i+n]-h[i] < x {
			return "NO"
		}
	}
	return "YES"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &x)
		h = make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			fmt.Fscan(reader, &h[i])
		}
		fmt.Println(solve(n, x, h))
	}
}

package main

import (
	"fmt"
	"sort"
)

func solve(arr []int, x int) bool {
	sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
	n := len(arr) / 2
	for i := 0; i < n; i++ {
		if arr[i+n]-arr[i] < x {
			return false
		}
	}
	return true
}

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

	for i := 0; i < k; i++ {
		var n, x int
		fmt.Scan(&n, &x)
		arr := make([]int, n*2)
		for i := range arr {
			fmt.Scan(&arr[i])
		}
		if solve(arr, x) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

type CF1705A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1705A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1705A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1705A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1705A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1705A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1705A
Date: 20/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1705/A
Problem: CF1705A
**/
func (in *CF1705A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, x := in.NextInt(), in.NextInt()
		arr := make([]int, 2*n)
		for i := 0; i < len(arr); i++ {
			arr[i] = in.NextInt()
		}

		sort.Ints(arr)
		ans := true
		for i := 0; i < n; i++ {
			if arr[i+n]-arr[i] < x {
				ans = false
				break
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func NewCF1705A(r *bufio.Reader) *CF1705A {
	return &CF1705A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1705A(bufio.NewReader(os.Stdin)).Run()
}

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

const NL = '\n'

func main() {
	defer writer.Flush()
	var t, n, x, j int
	var isOkay uint8
	var g string
	scanf("%d\n", &t)
	j = 0
	for j < t {
		isOkay = 0
		scanf("%d %d\n", &n, &x)
		g, _ = reader.ReadString(NL)
		a := StrToIntSlice(g)
		sort.Ints(a)
		for i := 0; i < n; i++ {
			if distOk(a[i], a[n+i], x) {
				isOkay = 1 - isOkay
				break
			}
		}
		printf("%s\n", yesNoMap(isOkay))
		j++
	}
}
func split(str string) []string {
	return strings.Fields(str)
}

func Atoi(str string) int {
	out, _ := strconv.ParseInt(str, 10, 64)
	return int(out)
}

func StrToIntSlice(str string) []int {
	sarr := split(str)
	iarr := make([]int, len(sarr))
	for i := range sarr {
		iarr[i] = Atoi(sarr[i])
	}
	return iarr
}

func distOk(f, b, minDist int) bool {
	return (b - f) < minDist
}

func yesNoMap(b uint8) string {
	return map[uint8]string{0: "YES", 1: "NO"}[b]
}

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

package main

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

var reader *bufio.Reader

// 1705A
func main() {
	var (
		t int
		n int
		x int
	)

	reader = bufio.NewReader(os.Stdin)

	_, _ = fmt.Fscanln(reader, &t)

	for i := 0; i < t; i++ {
		_, _ = fmt.Fscanln(reader, &n, &x)
		n = n * 2

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

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

		var failed = false
		for i := 0; i < n/2; i++ {
			a := heights[n/2+i]
			b := heights[i]
			if a-b < x {
				fmt.Println("NO")
				failed = true
				break
			}
		}

		if failed {
			continue
		}

		fmt.Println("YES")
	}
}

package main

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

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

	n := readInt(in)
	for i := 0; i < n; i++ {
		solution(in, out)
	}
}

func solution(in *bufio.Reader, out *bufio.Writer) {
	v := readArrInt(in)
	n := v[0]
	x := v[1]
	arr := readArrInt(in)

	sort.Ints(arr)

	for i := 0; i < n; i++ {
		if arr[i+n]-arr[i] < x {
			out.WriteString("NO\n")
			return
		}
	}

	out.WriteString("YES\n")
}

func Max(sum int, sum2 int) int {
	if sum > sum2 {
		return sum
	}
	return sum2

}

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	return line
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

func solve() {
	n := get()
	x := get()
	a := make([]int, 2*n)
	for i := range a {
		a[i] = get()
	}
	sort.Ints(a)
	for i := 0; i < n; i++ {
		if a[i]+x > a[i+n] {
			no()
			return
		}
	}
	yes()
}

const (
	once       = false
	maxBufSize = 10000000
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func gets() string {
	in.Scan()
	return in.Text()
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func puts(s string) {
	out.WriteString(s)
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES")
	line()
}

func no() {
	puts("NO")
	line()
}

//func putf(x float64) {
//	out.WriteString(strconv.FormatFloat(x))
//}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

package main

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

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n, k int
		fmt.Fscan(r, &n, &k)
		b := make([]int, 2*n)
		for i := range b {
			fmt.Fscan(r, &b[i])
		}
		w1 := do(n, k, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n, k int, b []int) string {
	sort.Ints(b)
	for i := 0; i < n; i++ {
		if b[i+n]-b[i] < k {
			return "NO"
		}
	}
	return "YES"
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, x int
	fmt.Fscan(rr, &n, &x)
	nums := make([]int, 2*n)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
	}
	sort.Ints(nums)
	for i:=0;i<n;i++ {
		if nums[i] + x > nums[i+n] {
			fmt.Fprintln(ww, "NO")
			return
		}
	}
	fmt.Fprintln(ww, "YES")
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"fmt"
	"sort"
)

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

	for tt := 0; tt < T; tt++ {
		var N, X int
		fmt.Scanf("%d %d\n", &N, &X)

		var arr []int
		var lim int = N << 1

		for i := 0; i < lim; i++ {
			var c int

			if i != lim - 1 {
				fmt.Scanf("%d ", &c)
			} else {
				fmt.Scanf("%d\n", &c)
			}

			arr = append(arr, c)
		}

		sort.Ints(arr)

        var done bool = false

		for i := 0; i < N; i++ {
			if arr[i + N] - arr[i] < X {
				fmt.Println("NO")
                done = true
                break
			}
		}

        if done {
            continue
        }

		fmt.Println("YES")
	}
}

// 2
package main

import (
	"fmt"
	"sort"
)

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

	outer: for tt := 0; tt < T; tt++ {
		var N, X int
		fmt.Scanf("%d %d\n", &N, &X)

		var arr []int
		var lim int = N << 1

		for i := 0; i < lim; i++ {
			var c int

			if i != lim - 1 {
				fmt.Scanf("%d ", &c)
			} else {
				fmt.Scanf("%d\n", &c)
			}

			arr = append(arr, c)
		}

		sort.Ints(arr)

		for i := 0; i < N; i++ {
			if arr[i + N] - arr[i] < X {
				fmt.Println("NO")
				goto outer
			}
		}

		fmt.Println("YES")
	}
}

package main

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

func solve() {
	n := get()
	x := get()
	var arr []int
	for i := 0; i < 2*n; i++ {
		arr = append(arr, get())
	}
	sort.Ints(arr)
	for i := 0; i < n; i++ {
		if arr[i+n]-arr[i] < x {
			puts("NO")
			line()
			return
		}
	}
	puts("YES")
	line()
}

const (
	maxBufSize = 10000000
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)
	out = bufio.NewWriter(os.Stdout)
	// defer out.Flush()
	t := get()
	for i := 0; i < t; i++ {
		solve()
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func gets() string {
	in.Scan()
	return in.Text()
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func puts(s string) {
	out.WriteString(s)
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES")
	line()
}

func no() {
	puts("NO")
	line()
}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

/******************************************************************************

                            Online Go Lang Compiler.
                Code, Compile, Run and Debug Go Lang program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

package main
import "fmt"
import "sort"

func main() {

    var testCase int
    fmt.Scan(&testCase)
    for testCase > 0 {

        var n, x int
        var nums []int

        fmt.Scan(&n)
        fmt.Scan(&x)
        for i:=0; i<n*2; i++ {
            var v int
            fmt.Scan(&v)
            nums = append(nums, v)
        }
        sort.Ints(nums)
        if nums[n]-nums[0] < x {
            fmt.Println("NO")
        } else {
            fmt.Println("YES")
        }

        testCase--
    }
}

// 1705A. Mark the Photographer
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, x int
		fmt.Fscan(reader, &n, &x)
		h := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			fmt.Fscan(reader, &h[i])
		}
		sort.Ints(h)
		if h[n]-h[0] >= x {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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, j int
		fmt.Fscan(in, &n, &j)
		aa := make([]int, n*2)
		for i := 0; i < n*2; i++ {
			fmt.Fscan(in, &aa[i])
		}

		sort.Ints(aa)
		f := true
		for i := 0; i < n/2; i++ {
			if aa[i+n]-aa[i] < j {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}


package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"log"
	"os"
)

func main() {
	var (
		n, k int
		s, l int64
	)

	if _, err := fmt.Fscanf(os.Stdin, "%d %d\n", &n, &k); err != nil {
		log.Fatal(err)
	}

	var (
		pq  = IntHeap{}
		in  = bufio.NewScanner(os.Stdin)
		out = bufio.NewWriter(os.Stdout)
	)

	heap.Init(&pq)

	for i := 0; i < n; i++ {
		in.Scan()
		if err := in.Err(); err != nil {
			log.Fatal("reading standard input:", err)
		}
		if _, err := fmt.Sscanf(in.Text(), "%d %d\n", &s, &l); err != nil {
			log.Fatal(err)
		}
		if pq.Len() == k {
			if pq[0] > s {
				s = pq[0]
			}
			pq[0] = s + l
			heap.Fix(&pq, 0)
		} else {
			heap.Push(&pq, s+l)
		}
		fmt.Fprintln(out, s+l)
	}

	out.Flush()
}

// An IntHeap is a min-heap of ints.
type IntHeap []int64

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int64))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

package main

import (
    "container/heap"

    "bufio"
    "os"
    "strconv"
)

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

func ReadInt64() int64 {
    scanner.Scan()
    ans, _ := strconv.ParseInt(scanner.Text(), 0, 64)
    return ans
}

func Print64Ints(ints ...int64) {
    for _, value := range ints {
        writer.WriteString(strconv.FormatInt(value, 10))
        writer.WriteByte(' ')
    }
}

type IntHeap []int64

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
    *h = append(*h, x.(int64))
}

func (h *IntHeap) Pop() interface{} {
    old := *h
    n := len(old)
    x := old[n-1]
    *h = old[0 : n-1]
    return x
}

func main() {
    defer writer.Flush()
    scanner.Split(bufio.ScanWords)
    videos, servers := ReadInt64(), ReadInt64()

    h := make(IntHeap, servers)
    heap.Init(&h)

    for videos > 0 {
        videos--
        start, length := ReadInt64(), ReadInt64()
        serv := heap.Pop(&h).(int64)
        if serv > start {
            serv = serv + length
        } else {
            serv = start + length
        }
        Print64Ints(serv)
        writer.WriteByte('\n')
        heap.Push(&h, serv)
    }
}

package main

import (
    "container/heap"

    "bufio"
    "os"
    "strconv"
)

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 PrintInts(ints ...int) {
    for _, value := range ints {
        writer.WriteString(strconv.Itoa(value))
        writer.WriteByte(' ')
    }
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
    *h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
    old := *h
    n := len(old)
    x := old[n-1]
    *h = old[0 : n-1]
    return x
}

func main() {
    defer writer.Flush()
    scanner.Split(bufio.ScanWords)
    videos, servers := ReadInt32(), ReadInt32()

    h := make(IntHeap, servers)
    heap.Init(&h)
    //heap.Push(&h, 3)
    //PrintInts((h)[0])

    for videos > 0 {
        videos--
        start, length := ReadInt32(), ReadInt32()
        serv := heap.Pop(&h).(int)
        if serv > start {
            serv = serv + length
        } else {
            serv = start + length
        }
        PrintInts(serv)
        writer.WriteByte('\n')
        heap.Push(&h, serv)
    }
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"log"
	"os"
)

func main() {
	var (
		n, k int
		s, l int
	)

	if _, err := fmt.Fscanf(os.Stdin, "%d %d\n", &n, &k); err != nil {
		log.Fatal(err)
	}

	var (
		pq  = &IntHeap{}
		out = bufio.NewWriter(os.Stdout)
	)

	heap.Init(pq)

	for i := 0; i < n; i++ {
		if _, err := fmt.Fscanf(os.Stdin, "%d %d\n", &s, &l); err != nil {
			log.Fatal(err)
		}
		if pq.Len() == k {
			if ns := heap.Pop(pq).(int); ns > s {
				s = ns
			}
		}
		heap.Push(pq, s+l)
		fmt.Fprintln(out, s+l)
	}

	out.Flush()
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


// 376B
package main

import (
	"fmt"
)

func main() {
	var arr [10100]int
	var a, b, c, d, e int
	ans := 0
	fmt.Scan(&a, &b)
	for i := 0; i < b; i++ {
		fmt.Scan(&c, &d, &e)
		arr[c] -= e
		arr[d] += e
	}
	for i := 0; i <= a; i++ {
		if arr[i] > 0 {
			ans += arr[i]
		}
	}
	fmt.Print(ans)
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var x,y,z,n,m,ans int
	var a [1100]int
	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	fmt.Scan(&n,&m)
	for i:=0;i<m;i++ {
		input.Scan()
		aa,_:=strconv.Atoi(input.Text())
		x=aa
		input.Scan()
		bb,_:=strconv.Atoi(input.Text())
		y=bb
		input.Scan()
		cc,_:=strconv.Atoi(input.Text())
		z=cc
		a[x]+=z
		a[y]-=z
	}
	for i:=1;i<=n;i++ {
		if a[i]>0 {
			ans+=a[i]
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m int
    ScanInts(&n,&m)
    ans, d, a, b, c := 0, make([]int,n+1), make([]int,m), make([]int,m), make([]int,m)
    for i := 0; i < m; i++ {
        ScanInts(&a[i],&b[i],&c[i])
        d[a[i]] += c[i]
        d[b[i]] -= c[i]
    }
    for i := 1; i <= n; i++ {
        if d[i] > 0 {
            ans += d[i]
        }
    }
    fmt.Println(ans)
}

// 376B-mic
package main

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

func main() {
	z := bufio.NewReader(os.Stdin)
	var n, m, i, a, b, c, sum int
	var p [105]int
	fmt.Fscan(z, &n, &m)
	for i = 1; i <= m; i++ {
		fmt.Fscan(z, &a, &b, &c)
		p[a] += c
		p[b] -= c
	}

	for i = 1; i <= n; i++ {
		if p[i] > 0 {
			sum += p[i]
		}
	}
	fmt.Println(sum)
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, m int
	var a, b, c int
	var arr [200][2]int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	min := 0
	for i:=0; i<m; i++ {
		r.Scan()
		a, _ = strconv.Atoi(r.Text())
		r.Scan()
		b, _ = strconv.Atoi(r.Text())
		r.Scan()
		c, _ = strconv.Atoi(r.Text())
		arr[a][0] += c
		arr[b][1] += c
	}
	for i:=1; i<=n; i++ {
		if arr[i][1] - arr[i][0] >= 0 {
			min += arr[i][1]-arr[i][0]
		} else {
			min += 0
		}
	}
	w.WriteString(strconv.Itoa(min)+"\n")
	w.Flush()
}


package main

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

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

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

	var t, n int
	fmt.Fscan(in, &t)

	arr := [100000]int64{}
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var sum, now int64
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			now += arr[j]
			sum = max(sum, now)
		}

		fmt.Fprintln(out, sum)
		defer out.Flush()
	}
}

package main

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

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

func max(a, b int) int {
	if a == min(a, b) {
		return b
	}
	return a
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func GetNum(p string) int64 {
	var ans int64 = 0
	flag := true
	i := 0
	n := len(p)
	if p[i] == '-' {
		flag = false
		i++
	}
	for ; i < n; i++ {
		ans = (ans << 1) + (ans << 3) + int64(p[i]-'0')
	}
	if !flag {
		ans = -ans
	}
	return ans
}
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	return int(GetNum(intStr))
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func ReadInt64() int64 {
	int64Str := ReadString()
	return GetNum(int64Str)
}
func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

func init() {

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1<<10), int(2e+5))
	in.Split(bufio.ScanWords)

	out = make(chan string, 1<<4)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)
	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()
		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

func work() {
	n := ReadInt()
	a := ReadIntSlice(n)
	var delt,ans int64 = 0,0
	for i := 0; i < n; i++ {
		delt += int64(a[i])
		if a[i] < 0 && delt < 0 {
			ans -= delt
			delt = 0
		}
	}
	fmt.Println(ans)
}

func main() {
	for t := ReadInt(); t > 0; t-- {
		work()
	}
	close(out)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 3*1024*1024)
	scanner.Split(bufio.ScanWords)

	in := func() int64 {
		scanner.Scan()
		i, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t -- {
		n := in()
		a := make([]int64, n)

		for i := range a {
			a[i] = in()
		}

		for i := range a {
			if a[i] > 0 && i != int(n-1) {
				a[i+1] += a[i]
				a[i] = 0
			}
		}

		var s int64 = 0

		for i := range a {
			if a[i] > 0 {
				s += a[i]
			}
		}

		fmt.Println(s)
	}
}

package main

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

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

	var t, n int
	fmt.Fscan(in, &t)

	var sum, x int64
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		sum = 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			sum += x
			if sum < 0 {
				sum = 0
			}
		}

		fmt.Fprintln(out, sum)
	}
	defer out.Flush()
}

package main

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

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

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

	var t, n int
	fmt.Fscan(in, &t)

	var sum, x int64
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		sum = 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			sum += x
			if sum < 0 {
				sum = 0
			}
		}

		fmt.Fprintln(out, sum)
	}
	defer out.Flush()
}

// dsfdsf

package main

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

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

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

	var t, n int
	fmt.Fscan(in, &t)

	arr := [100000]int64{}
	var sum, now int64
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		sum, now = 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			now += arr[j]
			sum = max(sum, now)
		}

		fmt.Fprintln(out, sum)
	}
	defer out.Flush()
}

// dsfdsf

package main

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

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

	var t, n int
	fmt.Fscan(in, &t)

	var sum, x int64
	for t > 0 {
		fmt.Fscan(in, &n)
		sum = 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			sum += x
			if sum < 0 {
				sum = 0
			}
		}

		fmt.Fprintln(out, sum)
		defer out.Flush()
		t--
	}

} //

package main

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

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

	var t, n int
	fmt.Fscan(in, &t)

	var sum, x int64
	for t > 0 {
		fmt.Fscan(in, &n)
		sum = 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			sum += x
			if sum < 0 {
				sum = 0
			}
		}

		fmt.Fprintln(out, sum)
		t--
	}
	defer out.Flush()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
-3 5 -3 1
*/

func ArrayCancellation(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var total int64
		for i := len(result) - 1; i >= 0; i-- {
			if result[i] < 0 {
				total -= result[i]
			} else if result[i] > 0 {
				if total >= result[i] {
					total -= result[i]
				} else {
					total = 0
				}
			}
		}

		Fprintln(out, total)
	}
}

func ArrayCancellation1(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var sum int64
		for i := 0; i < len(result); i++ {
			if result[i] > 0 {
				for j := i + 1; j < len(result); j++ {
					switch {
					case result[j] < 0:
						if result[i]+result[j] >= 0 {
							result[i] += result[j]
							result[j] = 0
						} else {
							result[j] += result[i]
							result[i] = 0
						}
					}

					if result[i] == 0 {
						break
					}
				}
				sum += result[i]
			}
		}

		Fprintln(out, sum)
	}
}

func main() {
	ArrayCancellation(os.Stdin, os.Stdout)
}

package main

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

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanInt := func(n *int) {
		scanner.Scan()
		num, _ := strconv.ParseInt(scanner.Text(), 10, 32)
		*n = int(num)
	}
	scanInt64 := func(n *int64) {
		scanner.Scan()
		num, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		*n = num
	}

	var t, n int
	var a int64
	scanInt(&t) // number of cases

	for x := 0; x < t; x++ {
		scanInt(&n)
		arrA := make([]int64, n)

		for y := 0; y < n; y++ {
			scanInt64(&a)
			arrA[y] = a
		}

		j := n - 1
		i := n - 1
		// free
		for ; i >= 0 && j >= 0; {
			if arrA[i] <= 0 && arrA[j] >= 0 {
				i--
				j--
				continue
			}

			if arrA[i] <= 0{
				i--
				continue
			}

			if arrA[j] >= 0 {
				j--
				continue
			}

			if i >= j {
				i--
				continue
			}

			if arrA[i] + arrA[j] >= 0 {
				arrA[i] += arrA[j]
				arrA[j] = 0
			} else {
				arrA[j] += arrA[i]
				arrA[i] = 0
			}
		}

		m := int64(0)
		j = n - 1
		i = n - 1
		// paid
		for ; i >= 0 && j >= 0; {
			if arrA[i] <= 0 && arrA[j] >= 0 {
				i--
				j--
				continue
			}
			if arrA[i] <= 0{
				i--
				continue
			}

			if arrA[j] >= 0 {
				j--
				continue
			}

			if arrA[i] + arrA[j] >= 0 {
				m += int64(math.Abs(float64(arrA[j])))
				arrA[i] += arrA[j]
				arrA[j] = 0
			} else {
				m += int64(math.Abs(float64(arrA[i])))
				arrA[j] += arrA[i]
				arrA[i] = 0
			}
		}

		fmt.Println(m)
	}
}

package main

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

const N = 1e5+5

var a [N]int64

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

var scanner *bufio.Scanner
func init() {
    scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1 << 20), 3 << 20)
	scanner.Split(bufio.ScanWords)
}

func read(p interface{}) {
    scanner.Scan()
    fmt.Sscan(scanner.Text(), p)
}

func main() {
    var t int
    for read(&t); t > 0; t-- {
        var n int
        read(&n)
        for i := 0; i < n; i++ {
            read(&a[i])
        }
        // fmt.Println("case #", t, a[:n])
        var result int64
        var more int64
        for i := 0; i < n; i++ {
            if a[i] < 0 {
                delta := min(-a[i], more)
                a[i] += delta
                more -= delta
                result += -a[i]
            } else {
                more += a[i]
                a[i] = 0
            }
        }
        fmt.Println(result)
    }
}

package main

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

const N = 1e5+5

var a [N]int64

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 3*1024*1024)
	scanner.Split(bufio.ScanWords)

	in := func() int64 {
		scanner.Scan()
		i, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		return i
    }
    for t := in(); t > 0; t-- {
        n := in()
        for i := 0; i < int(n); i++ {
            a[i] = in()
        }
        // fmt.Println("case #", ca, a[:n])
        var result int64
        var more int64
        for i := 0; i < int(n); i++ {
            if a[i] < 0 {
                delta := min(-a[i], more)
                a[i] += delta
                more -= delta
                result += -a[i]
            } else {
                more += a[i]
                a[i] = 0
            }
        }
        fmt.Println(result)
    }
}

package main

import "fmt"

const N = 1e5+5

var a [N]int64

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

func main() {
    var t int
    fmt.Scanln(&t)
    for ca := 0; ca < t; ca++ {
        var n int
        fmt.Scanln(&n)
        for i := 0; i < n; i++ {
            fmt.Scan(&a[i])
        }
        fmt.Scanln()
        var result int64
        var more int64
        for i := 0; i < n; i++ {
            if a[i] < 0 {
                delta := min(-a[i], more)
                a[i] += delta
                delta -= delta
                result += -a[i]
            } else {
                more += a[i]
                a[i] = 0
            }
        }
        fmt.Println(result)
    }
}

package main

import "fmt"

const N = 1e5+5

var a [N]int64

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

func main() {
    var t int
    fmt.Scanln(&t)
    for ca := 0; ca < t; ca++ {
        var n int
        fmt.Scanln(&n)
        for i := 0; i < n; i++ {
            fmt.Scanf("%d%c", &a[i])
        }
        // fmt.Println("case #", ca, a[:n])
        var result int64
        var more int64
        for i := 0; i < n; i++ {
            if a[i] < 0 {
                delta := min(-a[i], more)
                a[i] += delta
                more -= delta
                result += -a[i]
            } else {
                more += a[i]
                a[i] = 0
            }
        }
        fmt.Println(result)
    }
}

package main

import "fmt"

const N = 1e5+5

var a [N]int64

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

func main() {
    var t int
    fmt.Scanln(&t)
    for ca := 0; ca < t; ca++ {
        var n int
        fmt.Scanln(&n)
        for i := 0; i < n; i++ {
            fmt.Scan(&a[i])
        }
        var result int64
        var more int64
        for i := 0; i < n; i++ {
            if a[i] < 0 {
                delta := min(-a[i], more)
                a[i] += delta
                delta -= delta
                result += -a[i]
            } else {
                more += a[i]
                a[i] = 0
            }
        }
        fmt.Println(result)
    }
}

package main

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

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

func max(a, b int) int {
	if a == min(a, b) {
		return b
	}
	return a
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func GetNum(p string) int64 {
	var ans int64 = 0
	flag := true
	i := 0
	n := len(p)
	if p[i] == '-' {
		flag = false
		i++
	}
	for ; i < n; i++ {
		ans = (ans << 1) + (ans << 3) + int64(p[i]-'0')
	}
	if !flag {
		ans = -ans
	}
	return ans
}
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	return int(GetNum(intStr))
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func ReadInt64() int64 {
	int64Str := ReadString()
	return GetNum(int64Str)
}
func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

func init() {

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1<<10), int(2e+5))
	in.Split(bufio.ScanWords)

	out = make(chan string, 1<<4)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)
	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()
		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

func work() {
	n := ReadInt()
	a := ReadIntSlice(n)
	delt := 0
	ans := 0
	for i := 0; i < n; i++ {
		delt += a[i]
		if a[i] < 0 && delt < 0 {
			ans -= delt
			delt = 0
		}
	}
	fmt.Println(ans)
}

func main() {
	for t := ReadInt(); t > 0; t-- {
		work()
	}
	close(out)
}

package main

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

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

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

	var t, n int
	fmt.Fscan(in, &t)

	arr := [100000]int{}
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		sum, now := 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			now += arr[j]
			sum = max(sum, now)
		}

		fmt.Fprint(out, sum)
		defer out.Flush()
	}
}

package main

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

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

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

	var t, n int
	fmt.Fscan(in, &t)

	arr := [100000]int{}
	sum, now := 0, 0
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			now += arr[j]
			sum = max(sum, now)
		}
	}

	fmt.Fprint(out, sum)
	defer out.Flush()
}

package main

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

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

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

	var t, n int
	fmt.Fscan(in, &t)

	arr := [100000]int{}
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		sum, now := 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &arr[j])
		}

		for j := n - 1; j >= 0; j-- {
			now += arr[j]
			sum = max(sum, now)
		}

		fmt.Fprintln(out, sum)
		defer out.Flush()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
-3 5 -3 1
*/

func ArrayCancellation(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		for i := 0; i < len(result); i++ {
			if result[i] > 0 {
				for j := i + 1; j < len(result); j++ {
					switch {
					case result[j] < 0:
						if result[i]+result[j] >= 0 {
							result[i] += result[j]
							result[j] = 0
						} else {
							result[i] = 0
							result[j] += result[i]
						}
					}

					if result[i] == 0 {
						break
					}
				}
			}
		}

		var sum int64
		for i := 0; i < len(result); i++ {
			if result[i] > 0 {
				sum += result[i]
			}
		}

		Fprintln(out, sum)
	}
}

func main() {
	ArrayCancellation(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

/*
-3 5 -3 1
*/

func ArrayCancellation(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var result []int
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		for i := 0; i < len(result); i++ {
			if result[i] > 0 {
				for j := i + 1; j < len(result); j++ {
					switch {
					case result[j] < 0:
						if result[i]+result[j] >= 0 {
							result[i] += result[j]
							result[j] = 0
						} else {
							result[i] = 0
							result[j] += result[i]
						}
					}

					if result[i] == 0 {
						break
					}
				}
			}
		}

		sum := 0
		for i := 0; i < len(result); i++ {
			if result[i] > 0 {
				sum += result[i]
			}
		}

		Fprintln(out, sum)
	}
}

func main() {
	ArrayCancellation(os.Stdin, os.Stdout)
}


package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func main() {
	defer writer.Flush()
	var s, t, one []byte
	scan(&s)
	cnt1 := 0
	for _, i := range s {
		if i == byte('1') {
			cnt1++
			one = append(one, i)
		} else {
			t = append(t, i)
		}
	}

	i := 0
	for i < len(t) && t[i] == byte('0') {
		i++
	}
	println(string(t[:i]) + string(one) + string(t[i:]))
}

package main

import "fmt"

func main() {
	var s, t, one []byte
	fmt.Scan(&s)
	cnt1 := 0
	for _, i := range s {
		if i == byte('1') {
			cnt1++
			one = append(one, i)
		} else {
			t = append(t, i)
		}
	}

	i := 0
	for i < len(t) && t[i] == byte('0') {
		i++
	}
	fmt.Println(string(t[:i]) + string(one) + string(t[i:]))

}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func main() {
	defer writer.Flush()
	var s, t, one []byte
	scan(&s)
	cnt1 := 0
	for _, i := range s {
		if i == byte('1') {
			cnt1++
			one = append(one, i)
		} else {
			t = append(t, i)
		}
	}

	i := 0
	for i < len(t) && t[i] == byte('0') {
		i++
	}
	fmt.Println(string(t[:i]) + string(one) + string(t[i:]))
}

package main

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

func main() {
	sc := NewScanner()
  var input []byte
	inputs := sc.NextLine()
  for i:=0;i<len(inputs);i++ {
    input = append(input, inputs[i])
  }
  var counter int

  for i:=0;i<len(input);i++ {
		if input[i] == 49 {
			counter++
		}
  }

  var result string
	var flag bool = true
  for i:=0;i<len(input);i++ {
    if input[i] == 48 {
      result = result + "0"
    }
		if input[i] == 50 {
			if flag {
				for counter>0 {
					result = result + "1"
					counter--
				}
				flag = false
			}
			result = result + "2"
		}
  }
	if flag {
		for counter>0 {
			result = result + "1"
			counter--
		}
		flag = false
	}

	fmt.Println(result)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
  var input []byte
	inputs := sc.NextLine()
  for i:=0;i<len(inputs);i++ {
    input = append(input, inputs[i])
  }
  var counter int

  for i:=0;i<len(input);i++ {
		if input[i] == 49 {
			counter++
		}
  }

  var result string
	var flag bool = true
  for i:=0;i<len(input);i++ {
    if input[i] == 48 {
      result = result + "0"
    }
		if input[i] == 50 && flag{
			if flag {
				for counter>0 {
					result = result + "1"
					counter--
				}
				flag = false
			}
			result = result + "2"
		}
  }
	if flag {
		for counter>0 {
			result = result + "1"
			counter--
		}
		flag = false
	}

	fmt.Println(result)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
  var input []byte
	inputs := sc.NextLine()
  for i:=0;i<len(inputs);i++ {
    input = append(input, inputs[i])
  }
  var counter int

  for i:=0;i<len(input);i++ {
		if input[i] == 49 {
			counter++
		}
  }

  var result string
	var flag bool = true
  for i:=0;i<len(input);i++ {
    if input[i] == 48 {
      result = result + "0"
    }
		if input[i] == 50{
			if flag {
				for counter>0 {
					result = result + "1"
					counter--
				}
				flag = false
			}
			result = result + "2"
		}
  }

	fmt.Println(result)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func main() {

	var s, t, one []byte
	scan(&s)
	cnt1 := 0
	for _, i := range s {
		if i == byte('1') {
			cnt1++
			one = append(one, i)
		} else {
			t = append(t, i)
		}
	}

	i := 0
	for i < len(t) && t[i] == byte('0') {
		i++
	}
	println(string(t[:i]) + string(one) + string(t[i:]))
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func main() {

	var s, t, one []byte
	scan(&s)
	cnt1 := 0
	for _, i := range s {
		if i == byte('1') {
			cnt1++
			one = append(one, i)
		} else {
			t = append(t, i)
		}
	}

	i := 0
	for i < len(t) && t[i] == byte('0') {
		i++
	}
	print(string(t[:i]) + string(one) + string(t[i:]))
}