Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$): the number of bags for which you need to solve the problem. The first line of each bag description contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$): the number of patty-cakes in it. The second line of the bag description contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.  It is guaranteed that the sum of $$$n$$$ over all bags does not exceed $$$10^5$$$.

For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.

NoteFor the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): $$$1$$$, $$$6$$$, $$$4$$$, $$$7$$$, $$$1$$$, $$$6$$$, $$$4$$$ (in this way, the minimum distance is equal to $$$3$$$).For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): $$$1$$$, $$$4$$$, $$$6$$$, $$$7$$$, $$$4$$$, $$$1$$$, $$$6$$$, $$$4$$$ (in this way, the minimum distance is equal to $$$2$$$).

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		n:=0
		Fscan(in, &n)
		freq:=make(map[int]int)
		for i:=0;i<n;i++{
			var k int
			Fscan(in,&k)
			freq[k]++
		}
		// Fprintln(out,freq)
		bs:=func(mid int) bool{
			q,r:=n/mid,n%mid
			for _,v:=range(freq){
				// Fprintln(out,x,v)
				if v>q+1{
					return false
				}
				if v==q+1{
					r--
				}
			}
			return r>=0
		}

		left,right:=0,n+1
		for right-left>1{
			mid:=(left+right)/2
			// Fprintln(out,mid,bs(mid+1))
			if bs(mid+1){
				left=mid
			} else {
				right=mid
			}
		}
		Fprintln(out,left)
	}
}

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

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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
}

const N = 100010

var B [N]int

func solve(n int, A []int) int {

	check := func(dist int) bool {
		if dist == 1 {
			return true
		}
		cnt := make(map[int]int)
		for i := 0; i < n; i++ {
			cnt[A[i]]++
		}

		ps := make(Pairs, 0, len(cnt))

		for k, v := range cnt {
			p := Pair{v, k, len(ps) - 1}
			heap.Push(&ps, &p)
		}

		for i := 0; i < n; i++ {
			if i >= dist && cnt[B[i-dist]] > 0 {
				p := Pair{cnt[B[i-dist]], B[i-dist], len(ps) - 1}
				heap.Push(&ps, &p)
			}
			if len(ps) == 0 {
				return false
			}
			cur := heap.Pop(&ps).(*Pair)
			B[i] = cur.second
			cnt[cur.second]--
		}

		return true
	}

	var left = 2
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

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

type Pair struct {
	first, second int
	index         int
}

type Pairs []*Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first > ps[j].first || ps[i].first == ps[j].first && ps[i].second > ps[j].second
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

func (pq *Pairs) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Pair)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *Pairs) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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) int {
	cnt := make([]int, n+1)
	var mx int
	for i := 0; i < n; i++ {
		cnt[A[i]]++
		if cnt[A[i]] > mx {
			mx = cnt[A[i]]
		}
	}

	var y, k int

	for i := 1; i <= n; i++ {
		if cnt[i] == mx {
			k++
		} else {
			y += cnt[i]
		}
	}

	return y/(mx-1) + k - 1
}

const N = 100010

var B [N]int

func solve1(n int, A []int) int {

	check := func(dist int) bool {
		if dist == 1 {
			return true
		}
		cnt := make(map[int]int)
		for i := 0; i < n; i++ {
			cnt[A[i]]++
		}

		ps := make(Pairs, 0, len(cnt))

		for k, v := range cnt {
			p := Pair{v, k, len(ps) - 1}
			heap.Push(&ps, &p)
		}

		for i := 0; i < n; i++ {
			if i >= dist && cnt[B[i-dist]] > 0 {
				p := Pair{cnt[B[i-dist]], B[i-dist], len(ps) - 1}
				heap.Push(&ps, &p)
			}
			if len(ps) == 0 {
				return false
			}
			cur := heap.Pop(&ps).(*Pair)
			B[i] = cur.second
			cnt[cur.second]--
		}

		return true
	}

	var left = 2
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

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

type Pair struct {
	first, second int
	index         int
}

type Pairs []*Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first > ps[j].first || ps[i].first == ps[j].first && ps[i].second > ps[j].second
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

func (pq *Pairs) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Pair)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *Pairs) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

package main

import (
    "fmt"
)

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

func main() {
    var t int
    fmt.Scan(&t)
    for t > 0 {
        var n int
        fmt.Scan(&n)
        f := make([]int, n)
        for i := 0; i < n; i++ {
            fmt.Scan(&f[i])
        }

        cnt := make([]int, n + 1)
        for i := 0; i < n; i++ {
            cnt[f[i]]++
        }

        mx, total := 0, 0
        for i := 1; i <= n; i++ {
            if cnt[i] > mx {
                mx = cnt[i]
                total = 1
            } else if cnt[i] == mx {
                total++
            }
        }

        fmt.Println((n - (total - 1) - mx) / (mx - 1))

        t--
    }
}

package main

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

type cce struct {
	v, c int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		//fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		//fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		//fmt.Println(ccl)

		val := 0

		for i := 1; i < len(ccl); i++ {
			val += (ccl[i].c * ccl[i].v)
		}

		val /= (ccl[0].v - 1)

		val += (ccl[0].c - 1)

		fmt.Println(val)
	}
}

/*
URL:
https://codeforces.com/contest/1393/problem/C
*/

package main

import (
	"bufio"
	"container/heap"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n    int
	A    []int
	cnts []int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		cnts = make([]int, n+5)

		solve()
	}
}

