package main

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

const mod = 998244353

var f [2 * 100001]int

func mul(arr ...int) int {
	res := 1
	for _, v := range arr {
		res = int((int64(res) * int64(v)) % mod)
	}
	return res
}

func fact() {
	f[0] = 1
	for i := 1; i < len(f); i++ {
		f[i] = mul(f[i-1], i)
	}
}

func pow(a, p int) int {
	if p == 0 {
		return 0
	}
	if p == 1 {
		return a
	}
	x := pow(a, p/2)
	x = mul(x, x)
	if p%2 == 1 {
		x = mul(x, a)
	}
	return x
}

func inv(n int) int {
	return pow(f[n], mod-2)
}

func main() {
	fact()

	r := bufio.NewReaderSize(os.Stdin, 1024*1024)
	var T int
	fmt.Fscanf(r, "%d\n", &T)

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

		sort.Ints(arr)

		m, p := 0, 0
		for i := 0; i < n; i++ {
			if arr[i] == arr[n-1] {
				m++
			}
			if arr[i] == arr[n-2] {
				p++
			}
		}

		//1 2 3 3 3 4
		// 3 3 3 4
		// 3 3 3 X 4 X
		//

		if m > 1 {
			fmt.Println(f[n])
		} else if arr[n-1]-arr[n-2] > 1 {
			fmt.Println(0)
		} else {
			res := int64(f[n])

			for i := p + 1; i <= n; i++ {
				v := n - m - p
				k := i - p - 1
				res -= int64(mul(f[n-i], f[i-1], f[v], inv(k), inv(v-k)))
				if res < 0 {
					res += mod
				}
			}

			fmt.Println(res)
		}
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		ARRAY := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])

		}

		sort.Ints(ARRAY)

		q := ARRAY[n-1]

		if ARRAY[n-1]-ARRAY[n-2] > 1 {
			fmt.Println(0)
		} else {
			var m int64
			var tt int64
			var olol bool
			if q == ARRAY[n-2] {
				m = 1
				tt = 1
				olol = true
			} else {
				ans := 0
				for i := n - 2; i > -1; i-- {
					if ARRAY[i] == q-1 {
						ans++
					} else {
						break
					}
				}
				m = int64(ans)
				tt = int64(ans)
				olol = false
			}
			for i := 2; i < n+1; i++ {
				if int64(i) != tt+1 {
					m = m * int64(i)
					m = m % 998244353
				}
			}
			if olol == true {
				m = m * 2
				m = m % 998244353
				fmt.Println(m)
			} else {
				fmt.Println(m)
			}

		}

	}
}

package main

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

const MOD int64 = 998_244_353

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var test int
	fmt.Fscan(in, &test)
	for ; test > 0; test-- {
		var n int64
		fmt.Fscan(in, &n)

		ar := make([]int, n)
		for i := range ar {
			fmt.Fscan(in, &ar[i])
		}

		max := 0
		for i := range ar {
			if ar[i] > ar[max] {
				max = i
			}
		}

		c := 0
		k := 0
		for i := range ar {
			if ar[i] == ar[max] {
				c++
			}
			if ar[i] == ar[max]-1 {
				k++
			}
		}

		var fact int64 = 1
		var except int64 = 1
		for i := int64(1); i <= n; i++ {
			fact *= i
			fact %= MOD
			if i != int64(k+1) {
				except *= i
				except %= MOD
			}
		}

		if c == 1 {
			fact = (fact - except + MOD) % MOD
		}

		fmt.Fprintln(out, fact)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

const kMod int64 = 998_244_353

func factorialWithSkip(rawX, rawSkip int) int64 {
	x, skip := int64(rawX), int64(rawSkip)
	result := int64(1)
	for i := int64(1); i <= x; i++ {
		if i == skip {
			result *= i - 1
		} else {
			result *= i
		}
		result %= kMod
	}
	return result
}

func solve() {
	var n int
	fmt.Fscan(in, &n)

	aCnt := make(map[int]int)
	maxV := 0
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(in, &ai)

		aCnt[ai]++
		if ai > maxV {
			maxV = ai
		}
	}

	if aCnt[maxV] > 1 {
		fmt.Println(factorialWithSkip(n, 0))
		return
	}
	if aCnt[maxV] == 1 {
		secondFreq, ok := aCnt[maxV-1]
		if !ok {
			fmt.Println(0)
			return
		}
		fmt.Println(factorialWithSkip(n, secondFreq+1))
	} else {
		panic("impossible")
	}
}

