You have a blackboard and initially only an odd number $$$x$$$ is written on it. Your goal is to write the number $$$1$$$ on the blackboard.You may write new numbers on the blackboard with the following two operations.   You may take two numbers (not necessarily distinct) already on the blackboard and write their sum on the blackboard. The two numbers you have chosen remain on the blackboard.  You may take two numbers (not necessarily distinct) already on the blackboard and write their bitwise XOR on the blackboard. The two numbers you have chosen remain on the blackboard.  Perform a sequence of operations such that at the end the number $$$1$$$ is on the blackboard.

The single line of the input contains the odd integer $$$x$$$ ($$$3 \le x \le 999,999$$$).

Print on the first line the number $$$q$$$ of operations you perform. Then $$$q$$$ lines should follow, each describing one operation.    The "sum" operation is described by the line "$$$a$$$ + $$$b$$$", where $$$a, b$$$ must be integers already present on the blackboard.  The "xor" operation is described by the line "$$$a$$$ ^ $$$b$$$", where $$$a, b$$$ must be integers already present on the blackboard.  The operation symbol (+ or ^) must be separated from $$$a, b$$$ by a whitespace. You can perform at most $$$100,000$$$ operations (that is, $$$q\le 100,000$$$) and all numbers written on the blackboard must be in the range $$$[0, 5\cdot10^{18}]$$$. It can be proven that under such restrictions the required sequence of operations exists. You can output any suitable sequence of operations.

package main

import "fmt"

var ans []string

func main() {
	var x int64
	_, _ = fmt.Scan(&x)
	e := 0
	for int64(1<<(e+1)) <= x {
		e++
	}
	y := qMul(x, int64(1<<e))

	ans = append(ans, fmt.Sprint(y, " ^ ", x))
	y = y ^ x
	a, b := solve(x, y, int64(1))
	b = -b
	if (b & 1) == 1 {
		a += y
		b += x
	}
	_ = qMul(x, a)
	_ = qMul(y, b)
	ans = append(ans, fmt.Sprint(a*x, " ^ ", b*y))

	fmt.Println(len(ans))
	for _, it := range ans {
		fmt.Println(it)
	}
}

func solve(a int64, b int64, c int64) (x, y int64) {
	a_temp, b_temp, c_temp := a, b, c
	a = (a%b + b) % b
	c = (c%b + b) % b
	d := exGcd(a, b, &x, &y)
	mod := b / d
	x = x * (c / d)
	x = (x%mod + mod) % mod
	y = (c_temp - a_temp*x) / b_temp
	return x, y

}

func exGcd(a int64, b int64, x *int64, y *int64) int64 {
	var x0, y0, x1, y1 int64 = 1, 0, 0, 1
	r := (a%b + b) % b
	q := (a - r) / b
	*x, *y = 0, 1
	for r > 0 {
		*x = x0 - q*x1
		*y = y0 - q*y1
		x0, y0 = x1, y1
		x1, y1 = *x, *y
		a = b
		b = r
		r = a % b
		q = (a - r) / b
	}
	return b

}

