package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func bisectLeft(a []int64, val int64, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] >= val })
}

func bisectRight(a []int64, val int64, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] > val })
}

type IntSlice []int64

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

func solve(l, r int64, a []int64) int64 {
	var count int64
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()
	// return 0

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	lo, hi := len(a), len(a)
	for i := 0; i < len(a); i++ {
		lo = bisectLeft(a, l-a[i], i+1)
		hi = bisectRight(a, r-a[i], i+1)
		log.Printf("i, lo,hi = %+v:   (%+v,  %+v)\n", i, lo, hi)
		count += int64(hi - lo)
	}
	return count
}

func main() {
	log.Println("start")
	// a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	// // a := []int{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11}
	//
	// pp.Println(sort.Search(len(a), func(j int) bool { print(a[j]); return (j < len(a)) && a[j] > -3 }))
	// return

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n int
		var l, r int64
		fmt.Fscan(in, &n, &l, &r)
		arr := []int64{}
		for i := 0; i < n; i++ {
			var val int64
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

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

const Mod = 1000000007

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

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

	for tc := 1; tc <= t; tc++ {
		solveTest(in, out, tc)
	}

	out.Flush()
}

func solveTest(in *bufio.Reader, out *bufio.Writer, tc int) {
	var n, l, r int
	fmt.Fscan(in, &n, &l, &r)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	sort.Ints(a)

	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(first(a, r + 1 - a[i]) - first(a, l - a[i]))
		if a[i] * 2 >= l && a[i] * 2 <= r {
			ans--
		}
	}
	fmt.Fprintln(out, ans / 2)
}

func first(a []int, l int) int {
	n := len(a)
	if a[n - 1] < l {
		return n
	}

	lo, hi := -1, n - 1
	for hi - lo > 1 {
		mid := (hi + lo) / 2
		if a[mid] >= l {
			hi = mid
		} else {
			lo = mid
		}
	}

	return hi
}

func min(xs ...int) int {
	result := xs[0]
	for i := 1; i < len(xs); i++ {
		if result > xs[i] {
			result = xs[i]
		}
	}
	return result
}

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

package main

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

const (
	MOD int = int(1e9 + 7)
)

type Int int64

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

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

	for tc := 0; tc < t; tc++ {
		var n, l, r int
		fmt.Fscan(_r, &n, &l, &r)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(_r, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		var ans Int
		for i := 0; i < n; i++ {
			li, ri := Find(a, l-a[i]-1), Find(a, r-a[i])
			cnt := ri - li
			if li < i && i <= ri {
				cnt--
			}
			ans += Int(cnt)
		}

		fmt.Fprintf(_w, "%d\n", ans/Int(2))
	}
}

// x以下で最大の添字
func Find(arr []int, x int) int {
	n := len(arr)
	if arr[0] > x {
		return -1
	}
	l, r := 0, n
	for r-l > 1 {
		mid := (l + r) / 2
		if arr[mid] <= x {
			l = mid
		} else {
			r = mid
		}
	}
	return l
}

package main

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

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

	var t int
	Fscan(in, &t)

	for ; t > 0; t-- {
		var n int
		var l, r, res int64
		Fscan(in, &n, &l, &r)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})

		left, right := 0, 0
		for i := n - 1; i >= 0; i-- {
			for right < n && arr[right]+arr[i] <= r {
				right++
			}
			for left < n && arr[left]+arr[i] < l {
				left++
			}
			if i >= left && i < right {
				res -= 1
			}
			res += int64(right - left)
		}
		res = res / 2
		Fprintln(out, res)
	}

}

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

package main

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

func main() {
	var t, n, l, r int
	var arr []int
	var ans int64

	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for m := 0; m < t; m++ {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &l)
		fmt.Fscan(in, &r)

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

		sort.Sort(sort.IntSlice(arr))

		ans = 0
		for i := 0; i < n; i++ {
			lIdx := searchLeft(arr, i, i+1, n, l)
			rIdx := searchRight(arr, i, i+1, n, r)

			ans += int64(rIdx) - int64(lIdx)
		}
		fmt.Println(ans)

	}
}

func searchLeft(arr []int, i, st, ed, l int) int {
	for st < ed {
		mid := st + ((ed - st) >> 1)
		if arr[mid]+arr[i] >= l {
			ed = mid
		} else {
			st = mid + 1
		}
	}
	return st
}

func searchRight(arr []int, i, st, ed, r int) int {
	for st < ed {
		mid := st + ((ed - st) >> 1)
		if arr[mid]+arr[i] > r {
			ed = mid
		} else {
			st = mid + 1
		}
	}
	return st
}

package main

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

func testcase(reader *bufio.Reader, writer *bufio.Writer) {
  var n, l, r int
  fmt.Fscan(reader, &n, &l, &r)

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

  sort.Ints(a)

  var ans int64

  for i := 0; i < n-1; i++ {
    begin := sort.SearchInts(a[i+1:], l - a[i])
    end := sort.SearchInts(a[i+1:], r - a[i] + 1)
    ans += int64(end - begin)
  }

  fmt.Fprintln(writer, ans)
}

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

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

  for i := 0; i < t; i++ {
    testcase(reader, writer)
  }
}

package main

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

func testcase(reader *bufio.Reader, writer *bufio.Writer) {
  var n, l, r int
  fmt.Fscan(reader, &n, &l, &r)

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

  sort.Ints(a)
  min := make([]int, n)

  for i, j := 0, n-1; i < n; {
    if (i >= j) {
      min[i] = i
      i++
      continue
    }

    if a[i] + a[j] >= l {
      j--
    } else {
      min[i] = j
      i++
    }
  }

  var ans int64

  for i, j := 0, n-1; i < j; {
    if a[i] + a[j] <= r {
      ans += int64(j - min[i])
      i++
    } else {
      j--
    }
  }

  fmt.Fprintln(writer, ans)
}

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

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

  for i := 0; i < t; i++ {
    testcase(reader, writer)
  }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	solve := func(Case int) {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Ints(a)
		var ans int64 = 0
		x, y := n-1, n-1
		for i := 0; i < y; i++ {
			x = max(i, x)
			for ; x > i && a[i]+a[x] >= l; x-- {
			}
			for ; y > x && a[i]+a[y] > r; y-- {
			}
			ans += int64(y - x)
		}
		fmt.Fprintln(out, ans)
	}

	T := 1
	fmt.Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
}

func max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func min(a []int) int {
	mn := int(1e9)
	for i := range a {
		if a[i] < mn {
			mn = a[i]
		}
	}
	return mn
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

package main

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {
		var n, l, r int
		fmt.Fscan(read, &n, &l, &r)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(read, &a[j])
		}

		fmt.Println(solve(a, n, l, r))
	}
}

func solve(a[]int, n, l , r int) int64 {
	var ans int64

	sort.Ints(a)

	for i := 0; i < n; i++ {
		c := a[i]

		if c > r {
			break
		}

		if c < l {
			idxL := sort.Search(n, func(i int) bool {
				return c + a[i] >= l
			})

			if idxL == n {
				continue
			}

			if idxL <= i {
				idxL = i + 1
			}

			idxR := sort.Search(n, func(i int) bool {
				return c + a[i] > r
			})

			if idxR == n {
				ans += int64(n) - int64(idxL)
			} else if idxR <= i {
				continue
			} else {
				idxR--

				if idxR >= idxL {
					ans += int64(idxR) - int64(idxL) + 1
				}
			}

		} else {
			idxR := sort.Search(n, func(i int) bool {
				return c + a[i] > r
			})

			if idxR == n {
				ans += int64(n) - int64(i + 1)

			} else if idxR <= i {
				continue
			}else {
				idxR--
				ans += int64(idxR) - int64(i + 1) + 1
			}
		}
	}

	return ans

}

package main

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

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

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

	var n, l, r, num int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &l, &r)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &num)
			arr[i] = num
		}
		sort.Ints(arr)
		cnt := int64(0)
		for i, num := range arr {
			j := sort.SearchInts(arr[:i], l-num)
			k := sort.SearchInts(arr[:i], r-num+1)
			if j < k {
				cnt += int64(k - j)
			}
		}
		fmt.Fprintln(writer, cnt)
	}
}

package main

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

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

func calc1(arr *[]int, ind, x int) int {
	lo := ind + 1
	hi := len(*arr) - 1
	ans := -1
	for lo <= hi {
		mid := (lo + hi) >> 1
		if (*arr)[mid] >= x {
			hi = mid - 1
			ans = mid
		} else {
			lo = mid + 1
		}
	}
	return ans
}