func main() {
	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int
var a = make([]int, N)

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

func readInt() int{
	var n int
	fmt.Fscan(in, &n)
	return n
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	for i := 0; i < n; i++{
		a[i] = readInt()
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	//fmt.Println(M1, M2, cnt1, cnt2)
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i)
		ifact[i] = mul(ifact[i-1], inv(i))
	}
	//defer out.Flush()
	for T:=readInt();T>0;T--{
		Solve()
	}
}

package main

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

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int

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

func readInt() int{
	var n int
	fmt.Fscan(in, &n)
	return n
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	var a = make([]int, n)
	for i := 0; i < n; i++{
		a[i] = readInt()
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	//fmt.Println(M1, M2, cnt1, cnt2)
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i)
		ifact[i] = mul(ifact[i-1], inv(i))
	}
	//defer out.Flush()
	for T:=readInt();T>0;T--{
		Solve()
	}
}

package main

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

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int

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

func readInt() int{
	var n int
	fmt.Fscan(in, &n)
	return n
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	var a = make([]int, n)
	for i := 0; i < n; i++{
		a[i] = readInt()
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	//fmt.Println(M1, M2, cnt1, cnt2)
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i)
		ifact[i] = mul(ifact[i-1], inv(i))
	}
	defer out.Flush()
	for T:=readInt();T>0;T--{
		Solve()
	}
}

package main

import "fmt"

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int

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

func readArrayInt(n int) [] int{
	res := make([]int, n)
	for i := 0; i < n; i++{
		fmt.Scanf("%d", &res[i])
	}
	return res
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	var a = readArrayInt(n)
	for i := 0; i < n; i++{
		fmt.Print(a[i])
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	//fmt.Println(M1, M2, cnt1, cnt2)
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i)
		ifact[i] = mul(ifact[i-1], inv(i))
	}
	for T:=readInt();T>0;T--{
		Solve()
	}
}

package main

import "fmt"

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int

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

func readArrayInt(n int) [] int{
	res := make([]int, n)
	for i := 0; i < n; i++{
		fmt.Scanf("%d", &res[i])
	}
	return res
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	var a = readArrayInt(n)
	for i := 0; i < n; i++{
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	//fmt.Println(M1, M2, cnt1, cnt2)
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i)
		ifact[i] = mul(ifact[i-1], inv(i))
	}
	for T:=readInt();T>0;T--{
		Solve()
	}
}

package main

import "fmt"

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int

func readInt() int{
	var n int
	fmt.Scanf("%d", &n)
	return n
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	var a = make([]int, n)
	for i := 0; i < n; i++{
		a[i] = readInt()
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	//fmt.Println(M1, M2, cnt1, cnt2)
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i);
		ifact[i] = mul(ifact[i-1], inv(i));
	}
	for T:=readInt();T>0;T--{
		Solve()
	}
}

package main

import "fmt"

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int

func readInt() int{
	var n int
	fmt.Scanf("%d", &n)
	return n
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	var a = make([]int, n)
	for i := 0; i < n; i++{
		a[i] = readInt()
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i);
		ifact[i] = mul(ifact[i-1], inv(i));
	}
	var T int = readInt()
	for ;T>0;T--{
		Solve()
	}
}

package main

import "fmt"

const mod = 998244353

func add(a int, b int) int{
	a+=b
	if a>=mod{ a-=mod}
	return a
}

func sub(a int, b int) int{
	a-=b
	if (a<0){a+=mod}
	return a
}

func mul(a int, b int) int{
	res := int64(a) * int64(b) % mod
	return int(res)
}

func pow(a int , b int) int{
	if b==0{
		return 1;
	}
	var t int = pow(a, b >> 1)
	t = mul(t,t)
	if (b&1) > 0{
		t = mul(t, a)
	}
	return t
}