func qMul(a, b int64) int64 {
	if b == 1 {
		return a
	} else if (b & 1) == 1 {
		temp := qMul(a, b-1)
		ans = append(ans, fmt.Sprint(temp, " + ", a))
		//fmt.Println(temp, " + ", a)
		return temp + a
	} else {
		temp := qMul(a, b>>1)
		ans = append(ans, fmt.Sprint(temp, " + ", temp))
		//fmt.Println(temp, " + ", temp)
		return temp << 1
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1427E(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		x, y uint64
		op   byte
	}

	var x uint64
	Fscan(in, &x)
	ans := []pair{{x, x, '^'}}
	for i := 0; i < 20; i++ {
		ans = append(ans, pair{x << i, x << i, '+'})
	}
	const mx = 45
	b := [mx + 1]uint64{}
o:
	for i := uint64(1); b[0] == 0; i++ {
		a := []uint64{}
		for j, y := mx, x*i; j >= 0; j-- {
			if y>>j&1 > 0 {
				if b[j] == 0 {
					b[j] = y
					y = uint64(0)
					for k := i; k > 0; k &= k - 1 {
						v := x << bits.TrailingZeros64(k)
						ans = append(ans, pair{y, v, '+'})
						y += v
					}
					for _, v := range a {
						ans = append(ans, pair{y, v, '^'})
						y ^= v
					}
					continue o
				}
				if b[j] > 0 {
					y ^= b[j]
					a = append(a, b[j])
				}
			}
		}
	}
	Fprintln(out, len(ans))
	for _, p := range ans {
		Fprintf(out, "%d %c %d\n", p.x, p.op, p.y)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1427E(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		x, y uint64
		op   byte
	}

	var x uint64
	Fscan(in, &x)
	ans := []pair{{x, x, '^'}}
	for i := 0; i < 20; i++ {
		ans = append(ans, pair{x << i, x << i, '+'})
	}
	b := [40]uint64{}
o:
	for i := uint64(1); b[0] == 0; i++ {
		a := []uint64{}
		for j, y := 39, x*i; j >= 0; j-- {
			if y>>j&1 > 0 {
				if b[j] == 0 {
					b[j] = y
					y = uint64(0)
					for k := i; k > 0; k &= k - 1 {
						v := x << bits.TrailingZeros64(k)
						ans = append(ans, pair{y, v, '+'})
						y += v
					}
					for _, v := range a {
						ans = append(ans, pair{y, v, '^'})
						y ^= v
					}
					continue o
				}
				if b[j] > 0 {
					y ^= b[j]
					a = append(a, b[j])
				}
			}
		}
	}
	Fprintln(out, len(ans))
	for _, p := range ans {
		Fprintf(out, "%d %c %d\n", p.x, p.op, p.y)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1427E(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		x, y int64
		op   byte
	}

	var x int64
	Fscan(in, &x)
	ans := []pair{{x, x, '^'}}
	for i := 0; i < 20; i++ {
		ans = append(ans, pair{x << i, x << i, '+'})
	}
	b := [40]int64{}
o:
	for i := int64(1); b[0] == 0; i++ {
		a := []int64{}
		for j, y := 39, x*i; j >= 0; j-- {
			if y>>j&1 > 0 {
				if b[j] == 0 {
					b[j] = y
					y = int64(0)
					for k := i; k > 0; k &= k - 1 {
						v := k & -k * x
						ans = append(ans, pair{y, v, '+'})
						y += v
					}
					for _, v := range a {
						ans = append(ans, pair{y, v, '^'})
						y ^= v
					}
					continue o
				}
				if b[j] > 0 {
					y ^= b[j]
					a = append(a, b[j])
				}
			}
		}
	}
	Fprintln(out, len(ans))
	for _, p := range ans {
		Fprintf(out, "%d %c %d\n", p.x, p.op, p.y)
	}
}

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

package main

import "fmt"

var ans []string

func main() {
	var x int64
	_, _ = fmt.Scan(&x)
	e := 0
	for int64(1<<(e+1)) <= x {
		e++
	}
	y := qMul(x, int64(1<<e))

	ans = append(ans, fmt.Sprint(y, " ^ ", x))
	y = y ^ x
	a, b := solve(x, y, int64(1))
	b = -b
	if (b&1) == 1 {
		a += y
		b += x
	}
	_ = qMul(x, a)
	_ = qMul(y, b)
	ans = append(ans, fmt.Sprint(a*x, " ^ ", b*y))

	fmt.Println(len(ans))
	for _, it := range ans {
		fmt.Println(it)
	}
}

func solve(a int64, b int64, c int64) (x, y int64) {
	a_temp, b_temp, c_temp := a, b, c
	a = (a%b + b) % b
	c = (c%b + b) % b
	d := exGcd(a, b, &x, &y)
	mod := b / d
	x = x * (c / d)
	x = (x%mod + mod) % mod
	y = (c_temp - a_temp*x) / b_temp
	return x, y

}

func exGcd(a int64, b int64, x *int64, y *int64) int64 {
	var x0, y0, x1, y1 int64 = 1, 0, 0, 1
	r := (a%b + b) % b
	q := (a - r) / b
	*x, *y = 0, 1
	for r > 0 {
		*x = x0 - q*x1
		*y = y0 - q*y1
		x0, y0 = x1, y1
		x1, y1 = *x, *y
		a = b
		b = r
		r = a % b
		q = (a - r) / b
	}
	return b

}

func qMul(a, b int64) int64 {
	if b == 1 {
		return a
	} else if (b & 1) == 1 {
		temp := qMul(a, b-1)
		ans = append(ans, fmt.Sprint(temp, " + ", b))
		return temp + b
	} else {
		temp := qMul(a, b>>1)
		ans = append(ans, fmt.Sprint(temp, " + ", temp))
		return temp << 1
	}
}

package main

import "fmt"

var ans []string

func main() {
	var x int64
	_, _ = fmt.Scan(&x)
	e := 0
	for int64(1<<(e+1)) <= x {
		e++
	}
	y := qMul(x, int64(1<<e))

	ans = append(ans, fmt.Sprint(y, " ^ ", x))
	y = y ^ x
	a, b := solve(x, y, int64(1))
	b = -b
	_ = qMul(x, a)
	_ = qMul(y, b)
	ans = append(ans, fmt.Sprint(a*x, " ^ ", b*y))

	fmt.Println(len(ans))
	for _, it := range ans {
		fmt.Println(it)
	}
}

func solve(a int64, b int64, c int64) (x, y int64) {
	a_temp, b_temp, c_temp := a, b, c
	a = (a%b + b) % b
	c = (c%b + b) % b
	d := exGcd(a, b, &x, &y)
	mod := b / d
	x = x * (c / d)
	x = (x%mod + mod) % mod
	fmt.Println(c_temp, a_temp, x, b_temp)
	y = (c_temp - a_temp*x) / b_temp
	return x, y

}

func exGcd(a int64, b int64, x *int64, y *int64) int64 {
	var x0, y0, x1, y1 int64 = 1, 0, 0, 1
	r := (a%b + b) % b
	q := (a - r) / b
	*x, *y = 0, 1
	for r > 0 {
		*x = x0 - q*x1
		*y = y0 - q*y1
		x0, y0 = x1, y1
		x1, y1 = *x, *y
		a = b
		b = r
		r = a % b
		q = (a - r) / b
	}
	return b

}

func qMul(a, b int64) int64 {
	if b == 1 {
		return a
	} else if (b & 1) == 1 {
		temp := qMul(a, b-1)
		ans = append(ans, fmt.Sprint(temp, " + ", b))
		return temp + b
	} else {
		temp := qMul(a, b>>1)
		ans = append(ans, fmt.Sprint(temp, " + ", temp))
		return temp << 1
	}
}

package main

import "fmt"

var ans []string

func main() {
	var x int64
	_, _ = fmt.Scan(&x)
	e := 0
	for int64(1<<(e+1)) <= x {
		e++
	}
	y := qMul(x, int64(1<<e))

	ans = append(ans, fmt.Sprint(y, " ^ ", x))
	y = y ^ x
	a, b := solve(x, y, int64(1))
	b = -b
	_ = qMul(x, a)
	_ = qMul(y, b)
	ans = append(ans, fmt.Sprint(a*x, " ^ ", b*y))

	fmt.Println(len(ans))
	for _, it := range ans {
		fmt.Println(it)
	}
}

func solve(a int64, b int64, c int64) (x, y int64) {
	a_temp, b_temp, c_temp := a, b, c
	a = (a%b + b) % b
	c = (c%b + b) % b
	d := exGcd(a, b, &x, &y)
	mod := b / d
	x = x * (c / d)
	x = (x%mod + mod) % mod
	y = (c_temp - a_temp*x) / b_temp
	return x, y

}

func exGcd(a int64, b int64, x *int64, y *int64) int64 {
	var x0, y0, x1, y1 int64 = 1, 0, 0, 1
	r := (a%b + b) % b
	q := (a - r) / b
	*x, *y = 0, 1
	for r > 0 {
		*x = x0 - q*x1
		*y = y0 - q*y1
		x0, y0 = x1, y1
		x1, y1 = *x, *y
		a = b
		b = r
		r = a % b
		q = (a - r) / b
	}
	return b

}

func qMul(a, b int64) int64 {
	if b == 1 {
		return a
	} else if (b & 1) == 1 {
		temp := qMul(a, b-1)
		ans = append(ans, fmt.Sprint(temp, " + ", b))
		return temp + b
	} else {
		temp := qMul(a, b>>1)
		ans = append(ans, fmt.Sprint(temp, " + ", temp))
		return temp << 1
	}
}


A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.

The first line consists of two integers n and m . Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n. It is guaranteed that every pair of cities will appear at most once in the input.

You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi. If there are several solutions, you may print any of them.

NoteThis is one possible solution of the example:   These are examples of wrong solutions:   The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair.   The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads.   Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.

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

func main() {
	var n,m,x,y,i,j int
	a:=make([]int,1010)
	fmt.Scan(&n,&m)
	for i=0;i<m;i++ {
		fmt.Scan(&x,&y)
		a[x]=1
		a[y]=1
	}
	fmt.Println(n-1)
	for i=1;i<=n;i++{
		if a[i]==0 {
			break
		}
	}
	for j=1;j<=n;j++ {
		if i!=j {
			fmt.Println(i,j)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, m, a, b, i int
	fmt.Scan(&n, &m)
	restricted := make([]bool, n)
	for i=0; i<m; i++ {
		fmt.Scan(&a, &b)
		restricted[a-1] = true
		restricted[b-1] = true
	}
	for i=0; i<n; i++ {
		if !restricted[i] {
			i++
			break
		}
	}
	fmt.Println(n-1)
	for j:=1; j<=n; j++ {
		if i != j {
			fmt.Println(i, j)
		}
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m := getI(), getI()
  seen := map[int]bool{}
  for i := 0; i < m; i++ {
    u, v := getI(), getI()
    seen[u] = true
    seen[v] = true
  }
  u := 1
  for seen[u] {
    u++
  }
  writer.WriteString(fmt.Sprintf("%d\n", n-1))
  for v := 1; v <= n; v++ {
    if v == u {
      continue
    }
    writer.WriteString(fmt.Sprintf("%d %d\n", u, v))
  }
}

package main

import "fmt"

func main() {
    var n,m,a,b,p int
    var f [1005]bool
    fmt.Scan(&n,&m)
    for i := 0; i < m; i++ {
        fmt.Scan(&a,&b)
        f[a] = true
        f[b] = true
    }
    for i := 1; i <= n; i++ {
        if !f[i] { p = i; break }
    }
    fmt.Println(n-1)
    for i := 1; i <= n; i++ {
        if i != p { fmt.Println(p,i) }
    }
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	forbidden := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		forbidden[i] = make(map[int]bool)
	}
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		if v < u {
			u, v = v, u
		}
		forbidden[u][v] = true
		forbidden[v][u] = true
	}
	id := make([]int, n)
	for i := 0; i < n; i++ {
		id[i] = i
	}
	sort.Slice(id, func(i, j int) bool {
		if len(forbidden[id[i]]) == len(forbidden[id[j]]) {
			return id[i] < id[j]
		}
		return len(forbidden[id[i]]) < len(forbidden[id[j]])
	})
	bestIndex := id[0]
	fmt.Println(n - 1)
	for j := 0; j < n; j++ {
		if j != bestIndex {
			fmt.Println(bestIndex + 1, j + 1)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

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

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// 330B-mic
package main

import (
    "fmt"
)

func main() {
    var n, m, x, y int
    fmt.Scan(&n, &m)
    a := make([]int, n+1)
    for i := 0; i < n+1; i++ {
        a[i] = i
    }
    for i := 0; i < m; i++ {
        fmt.Scan(&x, &y)
        a[x] = 0
        a[y] = 0
    }
    for i := 0; i < n+1; i++ {
        if a[i] != 0 {
            fmt.Println(n - 1)
            for j := 1; j < n+1; j++ {
                if j != a[i] {
                    fmt.Print(a[i])
                    fmt.Print(" ")
                    fmt.Print(j)
                    fmt.Println()
                }
            }
            break
        }
    }

}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

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

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

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

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

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

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

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

	var s int
	for i := 0; i < n; i++ {
		if !a[i] {
			s = i
			break
		}
	}

	fmt.Println(n - 1)
	for i := 0; i < n; i++ {
		if i != s {
			fmt.Println(i + 1, s + 1)
		}
	}
}

func main() {

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

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

	solution(reader, writer)
}


You are given a positive integer $$$n$$$, it is guaranteed that $$$n$$$ is even (i.e. divisible by $$$2$$$).You want to construct the array $$$a$$$ of length $$$n$$$ such that:   The first $$$\frac{n}{2}$$$ elements of $$$a$$$ are even (divisible by $$$2$$$);  the second $$$\frac{n}{2}$$$ elements of $$$a$$$ are odd (not divisible by $$$2$$$);  all elements of $$$a$$$ are distinct and positive;  the sum of the first half equals to the sum of the second half ($$$\sum\limits_{i=1}^{\frac{n}{2}} a_i = \sum\limits_{i=\frac{n}{2} + 1}^{n} a_i$$$). If there are multiple answers, you can print any. It is not guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the array. It is guaranteed that that $$$n$$$ is even (i.e. divisible by $$$2$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) satisfying conditions from the problem statement on the second line.

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		if (n/2)%2 == 1 {
			P("NO")
		} else {
			solv(n)
		}
	}
	close(O)
	oWg.Wait()
}

func solv(n int) {
	evenStr := strings.Builder{}
	oddStr := strings.Builder{}
	lastOdd := 0
	evenSum := int64(0)
	oddSum := int64(0)

	for i := 1; i <= n/2; i++ {
		evenStr.WriteString(strconv.Itoa(2*i) + " ")
		evenSum += int64(2 * i)

		if i == n/2 {
			lastOdd = (2 * i) - 1
		} else {
			oddStr.WriteString(strconv.Itoa((2*i)-1) + " ")
		}
		oddSum += int64((2 * i) - 1)
	}
	diff := evenSum - oddSum

	if diff%2 == 0 {
		lastOdd += int(diff)
		oddStr.WriteString(strconv.Itoa(lastOdd))
	} else {
		P("NO")
		return
	}
	P("YES")
	P(evenStr.String(), oddStr.String())
	return
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		if (n/2)%2 == 1 {
			P("NO")
		} else {
			solv(n)
		}
	}
	close(O)
	oWg.Wait()
}

func solv(n int) {
	evenArr := make([]int, n/2)
	oddArr := make([]int, n/2)
	evenSum := int64(0)
	oddSum := int64(0)

	for i := 1; i <= n/2; i++ {
		evenArr[i-1] = 2 * i
		evenSum += int64(2 * i)

		oddArr[i-1] = (2 * i) - 1
		oddSum += int64((2 * i) - 1)
	}
	diff := evenSum - oddSum

	if diff%2 == 0 {
		oddArr[len(oddArr)-1] += int(diff)
	} else {
		P("NO")
		return
	}
	P("YES")
	P(SArr(evenArr) + SArr(oddArr))
	return
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)

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

	for i:=0; i< t ; i++ {
		if v := isBalanced(n[i]); v != nil {
			fmt.Println("YES")
			print(v)
		} else {
			fmt.Println("NO")
		}
	}
}

func print(arr []int) {
	for i:=0; i < len(arr); i++ {
		if i == len(arr)-1 {
			fmt.Println(arr[i])
		} else {
			fmt.Printf("%d ", arr[i])
		}
	}
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left []int

	i := 1

	for i=2; i < n+1; i=i+2 {
		left = append(left, i)
	}
	for i=1; i < n-1; i=i+2 {
		left = append(left, i)
	}
	// fmt.Println("right ",right)

	left = append(left, (n+n/2 -1))

	return left
}

package main

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

//-------------------------------------27.4.2020--------------------------------------

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(inBuf,"%d\n", &t)

	format := "%d"
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(inBuf, format, &n)
		format = "\n%d"
		if arr, err := SolveAndMaybeGenerateArray(n/2); err != nil {
			fmt.Println(err.Error())
		} else {
			fmt.Println("YES")
			format1 := "%v"
			for _, v := range arr {
				fmt.Printf(format1, v)
				format1 = " %v"
			}
			fmt.Println()
		}
	}
}