func calc2(arr *[]int, ind, x int) int {
	lo := ind + 1
	hi := len(*arr) - 1
	ans := -1
	for lo <= hi {
		mid := (lo + hi) >> 1
		if (*arr)[mid] > x {
			hi = mid - 1
		} else {
			lo = mid + 1
			ans = mid
		}
	}
	return ans
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Ints(arr)
		var ans int64
		for i := 0; i < len(arr); i++ {
			ind1 := calc1(&arr, i, l - arr[i])
			ind2 := calc2(&arr, i, r - arr[i])
			if ind1 <= ind2 && ind1 != -1 && ind2 != -1 {
				ans += int64(ind2 - ind1 + 1)
			}
		}
		fmt.Fprintln(out, ans)
		t--
	}
	out.Flush()

}

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, l, r int
		fmt.Fscan(in, &n, &l, &r)

		aa := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}
		sort.Ints(aa)
		var tot int64
		for i := 0; i < n; i++ {
			d := sort.SearchInts(aa[:i], l-aa[i])
			e := sort.SearchInts(aa[:i], r-aa[i]+1)
			if d < e {
				tot += int64(e - d)
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

/*
1
6 2 4
1 2 4 3 2 5
---
4

1 2 2 3 4 5

i=1
(r-a[i]+1) = 4 -> j=4 cnt=j-i-1=3

i=2
3 -> j=3 cnt=3-1-1=1

*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	pairCnt := int64(0)

	for k, num := range a {
		if num >= r {
			break
		}

		lft := l - num
		i := sort.SearchInts(a, lft)
		if i <= k {
			i = k + 1
		}

		nxtToRgt := r - num + 1
		j := sort.SearchInts(a, nxtToRgt)

		cnt := max(0, j-i)
		pairCnt += int64(cnt)
	}

	fmt.Fprintln(writer, pairCnt)
}

//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 int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[idx]
}

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

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

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

	for i := 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))
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func bisectLeft(a []int, val int, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] >= val })
}

func bisectRight(a []int, val int, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] > val })
}

type IntSlice []int

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

func solve(l, r int, a []int) int64 {
	var count int64
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()
	// return 0

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	lo, hi := len(a), len(a)
	for i := 0; i < len(a); i++ {
		lo = bisectLeft(a, l-a[i], i+1)
		hi = bisectRight(a, r-a[i], i+1)
		log.Printf("i, lo,hi = %+v:   (%+v,  %+v)\n", i, lo, hi)
		count += int64(hi - lo)
	}
	return count
}

func main() {
	log.Println("start")
	// a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	// // a := []int{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11}
	//
	// pp.Println(sort.Search(len(a), func(j int) bool { print(a[j]); return (j < len(a)) && a[j] > -3 }))
	// return

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n int
		var l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			var val int
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
/*const N = 200010
var a [N]int
func lowbit(x int) int {
	return x & -x
}
func add(x, y int) {
	for {
		if x >= N {
			break
		}
		a[x] += y
		x += lowbit(x)
	}
}
func get(x int) int {
	ans := 0
	for {
		if x <= 0 {
			break
		}
		ans += a[x]
		x -= lowbit(x)
	}
	return ans
}*/
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Scan(&t)
	for i := 0; i < t; i ++ {
		solve := func() {
			var n, l, r int
			fmt.Fscan(in, &n, &l, &r)
			b := make([]int, n)
			for i := 0; i < n; i++ {
				fmt.Fscan(in, &b[i])
			}
			sort.Ints(b)
			ans := int64(0)
			for i := 0; i < n; i++ {
				a := b[:i]
				pl := sort.SearchInts(a, l - b[i])
				pr := sort.SearchInts(a,r - b[i] + 1)
				if pl <= pr {
					ans += int64(pr - pl)
				}
			}
			fmt.Fprintln(out, ans)
		}
		solve()
	}
}

package main

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

var bytes []byte
var l, max int

/**
 * Perform Quick Scan of 1 data(with no spaces in-between) on the buffered input
 */
func fastScan() int64 {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	var result int64
	result = 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int64(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func fastScan32() int {
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	var result int
	result = 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func main(){
	// Read all the input into Buffer
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	test := fastScan()

	for ; test > 0; test--{
		runTest()
	}
}

func runTest(){
	var n int
	var l, r, ans int64

	ans = 0

	n = fastScan32()
	l = fastScan()
	r = fastScan()

	lis := make([]int64, n)

	for i := 0; i < n; i++ {
		lis[i] = fastScan()
	}

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

	x, y := n - 1, n - 1
	for i := 0; i < n; i++ {
	    if x < i{
	        x = i
	    }
	    if y < i{
	        y = i
	    }

		for ;x > i && x < n && lis[x] + lis[i] > r; {
			x--
		}
		for ; y > i && y < n && lis[y] + lis[i] >= l; {
			y--
		}

	//	fmt.Println(x, y)
		ans += int64(x - i - 1) - int64(y - i - 1)
	//	fmt.Println(ans)
	}

	fmt.Printf("%d\n", ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n, l, r int
		Fscan(in, &n, &l, &r)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		ans := int64(0)
		for i, v := range a {
			b := a[:i]
			j := sort.SearchInts(b, l-v)
			k := sort.SearchInts(b, r-v+1)-1
			if j<=k {
				ans += int64(k-j+1)
			}
		}
		Fprintln(out, ans)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

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

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, l, r int64
		Fscan(in, &n, &l, &r)
		nums := make([]int64, n)

		for i := range nums {
			Fscan(in, &nums[i])
		}

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

		var ans int64
		for i := int64(0); i < n-1; i++ {
			left := sort.Search(len(nums[i+1:]), func(j int) bool {
				return nums[i+1:][j] >= l - nums[i]
			})
			right := sort.Search(len(nums[i+1:]), func(j int) bool {
				return nums[i+1:][j] > r - nums[i]
			})
			ans += int64(right - left)
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	for i := 0; i < t; i++ {
		input, _ = reader.ReadString('\n')
		// Get n
		var n int
		n, input = GetInt(input)

		// Get min
		var min int64
		min, input = GetInt64(input)

		// Get max
		var max int64
		max, _ = GetInt64(input)

		// Get nums
		input, _ = reader.ReadString('\n')
		nums := []int64{}
		for input != "" {
			var num int64
			num, input = GetInt64(input)
			nums = append(nums, num)
		}

		sort.Slice(nums, func (l, r int) bool {
			return nums[l] > nums[r]
		})

		// Solve the problem
		result := uint64(0)
		for i := 0; i < n-1; i++ {
			val := nums[i]
			// Get left bound
			left, right := i+1, n-1
			for left < right {
				mid := left + (right - left) >> 1
				if nums[mid] <= max - val {
					right = mid

				} else {
					left = mid + 1
				}
			}
			left_bound := left
			if nums[left_bound] > max - val {
				result += 0
				continue
			}

			// Get right bound
			left, right = i+1, n-1
			for left < right {
				mid := left + (right - left + 1) >> 1
				if nums[mid] >= min - val {
					left = mid

				} else {
					right = mid - 1
				}
			}
			right_bound := left
			if nums[right_bound] < min - val {
				result += 0

			} else {
				result += uint64(right_bound - left_bound) + 1
			}
		}
		fmt.Println(result)
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(reader, &t)
	for k := 0; k < t; k++ {
		var n, l, r int
		fmt.Fscan(reader, &n, &l, &r)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] <= arr[j]
		})
		solve1538C(arr,l,r)
	}
}
func solve1538C(arr []int, l, r int)  {
	var res int64
	for k := 0; k < len(arr)-1; k++ {
		//确定arr[k]，找到arr[k]+arr[i]>=l的左边界,arr[k]+arr[i]<=r的右边界。
		var first, last int
		i, j := k+1, len(arr)
		for i < j {
			mid := (i + j) / 2
			if arr[k]+arr[mid] >= l {
				j = mid
			} else {
				i = mid + 1
			}
		}
		first = i

		i, j = k+1, len(arr)
		for i < j {
			mid := (i + j) / 2
			if arr[k]+arr[mid] <= r {
				i = mid + 1
			} else {
				j = mid
			}
		}
		last = i - 1
		res += int64(last - first + 1)
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func bisectLeft(a []int, val int, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] >= val })
}

func bisectRight(a []int, val int, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] > val })
}

type IntSlice []int

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

func solve(l, r int, a []int) int {
	var count int
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()
	// return 0

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	lo, hi := len(a), len(a)
	for i := 0; i < len(a); i++ {
		lo = bisectLeft(a, l-a[i], i+1)
		hi = bisectRight(a, r-a[i], i+1)
		log.Printf("i, lo,hi = %+v:   (%+v,  %+v)\n", i, lo, hi)
		count += int(hi - lo)
	}
	return count
}