func solve() {
	for _, a := range A {
		cnts[a]++
	}

	ok := BinarySearch(0, n, func(x int) bool {
		B := []*Element{}

		pq := NewElementPQ()
		for i := 1; i <= n; i++ {
			if cnts[i] >= 1 {
				pq.push(&Element{val: i, num: cnts[i]})
			}
		}

		C := []int{}
		for pq.Len() > 0 {
			resi := x + 1

			for resi > 0 {
				if pq.Len() == 0 {
					// return false
					break
				}

				pop := pq.pop()
				C = append(C, pop.val)
				pop.num--
				if pop.num > 0 {
					B = append(B, pop)
				}
				resi--
			}

			for _, e := range B {
				pq.push(e)
			}
			B = []*Element{}
		}

		bef := make([]int, n+5)
		for i := 1; i <= n; i++ {
			bef[i] = -1
		}

		// PrintfDebug("C: %v, x: %d\n", C, x)
		for i := 0; i < len(C); i++ {
			if bef[C[i]] == -1 {
				bef[C[i]] = i
				continue
			}

			dist := i - bef[C[i]] - 1
			// PrintfDebug("dist: %d\n", dist)
			if dist < x {
				return false
			}
			bef[C[i]] = i
		}
		// PrintfDebug("bef: %v\n", bef)
		// PrintfDebug("OK\n")

		return true
	})

	fmt.Println(ok)
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

type Element struct {
	pri      int
	val, num int
}
type ElementPQ []*Element

// Interfaces
func NewElementPQ() *ElementPQ {
	temp := make(ElementPQ, 0)
	pq := &temp
	heap.Init(pq)

	return pq
}
func (pq *ElementPQ) push(target *Element) {
	heap.Push(pq, target)
}
func (pq *ElementPQ) pop() *Element {
	return heap.Pop(pq).(*Element)
}

func (pq ElementPQ) Len() int { return len(pq) }
func (pq ElementPQ) Less(i, j int) bool {
	if pq[i].num > pq[j].num {
		return true
	} else if pq[i].num < pq[j].num {
		return false
	} else {
		return pq[i].val < pq[j].val
	}
} // <: ASC, >: DESC
func (pq ElementPQ) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *ElementPQ) Push(x interface{}) {
	item := x.(*Element)
	*pq = append(*pq, item)
}
func (pq *ElementPQ) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

// func solve() {
// 	for _, a := range A {
// 		cnts[a]++
// 	}
// 	PrintfDebug("cnts: %v\n", cnts)

// 	C := []int{}
// 	for i := 1; i <= n; i++ {
// 		C = append(C, cnts[i])
// 	}
// 	sort.Sort(sort.Reverse(sort.IntSlice(C)))

// 	if C[0] != C[1] {
// 		// 個数について単独首位がある
// 		cnt := C[0]
// 		ans := (n - cnt) / (cnt - 1)
// 		fmt.Println(ans)
// 		return
// 	}

// 	comp, cc := RunLengthEncoding(C)
// 	fv, sv := comp[0], comp[1]
// 	fk, sk := cc[0], cc[1]
// 	PrintfDebug("fv: %d, fk: %d, sv: %d, sk: %d\n", fv, fk, sv, sk)

// 	ans := fk - 1
// 	if fv-sv >= 2 {
// 		fmt.Println(ans)
// 	} else {
// 		fmt.Println(ans + sk)
// 	}
// }

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if debug != 0 && len(os.Args) > 1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024*1024)

	t := readInt()
	for ; t > 0; t-- {
		n := readInt()
		counts := make([]int, n+1)
		candies := readInts()
		for _, c := range candies {
			counts[c]++
		}
		sort.Ints(counts)

		max := counts[n]
		var i int64
		for i = n-1; i >= 0; i-- {
			if counts[i] != max {
				break
			}
		}
		max_count := n-i
		var left int64
		for ; i >= 0; i-- {
			left += int64(counts[i])
		}
		ans := left/(int64(max)-1) + max_count - 1
		fmt.Fprintln(writer, ans)
	}

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = v
	}
	return res
}

func readInt() int64 {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 32)
	return int64(n)
}

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

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		counts := map[int64]int64{}
		n := sint64()
		for i := int64(0); i < n; i++ {
			counts[sint64()]++
		}
		printf("%d\n", sol(n, counts))
	}
}

func sol(n int64, counts map[int64]int64) int64 {
	maxCount := int64(0)
	maxCountFreq := int64(0)
	for _, c := range counts {
		if c > maxCount {
			maxCount = c
			maxCountFreq = 1
		} else if c == maxCount {
			maxCountFreq++
		}
	}
	// printf("maxCount maxCountFreq %d %d\n", maxCount, maxCountFreq)
	rem := n - (maxCount * maxCountFreq)
	ngaps := maxCount - 1
	filledGaps := int64(0)
	if ngaps > 0 {
		filledGaps = rem / ngaps
	}
	return maxCountFreq - 1 + filledGaps
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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
}

const N = 100010

var B [N]int

func solve(n int, A []int) int {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[A[i]]++

	}
	ps := make([]Pair, 0, len(cnt))
	for k, v := range cnt {
		ps = append(ps, Pair{v, k})
	}

	sort.Sort(Pairs(ps))

	check := func(dist int) bool {
		if dist == 1 {
			return true
		}

		var j int
		var offset int

		for i := 0; i < len(ps); i++ {
			cur := ps[i]
			a := cur.first
			jj := j
			for a > 0 {
				if j != jj && abs(jj-j) < dist {
					return false
				}

				a--

				if j+dist < n {
					j += dist
				} else {
					offset++
					j = offset
				}
			}
		}

		return true
	}

	var left = 2
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

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