func SolveAndMaybeGenerateArray(n int) ([]int, error) {
	res := make([]int, n*2)
	if n%2 != 0 {
		return nil, fmt.Errorf("NO")
	}

	i := 1
	for i <= n {
		res[i-1] = i*2
		i++
	}

	i-=1
	suma := res[0] + res[n-1]
	p := 1
	for i < n*2-n/2 {
		res[i] = p
		res[n*2-(i-n+1)] = suma - p
		i++
		p+=2
	}

	return res, nil
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a, b int
	fmt.Scan(&a)
	for i := 0; i < a; i++ {
		fmt.Scan(&b)
		if b%2 != 0 || (b/2)%2 != 0 {
			fmt.Println("No")
		} else {
			fmt.Println("Yes")
			var c []string
			sum := 0
			sum1 := 0
			for j := 0; j < b; j += 2 {
				c = append(c, strconv.Itoa(j+2))
				sum += j + 2
			}
			for j := 1; j < b-2; j += 2 {
				// b-2 to append last value in line 28
				c = append(c, strconv.Itoa(j))
				sum1 += j
			}
			c = append(c, strconv.Itoa(sum-sum1))
			fmt.Println(strings.Join(c, " "))
		}
	}
}

package main

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

func main() {
	var noEx int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	fmt.Fscan(in, &noEx)
	for nE:=0; nE<noEx; nE++ {
		var n int
		fmt.Fscan(in, &n)
		if (n / 2) % 2 != 0 {fmt.Fprint(out, "NO\n"); continue}
		fmt.Fprint(out, "YES\n")
		for e,c:=2,0; c<n/2; c++ {
			fmt.Fprint(out, e)
			fmt.Fprint(out, " ")
			e += 4
		}
		for e,c,diff:=2,0,1; c<n/2; c++ {
			fmt.Fprint(out, e+diff)
			diff*=-1
			if c != n/2 -1 {fmt.Fprint(out, " ")}
			e += 4
		}
		fmt.Fprint(out, "\n")
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		if n%4 == 0 {
			fmt.Println("YES")
			for first := 2; first <= n; first += 2 {
				fmt.Printf("%v ", first)
			}
			for second := 1; second < n-2; second += 2 {
				fmt.Printf("%v ", second)
			}
			fmt.Printf("%v\n", n+n/2-1)
		} else {
			fmt.Println("NO")
		}
	}

}

package main

import (
	"fmt"
)

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

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

func max(arr []int) (max int) {
	max = arr[0]
	for _, val := range arr {
		if val > max {
			max = val
		}
	}
	return max
}

var mod int = 1000000007

func main() {
	var t int
	fmt.Scan(&t)
	for qt := 0; qt < t; qt++ {
		var n int
		fmt.Scan(&n)
		if (n/2)%2 == 1 {
			fmt.Println("NO")
		} else {
			arr := make([]int, n)
			j := 2
			sum := 0
			for i := 0; i < n/2; i++ {
				arr[i] = j
				sum += arr[i]
				j += 2
			}
			j = 1
			for i := n / 2; i < n-1; i++ {
				arr[i] = j
				sum -= arr[i]
				j += 2
			}
			arr[n-1] = sum
			fmt.Println("YES")
			for _, val := range arr {
				fmt.Printf("%d ", val)
			}
			fmt.Println()
		}
	}
}

package main

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

// https://codeforces.com/problemset/problem/1343/B
// B. Balanced Array
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// You are given a positive integer n
// , it is guaranteed that n is even (i.e. divisible by 2

// ).

// You want to construct the array a
// of length n

// such that:

//     The first n2

// elements of a are even (divisible by 2
// );
// the second n2
// elements of a are odd (not divisible by 2
// );
// all elements of a
// are distinct and positive;
// the sum of the first half equals to the sum of the second half (∑i=1n2ai=∑i=n2+1nai

//     ).

// If there are multiple answers, you can print any. It is not guaranteed that the answer exists.

// You have to answer t

// independent test cases.
// Input

// The first line of the input contains one integer t
// (1≤t≤104) — the number of test cases. Then t

// test cases follow.

// The only line of the test case contains one integer n
// (2≤n≤2⋅105) — the length of the array. It is guaranteed that that n is even (i.e. divisible by 2

// ).

// It is guaranteed that the sum of n
// over all test cases does not exceed 2⋅105 (∑n≤2⋅105

// ).
// Output

// For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array a1,a2,…,an
// (1≤ai≤109) satisfying conditions from the problem statement on the second line.

var bufStdin = bufio.NewReader(os.Stdin)
var bufStdout = bufio.NewWriter(os.Stdout)

func main() {
	defer bufStdout.Flush()

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

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

	for i := 0; i < t; i++ {
		v := tests[i]

		if v%4 != 0 {
			_, _ = fmt.Fprintln(bufStdout, "NO")
		} else {
			_, _ = fmt.Fprintln(bufStdout, "YES")
			arr := constructArray(v)
			for _, v := range arr {
				_, _ = fmt.Fprint(bufStdout, v, " ")
			}
			_, _ = fmt.Fprintln(bufStdout)
		}
	}
}

func constructArray(n int) []int {
	arr := make([]int, 0, n)

	for i := 0; i < n/2; i++ {
		arr = append(arr, (i+1)*2)
	}

	for i := 0; i < n/2; i++ {
		arr = append(arr, i*2+1)
	}
	arr[n-1] += n / 2

	return arr
}