func main() {
	log.Println("start")
	// a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	// // a := []int{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11}
	//
	// pp.Println(sort.Search(len(a), func(j int) bool { print(a[j]); return (j < len(a)) && a[j] > -3 }))
	// return

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n int
		var l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			var val int
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func bisectLeft(a []int64, val int64, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] >= val })
}

func bisectRight(a []int64, val int64, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] > val })
}

type IntSlice []int64

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

func solve(l, r int64, a []int64) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()
	// return 0

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	lo, hi := len(a), len(a)
	for i := 0; i < len(a); i++ {
		lo = bisectLeft(a, l-a[i], i+1)
		hi = bisectRight(a, r-a[i], i+1)
		if hi == 0 {
			hi = len(a)
		}
		log.Printf("i, lo,hi = %+v:   (%+v,  %+v)\n", i, lo, hi)
		count += hi - lo
	}
	return count
}

func main() {
	log.Println("start")
	// a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	// // a := []int{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11}
	//
	// pp.Println(sort.Search(len(a), func(j int) bool { print(a[j]); return (j < len(a)) && a[j] > -3 }))
	// return

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n int
		var l, r int64
		fmt.Fscan(in, &n, &l, &r)
		arr := []int64{}
		for i := 0; i < n; i++ {
			var val int64
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func bisectLeft(a []int, val, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] >= val })
}
func bisectRight(a []int, val, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] > val })
}

func solve(l, r int, a []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	lo, hi := len(a), len(a)
	for i := 0; i < len(a); i++ {
		lo = bisectLeft(a, l-a[i], i+1)
		hi = bisectRight(a, r-a[i], i+1)
		if hi == 0 {
			hi = len(a)
		}
		log.Printf("i, lo,hi = %+v:   (%+v,  %+v)\n", i, lo, hi)
		count += hi - lo
	}
	return count
}

func main() {
	log.Println("start")
	// a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	// // a := []int{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11}
	//
	// pp.Println(sort.Search(len(a), func(j int) bool { print(a[j]); return (j < len(a)) && a[j] > -3 }))
	// return

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func bisectLeft(a []int, val, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] >= val })
}
func bisectRight(a []int, val, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] > val })
}

func solve(l, r int, a []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	lo, hi := len(a), len(a)
	for i := 0; i < len(a); i++ {
		lo = bisectLeft(a, l-a[i], i+1)
		hi = bisectRight(a, r-a[i], i+1)
		if hi == 0 {
			hi = len(a) - 1
		}
		log.Printf("i, lo,hi = %+v:   (%+v,  %+v)\n", i, lo, hi)
		count += hi - lo
	}
	return count
}

func main() {
	log.Println("start")
	// a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	// // a := []int{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11}
	//
	// pp.Println(sort.Search(len(a), func(j int) bool { print(a[j]); return (j < len(a)) && a[j] > -3 }))
	// return

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func bisectLeft(a []int, val, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] >= val })
}
func bisectRight(a []int, val, lo int) int {
	return sort.Search(len(a), func(i int) bool { return !(i < lo) && a[i] > val })
}

func solve(l, r int, a []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	lo, hi := len(a), len(a)
	for i := 0; i < len(a); i++ {
		lo = bisectLeft(a, l-a[i], i+1)
		hi = bisectRight(a, r-a[i], i+1)
		log.Printf("i, lo,hi = %+v:   (%+v,  %+v)\n", i, lo, hi)
		count += hi - lo
	}
	return count
}