func choosen (k int , n int) int{
	if (k > n) {
		return 0
	}
	return mul(fact[n], mul(ifact[k], ifact[n-k]))
}

func inv(a int) int{
	return pow(a, mod-2)
}

const N = 2e5
var fact[N+1] int
var ifact[N+1] int

func readInt() int{
	var n int
	fmt.Scanf("%d", &n)
	return n
}

func Solve(){
	var n int = readInt()
	var M1 int = 0
	var M2 int = 0
	var cnt1 int = 0
	var cnt2 int = 0
	var a = make([]int, n)
	for i := 0; i < n; i++{
		a[i] = readInt()
		if (a[i] >= M1) {
			if (a[i] > M1){
				cnt2 = cnt1
				M2 = M1
				cnt1 = 0
				M1 = a[i]
			}
			cnt1++
		} else if (a[i] >= M2){
			if (a[i] > M2){
				cnt2 = 0
				M2 = a[i]
			}
			cnt2++
		}
	}
	//fmt.Println(M1, M2, cnt1, cnt2)
	if (cnt1 > 1){
		fmt.Println(fact[n])
		return
	}
	if (M1 - M2 > 1){
		fmt.Println(0)
		return
	}
	var ans int = 0
	for right := 1; right <= n - 1; right++{
		var t = mul(mul(fact[right], fact[n - 1 - right]), sub(choosen(right, n-1), choosen(right, n-1-cnt2)))
		ans = add(ans, t)
	}
	fmt.Println(ans)
}

func main(){
	fact[0] = 1
	ifact[0] = 1
	for i := 1; i <= N; i++{
		fact[i] = mul(fact[i-1], i);
		ifact[i] = mul(ifact[i-1], inv(i));
	}
	var T int = readInt()
	for ;T>0;T--{
		Solve()
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		ARRAY := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])

		}

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

		q := ARRAY[n-1]

		if ARRAY[n-1]-ARRAY[n-2] > 1 {
			fmt.Println(0)
		} else {
			var m int64 = 1
			for i := 2; i < n+1; i++ {
				m = m * int64(i)
				m = m - m/998244353
			}
			if q-ARRAY[n-2] == 0 {
				fmt.Println(m)
			} else {
				ans := 0
				for i := n - 2; i > -1; i-- {
					if ARRAY[i] == q-1 {
						ans++
					} else {
						break
					}
				}

				m = m * int64(ans)
				m = m / int64(ans+1)
				m = m - m/998244353
				fmt.Println(m)

			}

		}

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		ARRAY := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])

		}

		sort.Ints(ARRAY)

		q := ARRAY[n-1]

		if ARRAY[n-1]-ARRAY[n-2] > 1 {
			fmt.Println(0)
		} else {
			var m int64 = 1
			for i := 2; i < n+1; i++ {
				m = m * int64(i)
				m = m % 998244353
			}
			if q-ARRAY[n-2] == 0 {
				fmt.Println(m)
			} else {
				ans := 0
				for i := n - 2; i > -1; i-- {
					if ARRAY[i] == q-1 {
						ans++
					} else {
						break
					}
				}

				m = m * int64(ans)
				m = m / int64(ans+1)
				m = m % 998244353
				fmt.Println(m)

			}

		}

	}
}

package main

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

const mod = 998244353

var f [2 * 100001]int

func mul(arr ...int) int {
	res := 1
	for _, v := range arr {
		res = int((int64(res) * int64(v)) % mod)
	}
	return res
}

func fact() {
	f[0] = 1
	for i := 1; i < len(f); i++ {
		f[i] = mul(f[i-1], i)
	}
}

func pow(a, p int) int {
	if p == 0 {
		return 0
	}
	if p == 1 {
		return a
	}
	x := pow(a, p/2)
	x = mul(x, x)
	if p%2 == 1 {
		x = mul(x, a)
	}
	return x
}

func inv(n int) int {
	return pow(f[n], mod-2)
}