package main
import (
	"bufio"
	"fmt"
	"os"
)
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 n int
		fmt.Fscan(r, &n)
		if (n/2)%2 == 0 {
			fmt.Fprintln(w, "YES")
			for j := 2; j <= n; j += 2 {
				fmt.Fprintf(w, "%d ", j)
			}
			for j := 1; j < n-1; j += 2 {
				fmt.Fprintf(w, "%d ", j)
			}
			fmt.Fprintln(w, n + n/2 - 1)
		} else {
			fmt.Fprintln(w, "NO")
		}
	}

}

package main

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

// parse positive int from byte slice
func parseInt(a []byte, start int) (ans int) {
	for i := start; i < len(a) && a[i] >= '0' && a[i] <= '9'; i += 1 {
		// skip overflow check
		ans = 10*ans + int(a[i]-'0')
	}
	return ans
}

// left evens:
// (2 + n    )*(n/2)/2
// right odds without last:
// (1 + n - 3)*(n/2-1)/2
// last odd = left_sum - right_sum = 3*n/2-1
func generateNumbers(n int) []byte {
	ans := []byte{}
	for i := 2; i <= n; i += 2 {
		ans = append(ans, []byte(fmt.Sprintf("%d ", i))...)
	}
	for i := 1; i <= n-3; i += 2 {
		ans = append(ans, []byte(fmt.Sprintf("%d ", i))...)
	}
	ans = append(ans, []byte(fmt.Sprintln(3*n/2-1))...)
	return ans
}

// https://codeforces.com/problemset/problem/1343/B
// комментарии к решению
// Во первых для решения подходят только n кратные 4, т.к. нужна четная сумма нечетных
// Во вторых в самом простом решении при анализе примеров прослеживаются арифметические
// подпоследовательности в левой/правой частях решения для каждого n
// В третьих в виду ограничений по времени в 1 секунду лучше использовать bytes.ReadAll
// вместо fmt.Scan
func taskSolution(a []byte, t int) string {
	intStart := 0
	ans := []byte{}
	for i := 0; i < t; i += 1 {
		// find next
		// skip len check, because t value control number count
		for !(a[intStart] >= '0' && a[intStart] <= '9') {
			intStart += 1
		}
		cur := parseInt(a, intStart)
		if cur%4 != 0 {
			ans = append(ans, []byte("NO\n")...)
		} else {
			ans = append(ans, []byte("YES\n")...)
			ans = append(ans, generateNumbers(cur)...)
		}
		// skip parsed
		for a[intStart] >= '0' && a[intStart] <= '9' {
			intStart += 1
		}
	}
	return string(ans[:len(ans)-1])
}

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

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw, t))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1343/problem/B

package main

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

func Solve(n int) []int {
	if n/2%2 == 1 {
		return []int{}
	}
	ans := make([]int, n)
	for i := 0; i < n/2; i++ {
		ans[i] = 2 * (i + 1)
		ans[i+n/2] = 2*(i+1) - 1
	}
	ans[n-1] = n/2*(n/2+1) - (n/2-1)*(n/2-1)
	return ans
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		ans := Solve(n)
		if len(ans) == 0 {
			fmt.Fprintf(writer, "NO\n")
		} else {
			fmt.Fprintf(writer, "YES\n")
			for _, elem := range ans {
				fmt.Fprintf(writer, "%d ", elem)
			}
			fmt.Fprintf(writer, "\n")
		}
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()

    scanner.Scan()
    t, _ := strconv.Atoi(scanner.Text())

    for i := 0; i < t; i++ {
        scanner.Scan()
        n, _ := strconv.Atoi(scanner.Text())
        if n % 4 > 0 {
            fmt.Fprint(writer, "NO\n")
            continue
        }

        ar := make([]int, n, n)
        for k := range ar {
            if k < n / 2 {
                ar[k] = k * 2 + 2
            } else {
                ar[k] = (k - len(ar) / 2) * 2 + 1
            }
        }

        ar[len(ar)-1] += n / 2
        result := []rune(fmt.Sprintf("%v", ar))

        fmt.Fprintf(writer, "YES\n%s\n", string(result[1:len(result)-1]))
    }

}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		res := sol(reader.NextInt64())
		if res == nil {
			writer.Printf("NO\n")
		} else {
			writer.Printf("YES\n")
			for _, d := range res {
				writer.Printf("%d ", d)
			}
			writer.Printf("\n")
		}
	}
}

func sol(n int64) []int64 {
	if (n/2)&1 == 1 {
		return nil
	}
	ret := make([]int64, n)
	curr := int64(2)
	for i := int64(0); i < n/2; i++ {
		ret[i] = curr
		curr += 2
	}
	curr = int64(2)
	for i := n / 2; i < n; i++ {
		if i < n*3/4 {
			ret[i] = curr-1
		} else {
			ret[i] = curr+1
		}
		curr += 2
	}
	return ret
}

package main

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

func main() {
	var n, t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for j := 0; j < t; j++ {
		fmt.Fscan(in, &n)
		m := n / 2
		if m%2 == 0 {
			fmt.Println("YES")
			sum := 0
			for i := 1; i <= m; i++ {
				fmt.Printf("%d ", i*2)
				sum += i * 2
			}
			sum2 := 0
			for i := 0; i < m-1; i++ {
				fmt.Printf("%d ", i*2+1)
				sum2 += i*2 + 1
			}
			fmt.Printf("%d\n", sum-sum2)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func toInt(buff []byte) (n int64) {
	for _, v := range buff {
		n = n*10 + int64(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	scanner.Scan()
	for scanner.Scan() {
		b := toInt(scanner.Bytes())
		if (b/2)%2 == 0 {
			numbers := make([]int64, b)
			sumEven := int64(0)
			sumOdd  := int64(0)
			for i := int64(1); i <= b / 2; i++ {
				numbers[i - 1] = 2 * i
				numbers[(b / 2) + i - 1] = (2 * i) - 1
				sumEven += numbers[i - 1]
				sumOdd += 2 * i - 1
			}
			diff := sumEven - sumOdd
			if diff % 2 == 0 {
				numbers[b - 1] += diff
				writer.WriteString("YES\n")
				for _, num := range numbers {
					writer.WriteString(strconv.FormatInt(num, 10) + " ")
				}
				writer.WriteString("\n")
				continue
			}
		}
		writer.WriteString("NO\n")
	}

}

package main

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

func toInt(buff []byte) (n int64) {
	for _, v := range buff {
		n = n*10 + int64(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	scanner.Scan()
	for scanner.Scan() {
		b := toInt(scanner.Bytes())
		if (b/2)%2 == 0 {
			sumEven := int64(0)
			sumOdd  := int64(0)
			writer.WriteString("YES\n")
			for i := int64(1); i < b; i++ {
				var num int64
				if i <= (b / 2) {
					num = 2 * i
					sumEven += num
				} else {
					num = 2 * ( i - (b / 2)) - 1
					sumOdd += num
				}
				writer.WriteString(strconv.FormatInt(num, 10) + " ")
			}
			num := 2 * (b / 2) - 1
			diff := sumEven - (sumOdd + num)
			if diff % 2 == 0 {
				num += diff
				writer.WriteString(strconv.FormatInt(num, 10) + "\n")
				continue
			}
		}
		writer.WriteString("NO\n")
	}

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)
	for ; t>0; t-- {
		var n int
		fmt.Scanln(&n)
		if n/2%2==0 {
			fmt.Println("YES")
			for i:=1; i<=n/2; i++ {
				fmt.Printf("%d ", i*2)
			}
			for i:=n/2+1; i<n; i++ {
				fmt.Printf("%d ", (i-n/2-1)*2+1)
			}
			fmt.Printf("%d\n", n+n/2-1)
		} else {
			fmt.Println("NO")
		}
	}
	return
}

package main

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

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

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-- {
		var n int
		fmt.Fscan(in, &n)
		k := n / 2
		if k%2 == 1 {
			fmt.Fprintln(out, "NO")
			continue
		}
		fmt.Fprintln(out, "YES")
		for i := 1; i <= k; i++ {
			fmt.Fprintf(out, "%d ", i*2)
		}
		for i := 1; i <= k-1; i++ {
			fmt.Fprintf(out, "%d ", 2*i-1)
		}
		fmt.Fprintf(out, "%d\n", 3*k-1)
	}
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)

		ok := solve(n)

		if ok {
			fmt.Println("YES")
			for i := 0; i < n; i++ {
				fmt.Printf("%d ", res[i])
			}
			fmt.Println()
		} else {
			fmt.Println("NO")
		}
	}
}

const MAX_N = 200001

var res []int

func init() {
	res = make([]int, MAX_N)
}

func solve(n int) bool {
	h := n >> 1

	if h&1 == 1 {
		return false
	}

	for i := 0; i < h; i++ {
		res[i] = (i + 1) << 1
	}

	for i := h; i < n; i++ {
		res[i] = ((i - h + 1) << 1) - 1
	}

	res[n-1] += h

	return true
}

package main

import "fmt"

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

	if n % 4 != 0 {
		fmt.Println("NO")
		return
	} else {
		fmt.Println("YES")
	}

	arr := make([]int, n)
	n_half := n / 2
	even := 2
	var odd int
	for i := 0; i < n_half; i++ {
		if i % 2 == 0 {
			odd = even - 1
		} else {
			odd = even + 1
		}

		arr[i] = even
		arr[n_half + i] = odd

		if i % 2 == 0 {
			even += 2
		} else {
			even += 4
		}
	}
	// fmt.Println(arr)
	for i := 0; i < n; i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

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

// https://codeforces.com/contest/1343/problem/B

package main

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

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

func main() {
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	for i:=0;i<n;i++ {
		var t int
		scanf("%d\n", &t)
		if (t/2)%2 != 0 || t == 2 {
			printf("%s\n", "NO")
		} else {
			printf("%s\n", "YES")
			var odd,even []int
			sumOdd, sumEven := 0, 0
			for j:=1;j<=t;j++ {
				if j%2!=0 {
					if j!=t-1 {
						sumOdd += j
						odd = append(odd, j)
					}
				} else {
					sumEven += j
					even = append(even, j)
				}
			}
			for _, v := range even {
				printf("%d ", v)
			}
			for _, v := range odd {
				printf("%d ", v)
			}
			printf("%d\n", sumEven - sumOdd)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)

		if n/2%2 == 1 {
			fmt.Println("NO")
			continue
		}

		fmt.Println("YES")

		a := make([]int, n)
		for j := 1; j <= n/2; j++ {
			a[j-1] = 2 * j
			a[n/2+j-1] = 2*j - 1
		}

		a[n-1] += n / 2
		for j := 0; j < n; j++ {
			if j == n-1 {
				fmt.Printf("%d", a[j])
				continue
			}
			fmt.Printf("%d ", a[j])
		}
		fmt.Println()
	}
}

// https://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		T, n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Fscan(input, &n)
		p := n / 2
		if p % 2 == 1 {
			fmt.Println("NO")
			continue
		}

		fmt.Println("YES")
		for k := 1; k < p; k++ {
			fmt.Print(2*k, " ")
		}
		fmt.Print(2*p + p)

		for k := 1; k <= p; k++ {
			fmt.Print(" ", 2*k + 1)
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
)

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

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		n /= 2 // length of just one half
		if n % 2 == 1 {
			fmt.Println("NO")
			continue
		}

		// left half should just be n/2 even
		// n*(n+1)
		l := n*(n+1)
		// right half is n-1 odds + remainder
		// 2 4 6 = 12 => 1 3 5 = 12 - 3 = 9
		r := (n-1)*(n-1)
		fmt.Println("YES")
		for j := 1; j <= n; j++ {
			fmt.Printf("%d ", j*2)
		}
		for j := 1; j < n; j++ {
			fmt.Printf("%d ", j*2 - 1)
		}
		fmt.Println(l - r)
	}
}

package main

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

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

    var t int
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        var n int
        fmt.Fscan(in, &n)
        if n % 4 == 0 {
            fmt.Fprintln(out, "YES")
        } else {
            fmt.Fprintln(out, "NO")
            continue
        }
        var s int64
        for i := 2; i <= n; i += 2 {
            s += int64(i)
            fmt.Fprint(out, i, " ")
        }
        for i := 1; i <= n - 3; i += 2 {
            s -= int64(i)
            fmt.Fprint(out, i, " ")
        }
        fmt.Fprintln(out, s)
    }
    out.Flush()
}