func main() {
	log.Println("start")
	// a := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
	// // a := []int{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11}
	//
	// pp.Println(sort.Search(len(a), func(j int) bool { print(a[j]); return (j < len(a)) && a[j] > -3 }))
	// return

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

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

func init() {
	log.SetFlags(0)
	// log.SetOutput(ioutil.Discard)

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

func solve(l, r int, a []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	low, high := len(a), len(a)
	for i := 0; i < len(a); i++ {
		low = sort.Search(len(a), func(j int) bool { return !(j < i+1) && a[i] >= l-a[j] })
		if low == len(a) {
			// low = 0
			// continue
		}

		high = sort.Search(len(a), func(j int) bool { return !(j < i+1) && a[i] > r-a[j] })
		if high == len(a) {
			// high = len(a) - 1
		}
		if high-low < 0 {
			continue
		}

		log.Printf("i, low,high = %+v:   (%+v,  %+v)\n", i, low, high)
		count += high - low
	}
	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func solve(l, r int, a []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	low, high := len(a), len(a)
	for i := 0; i < len(a); i++ {
		low = sort.Search(len(a), func(j int) bool { return !(j < i+1) && a[i] >= l-a[j] })
		// if low == len(a) {
		// 	low = 0
		// }

		high = sort.Search(len(a), func(j int) bool { return !(j < i+1) && a[i] > r-a[j] })
		// if high == len(a) {
		// 	high = len(a) - 1
		// }

		log.Printf("i, low,high = %+v:   (%+v,  %+v)\n", i, low, high)
		count += high - low
	}
	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func solve(l, r int, a []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(a))
	log.Printf("a= %+v\n", a)
	log.Println("         -----------")
	low, high := len(a), len(a)
	for i := 0; i < len(a); i++ {
		low = sort.Search(len(a), func(j int) bool { return a[i] >= l-a[j] })
		high = sort.Search(len(a), func(j int) bool { return a[i] > r-a[j] })

		log.Printf("i, low,high = %+v:   (%+v,  %+v)\n", i, low, high)
		count += high - low
		if l <= 2*a[i] && 2*a[i] <= r {
			count--
		}
	}
	return count / 2
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func solve(l, r int, arr []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(arr))
	log.Printf("arr= %+v\n", arr)
	log.Println("         -----------")

	low, high := len(arr)-1, len(arr)-1
	for i := 0; i <= high; i++ {
		low = Max(i, low)
		for l <= arr[low]+arr[i] && i < low {
			low--
		}
		for arr[high]+arr[i] > r && low < high {
			high--
		}
		log.Printf("i, low, high = %#v, (%#v, %#v)\n", i, low, high)
		count += high - low
	}
	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func solve(l, r int, arr []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(arr))
	log.Printf("arr= %+v\n", arr)
	log.Println("         -----------")

	low, high := len(arr)-1, len(arr)-1
	for i := 0; i <= high; i++ {

		low = Max(i, low)

		for arr[i]+arr[high] > r && low < high {
			high--
		}
		for l <= arr[i]+arr[low] && i < low {
			low--
		}
		log.Printf("i, low, high = %#v, (%#v, %#v)\n", i, low, high)

		count += (high - low)
	}

	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

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

func init() {
	log.SetFlags(0)
	// log.SetOutput(ioutil.Discard)

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

func solve(l, r int, arr []int) int {
	count := 0
	log.Println("--------------------")
	defer func() {
		log.Printf("<<<<<<<<<<<<<<<<<<<<<<< %#v", count)
	}()

	log.Printf("l = %+v r = %+v\n", l, r)
	sort.Sort(sort.IntSlice(arr))
	log.Printf("arr= %+v\n", arr)
	log.Println("         -----------")

	low, high := len(arr)-1, len(arr)-1
	for i := 0; i <= high; i++ {

		low = Max(i, low)

		for arr[i]+arr[high] > r && low < high {
			high--
		}
		for l <= arr[i]+arr[low] && i < low {
			low--
		}
		log.Printf("i, low, high = %#v, (%#v, %#v)\n", i, low, high)

		count += (high - low)
	}

	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func solve(l, r int, arr []int) int {
	log.Printf("l = %+v\n", l)
	log.Printf("r = %+v\n", r)

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

	log.Printf("arr = %+v\n", arr)

	log.Printf("arr[-1] = %+v\n", arr[len(arr)-1])
	if arr[len(arr)-1] > r {
		return 0
	}

	count := 0
Loop:
	for i := 0; i < len(arr); i++ {
		// if arr[i] > r {
		// 	break
		// }
		for j := i + 1; j < len(arr); j++ {
			s := arr[i] + arr[j]
			log.Printf("arr[i, j] = %+v, %+v    %+v", arr[i], arr[j], s)
			if l <= s && s <= r {
				log.Printf("+")
				count++
			}
			if s < l {
				break Loop
			}
		}
	}

	// pp.Println(count)
	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &l)
		fmt.Fscan(in, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func solve(l, r int, arr []int) int {
	log.Printf("l = %+v\n", l)
	log.Printf("r = %+v\n", r)

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

	log.Printf("arr = %+v\n", arr)

	log.Printf("arr[-1] = %+v\n", arr[len(arr)-1])
	if arr[len(arr)-1] > r {
		return 0
	}

	count := 0
Loop:
	for i := 0; i < len(arr); i++ {
		if arr[i] > r {
			break
		}
		for j := i + 1; j < len(arr); j++ {
			s := arr[i] + arr[j]
			log.Printf("arr[i, j] = %+v, %+v    %+v", arr[i], arr[j], s)
			if l <= s && s <= r {
				log.Printf("+")
				count++
			}
			if s < l {
				break Loop
			}
		}
	}

	// pp.Println(count)
	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &l)
		fmt.Fscan(in, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)

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

func solve(l, r int, arr []int) int {
	log.Printf("l = %+v\n", l)
	log.Printf("r = %+v\n", r)

	sort.IntSlice(arr).Sort()

	log.Printf("arr = %+v\n", arr)

	count := 0
Loop:
	for i := 0; i < len(arr); i++ {
		for j := i + 1; j < len(arr); j++ {
			s := arr[i] + arr[j]
			if s > r {
				break Loop
			}
			if l <= s && s <= r {
				count++
			}
		}
	}

	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &l)
		fmt.Fscan(in, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

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

func init() {
	log.SetFlags(0)
	// log.SetOutput(ioutil.Discard)

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

func solve(l, r int, arr []int) int {
	log.Printf("l = %+v\n", l)
	log.Printf("r = %+v\n", r)

	sort.IntSlice(arr).Sort()

	log.Printf("arr = %+v\n", arr)

	count := 0
Loop:
	for i := 0; i < len(arr); i++ {
		for j := i + 1; j < len(arr); j++ {
			if l <= arr[i]+arr[j] && arr[i]+arr[j] <= r {
				count++
			}
			if arr[i]+arr[j] > r {
				break Loop
			}
		}
	}

	return count
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var n, l, r int
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &l)
		fmt.Fscan(in, &r)
		arr := []int{}
		for i := 0; i < n; i++ {
			val := 0
			fmt.Fscan(in, &val)
			arr = append(arr, val)
		}
		fmt.Fprintf(out, "%d\n", solve(l, r, arr))

	}
	log.Println("__end__")
}

package main

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

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

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, l, r int64
		Fscan(in, &n, &l, &r)
		nums := make([]int64, n)

		for i := range nums {
			Fscan(in, &nums[i])
		}

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

		ans := 0
		for i := int64(0); i < n-1; i++ {
			left := sort.Search(len(nums[i+1:]), func(j int) bool {
				return nums[i+1:][j] >= l - nums[i]
			})
			right := sort.Search(len(nums[i+1:]), func(j int) bool {
				return nums[i+1:][j] > r - nums[i]
			})
			ans += right - left
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, l, r int
		Fscan(in, &n, &l, &r)
		nums := make([]int, n)

		for i := range nums {
			Fscan(in, &nums[i])
		}

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

		ans := 0
		for i := 0; i < n-1; i++ {
			left := sort.Search(len(nums[i+1:]), func(j int) bool {
				return nums[i+1:][j] >= l - nums[i]
			})
			right := sort.Search(len(nums[i+1:]), func(j int) bool {
				return nums[i+1:][j] > r - nums[i]
			})
			ans += right - left
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	for i := 0; i < t; i++ {
		input, _ = reader.ReadString('\n')
		// Get n
		var n int
		n, input = GetInt(input)

		// Get min
		var min int64
		min, input = GetInt64(input)

		// Get max
		var max int64
		max, _ = GetInt64(input)

		// Get nums
		input, _ = reader.ReadString('\n')
		nums := []int64{}
		for input != "" {
			var num int64
			num, input = GetInt64(input)
			nums = append(nums, num)
		}

		sort.Slice(nums, func (l, r int) bool {
			return nums[l] > nums[r]
		})

		// Solve the problem
		result := 0
		for i := 0; i < n-1; i++ {
			val := nums[i]
			// Get left bound
			left, right := i+1, n-1
			for left < right {
				mid := left + (right - left) >> 1
				if nums[mid] <= max - val {
					right = mid

				} else {
					left = mid + 1
				}
			}
			left_bound := left
			if nums[left_bound] > max - val {
				result += 0
				continue
			}

			// Get right bound
			left, right = i+1, n-1
			for left < right {
				mid := left + (right - left + 1) >> 1
				if nums[mid] >= min - val {
					left = mid

				} else {
					right = mid - 1
				}
			}
			right_bound := left
			if nums[right_bound] < min - val {
				result += 0

			} else {
				result += right_bound - left_bound + 1
			}
		}
		fmt.Println(result)
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

func GetInt64(s string) (result int64, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.ParseInt(s[:iter], 10, 64)
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

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

	for i := 0; i < t; i++ {
		input, _ = reader.ReadString('\n')
		// Get n
		var n int
		n, input = GetInt(input)

		// Get min
		var min int
		min, input = GetInt(input)

		// Get max
		var max int
		max, _ = GetInt(input)

		// Get nums
		input, _ = reader.ReadString('\n')
		nums := []int{}
		for input != "" {
			var num int
			num, input = GetInt(input)
			nums = append(nums, num)
		}

		sort.Slice(nums, func (l, r int) bool {
			return nums[l] > nums[r]
		})

		// Solve the problem
		result := 0
		for i := 0; i < n-1; i++ {
			val := nums[i]
			// Get left bound
			left, right := i+1, n-1
			for left < right {
				mid := left + (right - left) >> 1
				if nums[mid] <= max - val {
					right = mid

				} else {
					left = mid + 1
				}
			}
			left_bound := left
			if nums[left_bound] > max - val {
				result += 0
				continue
			}

			// Get right bound
			left, right = i+1, n-1
			for left < right {
				mid := left + (right - left + 1) >> 1
				if nums[mid] >= min - val {
					left = mid

				} else {
					right = mid - 1
				}
			}
			right_bound := left
			if nums[right_bound] < min - val {
				result += 0

			} else {
				result += right_bound - left_bound + 1
			}
		}
		fmt.Println(result)
	}
}

// func abs(val float64) float64 {
//     if val >= 0.0 {
//         return val
//     }
//     return -val
// }

func GetInt(s string) (result int, output string) {
	iter, n := 0, len(s)
	for iter < n && s[iter] >= '0' && s[iter] <= '9' {
		iter++
	}
	result, _ = strconv.Atoi(s[:iter])
	// Skip the redundant characters
	for iter < n && (s[iter] < '0' || s[iter] > '9') {
		iter++
	}
	if iter == n {
		output = ""

	} else {
		output = s[iter:]
	}
	return
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(reader, &t)
	for k := 0; k < t; k++ {
		var n, l, r int
		fmt.Fscan(reader, &n, &l, &r)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] <= arr[j]
		})
		solve1538C(arr,l,r)
	}
}
func solve1538C(arr []int, l, r int)  {
	res := 0
	for k := 0; k < len(arr)-1; k++ {
		//确定arr[k]，找到arr[k]+arr[i]>=l的左边界,arr[k]+arr[i]<=r的右边界。
		var first, last int
		i, j := k+1, len(arr)
		for i < j {
			mid := (i + j) / 2
			if arr[k]+arr[mid] >= l {
				j = mid
			} else {
				i = mid + 1
			}
		}
		first = i

		i, j = k+1, len(arr)
		for i < j {
			mid := (i + j) / 2
			if arr[k]+arr[mid] <= r {
				i = mid + 1
			} else {
				j = mid
			}
		}
		last = i - 1
		res += last - first + 1
	}
	fmt.Println(res)
}

package main

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

const Mod = 1000000007

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

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

	for tc := 1; tc <= t; tc++ {
		solveTest(in, out, tc)
	}

	out.Flush()
}

func solveTest(in *bufio.Reader, out *bufio.Writer, tc int) {
	var n, l, r int
	fmt.Fscan(in, &n, &l, &r)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	sort.Ints(a)

	ans := 0
	for i := 0; i < n; i++ {
		ans += first(a, r + 1 - a[i]) - first(a, l - a[i])
		if a[i] * 2 >= l && a[i] * 2 <= r {
			ans--
		}
	}
	fmt.Fprintln(out, ans / 2)
}

func first(a []int, l int) int {
	n := len(a)
	if a[n - 1] < l {
		return n
	}

	lo, hi := -1, n - 1
	for hi - lo > 1 {
		mid := (hi + lo) / 2
		if a[mid] >= l {
			hi = mid
		} else {
			lo = mid
		}
	}

	return hi
}

func min(xs ...int) int {
	result := xs[0]
	for i := 1; i < len(xs); i++ {
		if result > xs[i] {
			result = xs[i]
		}
	}
	return result
}

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

package main

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

const Mod = 1000000007

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

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

	for tc := 1; tc <= t; tc++ {
		solveTest(in, out, tc)
	}

	out.Flush()
}

func solveTest(in *bufio.Reader, out *bufio.Writer, tc int) {
	var n, l, r int
	fmt.Fscan(in, &n, &l, &r)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)

	ans := 0
	for i := 0; i < n; i++ {
		ans += first(a, r + 1 - a[i]) - first(a, l - a[i])
		if a[i] * 2 >= l && a[i] * 2 <= r {
			ans--
		}
	}
	fmt.Fprintln(out, ans / 2)
}

func first(a []int, l int) int {
	n := len(a)
	if a[n - 1] < l {
		return n
	}

	lo, hi := -1, n - 1
	for hi - lo > 1 {
		mid := (hi + lo) / 2
		if a[mid] >= l {
			hi = mid
		} else {
			lo = mid
		}
	}

	return hi
}

func min(xs ...int) int {
	result := xs[0]
	for i := 1; i < len(xs); i++ {
		if result > xs[i] {
			result = xs[i]
		}
	}
	return result
}

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

package main

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

const (
	MOD int = int(1e9 + 7)
)

type int32 int64

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

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

	for tc := 0; tc < t; tc++ {
		var n, l, r int
		fmt.Fscan(_r, &n, &l, &r)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(_r, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		var ans int
		for i := 0; i < n; i++ {
			li, ri := Find(a, l-a[i]-1), Find(a, r-a[i])
			cnt := ri - li
			if li < i && i <= ri {
				cnt--
			}
			ans += cnt
		}

		fmt.Fprintf(_w, "%d\n", ans/2)
	}
}

// x以下で最大の添字
func Find(arr []int, x int) int {
	n := len(arr)
	if arr[0] > x {
		return -1
	}
	l, r := 0, n
	for r-l > 1 {
		mid := (l + r) / 2
		if arr[mid] <= x {
			l = mid
		} else {
			r = mid
		}
	}
	return l
}

package main

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

const (
	MOD int = int(1e9 + 7)
)

type int64 int32

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

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

	for tc := 0; tc < t; tc++ {
		var n, l, r int
		fmt.Fscan(_r, &n, &l, &r)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(_r, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		var ans int
		for i := 0; i < n; i++ {
			li, ri := Find(a, l-a[i]-1), Find(a, r-a[i])
			cnt := ri - li
			if li < i && i <= ri {
				cnt--
			}
			ans += cnt
		}

		fmt.Fprintf(_w, "%d\n", ans/2)
	}
}

// x以下で最大の添字
func Find(arr []int, x int) int {
	n := len(arr)
	if arr[0] > x {
		return -1
	}
	l, r := 0, n
	for r-l > 1 {
		mid := (l + r) / 2
		if arr[mid] <= x {
			l = mid
		} else {
			r = mid
		}
	}
	return l
}

package main

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

const (
	MOD int = int(1e9 + 7)
)

type Int int64

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

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

	for tc := 0; tc < t; tc++ {
		var n, l, r int
		fmt.Fscan(_r, &n, &l, &r)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(_r, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		ans := 0
		for i := 0; i < n; i++ {
			li, ri := Find(a, l-a[i]-1), Find(a, r-a[i])
			cnt := ri - li
			if li < i && i <= ri {
				cnt--
			}
			ans += cnt
		}

		fmt.Fprintf(_w, "%d\n", ans/2)
	}
}

// x以下で最大の添字
func Find(arr []int, x int) int {
	n := len(arr)
	if arr[0] > x {
		return -1
	}
	l, r := 0, n
	for r-l > 1 {
		mid := (l + r) / 2
		if arr[mid] <= x {
			l = mid
		} else {
			r = mid
		}
	}
	return l
}

package main

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

func main() {
	var t, n, l, r int
	var arr []int

	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for m := 0; m < t; m++ {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &l)
		fmt.Fscan(in, &r)

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

		// for duplication
		nMap := make(map[int]map[int]bool)
		ans := 0

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				// remove duplication
				if _, iExists := nMap[arr[i]]; iExists {
					if _, jExists := nMap[arr[i]][arr[j]]; jExists {
						continue
					}
				}
				if _, jExists := nMap[arr[j]]; jExists {
					if _, iExists := nMap[arr[j]][arr[i]]; iExists {
						continue
					}
				}

				sum := arr[i] + arr[j]
				if sum >= l && sum <= r {
					ans++
					if _, ok := nMap[arr[i]]; !ok {
						nMap[arr[i]] = make(map[int]bool)
					}
					nMap[arr[i]][arr[j]] = true
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

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

func main() {
	var t, n, l, r int
	var arr []int

	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for m := 0; m < t; m++ {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &l)
		fmt.Fscan(in, &r)

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

		// for duplication
		nMap := make(map[int]int)
		ans := 0

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if arrI, ok := nMap[arr[i]]; ok && arrI == arr[j] {
					continue
				}

				if arrJ, ok := nMap[arr[j]]; ok && arrJ == arr[i] {
					continue
				}

				sum := arr[i] + arr[j]
				if sum >= l && sum <= r {
					ans++
					nMap[arr[i]] = arr[j]
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

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

func testcase(reader *bufio.Reader, writer *bufio.Writer) {
  var n, l, r int
  fmt.Fscan(reader, &n, &l, &r)

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

  sort.Ints(a)
  min := make([]int, n)

  for i, j := 0, n-1; i < n; {
    if (i >= j) {
      min[i] = i
      i++
      continue
    }

    if a[i] + a[j] >= l {
      j--
    } else {
      min[i] = j
      i++
    }
  }

  ans := 0

  for i, j := 0, n-1; i < j; {
    if a[i] + a[j] <= r {
      ans += j - min[i]
      i++
    } else {
      j--
    }
  }

  fmt.Fprintln(writer, ans)
}

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

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

  for i := 0; i < t; i++ {
    testcase(reader, writer)
  }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	solve := func(Case int) {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Ints(a)
		ans, x, y := 0, n-1, n-1
		for i := 0; i < y; i++ {
			x = max(i, x)
			for x > i && a[i]+a[x] >= l {
				x--
			}
			for y > x && a[i]+a[y] > r {
				y--
			}
			ans += (y - x)
		}
		fmt.Fprintln(out, ans)
	}

	T := 1
	fmt.Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
}

func max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func min(a []int) int {
	mn := int(1e9)
	for i := range a {
		if a[i] < mn {
			mn = a[i]
		}
	}
	return mn
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	solve := func(Case int) {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Ints(a)
		ans := 0
		for i := range a {
			x := sort.SearchInts(a, l-a[i])
			y := sort.SearchInts(a, r-a[i])
			if x <= i {
				x = i + 1
			}

			if y < n && a[i]+a[y] > r {
				y--
			}
			y = min([]int{y, n - 1})
			if x <= y {
				ans += y - x + 1
			}
		}
		fmt.Fprintln(out, ans)
	}

	T := 1
	fmt.Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}
}

func max(x, y int64) int64 {
	if x < y {
		return y
	}
	return x
}

func min(a []int) int {
	mn := int(1e9)
	for i := range a {
		if a[i] < mn {
			mn = a[i]
		}
	}
	return mn
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

package main

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {
		var n, l, r int
		fmt.Fscan(read, &n, &l, &r)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(read, &a[j])
		}

		fmt.Println(solve(a, n, l, r))
	}
}

func solve(a[]int, n, l , r int) int64 {
	var ans int64

	sort.Ints(a)

	for i := 0; i < n; i++ {
		c := a[i]

		if c > r {
			continue
		}

		if c < l {
			idxL := sort.Search(n, func(i int) bool {
				return c + a[i] >= l
			})

			if idxL == n {
				continue
			}

			if idxL <= i {
				idxL = i + 1
			}

			idxR := sort.Search(n, func(i int) bool {
				return c + a[i] > r
			})

			if idxR == n {
				ans += int64(n) - int64(idxL)
			} else if idxR <= i {
				continue
			} else {
				idxR--

				if idxR >= idxL {
					ans += int64(idxR) - int64(idxL) + 1
				}
			}

		} else {
			idxR := sort.Search(n, func(i int) bool {
				return c + a[i] > r
			})

			if idxR == n {
				ans += int64(n) - int64(i + 1)

			} else if idxR <= i {
				continue
			}else {
				ans += int64(idxR) - int64(i + 1) + 1
			}
		}
	}

	return ans

}

package main

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {
		var n, l, r int
		fmt.Fscan(read, &n, &l, &r)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(read, &a[j])
		}

		fmt.Println(solve(a, n, l, r))
	}
}

func solve(a[]int, n, l , r int) int64 {
	var ans int64

	sort.Ints(a)

	for i := 0; i < n; i++ {
		c := a[i]

		if c > r {
			continue
		}

		if c < l {
			idxL := sort.Search(n, func(i int) bool {
				return c + a[i] >= l
			})

			if idxL == n {
				continue
			}

			if idxL <= i {
				idxL = i + 1
			}

			idxR := sort.Search(n, func(i int) bool {
				return c + a[i] > r
			})

			if idxR == n {
				ans += int64(n) - int64(idxL)
			} else if idxR <= i {
				continue
			} else {
				idxR--

				ans += int64(idxR) - int64(idxL) + 1
			}

		} else {
			idxR := sort.Search(n, func(i int) bool {
				return c + a[i] > r
			})

			if idxR == n {
				ans += int64(n - 1)

			} else if idxR <= i {
				continue
			}else {
				ans += int64(idxR)
			}
		}
	}

	return ans

}

package main

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

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

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

	var n, l, r, num int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &l, &r)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &num)
			arr[i] = num
		}
		sort.Ints(arr)
		cnt := 0
		for i, num := range arr {
			j := sort.SearchInts(arr[:i], l-num)
			k := sort.SearchInts(arr[:i], r-num+1)
			if j < k {
				cnt += k - j
			}
		}
		fmt.Fprintln(writer, cnt)
	}
}