func main() {
	fact()

	r := bufio.NewReaderSize(os.Stdin, 1024*1024)
	var T int
	fmt.Fscanf(r, "%d\n", &T)

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

		sort.Ints(arr)

		m, p := 0, 0
		for i := 0; i < n; i++ {
			if arr[i] == arr[n-1] {
				m++
			}
			if arr[i] == arr[n-2] {
				p++
			}
		}

		//1 2 3 3 3 4
		// 3 3 3 4
		// 3 3 3 X 4 X
		//

		if m > 1 {
			fmt.Println(f[n])
		} else if arr[n-1]-arr[n-2] > 1 {
			fmt.Println(0)
		} else {
			res := 0

			for i := p + 1; i <= n; i++ {
				v := n - m - p
				k := i - p - 1
				res += mul(f[n-i], f[i-1], f[v], inv(k), inv(v-k))
			}

			x := int64(f[n]) - int64(res)
			if x < 0 {
				x += mod
			}
			fmt.Println(x)
		}
	}
}

package main

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

const mod = 998244353

var f [2 * 100001]int

func mul(arr ...int) int {
	res := 1
	for _, v := range arr {
		res = int((int64(res) * int64(v)) % mod)
	}
	return res
}

func fact() {
	f[0] = 1
	for i := 1; i < len(f); i++ {
		f[i] = mul(f[i-1], i)
	}
}

func pow(a, p int) int {
	if p == 0 {
		return 0
	}
	if p == 1 {
		return a
	}
	x := pow(a, p/2)
	x = mul(x, x)
	if p%2 == 1 {
		x = mul(x, a)
	}
	return x
}

func inv(n int) int {
	return pow(f[n], mod-2)
}

func main() {
	fact()

	r := bufio.NewReaderSize(os.Stdin, 1024*1024)
	var T int
	fmt.Fscanf(r, "%d\n", &T)

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

		sort.Ints(arr)

		m, p := 0, 0
		for i := 0; i < n; i++ {
			if arr[i] == arr[n-1] {
				m++
			}
			if arr[i] == arr[n-2] {
				p++
			}
		}

		//1 2 3 3 3 4
		// 3 3 3 4
		// 3 3 3 X 4 X
		//

		if m > 1 {
			fmt.Println(f[n])
		} else if arr[n-1]-arr[n-2] > 1 {
			fmt.Println(0)
		} else {
			res := 0

			for i := p + 1; i <= n; i++ {
				v := n - m - p
				k := i - p - 1
				res += mul(f[n-i], f[i-1], f[v], inv(k), inv(v-k))
			}

			res = f[n] - res
			if res < 0 {
				res += mod
			}
			fmt.Println(res)
		}
	}
}

package main

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

const MOD int64 = 998_244_353

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var test int
	fmt.Fscan(in, &test)
	for ; test > 0; test-- {
		var n int
		fmt.Fscan(in, &n)

		ar := make([]int, n)
		for i := range ar {
			fmt.Fscan(in, &ar[i])
		}

		max1, max2 := 0, 0
		max2count := 0
		for i := range ar {
			if ar[i] >= ar[max1] {
				max2 = max1
				max1 = i
				max2count = 1
			}
			if ar[i] == ar[max2] {
				max2count++
			}
		}

		if ar[max1]-ar[max2] > 1 {
			fmt.Fprintln(out, 0)
		} else {
			var fact, except int64 = 1, 1
			var cur int64 = 1
			for i := 0; i < n; i++ {
				fact *= cur
				fact %= MOD
				if cur != int64(max2count+1) {
					except *= cur
					except %= MOD
				}
				cur++
			}

			if ar[max1] != ar[max2] {
				fact = (fact - except + MOD) % MOD
			}

			fmt.Fprintln(out, fact)
		}

	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

const kMod int64 = 998224353

func factorialWithSkip(rawX, rawSkip int) int64 {
	x, skip := int64(rawX), int64(rawSkip)
	result := int64(1)
	for i := int64(1); i <= x; i++ {
		if i == skip {
			result *= i - 1
		} else {
			result *= i
		}
		result %= kMod
	}
	return result
}

func solve() {
	var n int
	fmt.Fscan(in, &n)

	aCnt := make(map[int]int)
	maxV := 0
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(in, &ai)

		aCnt[ai]++
		if ai > maxV {
			maxV = ai
		}
	}

	if aCnt[maxV] > 1 {
		fmt.Println(factorialWithSkip(n, 0))
		return
	}
	if aCnt[maxV] == 1 {
		secondFreq, ok := aCnt[maxV-1]
		if !ok {
			fmt.Println(0)
			return
		}
		fmt.Println(factorialWithSkip(n, secondFreq+1))
	} else {
		panic("impossible")
	}
}