package main

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

func isEvenNumber(n int) bool {
	return n%2 == 0
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, t, j, limit int
	fmt.Fscanf(r, "%d\n", &t)

	for tc := 0; tc < t; tc++ {
		fmt.Fscanf(r, "%d\n", &n)
		if !isEvenNumber(n / 2) {
			fmt.Fprintf(os.Stdout, "%s\n", "NO")
		} else {
			arr := make([]int, n)
			j = 2
			limit = n + 2
			fmt.Fprintf(os.Stdout, "%s\n", "YES")
			for i := 0; i < n/2; i += 2 {
				arr[i] = j
				arr[i+1] = limit - j
				j += 2
			}

			j = 1
			for i := n / 2; i < n; i += 2 {
				arr[i] = j
				arr[i+1] = limit - j
				j += 2
			}

			for i := range arr {
				fmt.Fprintf(os.Stdout, "%d ", arr[i])
			}
			fmt.Fprintln(os.Stdout)
		}
	}
}

package main

import "fmt"

func main() {
	var i int
	fmt.Scanln(&i)
	for ; i > 0; i-- {
		var n int
		fmt.Scanln(&n)
		if n/2%2 != 0 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			var sum int = 0
			for t := 0; t < n/2; t++ {
				sum += (t + 1) * 2
				fmt.Printf("%d ", (t+1)*2)
			}
			for t := 0; t < n/2-1; t++ {
				sum -= t*2 + 1
				fmt.Printf("%d ", t*2+1)
			}
			fmt.Println(sum)
		}
	}
}

package main

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

func main() {
	var n,inp int
	// in := bufio.NewReader(os.Stdin)
	// fmt.Fscanf(in, "%d %d\n", &n, &m)
	fmt.Scan(&n)
	for i:=0; i < n; i++{
		fmt.Scan(&inp)
		if inp % 4 != 0{
			fmt.Println("NO")
		}else{
			var s []int
			var se, so int
			fmt.Println("YES")
			for j:=2; j <= inp; {
				s = append(s, j)
				se += j
				j += 2
			}
			for j:=1; j <= inp;{
				s = append(s, j)
				so += j
				j +=2
			}
			s[len(s) - 1] += se - so
			for k:=0; k < len(s); k++{
				fmt.Print(s[k], " ")
			}
			fmt.Println()
		}
	}

}

package main

import "fmt"

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

	for i:=0; i< t ; i++ {
		fmt.Scanf("%d", &n)
		if v := isBalanced(n); v != nil {
			fmt.Println("YES")
			fmt.Println(v)
		} else {
			fmt.Println("NO")
		}
	}
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left, right []int

	i := 1

	for i=1; i <= n/2; i++ {
		left = append(left, 2*i)
		if i < n/2 {
			right = append(right, 2*(i-1) +1)
		}
	}
	// fmt.Println("right ",right)

	right = append(right, 2*(i-2) + 1+ n/2)
	left = append(left, right...)

	return left
}

package main

import "fmt"

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

	for i:=0; i< t ; i++ {
		fmt.Scanln("%d", &n)
		if v := isBalanced(n); v != nil {
			fmt.Println("YES")
			fmt.Println(v)
		} else {
			fmt.Println("NO")
		}
	}
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left []int

	i := 1

	for i=2; i < n+1; i=i+2 {
		left = append(left, i)
	}
	for i=1; i < n-1; i=i+2 {
		left = append(left, i)
	}
	// fmt.Println("right ",right)

	left = append(left, (n+n/2 -1))

	return left
}

package main

import "fmt"

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

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

	for i:=0; i< t ; i++ {
		if v := isBalanced(n[i]); v != nil {
			fmt.Println("YES")
			print(v)
		} else {
			fmt.Println("NO")
		}
	}
}

func print(arr []int) {
	for i:=0; i < len(arr); i++ {
		if i == 0 {
			fmt.Printf("%d", arr[i])
		} else {
			fmt.Printf(" %d", arr[i])
		}
	}
	fmt.Println("")
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left []int

	i := 1

	for i=2; i < n+1; i=i+2 {
		left = append(left, i)
	}
	for i=1; i < n-1; i=i+2 {
		left = append(left, i)
	}
	// fmt.Println("right ",right)

	left = append(left, (n+n/2 -1))

	return left
}

package main

import "fmt"

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

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

	for i:=0; i< t ; i++ {
		if v := isBalanced(n[i]); v != nil {
			fmt.Println("Yes")
			print(v)
		} else {
			fmt.Println("No")
		}
	}
}

func print(arr []int) {
	for i:=0; i < len(arr); i++ {
		if i == len(arr)-1 {
			fmt.Println(arr[i])
		} else {
			fmt.Printf("%d ", arr[i])
		}
	}
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left []int

	i := 1

	for i=2; i < n+1; i=i+2 {
		left = append(left, i)
	}
	for i=1; i < n-1; i=i+2 {
		left = append(left, i)
	}
	// fmt.Println("right ",right)

	left = append(left, (n+n/2 -1))

	return left
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln("%d", &t)

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

	for i:=0; i< t ; i++ {
		if v := isBalanced(n[i]); v != nil {
			fmt.Println("YES")
			print(v)
		} else {
			fmt.Println("NO")
		}
	}
}