package main

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

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

func calc1(arr *[]int, ind, x int) int {
	lo := ind + 1
	hi := len(*arr) - 1
	ans := -1
	for lo <= hi {
		mid := (lo + hi) >> 1
		if (*arr)[mid] >= x {
			hi = mid - 1
			ans = mid
		} else {
			lo = mid + 1
		}
	}
	return ans
}

func calc2(arr *[]int, ind, x int) int {
	lo := ind + 1
	hi := len(*arr) - 1
	ans := -1
	for lo <= hi {
		mid := (lo + hi) >> 1
		if (*arr)[mid] > x {
			hi = mid - 1
		} else {
			lo = mid + 1
			ans = mid
		}
	}
	return ans
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n, l, r int
		fmt.Fscan(in, &n, &l, &r)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Ints(arr)
		ans := 0
		for i := 0; i < len(arr); i++ {
			ind1 := calc1(&arr, i, l - arr[i])
			ind2 := calc2(&arr, i, r - arr[i])
			if ind1 <= ind2 && ind1 != -1 && ind2 != -1{
				ans += ind2 - ind1 + 1
			}
		}
		fmt.Fprintln(out, ans)
		t--
	}
	out.Flush()

}


package main

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

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

const maxn = 200500;

func main() {
    reader := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()
    var n int
    fmt.Fscanln(reader, &n)
    var f, nf [maxn]int
    for i := 1; i <= n; i++ {
        fmt.Fscan(reader, &f[i])
        nf[f[i]] = i
    }
    senders := make([]int, 0, n)
    receivers := make([]int, 0, n)
    for i := 1; i <= n; i++ {
        if f[i] == 0 && nf[i] == 0 {
            senders = append(senders, i)
            receivers = append(receivers, i)
        }
    }
    for i := 1; i <= n; i++ {
        if f[i] == 0 && nf[i] != 0 {
            senders = append(senders, i)
        }
        if nf[i] == 0 && f[i] != 0 {
            receivers = append(receivers, i)
        }
    }
    for i := range(senders) {
        j := i + 1
        if j == len(receivers) {
            j = 0
        }
        f[senders[i]] = receivers[j]
    }
    for i := 1; i <= n; i++ {
        fmt.Fprint(writer, f[i], " ")
    }
}