type Pair struct {
	first, second int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first > ps[j].first || ps[i].first == ps[j].first && ps[i].second > ps[j].second
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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
}

const N = 100010

var B [N]int

func solve(n int, A []int) int {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[A[i]]++

	}
	ps := make([]Pair, 0, len(cnt))
	for k, v := range cnt {
		ps = append(ps, Pair{v, k})
	}

	sort.Sort(Pairs(ps))

	check := func(dist int) bool {
		if dist == 0 {
			return true
		}
		var offset int
		var j int
		var ok = true
		for i := 0; i < len(ps) && ok; i++ {
			cur := ps[i]
			a, b := cur.first, cur.second
			for a > 0 {
				for a > 0 && j < n {
					a--
					B[j] = b
					j += dist
				}
				offset++
				j = offset
				for j < n && B[j] > 0 {
					j++
				}
			}

		}
		pos := make(map[int]int)
		if ok {
			for i := 0; i < n && ok; i++ {
				if B[i] == 0 {
					ok = false
				}
				if j, found := pos[B[i]]; found && i-j < dist {
					ok = false
				}
				pos[B[i]] = i
			}
		}
		for i := 0; i < n; i++ {
			B[i] = 0
		}
		return ok
	}

	var left int
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first > ps[j].first || ps[i].first == ps[j].first && ps[i].second > ps[j].second
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

package main

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

type cce struct {
	v, c int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		//fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		//fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		//fmt.Println(ccl)

		val := ccl[0].c - 1

		for i := 1; i < len(ccl); i++ {
			val += ccl[i].c * ccl[i].v / (ccl[0].v - 1)
		}

		fmt.Println(val)
	}
}

package main

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

type cce struct {
	v, c int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		//fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		//fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		//fmt.Println(ccl)

		val := ccl[0].c - 1

		for i := 1; i < len(ccl); i++ {
			val += (ccl[i].c * ccl[i].v) / (ccl[0].v - 1)
		}

		fmt.Println(val)
	}
}

package main

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

type cce struct {
	v, c int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		// fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		// fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		val := ccl[0].c - 1

		for i := 1; i < len(ccl); i++ {
			val += ccl[i].c / (ccl[0].v - ccl[i].v)
		}

		fmt.Println(val)
	}
}