func print(arr []int) {
	for i:=0; i < len(arr); i++ {
		if i == len(arr)-1 {
			fmt.Println(arr[i])
		} else {
			fmt.Printf("%d ", arr[i])
		}
	}
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left []int

	i := 1

	for i=2; i < n+1; i=i+2 {
		left = append(left, i)
	}
	for i=1; i < n-1; i=i+2 {
		left = append(left, i)
	}
	// fmt.Println("right ",right)

	left = append(left, (n+n/2 -1))

	return left
}

package main

import "fmt"

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

	for i:=0; i< t ; i++ {
		fmt.Scanf("%d", &n)
		if v := isBalanced(n); v != nil {
			fmt.Println("YES")
			fmt.Println(v)
		} else {
			fmt.Println("NO")
		}
	}
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left []int

	i := 1

	for i=2; i < n+1; i=i+2 {
		left = append(left, i)
	}
	for i=1; i < n-1; i=i+2 {
		left = append(left, i)
	}
	// fmt.Println("right ",right)

	left = append(left, (n+n/2 -1))

	return left
}

package main

import "fmt"

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

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

	for i:=0; i< t ; i++ {
		if v := isBalanced(n[i]); v != nil {
			fmt.Println("Yes")
			print(v)
		} else {
			fmt.Println("No")
		}
	}
}

func print(arr []int) {
	for i:=0; i < len(arr); i++ {
		if i == 0 {
			fmt.Printf("%d", arr[i])
		} else {
			fmt.Printf(" %d", arr[i])
		}
	}
	fmt.Println("")
}

func isBalanced(n int) []int {

	if (n/2)%2 == 1 {
		return nil
	}

	var left []int

	i := 1

	for i=2; i < n+1; i=i+2 {
		left = append(left, i)
	}
	for i=1; i < n-1; i=i+2 {
		left = append(left, i)
	}
	// fmt.Println("right ",right)

	left = append(left, (n+n/2 -1))

	return left
}

package main

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

//-------------------------------------27.4.2020--------------------------------------

func main() {
	inBuf := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(inBuf,"%d\n", &t)

	format := "%d"
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(inBuf, format, &n)
		format = "\n%d"
		if arr, err := SolveAndMaybeGenerateArray(n/2); err != nil {
			fmt.Println(err.Error())
		} else {
			fmt.Println("YES")
			fmt.Println(arr)
		}
	}
}

func SolveAndMaybeGenerateArray(n int) ([]int, error) {
	res := make([]int, n*2)
	if n%2 != 0 {
		return nil, fmt.Errorf("NO")
	}

	i := 1
	for i <= n {
		res[i-1] = i*2
		i++
	}

	i-=1
	suma := res[0] + res[n-1]
	p := 1
	for i < n*2-n/2 {
		res[i] = p
		res[n*2-(i-n+1)] = suma - p
		i++
		p+=2
	}

	return res, nil
}

package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a)
	for i := 0; i < a; i++ {
		fmt.Scan(&b)
		if b%2 != 0 || (b/2)%2 != 0 {
			fmt.Println("No")
		} else {
			fmt.Println("Yes")
			var c []int
			sum := 0
			sum1 := 0
			for j := 0; j < b; j += 2 {
				c = append(c, j+2)
				sum += j + 2
			}
			for j := 1; j < b-2; j += 2 {
				// b-2 to append last value in line 28
				c = append(c, j)
				sum1 += j
			}
			c = append(c, sum-sum1)
			fmt.Println(c)
		}
	}
}

package main

import "fmt"

func main() {
	var noEx int
	fmt.Scan(&noEx)
	for nE:=0; nE<noEx; nE++ {
		var n int
		fmt.Scan(&n)
		if (n / 2) % 2 != 0 {fmt.Println("NO"); continue}
		fmt.Println("YES")
		for e,c:=2,0; c<n/2; c++ {
			fmt.Print(e)
			fmt.Print(" ")
			e += 4
		}
		for e,c,diff:=2,0,1; c<n/2; c++ {
			fmt.Print(e+diff)
			diff*=-1
			if c != n/2 -1 {fmt.Print(" ")}
			e += 4
		}
	}
}

package main

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

func main() {
	var noEx int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &noEx)
	for nE:=0; nE<noEx; nE++ {
		var n int
		fmt.Fscan(in, &n)
		if (n / 2) % 2 != 0 {fmt.Fprint(os.Stdout, "NO"); continue}
		fmt.Fprint(os.Stdout, "YES")
		for e,c:=2,0; c<n/2; c++ {
			fmt.Fprint(os.Stdout, e)
			fmt.Fprint(os.Stdout, " ")
			e += 4
		}
		for e,c,diff:=2,0,1; c<n/2; c++ {
			fmt.Print(e+diff)
			diff*=-1
			if c != n/2 -1 {fmt.Fprint(os.Stdout, " ")}
			e += 4
		}
		fmt.Fprint(os.Stdout, "\n")
	}
}

package main

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

// https://codeforces.com/problemset/problem/1343/B
// B. Balanced Array
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// You are given a positive integer n
// , it is guaranteed that n is even (i.e. divisible by 2

// ).

// You want to construct the array a
// of length n

// such that:

//     The first n2

// elements of a are even (divisible by 2
// );
// the second n2
// elements of a are odd (not divisible by 2
// );
// all elements of a
// are distinct and positive;
// the sum of the first half equals to the sum of the second half (∑i=1n2ai=∑i=n2+1nai

//     ).

// If there are multiple answers, you can print any. It is not guaranteed that the answer exists.

// You have to answer t

// independent test cases.
// Input

// The first line of the input contains one integer t
// (1≤t≤104) — the number of test cases. Then t

// test cases follow.

// The only line of the test case contains one integer n
// (2≤n≤2⋅105) — the length of the array. It is guaranteed that that n is even (i.e. divisible by 2

// ).

// It is guaranteed that the sum of n
// over all test cases does not exceed 2⋅105 (∑n≤2⋅105

// ).
// Output

// For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array a1,a2,…,an
// (1≤ai≤109) satisfying conditions from the problem statement on the second line.

var bufStdin = bufio.NewReader(os.Stdin)
var bufStdout = bufio.NewWriter(os.Stdout)

func main() {
	defer bufStdout.Flush()

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

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

	for i := 0; i < t; i++ {
		doTestCase(tests[i])
	}
}

func doTestCase(n int) {
	if (n/2)%2 == 1 {
		_, _ = fmt.Fprintln(bufStdout, "NO")
		return
	}

	_, _ = fmt.Fprintln(bufStdout, "YES")

	for i := 0; i < n/2; i++ {
		_, _ = fmt.Fprint(bufStdout, (i+1)*2, " ")
	}

	for i := 0; i < n/2-1; i++ {
		_, _ = fmt.Fprint(bufStdout, i*2+1, " ")
	}
	_, _ = fmt.Fprint(bufStdout, (n/2+1)*2+1)

	_, _ = fmt.Fprintln(bufStdout)
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		res := sol(reader.NextInt64())
		if res == nil {
			writer.Printf("NO\n")
		} else {
			writer.Printf("YES\n")
			for _, d := range res {
				writer.Printf("%d ", d)
			}
			writer.Printf("\n")
		}
	}
}

func sol(n int64) []int64 {
	if (n/2)&1 == 1 {
		return nil
	}
	ret := make([]int64, n)
	curr := int64(2)
	for i := int64(0); i < n/2; i++ {
		if i < n/4 {
			ret[i] = curr - 1
		} else {
			ret[i] = curr + 1
		}
		curr += 2
	}
	curr = int64(2)
	for i := n/2; i < n; i++ {
		ret[i] = curr
		curr += 2
	}
	return ret
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)

		if n/2%2 == 1 {
			fmt.Println("NO")
			continue
		}

		a := make([]int, n/2)
		b := make([]int, n/2)

		for j := 1; j <= n/2; j++ {
			a[j-1] = 2*j - 1
			b[j-1] = 2 * j
		}

		a[n/2-1] += n / 2

		fmt.Println("YES")
		for j := 0; j < n/2; j++ {
			fmt.Printf("%d ", a[j])
		}

		for j := 0; j < n/2; j++ {
			if j == n/2-1 {
				fmt.Printf("%d", b[j])
				continue
			}
			fmt.Printf("%d ", b[j])
		}
		fmt.Println()
	}
}


You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times):  choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number);  swap the elements on positions i and j; in other words, you are allowed to apply the following sequence of assignments: tmp = a[i], a[i] = a[j], a[j] = tmp (tmp is a temporary variable). You do not need to minimize the number of used operations. However, you need to make sure that there are at most 5n operations.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n distinct integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ n).