package main

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

type LinkList struct {
	d    int
	next *LinkList
}

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

func recurse(i, n int, unmatched *LinkList, a []int) bool {
	for ; i < n && a[i] != 0; i++ {
	}
	if i == n {
		return true
	}
	var prev *LinkList
	head := unmatched
	for curr := head; curr != nil; {
		c := curr.d
		if c == i+1 {
			prev = curr
			curr = curr.next
			continue
		}
		if curr == unmatched {
			head = unmatched.next
		} else {
			prev.next = curr.next
		}
		if recurse(i+1, n, head, a) {
			a[i] = c
			return true
		}
		if curr == unmatched {
			head = unmatched
		} else {
			prev.next = curr
		}
		prev = curr
		curr = curr.next
	}
	return false
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscanln(reader, &n)
	a := make([]int, n)
	filled := make([]bool, n)
	var ai int
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &ai)
		a[i] = ai
		if ai > 0 {
			filled[ai-1] = true
		}
	}
	var unmatched_head, curr *LinkList
	for i := 0; i < n; i++ {
		if filled[i] {
			continue
		}
		newnode := &LinkList{d: i + 1, next: nil}
		if unmatched_head == nil {
			unmatched_head = newnode
			curr = newnode
		} else {
			curr.next = newnode
			curr = newnode
		}
	}
	recurse(0, n, unmatched_head, a)
	for _, arri := range a {
		fmt.Fprintf(writer, "%d ", arri)
	}
}

package main

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

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024*1024*10)

	n, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	sending := make([]int, int(n))
	receiving := make([]int, len(sending))
	in := strings.Split(readLine(reader), " ")
	for i := range sending {
		v, err := strconv.ParseInt(in[i], 10, 64)
		checkError(err)
		sending[i] = int(v)
		if v != 0 {
			receiving[sending[i]-1] = i + 1
		}
	}

	// fmt.Println(sending, receiving)

	first, last := len(sending), len(sending)

	for i := range sending {
		if sending[i] == 0 && receiving[i] == 0 {
			if first == len(sending) {
				first = i
			} else {
				sending[i] = last + 1
				receiving[last] = i + 1
			}
			last = i
		}
	}

	dangling := len(sending)
	if first != last {
		sending[first] = last + 1
		receiving[last] = first + 1
	} else if first != len(sending) {
		dangling = first
	}

	for i := range sending {
		if sending[i] == 0 && receiving[i] != 0 {
			beginning := receiving[i] - 1
			for ; receiving[beginning] != 0; beginning = receiving[beginning] - 1 {
			}
			if dangling == len(sending) {
				sending[i] = beginning + 1
				receiving[beginning] = i + 1
			} else {
				sending[i] = dangling + 1
				receiving[dangling] = i + 1

				sending[dangling] = beginning + 1
				receiving[beginning] = dangling + 1

				dangling = len(sending)
			}
		}
	}

	for i := range sending {
		end := " "
		if i == len(sending)-1 {
			end = "\n"
		}
		fmt.Print(sending[i], end)
	}
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimSpace(string(str))
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

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

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

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

	n, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	sending := make([]int, int(n))
	receiving := make([]int, len(sending))
	in := strings.Split(readLine(reader), " ")
	for i := range sending {
		v, err := strconv.ParseInt(in[i], 10, 64)
		checkError(err)
		sending[i] = int(v)
		if v != 0 {
			receiving[sending[i]-1] = i + 1
		}
	}

	// fmt.Println(sending, receiving)

	first, last := len(sending), len(sending)

	for i := range sending {
		if sending[i] == 0 && receiving[i] == 0 {
			if first == len(sending) {
				first = i
			} else {
				sending[i] = last + 1
				receiving[last] = i + 1
			}
			last = i
		}
	}

	dangling := len(sending)
	if first != last {
		sending[first] = last + 1
		receiving[last] = first + 1
	} else if first != len(sending) {
		dangling = first
	}

	for i := range sending {
		if sending[i] == 0 && receiving[i] != 0 {
			beginning := receiving[i] - 1
			for ; receiving[beginning] != 0; beginning = receiving[beginning] - 1 {
			}
			if dangling == len(sending) {
				sending[i] = beginning + 1
				receiving[beginning] = i + 1
			} else {
				sending[i] = dangling + 1
				receiving[dangling] = i + 1

				sending[dangling] = beginning + 1
				receiving[beginning] = dangling + 1

				dangling = len(sending)
			}
		}
	}

	for i := range sending {
		end := " "
		if i == len(sending)-1 {
			end = "\n"
		}
		fmt.Print(sending[i], end)
	}
}