/*
URL:
https://codeforces.com/contest/1393/problem/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n    int
	A    []int
	cnts []int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		cnts = make([]int, n+5)

		solve()
	}
}

func solve() {
	for _, a := range A {
		cnts[a]++
	}
	PrintfDebug("cnts: %v\n", cnts)

	C := []int{}
	for i := 1; i <= n; i++ {
		C = append(C, cnts[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(C)))

	if C[0] != C[1] {
		// 個数について単独首位がある
		cnt := C[0]
		ans := (n - cnt) / (cnt - 1)
		fmt.Println(ans)
		return
	}

	comp, cc := RunLengthEncoding(C)
	fv, sv := comp[0], comp[1]
	fk, sk := cc[0], cc[1]
	PrintfDebug("fv: %d, fk: %d, sv: %d, sk: %d\n", fv, fk, sv, sk)

	ans := fk - 1
	if fv-sv >= 2 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans + sk)
	}
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}


Since Sonya has just learned the basics of matrices, she decided to play with them a little bit.Sonya imagined a new type of matrices that she called rhombic matrices. These matrices have exactly one zero, while all other cells have the Manhattan distance to the cell containing the zero. The cells with equal numbers have the form of a rhombus, that is why Sonya called this type so.The Manhattan distance between two cells ($$$x_1$$$, $$$y_1$$$) and ($$$x_2$$$, $$$y_2$$$) is defined as $$$|x_1 - x_2| + |y_1 - y_2|$$$. For example, the Manhattan distance between the cells $$$(5, 2)$$$ and $$$(7, 1)$$$ equals to $$$|5-7|+|2-1|=3$$$.    Example of a rhombic matrix. Note that rhombic matrices are uniquely defined by $$$n$$$, $$$m$$$, and the coordinates of the cell containing the zero.She drew a $$$n\times m$$$ rhombic matrix. She believes that you can not recreate the matrix if she gives you only the elements of this matrix in some arbitrary order (i.e., the sequence of $$$n\cdot m$$$ numbers). Note that Sonya will not give you $$$n$$$ and $$$m$$$, so only the sequence of numbers in this matrix will be at your disposal.Write a program that finds such an $$$n\times m$$$ rhombic matrix whose elements are the same as the elements in the sequence in some order.

The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^6$$$) — the number of cells in the matrix. The second line contains $$$t$$$ integers $$$a_1, a_2, \ldots, a_t$$$ ($$$0\leq a_i< t$$$) — the values in the cells in arbitrary order.

In the first line, print two positive integers $$$n$$$ and $$$m$$$ ($$$n \times m = t$$$) — the size of the matrix. In the second line, print two integers $$$x$$$ and $$$y$$$ ($$$1\leq x\leq n$$$, $$$1\leq y\leq m$$$) — the row number and the column number where the cell with $$$0$$$ is located. If there are multiple possible answers, print any of them. If there is no solution, print the single integer $$$-1$$$.

NoteYou can see the solution to the first example in the legend. You also can choose the cell $$$(2, 2)$$$ for the cell where $$$0$$$ is located. You also can choose a $$$5\times 4$$$ matrix with zero at $$$(4, 2)$$$.In the second example, there is a $$$3\times 6$$$ matrix, where the zero is located at $$$(2, 3)$$$ there.In the third example, a solution does not exist.

package main

import (
	"bufio"
	"os"
)

type Ans struct {
	m, n, x, y int
}

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

func create(a *Ans) map[int]int {
	res:=make(map[int]int)
	for i := 1; i <= a.m; i++ {
		for j := 1; j <= a.n; j++ {
			res[abs(a.x-i)+abs(a.y-j)] += 1
		}
	}

	return res
}

func verify(data map[int]int, a *Ans, mn int) bool {
	if mn != a.m*a.n {
		return false
	}
	expect := create(a)
	if len(data) != len(expect) {
		return false
	}
	for i := range data {
		if expect[i] != data[i] {
			return false
		}
	}
	return true
}

func solve(data map[int]int, mn int, max int) (*Ans, bool) {
	if max < 0 || data[0] != 1 {
		return nil, false
	}
	if len(data) == 1 {
		return &Ans{1, 1, 1, 1}, true
	}

	var (
		shortest  = -1
		unlimited = 0
	)
	for i := 1; i <= max; i++ {
		unlimited += 4
		expect := unlimited
		if shortest >= 0 {
			expect -= 2*(i-shortest) - 1
		}
		got := data[i]
		switch {
		case got > expect:
			return nil, false
		case got == expect:
			continue
		}

		switch dist, delta := i-1, expect-got; delta {
		case 1:
			if shortest >= 0 {
				return solve2(shortest, dist, mn, max, data)
			}
			shortest = dist
		case 2:
			if shortest < 0 {
				return solve2(dist, dist, mn, max, data)
			}
			return solve3(shortest, dist, mn, max, data)
		case 3:
			remain:= max-dist
			if shortest >= 0 {
				remain = shortest
			}
			a := newAns(dist, dist, dist, remain)
			return a, verify(data, a, mn)
		case 4:
			a := newAns(dist, dist, dist, dist)
			return a, verify(data, a, mn)
		default:
			return nil, false
		}
	}

	panic("Unknown situation")
}

func newAns(b1, b2, b3, b4 int) *Ans {
	return &Ans{
		b1 + b3 + 1,
		b2 + b4 + 1,
		b1 + 1,
		b2 + 1,
	}
}

func solve2(b1, b2, mn, max int, data map[int]int) (*Ans, bool) {
	// case 1: b1 and b2 is in a line
	longest := max - b2
	m := b1 + b2 + 1
	n := mn / m

	a := &Ans{m, n, b1 + 1, longest + 1}
	if verify(data, a, mn) {
		return a, true
	}

	// case 2: else
	sum := max + b1 + b2 + 2
	sub2 := sum*sum - 4*mn
	sub, r := isqrt(sub2)
	if r != 0 {
		return nil, false
	}

	m, n = (sum+sub)/2, (sum-sub)/2
	a = &Ans{m, n, b1 + 1, b2 + 1}
	if verify(data, a, mn) {
		return a, true
	}

	a = &Ans{m, n, b2 + 1, b1 + 1}
	return a, verify(data, a, mn)
}

func solve3(b1, b2, mn, max int, data map[int]int) (*Ans, bool) {
	// case 1: two b2 is in a line
	longest := max - b2
	m, n := longest+b1+1, b2*2+1
	a := &Ans{m, n, b1 + 1, b2 + 1}
	if verify(data, a, mn) {
		return a, true
	}

	// case 2: else
	m, n = max+1, b1+b2+1
	a = &Ans{m, n, b2 + 1, b2 + 1}
	return a, verify(data, a, mn)
}

func isqrt(x int) (int, int) {
	if x <= 0 {
		return 0, x
	}

	t := uint(x)
	p := uint(1 << 30)
	for p > t {
		p >>= 2
	}
	var b, r uint
	for ; p != 0; p >>= 2 {
		b = r | p
		r >>= 1
		if t >= b {
			t -= b
			r |= p
		}
	}
	return int(r), int(t)
}

func main() {
	defer out.Flush()

	mn := readInt()
	data := make(map[int]int)
	max := -1
	for i := 0; i < mn; i++ {
		x := readInt()
		data[x] += 1
		if max < x {
			max = x
		}
	}

	ans, ok := solve(data, mn, max)
	if !ok {
		out.WriteString("-1\n")
		return
	}

	w := func(i ...int) {
		n := len(i)
		for _, v := range i[:n-1] {
			writeInt(v)
			out.WriteByte(' ')
		}
		writeInt(i[n-1])
		out.WriteByte('\n')
	}
	w(ans.m, ans.n)
	w(ans.x, ans.y)
}

var in, out = io()

func io() (*bufio.Scanner, *bufio.Writer) {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	return in, bufio.NewWriter(os.Stdout)
}

func readInt() int {
	if !in.Scan() {
		panic("Input error")
	}

	b := in.Bytes()

	x := int(0)

	for _, v := range b {
		x = x*10 + int(v-'0')
	}

	return x
}

const (
	INTLEN = 22
)

func writeInt(x int) {
	var neg bool
	if x < 0 {
		neg = true
		x = -x
	}

	var b [INTLEN + 1]byte //negative
	i := INTLEN
	for x >= 10 {
		q := x / 10
		i--
		b[i] = byte(x-q*10) + '0'
		x = q
	}
	i--
	b[i] = byte(x) + '0'

	if neg {
		i--
		b[i] = '-'
	}
	out.Write(b[i:])
}


Given a positive integer $$$k$$$, two arrays are called $$$k$$$-similar if:  they are strictly increasing;  they have the same length;  all their elements are positive integers between $$$1$$$ and $$$k$$$ (inclusive);  they differ in exactly one position. You are given an integer $$$k$$$, a strictly increasing array $$$a$$$ and $$$q$$$ queries. For each query, you are given two integers $$$l_i \leq r_i$$$. Your task is to find how many arrays $$$b$$$ exist, such that $$$b$$$ is $$$k$$$-similar to array $$$[a_{l_i},a_{l_i+1}\ldots,a_{r_i}]$$$.

The first line contains three integers $$$n$$$, $$$q$$$ and $$$k$$$ ($$$1\leq n, q \leq 10^5$$$, $$$n\leq k \leq 10^9$$$) — the length of array $$$a$$$, the number of queries and number $$$k$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots,a_n$$$ ($$$1 \leq a_i \leq k$$$). This array is strictly increasing  — $$$a_1 < a_2 < \ldots < a_n$$$. Each of the following $$$q$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ ($$$1 \leq l_i \leq r_i \leq n$$$).

Print $$$q$$$ lines. The $$$i$$$-th of them should contain the answer to the $$$i$$$-th query.

NoteIn the first example:In the first query there are $$$4$$$ arrays that are $$$5$$$-similar to $$$[2,4]$$$: $$$[1,4],[3,4],[2,3],[2,5]$$$.In the second query there are $$$3$$$ arrays that are $$$5$$$-similar to $$$[4,5]$$$: $$$[1,5],[2,5],[3,5]$$$.

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 sint64() int64 {
	s := sstring()
	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 sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	n := sint64()
	q := sint64()
	k := sint64()
	a := sint64s(n)
	for i := q; i > 0; i-- {
		l, r := sint64(), sint64()
		l--
		r--
		h := a[r] - a[l] - (r - l)
		printf("%d\n", 2*h+a[l]-1+k-a[r])
	}
}

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 sint64() int64 {
	s := sstring()
	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 sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	n := sint64()
	q := sint64()
	k := sint64()
	a := make([]int64, n+2)
	for i := int64(1); i < n+1; i++ {
		a[i] = sint64()
	}
	a[n+1] = k + 1

	ps := make([]int64, n+2)
	for i := 1; i < len(a)-1; i++ {
		ps[i] = a[i+1] - a[i-1] - 2 + ps[i-1]
	}
	ps[n+1] = ps[n]

	for i := q; i > 0; i-- {
		l, r := sint64(), sint64()
		res := ps[r] - ps[l-1]
		if l != 1 {
			res += a[l-1]
		}
		if r != n {
			res += k - a[r+1] + 1
		}
		printf("%d\n", res)
	}
}

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 sint64() int64 {
	s := sstring()
	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 sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	n := sint64()
	q := sint64()
	k := sint64()
	a := sint64s(n)
	lr := make([][2]int64, q)
	for i := range lr {
		l := sint64()
		r := sint64()
		lr[i] = [2]int64{l, r}
	}
	sol(n, q, k, a, lr)
}

func sol(n, q, k int64, a []int64, lr [][2]int64) {
	tmp := make([]int64, n+2)
	tmp[0] = 0
	tmp[n+1] = k+1
	copy(tmp[1:n+1], a)
	ps := make([]int64, n+2)
	for i := 1; i < len(tmp)-1; i++ {
		ans := max(tmp[i+1]-tmp[i-1]-2, 0)
		ps[i] = ans
	}
	for i := 1; i < len(ps); i++ {
		ps[i] += ps[i-1]
	}
	for _, llrr := range lr {
		l := llrr[0]
		r := llrr[1]
		res := ps[r] - ps[l-1]
		if l != 1 {
			res += tmp[l-1]
		}
		if r != n {
			res += k - tmp[r+1] + 1
		}
		printf("%d\n", res)
	}
}

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

package main

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

func readLine(in *bufio.Reader) string {
  ret, _, err := in.ReadLine()

  if err == io.EOF {
    return ""
  }

  return strings.TrimRight(string(ret), "\r\n")
}

func parseInt(in string) int {
  ret, _ := strconv.ParseInt(in, 10, 64)
  return int(ret)
}

func split(in string) []string {
  return strings.Split(in, " ")
}

func main() {
  in := bufio.NewReaderSize(os.Stdin, 1024*1024)
  splited := split(readLine(in))
  n := parseInt(splited[0])
  q := parseInt(splited[1])
  k := parseInt(splited[2])
  a := make([]int, n + 1)

  splited = split(readLine(in))

  for i := 1; i <= n; i++ {
    a[i] = parseInt(splited[i - 1])
  }

  for i := 0; i < q; i++ {
    splited = split(readLine(in))
    l := parseInt(splited[0])
    r := parseInt(splited[1])

    fmt.Println(a[l] - 1 + k -  a[r] + 2*((a[r] - a[l] + 1) - (r - l + 1)))
  }
}

package main

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

var in = bufio.NewReader(os.Stdin)

func solve() {
	var n, q, k int64
	_, _ = fmt.Fscan(in, &n, &q, &k)
	arr := make([]int64, n)
	for i := 0; i < len(arr); i++ {
		fmt.Fscan(in, &arr[i])
	}
	p := make([]int64, n)
	if len(arr) == 1 {
		p[0] = k - 1
	} else {
		p[0] = arr[1] - 1 - 1
		for i := 1; i < len(arr)-1; i++ {
			t := arr[i+1] - arr[i-1] - 2
			p[i] = t
		}
		p[len(p)-1] = k - arr[len(arr)-1]
	}
	s := make([]int64, n)
	s[0] = p[0]
	t := s[0]
	for i := 1; i < len(arr); i++ {
		t += p[i]
		s[i] = t
	}
	for i := 0; i < int(q); i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		if x == y {
			fmt.Println(k - 1)
		} else {
			var count int64
			t1 := arr[x] - 1 - 1
			t2 := k - arr[y-2] - 1
			t3 := s[y-2] - s[x-1]
			count += t1
			count += t2
			count += t3
			fmt.Println(count)

		}
	}

}

func main() {
	solve()
}

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

//https://codeforces.com/problemset/problem/1485/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	solve()
}

func solve() {
	n, q, k := nextNum(), nextNum(), nextNum()
	a := make([]int, n)
	// dp := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
		// if i > 0 {
		// 	dp[i] = dp[i-1] + a[i] - a[i-1] - 1
		// }
	}
	for i := 0; i < q; i++ {
		l, r := nextNum()-1, nextNum()-1
		// println(a[l] - 1 + k - a[r] + (dp[r]-dp[l])*2)
		println(a[l] - 1 + k - a[r] + (a[r]-a[l]-(r-l))*2)
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

//https://codeforces.com/problemset/problem/1485/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	solve()
}

func solve() {
	n, q, k := nextNum(), nextNum(), nextNum()
	a := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
		if i > 0 {
			dp[i] = dp[i-1] + a[i] - a[i-1] - 1
		}
	}
	for i := 0; i < q; i++ {
		l, r := nextNum()-1, nextNum()-1
		println(a[l] - 1 + k - a[r] + (dp[r]-dp[l])*2)
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

package main

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

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

	var buf bytes.Buffer

	n, q, k := readThreeNums(reader)
	A := readNNums(reader, n)
	Q := make([][]int, q)
	for i := 0; i < q; i++ {
		Q[i] = readNNums(reader, 2)
	}
	res := solve(n, q, k, A, Q)

	for i := 0; i < q; i++ {
		buf.WriteString(fmt.Sprintf("%d\n", res[i]))
	}

	fmt.Print(buf.String())
}

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, q int, k int, A []int, Q [][]int) []int {
	ans := make([]int, q)

	for i := 0; i < q; i++ {
		l, r := Q[i][0], Q[i][1]
		l--
		r--
		if l == r {
			ans[i] = k - 1
			continue
		}
		//  𝑘+(𝑎𝑟−𝑎𝑙+1)−2(𝑟−𝑙+1)
		ans[i] = k + A[r] - A[l] + 1 - 2*(r-l+1)
	}

	return ans
}

package main

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

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

	var (
		n, q int
		k    int64
	)
	fmt.Fscanln(input, &n, &q, &k)
	data := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &data[i])
	}
	fmt.Fscanf(input, "\n")
	sum := make([]int64, n)
	for i := 2; i < n; i++ {
		sum[i] = data[i+1] - data[i-1] - 2
		sum[i] += sum[i-1]
	}
	for ; q > 0; q-- {
		var l, r int
		fmt.Fscanln(input, &l, &r)
		if l == r {
			fmt.Println(k - 1)
			continue
		}
		res := sum[r-1] - sum[l+1-1]
		res += data[l+1] - 2
		res += k - data[r-1] - 1
		fmt.Println(res)
	}
}

package main

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

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

func MAX(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 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
		}
	}

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var n int
	var q int
	var k int
	fmt.Fscan(input, &n)
	fmt.Fscan(input, &q)
	fmt.Fscan(input, &k)

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

	for o := 0; o < q; o++ {
		var l int
		var r int
		fmt.Fscan(input, &l)
		fmt.Fscan(input, &r)
		var ans int64
		ans = ARRAY[r] - ARRAY[l] + int64(k) - int64(2)*int64(r-l) - int64(1)
		fmt.Println(ans)
	}

}

package main

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

func main() {
	var tcs int = 1
	in := bufio.NewReader(os.Stdin)

	for tc := 0; tc < tcs; tc++ {
		var n, q, k int64
		_, _ = fmt.Fscan(in, &n, &q, &k)
		a := make([]int64, n+2)
		s := make([]int64, n+2)

		for i := int64(1); i < n+1; i++ {
			_, _ = fmt.Fscan(in, &a[i])
		}
		a[n+1] = k
		for i := int64(1); i < n+1; i++ {
			s[i] = s[i-1] + a[i+1] - a[i-1] - 2
		}

		for i := int64(0); i < q; i++ {
			var l, r int
			_, _ = fmt.Fscan(in, &l, &r)
			var ans int64
			if l < r {
				ans = s[r-1] - s[l] + (a[l+1] - 1) + (k - a[r-1]) - 2
			} else {
				ans = k - 1
			}
			fmt.Println(ans)
		}
	}
}

package main

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

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

	var n, q int
	var k int64
	Fscan(in, &n, &q, &k)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		Fscan(in, &l, &r)
		l--
		r--
		if l == r {
			Fprintln(out, k-1)
			continue
		}
		ans := (a[r] - a[l] - int64(r-l)) * 2
		ans += a[l] - 1
		ans += k - a[r]
		Fprintln(out, ans)
	}
}

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

package main

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

func readLine(in *bufio.Reader) string {
  ret, _, err := in.ReadLine()

  if err == io.EOF {
    return ""
  }

  return strings.TrimRight(string(ret), "\r\n")
}

func parseInt(in string) int {
  ret, _ := strconv.ParseInt(in, 10, 64)
  return int(ret)
}

func split(in string) []string {
  return strings.Split(in, " ")
}

func main() {
  in := bufio.NewReaderSize(os.Stdin, 1024*1024)
  splited := split(readLine(in))
  n := parseInt(splited[0])
  q := parseInt(splited[1])
  k := parseInt(splited[2])
  a := make([]int, n + 1)

  splited = split(readLine(in))

  for i := 1; i <= n; i++ {
    a[i] = parseInt(splited[i - 1])
  }

  for i := 0; i < q; i++ {
    splited = split(readLine(in))
    l := parseInt(splited[0])
    r := parseInt(splited[1])

    fmt.Println(a[l] - 1 + k -  a[r] + 2*((a[r] - a[l] + 1) - (r - l - 1)))
  }
}

package main

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

func readLine(in *bufio.Reader) string {
  ret, _, err := in.ReadLine()

  if err == io.EOF {
    return ""
  }

  return strings.TrimRight(string(ret), "\r\n")
}

func parseInt(in string) int {
  ret, _ := strconv.ParseInt(in, 10, 64)
  return int(ret)
}

func split(in string) []string {
  return strings.Split(in, " ")
}

func main() {
  in := bufio.NewReaderSize(os.Stdin, 1024*1024)
  splited := split(readLine(in))
  n := parseInt(splited[0])
  q := parseInt(splited[1])
  k := parseInt(splited[2])
  a := make([]int, n + 1)

  splited = split(readLine(in))

  for i := 1; i <= n; i++ {
    a[i] = parseInt(splited[i - 1])
  }

  for i := 0; i < q; i++ {
    splited = split(readLine(in))
    l := parseInt(splited[0])
    r := parseInt(splited[1])

    fmt.Println(a[l] - 1 + k -  a[r] + 2*((a[r] - a[l] + 1) - (l - r - 1)))
  }
}

package main

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

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

func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }
func println(a ...interface{}) (n int, err error)          { return fmt.Fprintln(out, a...) }

//https://codeforces.com/problemset/problem/1485/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	solve()
}

func solve() {
	n, q, k := nextNum(), nextNum(), nextNum()
	a := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
		if i > 0 {
			dp[i] = dp[i-1] + a[i] - a[i-1] - 1
		}
	}
	for i := 0; i < q; i++ {
		l, r := nextNum()-1, nextNum()-1
		if l == r {
			println(0)
		} else {
			println(a[l] - 1 + k - a[r] + (dp[r]-dp[l])*2)
		}
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}


Phoenix is playing with a new puzzle, which consists of $$$n$$$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below.    A puzzle piece The goal of the puzzle is to create a square using the $$$n$$$ pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all $$$n$$$ pieces must be used (of course, the square shouldn't contain any holes as well). Can he do it?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of puzzle pieces.

For each test case, if Phoenix can create a square with the $$$n$$$ puzzle pieces, print YES. Otherwise, print NO.

NoteFor $$$n=2$$$, Phoenix can create a square like this:    For $$$n=4$$$, Phoenix can create a square like this:    For $$$n=6$$$, it is impossible for Phoenix to create a square.

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		// for n > 1 {
		// 	if n&1 != 0 {
		// 		break
		// 	}
		// 	n >>= 1
		// }
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {
			Fprintln(out, "YES")
			return
		}
		sqrt2 := int(math.Sqrt(float64(n / 2)))
		if sqrt2*sqrt2 == n/2 {
			Fprintln(out, "YES")
			return
		}
		Fprintln(out, "NO")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		n /= 2
		for n > 1 {
			if n&1 != 0 {
				break
			}
			n >>= 1
		}
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {
			Fprintln(out, "YES")
			return
		}
		Fprintln(out, "NO")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if n < 4 {
		return false
	}
	if isSquare(n) && n%2 == 0 {
		return true
	}
	return isSquare(n * 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

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

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

		tmp := n
		for n & 0x1 == 0 {
			n >>= 1
		}
		if n == tmp {
			Fprintln(out, "NO")
			continue
		}
		square := int(math.Sqrt(float64(n)))
		if square * square != n {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

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

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

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

		if n == 1 {
			Fprintln(out, "NO")
			continue
		}
		factors := decomposition(n)
		//size := len(factors)
		pos := sort.Search(len(factors), func(i int) bool {
			return factors[i] > 2
		})
		if pos == 0 {
			Fprintln(out, "NO")
			continue
		}
		square := int(math.Sqrt(float64(n / (1 << pos))))
		if square * square != n / (1 << pos) {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

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

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if m == int64(a)*int64(a) {
				z++

			}
			if z == 1 {
				fmt.Println("YES")
			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if mm == int64(a)*int64(a) {
						z++
					}
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func Max(x, y int) int{
	if x > y {
		return x
	}
	return y
}
const limit int = 2000005;
var vis = make([]bool,limit);
func Init(){
	for i := 1 ; i < limit; i++{
		vis[i] = false
	}
	for i := 1 ; i < limit; i++{
		if i * i >= limit{
			break;
		}
		vis[i * i] = true
	}
}

func Solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var kase int
	fmt.Fscan(in, &kase)
	for i := 1 ; i <= kase; i++{
		var n int
		fmt.Fscan(in, &n)
		if n % 2 == 1{
			fmt.Fprintln(out, "No")
			continue;
		}
		var b = math.Sqrt(float64(n / 2))
		var base  = int(math.Round(b))
		if base * base == n / 2{
			fmt.Fprintln(out, "Yes")
			continue
		}
		if n % 4 != 0{
			fmt.Fprintln(out, "No")
			continue;
		}
		b = math.Sqrt(float64(n / 4))
		base  = int(math.Round(b))
		if base * base == n / 4{
			fmt.Fprintln(out, "Yes")
			continue;
		}
		fmt.Fprintln(out, "No")
	}

}

func main() {
	Init()

	Solve(os.Stdin, os.Stdout)
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	if n%2 == 1 {
		return "NO"
	}
	k := n / 2
	for i := 1; i*i <= k; i++ {
		if i*i == k {
			return "YES"
		}
		if 2*i*i == k {
			return "YES"
		}
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		p := math.Floor(math.Sqrt(float64(n / 2)))
		o := math.Floor(math.Sqrt(float64(n / 4)))
		if n%2 == 0 && p*p == float64(n/2) || n%4 == 0 && o*o == float64(n/4) {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n int
		fmt.Scan(&n)
		result := false
		for i := 1; i*i <= n/2; i++ {
			if 2*i*i == n {
				result = true
			}
			if 4*i*i == n {
				result = true
			}
		}
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		t--
	}
}

package main

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

func isSquare(x int) bool {
	var d = int(math.Sqrt(float64(x)))
	return d * d == x
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		if n % 2 != 0 && n % 4 != 0 {
			fmt.Fprintf(writer, "NO\n")
			continue
		}

		if (n % 2 == 0 && isSquare(n / 2)) || (n % 4 == 0 && isSquare(n / 4)) {
			fmt.Fprintf(writer, "YES\n")
			continue
		}
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int64
		_, _ = fmt.Fscan(in, &n)

		if n%2 == 0 {
			if sqrt(n/2) > 0 {
				fmt.Println("YES")
				continue
			}
		}

		if n%4 == 0 {
			if sqrt(n/4) > 0 {
				fmt.Println("YES")
				continue
			}
		}

		fmt.Println("NO")
	}
}

func sqrt(n int64) int64 {
	l := int64(1)
	r := n

	for l <= r {
		m := (l + r) / 2

		if m*m < n {
			l = m + 1
		} else if m*m > n {
			r = m - 1
		} else {
			return m
		}
	}

	return -1
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		sqrt := int(math.Sqrt(float64(n / 2)))
		if sqrt*sqrt == n/2 {
			Fprintln(out, "YES")
			return
		}
		for n > 1 {
			if n&1 != 0 {
				Fprintln(out, "NO")
				return
			}
			n >>= 1
		}
		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		for n > 1 {
			if n&1 != 0 {
				Fprintln(out, "NO")
				return
			}
			n >>= 1
		}
		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		n /= 2
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {

			Fprintln(out, "YES")
			return
		}
		n *= 2
		for n > 1 {
			if n&(3) != 0 {
				Fprintln(out, "NO")
				return
			}
			n >>= 2
		}

		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		n /= 2
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {

			Fprintln(out, "YES")
			return
		}
		for n > 1 {
			if n&1 != 0 {
				Fprintln(out, "NO")
				return
			}
			n /= 2
		}

		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if n < 4 {
		return false
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n * 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if n < 4 {
		return false
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n / 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	if n == 1 {
		return false
	}
	_, ok := t[n]
	if ok {
		return true
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n / 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n / 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if isPowerOf2(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func isPowerOf2(n int) bool {
	_, ok := t[n]
	return ok
}

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

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

		if n == 1 {
			Fprintln(out, "NO")
			continue
		}
		factors := decomposition(n)
		size := len(factors)
		pos := sort.Search(len(factors), func(i int) bool {
			return factors[i] > 2
		})
		if pos == 0 {
			Fprintln(out, "NO")
			continue
		}
		if pos < size && (factors[pos] != factors[size-1] || (size - pos) & 0x1 != 0) {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

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

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

		if n == 1 {
			Fprintln(out, "NO")
		}
		factors := decomposition(n)
		size := len(factors)
		pos := sort.Search(len(factors), func(i int) bool {
			return factors[i] > 2
		})
		if pos == 0 {
			Fprintln(out, "NO")
			continue
		}
		if pos < size && (factors[pos] != factors[size-1] || (size - pos) & 0x1 != 0) {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

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

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

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

		if n == 1 {
			Fprintln(out, "NO")
		} else if (n & (n - 1)) == 0 {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

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

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

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

package main

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

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if m == int64(a)*int64(a) {
				z++
				fmt.Println(a)

			}
			if z == 1 {
				fmt.Println("YES")
			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if mm == int64(a)*int64(a) {
						z++
					}
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if float64(m) == a*a {
				z++
			}
			if z == 1 {
				fmt.Println("YES")

			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if float64(mm) == a*a {
						z++
					}
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if float64(m) == a*a {
				z++
			}
			if z == 1 {
				fmt.Println("YES")
			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if float64(mm) == a*a {
						z++
					}
				} else {
					fmt.Println("NO")
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			var m int64
			if n%4 != 0 {
				m = n / 2
			} else {
				m = n / 4
			}

			a := math.Sqrt(float64(m))
			if float64(m) != a*a {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}

		}

	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	if n%2 == 0 {
		return "YES"
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	for i := 2; i*i <= n; i++ {
		if i*i == n {
			return "YES"
		}
	}
	for i := 1; 2*i*i <= n; i++ {
		if 2*i*i == n {
			return "YES"
		}
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	for i := 1; i*i <= n; i++ {
		if i*i == n {
			return "YES"
		}
	}
	for i := 1; 2*i*i <= n; i++ {
		if 2*i*i == n {
			return "YES"
		}
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		if n%2 == 0 {
			p := math.Floor(math.Log2(float64(n)))
			if math.Pow(2.0, p) == float64(n) {
				fmt.Fprintln(w, "YES")
			} else {
				fmt.Fprintln(w, "NO")
			}
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n int
		fmt.Scan(&n)
		if n % 2 == 0 && (n / 2) & (n / 2 - 1) == 0 {
			fmt.Println("YES")
		} else if n % 4 == 0 && (n / 4) & (n / 4 - 1) == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		t--
	}
}