func main() {
	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve()
	}
}


package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		a, b, n := readThreeNums(reader)

		fmt.Println(solve(a, b, n))
	}
}

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

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

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

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

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

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

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

	return i
}

func solve(a, b, n int) int {
	if a > n || b > n {
		return 0
	}

	if a > b {
		a, b = b, a
	}
	var res int
	for b <= n {
		a += b
		a, b = b, a
		res++
	}
	return res
}

package main

import (
  "fmt"
)

var T int
var fibs = [1000000]int{}
func main() {
  fmt.Scan(&T)
  for tc := 0; tc < T; tc++ {
    var a,b,n int
    fmt.Scan(&a, &b, &n)
    if a > b {
      a, b = b, a
    }
    if b > n {
      fmt.Println(0)
      continue
    }
    i := 1
    for {
      sum := a*(fib(i-1)) + b*fib(i)
      if sum > n {
        break
      }
      i++
    }
    fmt.Println(i)
  }

}

func fib(n int) int {
  if fibs[n] != 0 {
    return fibs[n]
  }
  if n == 0 || n == 1 {
    return 1
  }
  fibs[n] = fib(n-1) + fib(n-2)
  return fibs[n]
}

package main

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

func main() {
	var t, a, b, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &n)
		a, b := minmax(a, b)
		count := 0
		for b <= n {
			//fmt.Println(a, b)
			t := b
			b = a + b
			a = t
			count++

		}
		fmt.Println(count)
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	//fmt.Println("debug", t)
	for tt := int64(0); tt < t; tt++ {
		a, b, n := int64(0), int64(0), int64(0)
		fmt.Fscanf(in, "%d %d %d\n", &a, &b, &n)
		if a > b {
			a, b = b, a
		}
		ans := 0
		for b <= n {
			ans++
			a = a + b
			a, b = b, a
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

var nTest, a, b, n int

func count(x, y, z int) int {
	cnt := 0
	for x <= z && y <= z {
		x += y
		cnt++
		if x > z {
			break
		}
		y += x
		cnt++
	}

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &a, &b, &n)

		if a > b {
			a, b = b, a
		}
		cnt2 := count(a, b, n)

		fmt.Fprintln(out, cnt2)
	}

	out.Flush()
}

package main

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

var nTest, a, b, n int

func count(x, y, z int) int {
	cnt := 0
	for x <= z && y <= z {
		x += y
		cnt++
		if x > z {
			break
		}
		y += x
		cnt++
	}

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &a, &b, &n)

		cnt1 := count(b, a, n)
		cnt2 := count(a, b, n)

		if cnt1 < cnt2 {
			fmt.Fprintln(out, cnt1)
		} else {
			fmt.Fprintln(out, cnt2)
		}
	}

	out.Flush()
}

package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, a, b, n int
	for Scan(&t); t > 0; t-- {
		Scan(&a, &b, &n)
		if a > b {
			a, b = b, a
		}
		i := 0
		for ; a <= n && b <= n; i++ {
			a, b = b, a+b
		}
		Println(i)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1368A(in io.Reader, out io.Writer) {
	var t, a, b, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &a, &b, &n)
		if a > b {
			a, b = b, a
		}
		i := 0
		for ; a <= n && b <= n; i++ {
			a, b = b, a+b
		}
		Fprintln(out, i)
	}
}

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

package main
import (
        "fmt"
        "os"
        "bufio"
)
func main(){
    var t, a, b, n, ans int
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &a, &b, &n)
        ans = 0
        for a <= n && b <= n {
            if a > b {
                a, b = b+a, a
            } else {
                a, b = a+b, b
            }
            ans++
        }
        fmt.Fprintln(out, ans)
    }
}