func readLine(reader *bufio.Reader) string {
	str, err := reader.ReadString('\n')
	if err == io.EOF {
		return ""
	}

	return strings.TrimSpace(str)
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}


package main

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

const mod = 998244353

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var l,r int
	fmt.Fscan(in,&l,&r)
	arr := make([][]int,31)
	for i := 0; i < 31; i++ {
		arr[i] = make([]int,2)
	}
	for i := 0;i <= r;i++{
		var item int
		fmt.Fscan(in,&item)
		for j := 0;j < 30;j++{
			arr[j][(item >> j) & 1]++
		}
	}
	ans := 0
	for i := 0;i < 30;i++{
		var bit int
		if arr[i][0] > arr[i][1]{
			bit = 0
		}else{
			bit = 1
		}
		ans |= bit * (1 << i)
	}
	fmt.Fprintln(out,ans)
}

func abs(a,b int)int{
	if a > b{
		return a - b
	}
	return b - a
}
func sum(a,b int64)int64{
	return (b + a) * (b - a + 1) / 2
}

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 gcd(a,b int)int{
	if a % b == 0{
		return b
	}
	return gcd(b,a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int
		Fscan(in, &l, &r)

		a := make([]int, r-l+1)
		ma := 0
		for j := 0; j < r-l+1; j++ {
			Fscan(in, &a[j])
			if a[j] > ma {
				ma = a[j]
			}
		}

		ans := 0
		for j := 1; j <= ma; j <<= 1 {
			c0, c1 := 0, 0
			for index := range a {
				if a[index]&j == j {
					c1++
				} else {
					c0++
				}
			}
			if c1 > c0 {
				ans |= j
			}

		}
		Fprintln(out, ans)
	}

}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		l := _int()
		r := _int()
		a := make([]int, r-l+1)
		for i := range a {
			a[i] = _int()
		}
		printf("%d\n", sol(l, r, a))
	}
}

func sol(l, r int, a []int) int {
	m := max(a)
	bit := 1
	ret := 0
	for bit <= m {
		c0 := 0
		c1 := 0
		for i := range a {
			if (a[i] & bit) != 0 {
				c1 += 1
			} else {
				c0 += 1
			}
		}
		// printf("debug: %d\n", bit)
		if c1 > c0 {
			ret |= bit
		}
		bit <<= 1
	}
	return ret
}

func max(a []int) int {
	ret := a[0]
	for i := range a {
		if a[i] > ret {
			ret = a[i]
		}
	}
	return ret
}

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

package main

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

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 readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}
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
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readArrInt(ip)
		a := readArrInt(ip)
		cnt := make([][]int, 33)
		for i := range cnt {
			cnt[i] = make([]int, 2)
		}
		for _, i := range a {
			j := 0
			for j<33 {
				if i&1 == 1 {
					cnt[j][1]++
				} else {
					cnt[j][0]++
				}
				i >>= 1
				j++
			}
		}

		ans := 0
		for i := range cnt {
			if cnt[i][0] < cnt[i][1] {
				ans |= 1 << i
			}
		}
		fmt.Println(ans)
	}
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int64
		Fscan(in, &l, &r)

		a := make([]int64, r-l+1)
		aMap := make(map[int64]bool)
		for j := l; j <= r; j++ {
			Fscan(in, &a[j-l])
			aMap[a[j-l]] = true

		}

		Fprintln(out, solver(&aMap, l, r))
	}

}

func solver(a *map[int64]bool, l int64, r int64) int64 {
	if (r-l+1)%2 == 0 {
		tmpMap := make(map[int64]bool)
		for key := range *a {
			tmpMap[key>>1] = true
		}
		return solver(&tmpMap, l>>1, r>>1) << 1
	} else {
		ans := int64(0)
		for i := l; i <= r; i++ {
			ans ^= i
		}
		for v := range *a {
			ans ^= v
		}
		return ans
	}

}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int
		Fscan(in, &l, &r)

		a := make([]int, r-l+1)
		ma := 0
		for j := 0; j < r-l+1; j++ {
			Fscan(in, &a[j])
			if a[j] > ma {
				ma = a[j]
			}
		}

		ans := 0
		for j := 1; j < ma; j <<= 1 {
			c0, c1 := 0, 0
			for index := range a {
				if a[index]&j == j {
					c1++
				} else {
					c0++
				}
			}
			if c1 > c0 {
				ans |= j
			}

		}
		Fprintln(out, ans)
	}

}

func xorN(n uint64) uint64 {
	t := n & 3
	if t&1 > 0 {
		return t/uint64(2) ^ 1
	}
	return t/uint64(2) ^ n
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int
		Fscan(in, &l, &r)

		var k uint64
		if r%2 == 0 {
			k = xorN(uint64(r))
		} else {
			k = xorN(uint64(r-1)) ^ uint64(r)
		}

		a := make([]uint64, r-l+1)
		for j := 0; j < r-l+1; j++ {
			Fscan(in, &a[j])
			k ^= a[j]
		}

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

		if k != 0 {
			Fprintln(out, k)
		} else {
			Fprintln(out, a[r/2])
		}

	}

}

func xorN(n uint64) uint64 {
	t := n & 3
	if t&1 > 0 {
		return t/uint64(2) ^ 1
	}
	return t/uint64(2) ^ n
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int
		Fscan(in, &l, &r)

		var k uint64
		if r%2 == 0 {
			k = xorN(uint64(r))
		} else {
			k = xorN(uint64(r-1)) ^ uint64(r)
		}

		var x uint64
		var max uint64
		for j := 0; j < r-l+1; j++ {
			Fscan(in, &x)
			if max < x {
				max = x
			}
			k ^= x
		}

		if k != 0 {
			Fprintln(out, k)
		} else {
			Fprintln(out, max-uint64(r/2))
		}

	}

}

func xorN(n uint64) uint64 {
	t := n & 3
	if t&1 > 0 {
		return t/uint64(2) ^ 1
	}
	return t/uint64(2) ^ n
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int
		Fscan(in, &l, &r)

		var k uint64
		if r%2 == 0 {
			k = xorN(uint64(r))
		} else {
			k = xorN(uint64(r-1)) ^ uint64(r)
		}

		var x uint64
		var max uint64
		for j := 0; j < r-l+1; j++ {
			Fscan(in, &x)
			if max < x {
				max = x
			}
			k ^= x
		}

		if k != 0 {
			Fprintln(out, k)
		} else {
			Fprintln(out, max-uint64(l/2))
		}

	}

}

func xorN(n uint64) uint64 {
	t := n & 3
	if t&1 > 0 {
		return t/uint64(2) ^ 1
	}
	return t/uint64(2) ^ n
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int
		Fscan(in, &l, &r)

		var k uint64
		if r%2 == 0 {
			k = xorN(uint64(r))
		} else {
			k = xorN(uint64(r-1)) ^ uint64(r)
		}

		var x uint64
		var max uint64
		for j := 0; j < r-l+1; j++ {
			Fscan(in, &x)
			if max < x {
				max = x
			}
			k ^= x
		}

		if k != 0 {
			Fprintln(out, k)
		} else {
			Fprintln(out, max)
		}

	}

}

func xorN(n uint64) uint64 {
	t := n & 3
	if t&1 > 0 {
		return t/uint64(2) ^ 1
	}
	return t/uint64(2) ^ n
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var n int
	Fscan(in, &n)

	for i := 0; i < n; i++ {
		var l, r int
		Fscan(in, &l, &r)

		var k uint64
		if r%2 == 0 {
			k = xorN(uint64(r))
		} else {
			k = xorN(uint64(r-1)) ^ uint64(r)
		}

		var x uint64
		for j := 0; j < r-l+1; j++ {
			Fscan(in, &x)
			k ^= x
		}

		if k != 0 {
			Fprintln(out, k)
		} else {
			Fprintln(out, x)
		}

	}

}

func xorN(n uint64) uint64 {
	t := n & 3
	if t&1 > 0 {
		return t/uint64(2) ^ 1
	}
	return t/uint64(2) ^ n
}