In the first line, print integer k (0 ≤ k ≤ 5n) — the number of used operations. Next, print the operations. Each operation must be printed as "i j" (1 ≤ i < j ≤ n; (j - i + 1) is a prime). If there are multiple answers, you can print any of them.

package main

import (
	"bufio"
	"errors"
	"flag"
	"fmt"
	"log"
	"os"
	"strconv"
	"time"
)

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

var ()

func solve() {
	n := readInt()
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = readInt() - 1
	}

//	n = 100000
//	array = make([]int, n)
//	for i := 0; i < n; i++ {
//		array[i] = n - 1 - i
//	}

	next := make([]int, n + 10)
	for j := 2; int64(j) * int64(j) < int64(len(next)); j++ {
		if next[j] == 0 {
			for i := j * j; i < len(next); i += j {
				next[i] = 1
			}
		}
	}

	prev := -1
	for i := 0; i < len(next); i++ {
		if next[i] == 0 {
			prev = i
		}
		next[i] = prev
	}

	M := make([]int, n)
	for i := 0; i < n; i++ {
		M[array[i]] = i
	}

	ans := 0
	var J []int
	var I []int

			// logln(next)
			// logln(array)
	for i := 0; i < n - 1; i++ {
		// logln("lol")
		for M[i] != i {
			pos := M[i]
			value := next[pos - i + 1]
			newPos := pos - value + 1
			array[pos], array[newPos] = array[newPos], array[pos]
			M[array[pos]] = pos
			M[array[newPos]] = newPos
			ans++
			J = append(J, newPos + 1)
			I = append(I, pos + 1)
			// logln(array)
		}
	}

	printInt(ans)
	printLine()
	for i := 0; i < ans; i++ {
		printInt(J[i])
		printString(" ")
		printInt(I[i])
		printLine()
	}

}

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

// IO.

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

func main() {
	local := flag.Bool("local", false, "Equals true, if run is local.")
	flag.Parse()

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

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

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

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

	solve()
}

// Read.

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

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

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

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

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

// Write.

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

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

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

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

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

// Log.

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

// Tuple

type Tuple struct {
	a, b int
}

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

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

type TupleSlice []Tuple

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

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

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

// Min, max, abs.

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

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

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

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

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

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

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

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

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

// Set Key interface implementations.

type Int int

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

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

// Set.

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

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

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

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

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

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

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

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

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

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

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

	return x
}

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

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

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

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

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

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

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

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

package main

import (
	"bufio"
	"errors"
	"flag"
	"fmt"
	"log"
	"os"
	"strconv"
	"time"
)

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

var ()

func solve() {
	n := readInt()
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = readInt() - 1
	}

	next := make([]int, n + 10)
	for j := 2; j < len(next); j++ {
		if next[j] == 0 {
			for i := j * j; i * i < len(next); i += j {
				next[i] = 1
			}
		}
	}

	prev := -1
	for i := 0; i < len(next); i++ {
		if next[i] == 0 {
			prev = i
		}
		next[i] = prev
	}

	M := make([]int, n)
	for i := 0; i < n; i++ {
		M[array[i]] = i
	}

	ans := 0
	var J []int
	var I []int

	for i := 0; i < n - 1; i++ {
		for M[i] != i {
			pos := M[i]
			value := next[pos - i + 1]
			newPos := pos - value + 1
			M[pos], M[newPos] = M[newPos], M[pos]
			ans++
			J = append(J, newPos + 1)
			I = append(I, pos + 1)
		}
	}

	printInt(ans)
	printLine()
	for i := 0; i < ans; i++ {
		printInt(J[i])
		printString(" ")
		printInt(I[i])
		printLine()
	}

}

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

// IO.

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

func main() {
	local := flag.Bool("local", false, "Equals true, if run is local.")
	flag.Parse()

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

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

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

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

	solve()
}

// Read.

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

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

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

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

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

// Write.

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

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

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

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

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

// Log.

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

// Tuple

type Tuple struct {
	a, b int
}

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

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

type TupleSlice []Tuple

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

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

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

// Min, max, abs.

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

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

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

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

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

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

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

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

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

// Set Key interface implementations.

type Int int

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

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

// Set.

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

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

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

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

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

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

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

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

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

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

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

	return x
}

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

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

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

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

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

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

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

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


Polycarp has $$$n$$$ friends, the $$$i$$$-th of his friends has $$$a_i$$$ candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all $$$a_i$$$ to be the same. To solve this, Polycarp performs the following set of actions exactly once:   Polycarp chooses $$$k$$$ ($$$0 \le k \le n$$$) arbitrary friends (let's say he chooses friends with indices $$$i_1, i_2, \ldots, i_k$$$);  Polycarp distributes their $$$a_{i_1} + a_{i_2} + \ldots + a_{i_k}$$$ candies among all $$$n$$$ friends. During distribution for each of $$$a_{i_1} + a_{i_2} + \ldots + a_{i_k}$$$ candies he chooses new owner. That can be any of $$$n$$$ friends. Note, that any candy can be given to the person, who has owned that candy before the distribution process. Note that the number $$$k$$$ is not fixed in advance and can be arbitrary. Your task is to find the minimum value of $$$k$$$.For example, if $$$n=4$$$ and $$$a=[4, 5, 2, 5]$$$, then Polycarp could make the following distribution of the candies:   Polycarp chooses $$$k=2$$$ friends with indices $$$i=[2, 4]$$$ and distributes $$$a_2 + a_4 = 10$$$ candies to make $$$a=[4, 4, 4, 4]$$$ (two candies go to person $$$3$$$). Note that in this example Polycarp cannot choose $$$k=1$$$ friend so that he can redistribute candies so that in the end all $$$a_i$$$ are equal.For the data $$$n$$$ and $$$a$$$, determine the minimum value $$$k$$$. With this value $$$k$$$, Polycarp should be able to select $$$k$$$ friends and redistribute their candies so that everyone will end up with the same number of candies.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^4$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output:    the minimum value of $$$k$$$, such that Polycarp can choose exactly $$$k$$$ friends so that he can redistribute the candies in the desired way;  "-1" if no such value $$$k$$$ exists.

package main

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

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

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

  if sum % n != 0 {
    fmt.Fprintln(writer, -1)
  } else {
    total := 0

    for _, v := range a {
      if (v > sum/n) {
        total++
      }
    }

    fmt.Fprintln(writer, total)
  }
}

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

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

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

package main

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

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

func testcase() {
  var n int
  fmt.Fscan(reader, &n)

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

  if sum % n != 0 {
    fmt.Fprintln(writer, -1)
  } else {
    total := 0

    for _, v := range a {
      if (v > sum/n) {
        total++
      }
    }

    fmt.Fprintln(writer, total)
  }
}

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

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

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,sum int
		fmt.Fscan(in,&n)
		var list []int = make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
			sum+=list[j]
		}
		if n == 1 {
			fmt.Println(0)
		} else if sum%n != 0 {
			fmt.Println(-1)
		} else {
			count:=0
			for j:=0;j<n;j++{
				if list[j] > sum/n {
					count++
				}
			}
			fmt.Println(count)
		}
	}
}

package main

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

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

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

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

func Solve(in []int) int {
	var sum, res int

	for _, v := range in {
		sum += v
	}

	if sum%len(in) != 0 {
		return -1
	}

	for _, v := range in {
		if v > sum/len(in) {
			res++
		}
	}

	return res
}

func SolveSlow(in []int) int {
	var sumMax int

	if len(in) == 1 {
		return 0
	}

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

	if in[0] == in[len(in)-1] {
		return 0
	}

	for k := 0; k < len(in)-1; k++ {
		sumMax += in[k]

		var diff int
		var rem int

		for j := k + 1; j < len(in); j++ {
			diff += in[k+1] - in[j]
		}

		rem = sumMax - diff - in[k+1]*(k+1)

		if rem < 0 {
			continue
		}

		if rem%len(in) == 0 {
			return k + 1
		}
	}

	return -1
}

func main() {
	in := bufio.NewReader(os.Stdin)
	n := readInt(in)

	for i := 0; i < n; i++ {
		_ = readInt(in)

		input := readArrInt(in)

		res := Solve(input)
		fmt.Printf("%d\n", res)
	}
}

package main

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
var a [200010]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Scan(&t)
	for i := 0; i < t; i ++ {
		solve := func() {
			var n, sum int
			fmt.Fscan(in, &n)
			for i := 0; i < n; i++ {
				fmt.Fscan(in, &a[i])
				sum += a[i]
			}
			if sum%n != 0 {
				fmt.Fprintln(out, -1)
			} else {
				sum /= n
				ans := 0
				for i := 0; i < n; i++ {
					if a[i] > sum {
						ans++
					}
				}
				fmt.Fprintln(out, ans)
			}
		}
		solve()
	}
}