package main

import (
	"fmt"
)

func main() {
	var a, b, n, t int
	fmt.Scan(&t)

	for t != 0 {
		fmt.Scan(&a, &b, &n)
		count := 0
		for a <= n && b <= n {
			if a <= b {
				a += b
			} else {
				b += a
			}
			count++
		}
		fmt.Println(count)
		t--
	}
}

// a= 5 b =4

// a+=b  a = 9,4
// b += a a= 5,b=9  always increase the small one

package main

import (
	"fmt"
	"os"
)

func read(t ...interface{}) {
	fmt.Fscan(os.Stdin, t...)
}

func main() {
	var t int
	read(&t)
	for i:=0; i<t; i++ {
		var a, b, n, next, count int
		read(&a, &b, &n)
		next = max(a, b)
		for a <= n && b <= n {
			if next == b {
				a += b
				next = a
			} else  {
				b += a
				next = b
			}
			count++
		}
		fmt.Println(count)
	}
}

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

package main

import "fmt"

func main()  {
	var a,b,n,ans int64
	var c int
	_, _ = fmt.Scan(&c)
	for i:=0;i<c;i++{
		_, _ = fmt.Scan(&a, &b, &n)
		ans=0
		for {
			if a>b{
				b=a+b
			}else {
				a=a+b
			}
			ans++
			if a>n||b>n{
				fmt.Println(ans)
				break
			}
		}
	}
}

package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var t int
	fmt.Fscan(r, &t)
	for i := 0; i < t; i++ {
		var a, b, n int
		fmt.Fscan(r, &a, &b, &n)
		cnt := 1
		for a + b <= n {
			if a > b {
				b += a
			} else {
				a += b
			}
			cnt++
		}
		fmt.Fprintln(w, cnt)
	}
}

package main

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

func main() {
	var t, a, b, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &n)
		b, a := minmax(a, b)
		count := 0
		for b <= n {
			t := b
			b = a + b
			a = t
			count++
		}
		fmt.Println(count)
	}

}

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

package main

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

var nTest, a, b, n int

func count(x, y, z int) int {
	cnt := 0
	for x <= z && y <= z {
		x += y
		cnt++
		if x > z {
			break
		}
		y += x
		cnt++
	}

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &a, &b, &n)

		cnt2 := count(a, b, n)

		fmt.Fprintln(out, cnt2)
	}

	out.Flush()
}


package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, cnt, ans int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
			if a[i] == 0 { cnt++ }
		}

		for _, v := range a {
			if v == 0 {
				cnt--
			} else if cnt > 0 {
				ans++
				cnt--
			} else {
				break
			}
		}

		fmt.Fprintln(w, ans)

	}

}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1746B
Date: 10/19/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1746/B
Problem: CF1746B
**/
func (in *CF1746B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		ans := 0
		arr := make([]int, n)
		cpy := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			cpy[i] = arr[i]
		}

		sort.Ints(arr)
		for i := n - 1; i >= 0; i-- {
			if arr[i] == 1 && cpy[i] != 1 {
				ans++
			}
		}

		fmt.Println(ans)
	}
}

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

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

package main

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

var in = bufio.NewReader(os.Stdin)

func  gcd(a, b int) int {
  for b != 0 {
      a, b = b, a%b
  }
  return a
}

func pl(a ...interface{}) { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }

func main() {
	var T int
	scan(&T)

	for ; T > 0; T-- {
    var n int
    scan(&n)
    a := make([]int, n, n)
    b := make([]int, n, n)
    for i := range a {
      scan(&a[i])
      b[i]=a[i]
    }
    sort.Ints(a[:])
    var ret int
    for i := range a {
      if a[i] != b[i] {
        ret ++
      }
    }
    pf("%d\n", ret/2)
	}
}

func ys(b bool) string { return map[bool]string {true: "YES", false: "NO"}[b] }

package main

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

func main() {
	var tc int

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

	defer writer.Flush()

	fmt.Fscan(reader, &tc)

	for t := 0; t < tc; t++ {
		var n int

		fmt.Fscan(reader, &n)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &arr[i])
		}
		output := solve(&arr, n)
		fmt.Fprintln(writer, output)
	}
}