package main

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

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 readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}
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
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		_ = readArrInt(ip)
		a := readArrInt(ip)
		cnt := make([][]int, 33)
		for i := range cnt {
			cnt[i] = make([]int, 2)
		}
		for _, i := range a {
			j := 0
			for i > 0 {
				if i&1 == 1 {
					cnt[j][1]++
				} else {
					cnt[j][0]++
				}
				i >>= 1
				j++
			}
		}

		ans := 0
		for i := range cnt {
			if cnt[i][0] < cnt[i][1] {
				ans |= 1 << i
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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 readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}
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
}

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	xor := make([]int, 1<<17+1)
	for i := 1; i < len(xor); i++ {
		xor[i] = xor[i-1] ^ i
	}
	//fmt.Println(xor)
	for t > 0 {
		t--
		tmp := readArrInt(ip)
		_ = tmp[1]
		a := readArrInt(ip)
		cnt := make([][]int, 33)
		for i := range cnt {
			cnt[i] = make([]int, 2)
		}
		for _, i := range a {
			j := 0
			for i > 0 {
				if i&1 == 1 {
					cnt[j][1]++
				} else {
					cnt[j][0]++
				}
				i >>= 1
				j++
			}
		}

		ans := 0
		for i := range cnt {
			if cnt[i][0] < cnt[i][1] {
				ans += 1 << i
			}
		}
		fmt.Println(ans)
	}
}


package main

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

const MOD int64 = 1000000007

var n int

var a[]int

const MAX int = 2e5 + 5

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

const LOCAL = false

var w *bufio.Writer

var cntGet int64
var cntAdd int64
var all int64
var cntLoop int64

func main() {

	read := bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

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

	if LOCAL {

		rand.Seed(time.Now().UnixNano())

		s := time.Now().UnixNano()

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

			n = 10

			a = make([]int, n)

			for j := 0; j < n; j++ {
				s := 1 + rand.Intn(n)
				a[j] = s
			}

			st := time.Now().UnixNano()
			solve()
			en := time.Now().UnixNano()
			all += en - st
		}

		w.Flush()

		e := time.Now().UnixNano()

		fmt.Println((e - s)/1000000)
		fmt.Println(cntGet/1000000)
		fmt.Println(cntAdd/1000000)
		fmt.Println(all/1000000)
		fmt.Println(cntLoop/1000000)

		return

	}

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

		fmt.Fscan(read, &n)

		a = make([]int, n)

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

		solve()
	}

	w.Flush()
}

type pair struct {
	v int
	idx []int
}

func solve() {
	//[10,50,30,20,40,60]
    //    i      k  j

    mp := make(map[int]int)

   for i := 0; i < n; i++ {
   	mp[a[i]]++
   }
   for _, v := range mp{
   	if v > 1 {
		fmt.Fprintln(w, "YES")
		return
	}
   }

   bit := make([]int, n + 1)

   init := 0

	for j := n - 1; j >= 0; j-- {
		cur := a[j]
		var s int
		if cur != 1 {
			s = get(cur - 1, &bit)
		}

		init +=s

		add(cur, 1, &bit, n)
	}

	if init % 2 == 0 {
		fmt.Fprintln(w, "YES")
		return
	}

	fmt.Fprintln(w, "NO")
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1585D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		p := make([]int, n+1)
		eq := false
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
			if p[a[i]] > 0 {
				eq = true
			}
			p[a[i]] = i
		}
		if eq || n < 2 {
			Fprintln(out, "YES")
			continue
		}
		for i := 1; i < n-1; i++ {
			if p[i] == i {
				continue
			}
			x, y := p[i], i
			z := n
			if x == n {
				z--
			}
			p[a[z]] = x
			p[a[y]] = z
			a[x] = a[z]
			a[z] = a[y]
		}
		if a[n-1] < a[n] {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1585D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		p := make([]int, n+1)
		eq := false
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
			if p[a[i]] > 0 {
				eq = true
			}
			p[a[i]] = i
		}
		if eq || n < 2 {
			Fprintln(out, "YES")
			continue
		}
		for i := 1; i < n-1; i++ {
			if p[i] == i {
				continue
			}
			x, y := p[i], i
			z := n
			if x == n {
				z--
			}
			p[a[z]] = p[i]
			p[a[y]] = z
			a[x], a[y], a[z] = a[z], a[x], a[y]
		}
		if a[n-1] < a[n] {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1585D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		p := make([]int, n+1)
		eq := false
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
			if p[a[i]] > 0 {
				eq = true
			}
			p[a[i]] = i
		}
		if !eq {
			for i := 1; i < n-1; i++ {
				if p[i] == i {
					continue
				}
				x, y := p[i], i
				if x < n {
					z := n
					p[a[z]] = p[i]
					p[a[y]] = z
					a[x], a[y], a[z] = a[z], a[x], a[y]
				} else {
					z := n - 1
					p[a[z]] = p[i]
					p[a[y]] = z
					a[x], a[y], a[z] = a[z], a[x], a[y]
				}
			}
		}
		if eq || n == 1 || a[n-1] < a[n] {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

const MAX int = 2e5 + 5

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

const LOCAL = false

var w *bufio.Writer

var cntGet int64
var cntAdd int64
var all int64
var cntLoop int64

func main() {

	read := bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

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

	if LOCAL {

		rand.Seed(time.Now().UnixNano())

		s := time.Now().UnixNano()

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

			n = 10

			a = make([]int, n)

			for j := 0; j < n; j++ {
				s := 1 + rand.Intn(n)
				a[j] = s
			}

			st := time.Now().UnixNano()
			solve()
			en := time.Now().UnixNano()
			all += en - st
		}

		w.Flush()

		e := time.Now().UnixNano()

		fmt.Println((e - s)/1000000)
		fmt.Println(cntGet/1000000)
		fmt.Println(cntAdd/1000000)
		fmt.Println(all/1000000)
		fmt.Println(cntLoop/1000000)

		return

	}

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

		fmt.Fscan(read, &n)

		a = make([]int, n)

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

		solve()

		w.Flush()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {
	//[10,50,30,20,40,60]
    //    i      k  j

   //50 20 40

   //
   bit := make([]int, n + 1)

   init := 0

	for j := n - 1; j >= 0; j-- {
		cur := a[j]
		var s int
		if cur != 1 {
			s = get(cur - 1, &bit)
		}

		init +=s

		add(cur, 1, &bit, n)
	}

	if init % 2== 0 {
		fmt.Fprintln(w, "YES")
		return
	}

	fmt.Fprintln(w, "NO")
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

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

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

const MAX int = 2e5 + 5

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

const LOCAL = false

var w *bufio.Writer

var cntGet int64
var cntAdd int64
var all int64
var cntLoop int64

func main() {

	read := bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

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

	if LOCAL {

		rand.Seed(time.Now().UnixNano())

		s := time.Now().UnixNano()

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

			n = 10

			a = make([]int, n)

			for j := 0; j < n; j++ {
				s := 1 + rand.Intn(n)
				a[j] = s
			}

			st := time.Now().UnixNano()
			solve()
			en := time.Now().UnixNano()
			all += en - st
		}

		w.Flush()

		e := time.Now().UnixNano()

		fmt.Println((e - s)/1000000)
		fmt.Println(cntGet/1000000)
		fmt.Println(cntAdd/1000000)
		fmt.Println(all/1000000)
		fmt.Println(cntLoop/1000000)

		return

	}

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

		fmt.Fscan(read, &n)

		a = make([]int, n)

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

		solve()
	}
	w.Flush()

}

type pair struct {
	v int
	idx []int
}

func solve() {
	//[10,50,30,20,40,60]
    //    i      k  j

   //50 20 40

   //
   bit := make([]int, n + 1)

   init := 0

	for j := n - 1; j >= 0; j-- {
		cur := a[j]
		var s int
		if cur != 1 {
			s = get(cur - 1, &bit)
		}

		init +=s

		add(cur, 1, &bit, n)
	}

	if init % 2== 0 {
		fmt.Fprintln(w, "YES")
		return
	}

	fmt.Fprintln(w, "NO")
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

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

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

const MAX int = 2e5 + 5

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

const LOCAL = false

var w *bufio.Writer

func main() {

	read := bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

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

	if LOCAL {

		rand.Seed(time.Now().UnixNano())

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

			n = 50

			a = make([]int, n)

			for j := 0; j < n; j++ {
				s := 1 + rand.Intn(n)
				a[j] = s
			}

			solve()
		}

		return

	}

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

		fmt.Fscan(read, &n)

		a = make([]int, n)

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

		solve()

		w.Flush()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {
	//[10,50,30,20,40,60]
    //    i      k  j

   //50 20 40

   //
   bit := make([]int, MAX)

   init := 0

	for j := n - 1; j >= 0; j-- {
		cur := a[j]
		var s int
		if cur != 1 {
			s = get(cur - 1, &bit)
		}

		init +=s

		add(cur, 1, &bit, n)
	}

	if init % 2== 0 {
		fmt.Fprintln(w, "YES")
	}

	fmt.Fprintln(w, "NO")

}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

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