package main

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

const Mod = 1000000007

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

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

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

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

	out.Flush()
}

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

	sum := 0
	for i := 0; i < n; i++ {
		sum += a[i]
	}
	if sum%n != 0 {
		fmt.Fprintln(out, -1)
		return
	}
	sum /= n

	ans := 0
	for i := 0; i < n; i++ {
		if a[i] > sum {
			ans += 1
		}
	}
	fmt.Fprintln(out, ans)
}

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

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

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		sum := 0
		for _, v := range a {
			sum += v
		}
		if sum % n > 0 {
			Fprintln(out, -1)
			return
		}
		c:=0
		for _, v := range a {
			if v > sum/n {
			c++
			}
		}
		Fprintln(out, c)
	}

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

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

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

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		n := parseInt(getString(reader))
		A := getIntln(reader)
		var sum, res int
		for _, v := range A {
			sum += v
		}
		if sum%n != 0 {
			res = -1
		} else {
			mean := sum / n
			for _, v := range A {
				if v > mean {
					res++
				}
			}
		}
		writer.WriteString(fmt.Sprintln(res))
	}
	writer.Flush()
}

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

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"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)
		o, p, sum := []int{}, 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o = append(o, p)
			sum += p
		}
		if sum%n == 0 {
			quota, tot := sum/n, 0
			for j := 0; j < n; j++ {
				if o[j] > quota {
					tot++
				}
			}
			fmt.Fprintln(w, tot)
		} else {
			fmt.Fprintln(w, "-1")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func solve(n int, a []int) int {
	var (
		sum, avg, cl int
	)
	for i := 0; i < n; i++ {
		sum += a[i]
	}
	if sum%n > 0 {
		return -1
	}
	avg = sum / n
	for i := 0; i < n; i++ {
		if a[i] > avg {
			cl++
		}
	}
	return cl
}

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

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

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

		sum := 0
		for i := range a {
			Fscan(in, &a[i])
			sum += a[i]
		}

		if sum % n != 0 {
			Fprintln(out, -1)
			continue
		}

		avg, ans := sum / n, 0
		for _, val := range a {
			if avg < val {
				ans++
			}
		}
		Fprintln(out, ans)
	}
}

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
}

package main

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

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

func (in *CF1538B) 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 *CF1538B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1538B
 Date: 21/08/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1538/B
 Problem: CF1538B
**/
func (in *CF1538B) Run() {
	N := in.NextInt()
	for ; N > 0; N-- {
		t := in.NextInt()
		arr := []int{}
		sum := 0
		for i:=0;i<t;i++{
			num := in.NextInt()
			arr = append(arr, num)
			sum += num
		}
		ans := -1
		values := sum / t
		if values * t == sum {
			k := 0
			for i:=0;i<t;i++{
				if arr[i] > values {
					k++
				}
			}
			ans = k
		}
		fmt.Println(ans)
	}
}

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

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

package main

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

func sum(arr []int32) int32 {
	output := int32(0)
	for _, value := range arr {
		output += value
	}
	return output
}

func solve(n int32, arr []int32) int32 {
	total := sum(arr)
	if total%n != 0 {
		return -1
	}
	avg := total / n
	output := int32(0)
	for _, value := range arr {
		if value > avg {
			output++
		}
	}
	return output
}

func arrayScanf(in *bufio.Reader, n int32, arr *[]int32) {
	m := int32(0)
	for i := int32(0); i < n; i++ {
		if i > 0 {
			fmt.Fscanf(in, " ")
		}
		fmt.Fscanf(in, "%d", &m)
		*arr = append(*arr, m)
	}
	fmt.Fscanf(in, "\n")
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		arr := []int32{}
		fmt.Fscanf(in, "%d\n", &n)
		arrayScanf(in, n, &arr)
		fmt.Fprintf(out, "%d\n", solve(n, arr))
		tt--
	}
	out.Flush()
}

package main

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

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

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

	var n, num int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		sum := 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &num)
			arr[i] = num
			sum += num
		}
		if sum%n > 0 {
			fmt.Fprintln(writer, -1)
			continue
		}
		k := 0
		target := sum / n
		for _, num := range arr {
			if num > target {
				k++
			}
		}
		fmt.Fprintln(writer, k)
	}
}

package main

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

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

type Array []int

func main() {
    defer writer.Flush()
    var T int
    scanf("%d\n", &T)
    for cas := 1; cas <= T; cas++ {
        var N int
        scanf("%d\n", &N)
        // var arr [N]int
        arr := make(Array, N)
        ans := 0
        for i := 0; i < N; i++ {
            scanf("%d", &arr[i])
            ans += arr[i]
        }
        scanf("\n")
        if ans % N > 0 {
            printf("-1\n")
        } else {
            sort.Ints(arr)
            res := arr.upper_bound(N, ans / N)
            printf("%d\n", N - res)
        }
    }
    return
}

func (i Array) upper_bound(sz int, key int) int {
    lo := 0
    hi := sz

    for lo < hi {
        mid := (lo + hi) / 2
        if i[mid] <= key {
            lo = mid + 1
        } else {
            hi = mid
        }
    }
    return lo
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		Readln(reader)
		line,_  := Readln(reader)
		pln := strings.Split(line, " ")
		ln := make([] int, len(pln))
		tot := 0
		for i:= range ln {
			ln[i],_ = strconv.Atoi(pln[i])
			tot += ln[i]
		}

		if tot % len(pln) != 0 {
			fmt.Println("-1")
			continue
		}
		avg:= tot/len(pln)
		res := 0
		for _, v:= range ln {
			if v>avg {
				res++
			}
		}
		fmt.Println(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
		}
	}
}

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
}

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)
		var Sum int64
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])
			Sum = Sum + ARRAY[i]

		}

		m := Sum % int64(n)
		if m != 0 {
			fmt.Println(-1)
		} else {
			q := int64(Sum / int64(n))
			aount := 0
			for i := 0; i < n; i++ {
				if ARRAY[i] > q {
					aount++
				}
			}
			fmt.Println(aount)
		}
	}

}

package main

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

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

type Int int64

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

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

	for tc := 0; tc < t; tc++ {
		fmt.Fscan(_r, &n)
		a := make([]int, n)
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(_r, &a[i])
			sum += a[i]
		}
		if sum%n != 0 {
			fmt.Fprintf(_w, "-1\n")
			continue
		}
		sum /= n
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		ans := 0
		for i := n - 1; i >= 0; i-- {
			if a[i] > sum {
				ans++
			} else {
				break
			}
		}

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

package main

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

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

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

func solve(arr []int) int {
	log.Printf("arr = %+v\n", arr)
	log.Printf("sum(arr)/len(arr) = %+v\n", sum(arr)/len(arr))
	mid := sum(arr) / len(arr)
	// log.Printf("float(sum(arr)) = %+v\n", float32(sum(arr))/float32(len(arr)))
	if float32(sum(arr))/float32(len(arr))-float32(sum(arr)/len(arr)) > 0 {
		return -1
	}

	count := 0
	for _, v := range arr {
		if v > mid {
			count++
		}
	}

	return count
}

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

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

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

	}
	log.Println("__end__")
}

package main

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

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

func calc(arr []int, x int) int {
	cnt := 0
	for _, val := range arr {
		if val > x {
			cnt++
		}
	}
	return cnt
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		sum := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			sum += arr[i]
		}
		ans := n + 1
		if sum % n == 0 {
			ans = min(ans, calc(arr, sum / n))
		}
		if ans == n + 1 {
			ans = -1
		}
		fmt.Fprintln(out, ans)
		t--
	}
	out.Flush()

}

package main

import (
	"bufio"
	"os"

	"fmt"
	"sort"
)

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		a := make([]int, n)

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

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

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

	var s int64

	for i := 0; i < n; i++ {
		s += int64(a[i])
	}

	if s % int64(n) != 0 {
		return -1
	}

	each := s/int64(n)

	sort.Ints(a)

	var k int

	for i := n - 1; i >= 0; i-- {
		if int64(a[i]) > each {
			k++
			continue
		}
		break
	}

	return k
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	solve := func(Case int) {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		sm := 0
		for i := range a {
			fmt.Fscan(in, &a[i])
			sm += a[i]
		}
		if sm%n != 0 {
			fmt.Fprintln(out, -1)
			return
		}
		div := int(sm / n)
		ans := 0
		for i := range a {
			if a[i] > div {
				ans++
			}
		}
		fmt.Fprintln(out, ans)

	}

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

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

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

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