func solve(arr *[]int, n int) int {
	offPlaceOnes := 0

	for left, right := 0, n-1; left < right; {
		if (*arr)[left] == 1 && (*arr)[right] == 0 {
			offPlaceOnes++
			left++
			right--
			continue
		}
		if (*arr)[left] == 0 && (*arr)[right] == 1 {
			left++
			right--
			continue
		}
		if (*arr)[left] == 1 && (*arr)[right] == 1 {
			right--
			continue
		}
		if (*arr)[left] == 0 && (*arr)[right] == 0 {
			left++
		}
	}
	return offPlaceOnes
}

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

		aa := make([]int, n)
		bb := make([]int, n)
		for i := range aa {
			var v int
			fmt.Fscan(in, &v)
			aa[i] = v
			bb[i] = v
		}

		sort.Ints(bb)
		var tot int
		for i := range aa {
			if aa[i] == 0 && bb[i] == 1 {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	i1, i2 := -1, -1
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		if arr[i] == 1 && i1 == -1 {
			i1 = i
		}
		if arr[i] == 0 {
			i2 = i
		}
	}
	ans := 0
	if i1 == -1 || i2 == -1 {
		fmt.Fprintln(out, 0)
		return
	}
	for i1 < i2 {
		ans++
		i1++
		i2--
		for i1 < n && arr[i1] == 0 {
			i1++
		}
		for i2 >= 0 && arr[i2] == 1 {
			i2--
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

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-- {
		n := _int()
		a := make([]int, n)
		for i := range a {
			a[i] = _int()
		}
		printf("%d\n", sol(n, a))
	}
}

func sol(n int, a []int) int {
	nz := 0
	for _, i := range a {
		if i == 0 {
			nz++
		}
	}
	ret := 0
	for _, i := range a[:nz] {
		if i == 1 {
			ret++
		}
	}
	return ret
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1746B
Date: 10/19/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1746/B
Problem: CF1746B
**/
func (in *CF1746B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		ans := 0
		last := -1
		for i := 0; i < n; i++ {
			val := in.NextInt()
			if i == 0 {
				last = val
			} else {
				if last > val {
					ans++
				}
			}
			last = val
		}
		fmt.Println(ans)
	}
}

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

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


package main

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

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

	n := readNum(reader)

	A := readNNums(reader, (n+1)/2)

	X := readNum(reader)

	fmt.Println(solve(n, A, X))
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A []int, X int) int {
	h := (n + 1) >> 1

	M := make([]int64, h+1)

	var presum int64

	for i := 0; i < h; i++ {
		presum += int64(X) - int64(A[i])
		M[i+1] = min(presum, M[i])
	}

	var sum int64
	for k := 1; k <= h; k++ {
		sum += int64(A[k-1])
	}

	for k := h; k <= n; k++ {
		if sum+M[n-k] > 0 {
			return k
		}

		sum += int64(X)
	}
	return -1
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1358E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}

	var n2, x, s int64
	Fscan(in, &n2)
	n := (n2 + 1) / 2
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	Fscan(in, &x)

	mins := make([]int64, n+1)
	for i, v := range a {
		s += x - v
		mins[i+1] = min(mins[i], s)
	}
	s = 0
	for _, v := range a {
		s += v
	}
	for k := n; k <= n2; k++ {
		if s+mins[n2-k] > 0 {
			Fprint(out, k)
			return
		}
		s += x
	}
	Fprint(out, -1)
}

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

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, (n+1)/2)

	X := readNum(reader)

	fmt.Println(solve(n, A, X))
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A []int, X int) int {
	h := (n + 1) >> 1

	M := make([]int, h+1)

	var presum int

	for i := 0; i < h; i++ {
		presum += X - A[i]
		M[i+1] = min(presum, M[i])
	}

	var sum int
	for k := 1; k <= h; k++ {
		sum += A[k-1]
	}

	for k := h; k <= n; k++ {
		if sum+M[n-k] > 0 {
			return k
		}

		sum += X
	}
	return -1
}

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