You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ and an integer $$$k$$$. Find the maximum value of $$$i \cdot j - k \cdot (a_i | a_j)$$$ over all pairs $$$(i, j)$$$ of integers with $$$1 \le i < j \le n$$$. Here, $$$|$$$ is the bitwise OR operator.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains two integers $$$n$$$ ($$$2 \le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le \min(n, 100)$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print a single integer  — the maximum possible value of $$$i \cdot j - k \cdot (a_i | a_j)$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int64) int64{
	if x>y{
		return x
	}
	return y
}
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 c:=1;c<=t;c++{
		var n int64
		var k int64
		fmt.Fscan(in,&n,&k)
		var a [100005]int64
		var i int64
		for i=1;i<=n;i++ {
			fmt.Fscan(in, &a[i])
		}
		st := max(n-2*k,1)
		var ans int64
		ans = -99999999
		for i=st;i<=n;i++{
			for j:=i+1;j<=n;j++{
				ans = max(ans, i*j-(a[i]|a[j])*k)
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k int64
	scan(&n, &k)
	var a = make([][2]int64, n)
	for i := range a {
		scan(&a[i][0])
		a[i][1] = int64(i + 1)
	}
	if len(a) > 500 {
		a = a[len(a)-500:]
	}
	var ans int64 = -(1 << 60)
	for i := range a {
		for j := i + 1; j < len(a); j++ {
			r := a[i][1]*a[j][1] - k*(a[i][0]|a[j][0])
			if ans < r {
				ans = r
			}
		}
	}
	printf("%v\n", ans)
}

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func() {
		var n int
		var k int
		var ans int64
		Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans = -1000000000
		for i := n - 205; i < n; i++ {
			if i < 0 {
				continue
			}
			for j := i + 1; j < n; j++ {
				ans = max(ans, int64(i+1)*int64(j+1)-int64(k)*(a[i]|a[j]))
			}
		}
		Fprintln(out, ans)
	}
	var T int
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

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

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

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

	n, k int
	a [100000]int64
	res int64
)

func main() {
	initBuffer()
	var t int = 1
	t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {
	res = -1e18
}

func input() {
	n = getInt()
	k = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt64()
	}
}

func count() {
	for i := max(0, n - 1 - 2 * k); i < n; i++ {
		for j := i + 1; j < n; j++ {
			res = max64(res, int64(i + 1) * int64(j + 1) - int64(k) * int64(a[i]|a[j]))
		}
	}
}

func output() {
	out.Write(int64ToBytes(res))
	out.WriteByte(NL)
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

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

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1554B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ fi, se int }

	var T, n, k, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		mx := bits.Len(uint(n))
		dp := make([]pair, 1<<mx)
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			dp[v] = pair{i, dp[v].fi}
		}
		for i := 0; i < mx; i++ {
			for s := 0; s < 1<<mx; s++ {
				s |= 1 << i
				p, q := dp[s], dp[s^1<<i]
				if q.se > p.fi {
					dp[s] = q
				} else if q.fi > p.fi {
					dp[s] = pair{q.fi, p.fi}
				} else if q.fi > p.se {
					dp[s].se = q.fi
				}
			}
		}
		ans := int64(-1e18)
		for s, p := range dp {
			if p.se > 0 {
				if v := int64(p.fi)*int64(p.se) - int64(k*s); v > ans {
					ans = v
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int64) int64{
	if x>y{
		return x
	}
	return y
}
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)
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n int64
		var k int64
		fmt.Fscan(in,&n,&k)
		var a [300005]int64
		var i int64
		for i=1;i<=n;i++ {
			fmt.Fscan(in, &a[i])
		}
		st := max(n-2*k,1)
		var ans int64
		ans = -99999999
		for i=st;i<=n;i++{
			for j:=i+1;j<=n;j++{
				ans = max(ans, i*j-(a[i]|a[j])*k)
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int) int{
	if x>y{
		return x
	}
	return y
}
func min(x, y int) int{
	if x<y{
		return x
	}
	return y
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var n, k int
		fmt.Fscan(in,&n,&k)
		var a [300005]int
		for i:=1;i<=n;i++ {
			fmt.Fscan(in, &a[i])
		}
		st := max(n-2*k,1)
		ans := -99999999
		for i:=st;i<=n;i++{
			for j:=i+1;j<=n;j++{
				ans = max(ans, i*j-(a[i]|a[j])*k)
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k int64
	scan(&n, &k)
	var a = make([]int64, n)
	for i := range a {
		scan(&a[i])
	}
	var ans int64 = -(1 << 60)
	for b := 0; b < 20; b++ {
		res := [][2]int64{}
		var mask int64 = ^(1<<b - 1)
		for i := n - 1; len(res) < 2 && i >= 0; i-- {
			if mask&a[i] == 0 {
				res = append(res, [2]int64{i + 1, a[i]})
			}
		}
		if len(res) == 2 {
			r := res[0][0]*res[1][0] - k*(res[0][1]|res[1][1])
			if ans < r {
				ans = r
			}
		}
	}
	printf("%v\n", ans)
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n, k int
	scan(&n, &k)
	var a = make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	var ans = -(1 << 30)
	for b := 0; b < 20; b++ {
		res := [][2]int{}
		mask := ^(1<<b - 1)
		for i := n - 1; len(res) < 2 && i >= 0; i-- {
			if mask&a[i] == 0 {
				res = append(res, [2]int{i + 1, a[i]})
			}
		}
		if len(res) == 2 {
			r := res[0][0]*res[1][0] - k*(res[0][1]|res[1][1])
			if ans < r {
				ans = r
			}
		}
	}
	printf("%v\n", ans)
}

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func() {
		var n int
		var k int
		var ans int64
		Fscan(in, &n, &k)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans = -1000000000
		for i := n/2 - 105; i < n/2+105; i++ {
			if i < 0 || i >= n {
				continue
			}
			for j := i + 1; j < n/2+105; j++ {
				if j >= n {
					break
				}
				ans = max(ans, int64(i+1)*int64(j+1)-int64(k)*(a[i]|a[j]))
			}
		}
		Fprintln(out, ans)
	}
	var T int
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

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


Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij.Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love.

The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue.

Print the only integer a — the cost of the dinner for Jack and Emma.

NoteIn the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1.

package main

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

func main() {
    var n,m int
    var c [100][100]int
    var mins [100]int
    for i := 0; i < 100; i++ {
        mins[i] = 1000000000
    }

    fmt.Scanf("%d %d\n", &n, &m)
    //fmt.Printf("%d %d\n", n, m)

    scanner := bufio.NewScanner(os.Stdin)
    for i := 0; i < n; i++ {
        scanner.Scan()
        s := scanner.Text()
        ss := strings.Fields(s)
        for j := 0; j < m; j++ {
            c[i][j], _ = strconv.Atoi(ss[j])
            if c[i][j] < mins[i] {
                mins[i] = c[i][j]
            }
        }
    }
//    for i := 0; i < n; i++ {
//        fmt.Printf("%d -> %d\n", i, mins[i])
//    }
    var s int = 0
    for i := 0; i < n; i++ {
        if mins[i] > s {
            s = mins[i]
        }
    }
    fmt.Printf("%d", s)
}

package main

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

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

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

func main() {
    stdin := bufio.NewReader(os.Stdin)
    var n, m int
    fmt.Fscan(stdin, &n, &m)

    r := int64(0)
    for i := 0; i < n; i++ {
      c := int64(1000000001)
      for j := 0; j < m; j++ {
        var t int64
        fmt.Fscan(stdin, &t)
        c = min(c, t)
      }
      r = max(r, c)
    }
    fmt.Println(r)
}

package main
import "fmt"
func main () {
    var n,m,t int
    fmt.Scan(&n,&m)
    r:=make([]int,n)
    for i:=0;i<n;i++ {
        fmt.Scan(&r[i])
        for j:=1;j<m;j++ {
            fmt.Scan(&t)
            if t<r[i] {
                r[i]=t
            }
        }
    }
    t=r[0]
    for i:=0;i<n;i++ {
        if r[i]>t {
            t=r[i]
        }
    }
    fmt.Println(t)
}

package main

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

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

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

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

	var st, av int64
	fmt.Fscanln(in, &st, &av)

	min_arr := make([]int64, st)
	for index, _ := range min_arr {
		min_arr[index] = 1<<40
	}

	for i:=0; int64(i)<st; i++ {
		for j:=0; int64(j)<av; j++ {
			var ij int64
			fmt.Fscan(in, &ij)
			min_arr[i] = Min(min_arr[i], ij)
		}
	}

	var max int64
	max = 0
	for i:=0; int64(i)<st;i++ {
		max = Max(max, min_arr[i])
	}

	fmt.Fprintln(out, max)
	out.Flush()
}

package main

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

//N _
const (
	N = 2*1e5 + 5
)

func inputter(inputReader *bufio.Reader,strs chan *string){
	for {
		input , _ := inputReader.ReadString('\n')
		input = strings.TrimSpace(input)
		if len(input) > 0 {
			inputs := strings.Split(input, " ")
			for i := range inputs{
				strs <- &inputs[i]
			}
		}
	}
}

func min(values []int64) int64{
	mn := values[0]
	for _, v := range values {
			if (v < mn) {
				mn = v
			}
	}
	return mn
}

func main(){
	rs := bufio.NewReader(os.Stdin)
	ws := bufio.NewWriter(os.Stdout)

	strs := make(chan *string, 100)

	go inputter(rs, strs)

	n , _ := strconv.ParseInt(*<-strs, 10, 64)
	m , _ := strconv.ParseInt(*<-strs, 10, 64)

	a := make([]int64, m)

	mx := int64(0)
	for i := int64(0); i < n; i++ {

		for j := int64(0); j < m; j++ {
			x, _ := strconv.ParseInt(*<-strs, 10, 64)
			a[j] = x
		}

		y := min(a)

		if y > mx {
			mx = y
		}
	}

	ws.WriteString(fmt.Sprint(mx))

	ws.Flush()
}

package main

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

//N _
const (
	N = 2*1e5 + 5
)

func inputter(inputReader *bufio.Reader,strs chan *string){
	for {
		input , _ := inputReader.ReadString('\n')
		input = strings.TrimSpace(input)
		if len(input) > 0 {
			inputs := strings.Split(input, " ")
			for i := range inputs{
				strs <- &inputs[i]
			}
		}
	}
}

func min(values []int64) int64{
	mn := values[0]
	for _, v := range values {
			if (v < mn) {
				mn = v
			}
	}
	return mn
}

func main(){
	rs := bufio.NewReader(os.Stdin)
	ws := bufio.NewWriter(os.Stdout)

	strs := make(chan *string, 100)

	go inputter(rs, strs)

	n , _ := strconv.ParseInt(*<-strs, 10, 64)
	m , _ := strconv.ParseInt(*<-strs, 10, 64)

	mx := int64(0)
	for i := int64(0); i < n; i++ {
		a := make([]int64, m)
		for j := int64(0); j < m; j++ {
			x, _ := strconv.ParseInt(*<-strs, 10, 64)
			a[j] = x
		}

		y := min(a)

		if y > mx {
			mx = y
		}
	}

	ws.WriteString(fmt.Sprint(mx))

	ws.Flush()
}

package main

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

//N _
const (
	N = 2*1e5 + 5
)

func inputter(inputReader *bufio.Reader,strs chan *string){
	for {
		input , _ := inputReader.ReadString('\n')
		input = strings.TrimSpace(input)
		if len(input) > 0 {
			inputs := strings.Split(input, " ")
			for i := range inputs{
				strs <- &inputs[i]
			}
		}
	}
}

func min(values []int64, ch chan int64) {
	mn := values[0]
	for _, v := range values {
			if (v < mn) {
				mn = v
			}
	}
	ch <- mn
}

func main(){
	rs := bufio.NewReader(os.Stdin)
	ws := bufio.NewWriter(os.Stdout)

	strs := make(chan *string, 100)

	go inputter(rs, strs)

	n , _ := strconv.ParseInt(*<-strs, 10, 64)
	m , _ := strconv.ParseInt(*<-strs, 10, 64)

	ch := make(chan int64, n)

	for i := int64(0); i < n; i++ {
		a := make([]int64, m)
		for j := int64(0); j < m; j++ {
			x, _ := strconv.ParseInt(*<-strs, 10, 64)
			a[j] = x
		}
		go min(a, ch)
	}

	mx := int64(0)
	for i:=int64(0); i < n; i++{
		x := <-ch
		if x > mx {
			mx = x
		}
	}

	ws.WriteString(fmt.Sprint(mx))
	ws.Flush()
}

package main

import "fmt"

func main() {
	var n, m int
	var ans uint32 = 0
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		var x uint32
		var t uint32 = ^(uint32(0))
		for j := 0; j < m; j++ {
			fmt.Scan(&x)
			if x < t {
				t = x
			}
		}
		if t > ans {
			ans = t
		}
	}
	fmt.Println(ans)
}

package main

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

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

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

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

	var st, av int64
	fmt.Fscanln(in, &st, &av)

	min_arr := make([]int64, av)
	for index, _ := range min_arr {
		min_arr[index] = 1<<40
	}

	for i:=0; int64(i)<st; i++ {
		for j:=0; int64(j)<av; j++ {
			var ij int64
			fmt.Fscan(in, &ij)
			min_arr[j] = Min(min_arr[j], ij)
		}
	}

	var max int64
	max = 0
	for i:=0; int64(i)<av;i++ {
		max = Max(max, min_arr[i])
	}

	fmt.Fprintln(out, max)
	out.Flush()
}


Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows:   if a word was written by one person — that person gets 3 points,  if a word was written by two people — each of the two gets 1 point,  if a word was written by all — nobody gets any points.  In the end, how many points does each player have?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.

For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.

3

1

abc

def

abc

3

orz for qaq

qaq orz for

cod for ces

5

iat roc hem ica lly

bac ter iol ogi sts

bac roc lly iol iat

NoteIn the first test case:   The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point.  The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.

package main

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

func Solve_1722C() {
	var t, n int
	br := bufio.NewReaderSize(os.Stdin, 4)
	bw := bufio.NewWriterSize(os.Stdout, 4)
	fmt.Fscan(br, &t)
	words := make([][]string, 3)
	for i := 0; i < 3; i++ {
		words[i] = make([]string, 1000)
	}
	for t > 0 {
		t--
		fmt.Fscan(br, &n)
		word2cnt := make(map[string]int, 0)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Fscan(br, &words[i][j])
				word2cnt[words[i][j]]++
			}
		}
		score := make([]int, 3)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				switch word2cnt[words[i][j]] {
				case 1:
					{
						score[i] += 3
					}
				case 2:
					{
						score[i] += 1
					}
				}
			}
		}
		fmt.Fprintf(bw, "%d %d %d\n", score[0], score[1], score[2])
	}
	bw.Flush()
}

func main() {
  Solve_1722C()
}

package main

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

func Solve_1722C() {
	var t, n int
	br := bufio.NewReaderSize(os.Stdin, 4)
	bw := bufio.NewWriterSize(os.Stdout, 4)
	defer bw.Flush()
	fmt.Fscan(br, &t)
	words := make([][]string, 3)
	for i := 0; i < 3; i++ {
		words[i] = make([]string, 1000)
	}
	for t > 0 {
		t--
		fmt.Fscan(br, &n)
		word2cnt := make(map[string]int, 0)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Fscan(br, &words[i][j])
				word2cnt[words[i][j]]++
			}
		}
		score := make([]int, 3)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				switch word2cnt[words[i][j]] {
				case 1:
					{
						score[i] += 3
					}
				case 2:
					{
						score[i] += 1
					}
				}
			}
		}
		fmt.Fprintf(bw, "%d %d %d\n", score[0], score[1], score[2])
	}
}

func main() {
  Solve_1722C()
}

package main

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

func Solve_1722C() {
	var t, n int
	br := bufio.NewReader(os.Stdin)
	bw := bufio.NewWriter(os.Stdout)
	defer bw.Flush()
	fmt.Fscan(br, &t)
	words := make([][]string, 3)
	for i := 0; i < 3; i++ {
		words[i] = make([]string, 1000)
	}
	for t > 0 {
		t--
		fmt.Fscan(br, &n)
		word2cnt := make(map[string]int, 0)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Fscan(br, &words[i][j])
				word2cnt[words[i][j]]++
			}
		}
		score := make([]int, 3)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				switch word2cnt[words[i][j]] {
				case 1:
					{
						score[i] += 3
					}
				case 2:
					{
						score[i] += 1
					}
				}
			}
		}
		fmt.Fprintf(bw, "%d %d %d\n", score[0], score[1], score[2])
	}
}

func main() {
  Solve_1722C()
}

package main

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

func Solve_1722C() {
	var t, n int
	br := bufio.NewReader(os.Stdin)
	fmt.Fscan(br, &t)
	words := make([][]string, 3)
	for i := 0; i < 3; i++ {
		words[i] = make([]string, 1000)
	}
	for t > 0 {
		t--
		fmt.Fscan(br, &n)
		word2cnt := make(map[string]int, 0)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Fscan(br, &words[i][j])
				word2cnt[words[i][j]]++
			}
		}
		score := make([]int, 3)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				switch word2cnt[words[i][j]] {
				case 1:
					{
						score[i] += 3
					}
				case 2:
					{
						score[i] += 1
					}
				}
			}
		}
		fmt.Printf("%d %d %d\n", score[0], score[1], score[2])
	}
}

func main() {
  Solve_1722C()
}

package main

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

func main() {
	var T int
	var N int
	var S string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &T)
	for T > 0 {
		fmt.Fscan(in, &N)
		playersWords := make([][]string, 3)
		m := make(map[string]int)
		for i := 0; i < 3; i++ {
			playersWords[i] = make([]string, N)
			for j := 0; j < N; j++ {
				fmt.Fscan(in, &S)
				m[S]++
				playersWords[i][j] = S
			}
		}
		for i := 0; i < 3; i++ {
			resOfPlayer := 0
			for j := 0; j < N; j++ {
				word := playersWords[i][j]
				countOfWords := m[word]
				switch countOfWords {
				case 1:
					resOfPlayer += 3
				case 2:
					resOfPlayer += 1
				case 3:
					resOfPlayer += 0
				}
			}
			fmt.Print(resOfPlayer, " ")
		}
		fmt.Println()
		T--
	}
}

package main

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

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

	var t, n int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var words1, words2, words3 [1005]string
		cnt := make(map[string]int)
		fmt.Fscan(in, &n)
		input := func(ws *[1005]string) {
			for i := 0; i < n; i++ {
				fmt.Fscan(in, &ws[i])
				cnt[ws[i]]++
			}
		}
		output := func(ws [1005]string) {
			res := 0
			for i := 0; i < n; i++ {
				switch cnt[ws[i]] {
				case 1:
					res += 3
				case 2:
					res += 1
				}
			}
			fmt.Fprint(out, res)
		}
		input(&words1)
		input(&words2)
		input(&words3)
		output(words1)
		fmt.Fprint(out, " ")
		output(words2)
		fmt.Fprint(out, " ")
		output(words3)
		fmt.Fprintln(out)
	}
}

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

package main

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

func solve(n int, mat [][]string) (int, int, int) {
	// solution here
	sol := make([]int, 3)

	maps := make(map[string]int)
	for i := 0; i < 3; i++ {
		for j := 0; j < n; j++ {
			maps[mat[i][j]]++
		}
	}

	for i := 0; i < 3; i++ {
		for j := 0; j < n; j++ {
			val, _ := maps[mat[i][j]]
			if val == 2 {
				sol[i] += 1
			} else if val == 1 {
				sol[i] += 3
			}
		}
	}

	return sol[0], sol[1], sol[2]
}

func f(mat [][]string, j, p int) int {
	r := 0
	total := 0
	for i := 0; i < 3; i++ {
		if mat[p][j] == mat[i][j] {
			total++
		}
	}
	if total == 2 {
		r += 1
	} else if total == 1 {
		r += 3
	}
	return r
}

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

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

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

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

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

func (in *CF1722C) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		mat := make([][]string, 3)

		for i := 0; i < 3; i++ {
			mat[i] = make([]string, n)
			for j := 0; j < n; j++ {
				mat[i][j] = in.NextString()
			}
		}

		a, b, c := solve(n, mat)
		fmt.Println(a, b, c)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1722C
Date: 9/3/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1722/C
Problem: CF1722C
**/
func (in *CF1722C) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		mapas := make([]map[string]bool, 3)

		for i := 0; i < 3; i++ {
			mapas[i] = make(map[string]bool)
		}

		sol := make([]int, 3)

		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				str := in.NextString()
				mapas[i][str] = true
			}
		}

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

			for str := range mapas[i] {
				points := 3
				count := 0
				for j := 0; j < 3; j++ {
					if j != i {
						_, e := mapas[j][str]
						if e {
							count++
						}
					}
				}
				if count == 2 {
					points = 0
				} else if count == 1 {
					points = 1
				}
				sol[i] += points
			}
		}

		fmt.Println(sol[0], sol[1], sol[2])

	}
}

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

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

package main

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

type words map[string]struct{}

func (w words) add(word string) {
	w[word] = struct{}{}
}

func (w words) exists(word string) bool {
	_, ok := w[word]
	return ok
}

func getPoint(w string, a, b words) int {
	switch {
	case a.exists(w) && b.exists(w):
		return 0
	case a.exists(w) || b.exists(w):
		return 1
	default:
		return 3
	}
}

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

	for t > 0 {
		t--
		n := readInt(in)
		w1 := make(words, n)
		w2 := make(words, n)
		w3 := make(words, n)
		var p1, p2, p3 int

		for _, v := range readLineNumbs(in) {
			w1.add(v)
		}
		for _, v := range readLineNumbs(in) {
			w2.add(v)
		}
		for _, v := range readLineNumbs(in) {
			w3.add(v)
		}

		for k := range w1 {
			p := getPoint(k, w2, w3)
			p1 += p
		}
		for k := range w2 {
			p := getPoint(k, w1, w3)
			p2 += p
		}
		for k := range w3 {
			p3 += getPoint(k, w1, w2)
		}

		fmt.Printf("%d %d %d\n", p1, p2, p3)
	}
}

// ================================
// NO EDIT

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 readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

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

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

		aa := make([][]string, 3)
		for i := 0; i < 3; i++ {
			aa[i] = make([]string, n)
		}
		mm := make(map[string]int, n*3)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Fscan(in, &aa[i][j])
				mm[aa[i][j]]++
			}
		}

		bb := make([]int, 3)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				if mm[aa[i][j]] == 1 {
					bb[i] += 3
				} else if mm[aa[i][j]] == 2 {
					bb[i] += 1
				}
			}
		}
		fmt.Fprintln(out, bb[0], bb[1], bb[2])
	}
}

package main

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

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

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

		aa := make([][]string, 3)
		for i := 0; i < 3; i++ {
			aa[i] = make([]string, n)
		}
		mm := make(map[string]int, n*3)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[0][i])
			mm[aa[0][i]]++
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[1][i])
			mm[aa[1][i]]++
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[2][i])
			mm[aa[2][i]]++
		}

		var a, b, c int
		for i := 0; i < n; i++ {
			if mm[aa[0][i]] == 1 {
				a += 3
			} else if mm[aa[0][i]] == 2 {
				a += 1
			}
		}
		for i := 0; i < n; i++ {
			if mm[aa[1][i]] == 1 {
				b += 3
			} else if mm[aa[1][i]] == 2 {
				b += 1
			}
		}
		for i := 0; i < n; i++ {
			if mm[aa[2][i]] == 1 {
				c += 3
			} else if mm[aa[2][i]] == 2 {
				c += 1
			}
		}
		fmt.Fprintln(out, a, b, c)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		mapper:= make(map[string]int)
		var list [][]string
		for j:=0;j<3;j++{
			innerlist:= make([]string,n)
			for k:=0;k<n;k++{
				fmt.Fscan(in,&innerlist[k])
				if mapper[string(innerlist[k])] >= 1 {
					mapper[string(innerlist[k])]+=1
					continue
				}
				mapper[string(innerlist[k])] = 1
			}
			list = append(list,innerlist)
		}
		var output []int
		for j:=0;j<3;j++{
			for k:=0;k<n;k++{
				if mapper[string(list[j][k])] == 3 {
					output = append(output, 0)
				} else if mapper[string(list[j][k])] == 2 {
					output = append(output, 1)
				} else if mapper[string(list[j][k])] == 1 {
					output = append(output, 3)
				}
			}
		}
		tally:=0
		for j:=0;j<len(output);j++{
			tally+=output[j]
			if (j+1)%n == 0 {
				fmt.Fprintf(out,"%v ",tally)
				tally=0
			}
		}
		fmt.Fprintln(out,)
	}
}

package main

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

func main() {
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(cin, &n)
		wordOccuranceGlobal := map[string]int{}
		person := map[int]map[string]bool{}
		for j := 0; j < 3; j++ {
			person[j] = make(map[string]bool)
			for k := 0; k < n; k++ {
				var word string
				fmt.Fscan(cin, &word)
				wordOccuranceGlobal[word]++
				person[j][word] = true
			}
		}
		scoreboard := make([]int, 3)
		for j := 0; j < 3; j++ {
			for k, v := range wordOccuranceGlobal {
				if _, ok := person[j][k]; ok {
					switch {
					case v == 1:
						scoreboard[j] += 3
					case v == 2:
						scoreboard[j] += 1
					}
				}
			}
		}

		fmt.Printf("%d %d %d\n", scoreboard[0], scoreboard[1], scoreboard[2])
	}
}

package main

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

func sum(vals ...int) int {
	x := 0
	for _, u := range vals {
		x += u
	}
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	nrTests, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < nrTests; i++ {
		dict := make(map[string][]int)
		for j := 0; j < 4; j++ {
			scanner.Scan()
			if j == 0 {
				continue
			}
			for _, x := range strings.Split(scanner.Text(), " ") {
				if arr, ok := dict[x]; ok {
					arr[j-1] = 1
				} else {
					dict[x] = make([]int, 3)
					dict[x][j-1] = 1
				}
			}
		}
		var points [3]int
		for _, persons := range dict {
			nrPoints := 0
			switch sum(persons...) {
			case 1:
				nrPoints = 3
			case 2:
				nrPoints = 1
			}
			for idx, v := range persons {
				points[idx] += v * nrPoints
			}
		}
		fmt.Println(points[0], points[1], points[2])
	}
}

package main

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

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

func solve(arr map[string][]int) string {
	var p [3]int
	for _, x := range arr {
		l := len(x)
		var q int
		if l == 1 {
			q = 3
		} else if l == 2 {
			q = 1
		}
		for _, y := range x {
			p[y] += q
		}
	}
	return strings.Trim(fmt.Sprint(p), "[]")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		arr := make(map[string][]int)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Fscan(reader, &s)
				arr[s] = append(arr[s], i)
			}
		}
		fmt.Println(solve(arr))
	}
}

package main

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

func main() {
	r := readerStdin()
	cases := readInt(r)

	for cases != 0 {
		_ = readInt(r)

		var allWords = make([][]string, 0, 3)
		for i := 0; i < 3; i++ {
			allWords = append(allWords, readSliceString(r))
		}

		var hash = make(map[string]int)
		for _, words := range allWords {
			for _, word := range words {
				hash[word]++
			}
		}

		var persons [3]int
		for i, words := range allWords {
			for _, word := range words {
				quantity := hash[word]
				switch quantity {
				case 1:
					persons[i] += 3
				case 2:
					persons[i] += 1
				}
			}
		}

		fmt.Printf("%d %d %d\n", persons[0], persons[1], persons[2])
		cases--
	}
}

func readerStdin() *bufio.Reader {
	return bufio.NewReader(os.Stdin)
}

func readString(r *bufio.Reader) (s string) {
	s, _ = r.ReadString('\n')
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return
}

func readInt(r *bufio.Reader) (i int) {
	str := readString(r)
	i, _ = strconv.Atoi(str)
	return
}

func readSliceString(r *bufio.Reader) []string {
	str := readString(r)

	return strings.Split(str, " ")
}

package main

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

type float = float32
type double = float64
type long = int64
type ulong = uint64

type Readable interface {
	bool | int | uint64 | int64 | double | float | byte
}

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

func print(arg ...interface{})            { fmt.Fprint(out, arg...) }
func println(arg ...interface{})          { fmt.Fprintln(out, arg...) }
func printf(f string, arg ...interface{}) { fmt.Fprintf(out, f, arg...) }
func scanf(f string, arg ...interface{})  { fmt.Fscanf(in, f, arg...) }

func readLn() string {
	ln, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}

	return strings.Trim(ln, " \n\r")
}

func readString() string {
	return readLn()
}

func readStrings() []string {
	return strings.Split(readLn(), " ")
}

func read[T Readable](f func(string) (T, error), input ...string) T {
	if len(input) == 0 {
		input = []string{readLn()}
	}

	res, err := f(input[0])
	if err != nil {
		panic(err)
	}

	return res
}

func readMany[T Readable](f func(...string) T) []T {
	input := readStrings()
	arr := make([]T, len(input))
	for i := 0; i < len(arr); i++ {
		arr[i] = f(input[i])
	}

	return arr
}

func readBool(input ...string) bool {
	return read(strconv.ParseBool, input...)
}

func readInt(input ...string) int {
	return read(strconv.Atoi, input...)
}

func readByte(input ...string) byte {
	return byte(read(func(s string) (uint64, error) {
		return strconv.ParseUint(s, 10, 8)
	}, input...))
}

func readDouble(input ...string) double {
	return read(func(s string) (float64, error) {
		return strconv.ParseFloat(s, 64)
	}, input...)
}

func readFloat(input ...string) float {
	return float32(read(func(s string) (float64, error) {
		return strconv.ParseFloat(s, 32)
	}, input...))
}

func readLong(input ...string) long {
	return read(func(s string) (int64, error) {
		return strconv.ParseInt(s, 10, 64)
	}, input...)
}

func readULong(input ...string) ulong {
	return read(func(s string) (uint64, error) {
		return strconv.ParseUint(s, 10, 64)
	}, input...)
}

func readBinary(input ...string) long {
	return read(func(s string) (int64, error) {
		return strconv.ParseInt(s, 2, 64)
	}, input...)
}

func readBools() []bool {
	return readMany(readBool)
}

func readInts() []int {
	return readMany(readInt)
}

func readBytes() []byte {
	return readMany(readByte)
}

func readDoubles() []double {
	return readMany(readDouble)
}

func readFloats() []float {
	return readMany(readFloat)
}

func readLongs() []long {
	return readMany(readLong)
}

func readULongs() []ulong {
	return readMany(readULong)
}

func main() {
	defer out.Flush()

	// solution
	t := readInt()
	ans := make([][3]int, t)
	for i := 0; i < t; i++ {
		n := readInt()
		s1 := readString()
		arr1 := strings.Split(s1, " ")
		s2 := readString()
		arr2 := strings.Split(s2, " ")
		s3 := readString()
		arr3 := strings.Split(s3, " ")
		m1 := make(map[string]struct{}, n)
		m2 := make(map[string]struct{}, n)
		m3 := make(map[string]struct{}, n)
		for j := 0; j < n; j++ {
			m1[arr1[j]] = struct{}{}
			m2[arr2[j]] = struct{}{}
			m3[arr3[j]] = struct{}{}
		}
		c1 := 0
		c2 := 0
		c3 := 0
		for k := range m1 {
			_, ok2 := m2[k]
			_, ok3 := m3[k]
			if ok2 && ok3 {
				continue
			}
			if !ok2 && !ok3 {
				c1 += 3
				continue
			}
			c1 += 1
		}
		for k := range m2 {
			_, ok1 := m1[k]
			_, ok3 := m3[k]
			if ok1 && ok3 {
				continue
			}
			if !ok1 && !ok3 {
				c2 += 3
				continue
			}
			c2 += 1
		}
		for k := range m3 {
			_, ok1 := m1[k]
			_, ok2 := m2[k]
			if ok1 && ok2 {
				continue
			}
			if !ok1 && !ok2 {
				c3 += 3
				continue
			}
			c3 += 1
		}
		ans[i][0] = c1
		ans[i][1] = c2
		ans[i][2] = c3
	}
	for i := 0; i < t; i++ {
		println(ans[i][0], ans[i][1], ans[i][2])
	}
}

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

	return x
}

func max(x, y long) long {
	if x > y {
		return x
	}

	return y
}

func min(x, y long) long {
	if x > y {
		return y
	}

	return x
}

package main

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

var (
	in    *bufio.Reader = bufio.NewReader(os.Stdin)
	t, n  int
	s     [3][2000]string
	mp    map[string]int
	score map[int]int = map[int]int{
		1: 3,
		2: 3,
		4: 3,
		3: 1,
		5: 1,
		6: 1,
		7: 0,
	}
)

func main() {
	fmt.Fscan(in, &t)
	for t > 0 {
		fmt.Fscan(in, &n)
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Fscan(in, &s[i][j])
			}
		}
		solve()
		t--
	}
}

func solve() {
	mp = map[string]int{}
	for i := 0; i < 3; i++ {
		for j := 0; j < n; j++ {
			mp[s[i][j]] = mp[s[i][j]] | (1 << i)
		}
	}
	var buf bytes.Buffer
	for i := 0; i < 3; i++ {
		ans := 0
		for j := 0; j < n; j++ {
			ans += score[mp[s[i][j]]]
		}
		buf.WriteString(strconv.Itoa(ans))
		if i != 2 {
			buf.WriteByte(' ')
		}
	}
	fmt.Println(buf.String())
}

package main

import (
	"fmt"
)

type words map[string]struct{}

func (w words) add(word string) {
	w[word] = struct{}{}
}

func (w words) exists(word string) bool {
	_, ok := w[word]
	return ok
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	var getPoint = func(w string, a, b words) int {
		switch {
		case a.exists(w) && b.exists(w):
			return 0
		case a.exists(w) || b.exists(w):
			return 1
		default:
			return 3
		}
	}
	for t > 0 {
		t--
		var n int
		fmt.Scanf("%d\n", &n)
		w1 := make(words, n)
		w2 := make(words, n)
		w3 := make(words, n)
		var p1, p2, p3 int
		for i := 0; i < n; i++ {
			var tmp string
			fmt.Scanf("%s", &tmp)
			w1.add(tmp)
		}
		for i := 0; i < n; i++ {
			var tmp string
			fmt.Scanf("%s", &tmp)
			w2.add(tmp)
		}
		for i := 0; i < n; i++ {
			var tmp string
			fmt.Scanf("%s", &tmp)
			w3.add(tmp)
		}

		for k := range w1 {
			p := getPoint(k, w2, w3)
			p1 += p
		}
		for k := range w2 {
			p := getPoint(k, w1, w3)
			p2 += p
		}
		for k := range w3 {
			p3 += getPoint(k, w1, w2)
		}

		fmt.Printf("%d %d %d\n", p1, p2, p3)
	}
}


Not so long ago, Vlad had a birthday, for which he was presented with a package of candies. There were $$$n$$$ types of candies, there are $$$a_i$$$ candies of the type $$$i$$$ ($$$1 \le i \le n$$$).Vlad decided to eat exactly one candy every time, choosing any of the candies of a type that is currently the most frequent (if there are several such types, he can choose any of them). To get the maximum pleasure from eating, Vlad does not want to eat two candies of the same type in a row.Help him figure out if he can eat all the candies without eating two identical candies in a row.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of input test cases. The following is a description of $$$t$$$ test cases of input, two lines for each. The first line of the case contains the single number $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of types of candies in the package. The second line of the case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the number of candies of the type $$$i$$$. It is guaranteed that the sum of $$$n$$$ for all cases does not exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case of input. As an answer, output "YES" if Vlad can eat candy as planned, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first example, it is necessary to eat sweets in this order: a candy of the type $$$2$$$, it is the most frequent, now $$$a = [2, 2]$$$; a candy of the type $$$1$$$, there are the same number of candies of the type $$$2$$$, but we just ate one, now $$$a = [1, 2]$$$; a candy of the type $$$2$$$, it is the most frequent, now $$$a = [1, 1]$$$; a candy of the type $$$1$$$, now $$$a = [0, 1]$$$; a candy of the type $$$2$$$, now $$$a = [0, 0]$$$ and the candy has run out.In the second example, all the candies are of the same type and it is impossible to eat them without eating two identical ones in a row.In the third example, first of all, a candy of the type $$$2$$$ will be eaten, after which this kind will remain the only kind that is the most frequent, and you will have to eat a candy of the type $$$2$$$ again.

package main

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

var in = bufio.NewReader(os.Stdin)

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

func Calculation() string {
	var cnt int
	Scan(&cnt)
	data := make([]int, cnt)
	for idx := 0; idx < cnt; idx++ {
		Scan(&data[idx])
	}
	if cnt == 1 && data[0] == 1 {
		return "YES"
	}
	if cnt == 1 {
		return "NO"
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i] > data[j]
	})
	if data[0]-data[1] > 1 {
		return "NO"
	}
	return "YES"
}

func Scan(a interface{}) {
	fmt.Fscan(in, a)
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for idx := 0; idx < t; idx++ {
		fmt.Println(Calculation())
	}
}

func Calculation() string {
	var cnt int
	Scan(&cnt)
	data := make([]int, cnt)
	for idx := 0; idx < cnt; idx++ {
		Scan(&data[idx])
	}
	if cnt == 1 && data[0] == 1 {
		return "YES"
	}
	if cnt == 1 {
		return "NO"
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i] > data[j]
	})
	if data[0]-data[1] > 1 {
		return "NO"
	}
	return "YES"
}

func Scan(a interface{}) {
	fmt.Fscan(in, a)
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for idx := 0; idx < t; idx++ {
		fmt.Println(Calculation())
	}
}

func Calculation() string {
	var cnt int
	fmt.Fscan(in, &cnt)
	data := make([]int, cnt)
	for idx := 0; idx < cnt; idx++ {
		fmt.Fscan(in, &data[idx])
	}
	if cnt == 1 && data[0] == 1 {
		return "YES"
	}
	if cnt == 1 {
		return "NO"
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i] > data[j]
	})
	if data[0] - data[1] > 1 {
		return "NO"
	}
	return "YES"
}

package main

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

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

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

	defer out.Flush()

	var t, typeNum, element int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &typeNum)
		max1, max2 := 0, 0
		for i := 0; i < typeNum; i++ {
			fmt.Fscan(in, &element)
			if max1 < element {
				max1, max2 = element, max1
			} else if max2 < element {
				max2 = element
			}
		}
		if max1-max2 >= 2 {
			fmt.Fprintln(out, "no")
		} else {
			fmt.Fprintln(out, "yes")
		}
	}
}

package main

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

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

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

	defer out.Flush()

	var t, typeNum, element int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &typeNum)
		arr := make([]int, typeNum)
		for i := 0; i < typeNum; i++ {
			fmt.Fscan(in, &element)
			arr[i] = element
		}
		if process(arr) {
			fmt.Fprintln(out, "yes")
		} else {
			fmt.Fprintln(out, "no")
		}
	}
}

func process(arr []int) bool {
	if len(arr) == 0 {
		return true
	} else if len(arr) == 1 {
		if arr[0] <= 1 {
			return true
		} else {
			return false
		}
	}
	sort.Ints(arr)
	return arr[len(arr)-1]-arr[len(arr)-2] <= 1
}

package main

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

var in = bufio.NewReader(os.Stdin)

func solve(){
	var n int
	fmt.Fscan(in, &n)
    v:=make([]int,n)

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

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

	// fmt.Println(v)
	if n==1{
		if v[0]<2{
			fmt.Println("YES")
		} else{
			fmt.Println("NO")
		}
		return
	}

	if v[0]<=v[1]+1{
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}
func main() {
	var tc int
    fmt.Scan(&tc)
	// fmt.Print(tc)
	for i:=0;i<tc;i++{
		solve()
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func solve(){
	var n int
	fmt.Fscan(in, &n)
    v:=make([]int,n)

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

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

	// fmt.Println(v)
	if n==1{
		if v[0]<2{
			fmt.Println("YES")
		} else{
			fmt.Println("NO")
		}
		return
	}

	if v[0]<=v[1]+1{
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}
func main() {
	var tc int
    fmt.Fscan(in,&tc)
	// fmt.Print(tc)
	for i:=0;i<tc;i++{
		solve()
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1660B
Date: 3/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1660/B
Problem: CF1660B
**/
func (in *CF1660B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			sum += int64(arr[i])
		}

		ans := false
		if n == 1 {
			if sum == 1 {
				ans = true
			}
		} else {
			sort.Ints(arr)
			ws := true
			if arr[n-1]-arr[n-2] > 1 {
				ws = false
			}

			ans = ws
		}

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

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

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

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for i := read(); i > 0; i-- {
		n := read()
		max1, max2 := 0, 0
		for i := 1; i <= n; i++ {
			if tmp := read(); max1 <= tmp {
				max1, max2 = tmp, max1
			} else if tmp > max2 {
				max2 = tmp
			}
		}
		if max1-max2 >= 2 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		if n == 1 {
			var x int
			fmt.Fscan(in,&x)
			if x > 1 {
				fmt.Fprintln(out,"NO")
				continue
			} else {
				fmt.Fprintln(out,"YES")
				continue
			}
		}
		largest:=0
		second_largest:=0
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x >= largest {
				second_largest= largest
				largest = x
			} else if x > second_largest  {
				second_largest= x
			}
		}
		if largest - second_largest > 1 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out,"YES")
		}
	}
}

package main

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

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

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

package main

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

const (
	MaxInt32 = 1 << 31 - 1
)

func main(){
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for t > 0 {
		var n int
		fmt.Fscan(cin, &n)
		candies := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(cin, &candies[i])
		}
		sort.Slice(candies, func(i, j int) bool {
			return candies[i] < candies[j]
		})
		if n == 1 {
			if candies[0] > 1 {
				fmt.Println("NO")
			}else {
				fmt.Println("YES")
			}
		}else if candies[n-1] - candies[n-2] > 1 {
			fmt.Println("NO")
		}else {
			fmt.Println("YES")
		}

		 t -= 1
	}
}

package main

// Problem description URL https://atcoder.jp/contests/abc236/tasks/abc240_a

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"sort"
)

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

func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

type pair struct {
	Color int
	Size  int
}

var (
	n   = 0
	t   = 0
	a []int
	res []int
	s   *list.List
	cur = 0
)

func solve() {
	scan(&t)
	for t != 0 {
		t--
		scan(&n)
		if n == 1 {
			x := 0
			scan(&x)
			if x >= 2 {
				printf("no\n")
			}else {
				printf("yes\n")
			}
			continue
		}
		ar := make([]int, n)

		sum := 0
		for i:=0;i<n;i++{
			scan(&ar[i])
			sum += ar[i]
		}
		sort.Slice(ar, func(i, j int) bool {
			return ar[i] > ar[j]
		})

		if ar[0]-ar[1] >= 2 {
			printf("no\n")
		}else {
			printf("yes\n")
		}
	}
}

func main() {
	defer out.Flush()
	solve()
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if a[n]-a[n-1] > 1 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

package main

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

const mod = 998244353
const mx = 3000

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in,&n)
	arr := make([]int,n)
	for i := 0;i < n;i++{
		fmt.Fscan(in,&arr[i])
	}
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
	if n == 1{
		if arr[0] != 1{
			fmt.Fprintln(out,"No")
		}else{
			fmt.Fprintln(out,"Yes")
		}
		return
	}
	b := arr[n - 1] - arr[n - 2] <= 1
	if b{
		fmt.Fprintln(out,"Yes")
	}else{
		fmt.Fprintln(out,"No")
	}
}

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

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

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

package main

import (
  "bufio"
  "fmt"
  "os"
  "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...) }

func main() {
  defer writer.Flush()
  var t int
  for scanf("%d\n", &t) ; t > 0 ; t-- {
    var n int
    scanf("%d\n", &n)
    a := make([]int, n)
    for i := 0 ; i < n ; i++ {
      var v int
      scanf("%d", &v)
      a[i] = v
    }
    scanf("\n")
    sort.SliceStable(a, func(i, j int) bool { return a[i] > a[j]})
    if (n == 1 && a[0] > 1) || (n >= 2 && a[0] > a[1] + 1) {
      printf("NO\n")
    } else {
      printf("YES\n")
    }
  }
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int

	Fscan(in, &t)

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

		max := int64(0)
		second := int64(0)

		Fscan(in, &n)

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

			if x > second {
				second = x
			}

			if second > max {
				max, second = second, max
			}
		}
		if max > second+1 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}

}

package main

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

/*
5
4
3 3 5 5
3
1 2 4
4
1 1 3 4
5
1 4 5 6 7
3
1 7 8
---
YES
NO
YES
YES
YES
======

*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	if n == 1 && a[0] > 1 || n > 1 && a[n-1]-a[n-2] > 1 {
		fmt.Fprintln(writer, "NO")
	} else {
		fmt.Fprintln(writer, "YES")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for t := t; t > 0; t-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		mx := 0
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
			if a[i] > mx {
				mx = a[i]
			}
		}
		fmt.Fscanf(in, "\n")
		cnt := 0
		mx1 := 0
		for i := 0; i < n; i++ {
			if a[i] != mx {
				if a[i] > mx1 {
					mx1 = a[i]
				}
			} else {
				cnt++
			}
		}
		if (cnt == 1 && mx-mx1 > 1) || (n < 2 && mx > 1) {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}

	}
}

package main

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

func main() {
	in,out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t:=0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums:= make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		sort.Ints(nums)
		if len(nums)==1{
			if nums[0] >1{
				fmt.Fprintln(out, "NO")
			}else {
				fmt.Fprintln(out, "YES")
			}
		}else {
			if nums[len(nums)-1]-nums[len(nums)-2]>1{
				fmt.Fprintln(out, "NO")
			}else {
				fmt.Fprintln(out, "YES")
			}

		}
	}
}

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

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n := cin.NextInt()
	a := cin.NextInts(n)
	if n == 1 {
		if a[0] >= 2 {
			cout.Println("NO")
		} else {
			cout.Println("yEs")
		}
		return
	}
	sort.Ints(a)
	if a[n-2] == a[n-1] || a[n-2]+1 == a[n-1] {
		cout.Println("YeS")
	} else {
		cout.Println("nO")
	}
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

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

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

		var a, b int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v > a {
				a, b = v, a
			} else if v > b {
				b = v
			}
		}

		if a-b <= 1 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

func Calculation() string {
	var cnt int
	Scan(&cnt)
	data := make([]int, cnt)
	for idx := 0; idx < cnt; idx++ {
		Scan(&data[idx])
	}
	if cnt == 1 && data[0] == 1 {
		return "YES"
	}
	if cnt == 1 {
		return "NO"
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i] > data[j]
	})
	if data[0]-data[1] > 1 {
		return "NO"
	}
	return "YES"
}

func Scan(a interface{}) {
	fmt.Fscan(bufio.NewReader(os.Stdin), &a)
}

func Scanln(a interface{}) {
	fmt.Fscanln(bufio.NewReader(os.Stdin), &a)
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for idx := 0; idx < t; idx++ {
		fmt.Println(Calculation())
	}
}

func Calculation() string {
	var cnt int
	fmt.Fscan(in, &cnt)
	data := make([]int, cnt)
	for idx := 0; idx < cnt; idx++ {
		fmt.Fscan(in, &data[idx])
	}
	if cnt == 1 && data[0] != 1 {
		return "NO"
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i] > data[j]
	})
	currCnt := data[0]
	for idx := 0; idx < cnt; idx++ {
		if currCnt == data[idx] {
			continue
		}
		if currCnt == data[idx]+1 {
			if idx+1 == cnt {
				return "YES"
			}
			currCnt = data[idx+1]
			continue
		}
		return "NO"
	}
	return "YES"
}

package main

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

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

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

	defer out.Flush()

	var t, typeNum, element int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &typeNum)
		arr := make([]int, typeNum)
		for i := 0; i < typeNum; i++ {
			fmt.Fscan(in, &element)
			arr[i] = element
		}
		if process(arr) {
			fmt.Fprintln(out, "yes")
		} else {
			fmt.Fprintln(out, "no")
		}
	}
}

func process(arr []int) bool {
	if len(arr) == 0 {
		return false
	} else if len(arr) == 1 {
		if arr[0] <= 1 {
			return true
		} else {
			return false
		}
	}
	var a, b int
	if arr[0] > arr[1] {
		a, b = arr[0], arr[1]
	} else {
		a, b = arr[1], arr[0]
	}
	for i:=2;i<len(arr);i++{
		if arr[i]>a{
			a = arr[i]
		} else if arr[i]>b{
			b = arr[i]
		}
	}
	return a-b <= 1
}

package main

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

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

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

	defer out.Flush()

	var t, typeNum, element int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &typeNum)
		arr := make([]int, typeNum)
		for i := 0; i < typeNum; i++ {
			fmt.Fscan(in, &element)
			arr[i] = element
		}
		if process(arr) {
			fmt.Fprintln(out, "yes")
		} else {
			fmt.Fprintln(out, "no")
		}
	}
}

func process(arr []int) bool {
	if len(arr) == 0 {
		return false
	} else if len(arr) == 1 {
		if arr[0] <= 1{
			return true
		} else {
			return false
		}
	}
	a, b := arr[0], arr[0]
	for _, v := range arr {
		if v > a {
			a = v
		} else if v > b {
			b = v
		}
	}
	return a-b <= 1
}

package main

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

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

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

	defer out.Flush()

	var t, typeNum, element int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &typeNum)
		arr := make([]int, typeNum)
		for i := 0; i < typeNum; i++ {
			fmt.Fscan(in, &element)
			arr[i] = element
		}
		if process(arr) {
			fmt.Fprintln(out, "yes")
		} else {
			fmt.Fprintln(out, "no")
		}
	}
}

func process(arr []int) bool {
	if len(arr) == 0 {
		return false
	} else if len(arr) == 1 {
		return true
	}
	a, b := arr[0], arr[0]
	for _, v := range arr {
		if v > a {
			a = v
		} else if v > b {
			b = v
		}
	}
	return a-b <= 1
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1660B
Date: 3/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1660/B
Problem: CF1660B
**/
func (in *CF1660B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			sum += int64(arr[i])
		}

		ans := false
		if n == 1 {
			if sum == 1 {
				ans = true
			}
		} else {
			sort.Ints(arr)
			ws := true

			diff := -1
			for i := n - 2; i >= 0; i-- {
				if arr[i+1]-arr[i] > 1 {
					if diff == arr[i] {
						continue
					}
					ws = false
					break
				}
				diff = arr[i+1] - arr[i]
			}

			ans = ws
		}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1660B
Date: 3/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1660/B
Problem: CF1660B
**/
func (in *CF1660B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			sum += int64(arr[i])
		}

		ans := false
		if n == 1 {
			if sum == 1 {
				ans = true
			}
		} else {
			sort.Ints(arr)
			ws := true

			diff := -1
			for i := n - 2; i >= 0; i-- {
				if arr[i+1]-arr[i] > 1 {
					if diff == 1 && arr[i]==1 {
						continue
					}
					ws = false
					break
				}
				diff = arr[i+1] - arr[i]
			}

			ans = ws
		}

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1660B
Date: 3/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1660/B
Problem: CF1660B
**/
func (in *CF1660B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			sum += int64(arr[i])
		}

		ans := false
		if n == 1 {
			if sum == 1 {
				ans = true
			}
		} else {
			sort.Ints(arr)
			ws := true
			for i := n - 2; i >= 0; i-- {
				if arr[i+1]-arr[i] > 1 && arr[i] > 1 {
					ws = false
					break
				}
			}

			ans = ws
		}

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

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

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

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for i := read(); i > 0; i-- {
		n := read()
		if n == 1 {
			if read() != 1 {
				Fprintln(out, "NO")
			} else {
				Fprintln(out, "YES")
			}
			continue
		}
		res := read()
		for j := n - 1; j > 0; j-- {
			res = abs(res - read())
		}
		if res == 0 || res == 1 {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	for i := read(); i >= 0; i-- {
	    n := read()
	    if n == 1 {
	        Fprintln(out, "NO")
	        continue
	    }
	    res := read()
	    for j := n; j > 0; j-- {
	        res = abs(res - read())
	    }
	    if res == 0 || res == 1 {
	        Fprintln(out, "YES")
	    } else {
	        Fprintln(out, "NO")
	    }
	}
}

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


Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria.Initially, on day $$$1$$$, there is one bacterium with mass $$$1$$$.Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass $$$m$$$ splits, it becomes two bacteria of mass $$$\frac{m}{2}$$$ each. For example, a bacterium of mass $$$3$$$ can split into two bacteria of mass $$$1.5$$$.Also, every night, the mass of every bacteria will increase by one.Phoenix is wondering if it is possible for the total mass of all the bacteria to be exactly $$$n$$$. If it is possible, he is interested in the way to obtain that mass using the minimum possible number of nights. Help him become the best scientist!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 10^9$$$) — the sum of bacteria masses that Phoenix is interested in.

For each test case, if there is no way for the bacteria to exactly achieve total mass $$$n$$$, print -1. Otherwise, print two lines. The first line should contain an integer $$$d$$$  — the minimum number of nights needed. The next line should contain $$$d$$$ integers, with the $$$i$$$-th integer representing the number of bacteria that should split on the $$$i$$$-th day. If there are multiple solutions, print any.

NoteIn the first test case, the following process results in bacteria with total mass $$$9$$$:   Day $$$1$$$: The bacterium with mass $$$1$$$ splits. There are now two bacteria with mass $$$0.5$$$ each.  Night $$$1$$$: All bacteria's mass increases by one. There are now two bacteria with mass $$$1.5$$$.  Day $$$2$$$: None split.  Night $$$2$$$: There are now two bacteria with mass $$$2.5$$$.  Day $$$3$$$: Both bacteria split. There are now four bacteria with mass $$$1.25$$$.  Night $$$3$$$: There are now four bacteria with mass $$$2.25$$$.  The total mass is $$$2.25+2.25+2.25+2.25=9$$$. It can be proved that $$$3$$$ is the minimum number of nights needed. There are also other ways to obtain total mass 9 in 3 nights.$$$ $$$In the second test case, the following process results in bacteria with total mass $$$11$$$:   Day $$$1$$$: The bacterium with mass $$$1$$$ splits. There are now two bacteria with mass $$$0.5$$$.  Night $$$1$$$: There are now two bacteria with mass $$$1.5$$$.  Day $$$2$$$: One bacterium splits. There are now three bacteria with masses $$$0.75$$$, $$$0.75$$$, and $$$1.5$$$.  Night $$$2$$$: There are now three bacteria with masses $$$1.75$$$, $$$1.75$$$, and $$$2.5$$$.  Day $$$3$$$: The bacteria with mass $$$1.75$$$ and the bacteria with mass $$$2.5$$$ split. There are now five bacteria with masses $$$0.875$$$, $$$0.875$$$, $$$1.25$$$, $$$1.25$$$, and $$$1.75$$$.  Night $$$3$$$: There are now five bacteria with masses $$$1.875$$$, $$$1.875$$$, $$$2.25$$$, $$$2.25$$$, and $$$2.75$$$.  The total mass is $$$1.875+1.875+2.25+2.25+2.75=11$$$. It can be proved that $$$3$$$ is the minimum number of nights needed. There are also other ways to obtain total mass 11 in 3 nights.$$$ $$$In the third test case, the bacterium does not split on day $$$1$$$, and then grows to mass $$$2$$$ during night $$$1$$$.

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		ans := []int{}
		for i := 1; i <= n; i <<= 1 {
			ans = append(ans, i)
			n -= i
		}
		if n > 0 {
			ans = append(ans, n)
		}
		sort.Ints(ans)
		for i := len(ans) - 1; i > 0; i-- {
			ans[i] -= ans[i-1]
		}
		Fprintln(out, len(ans)-1)
		for _, v := range ans[1:] {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		ans := []int{}
		for i := 0; 1<<i <= n; i++ {
			ans = append(ans, 1<<i)
			n -= 1 << i
		}
		if n > 0 {
			ans = append(ans, n)
		}
		sort.Ints(ans)
		for i := len(ans) - 1; i > 0; i-- {
			ans[i] -= ans[i-1]
		}
		Fprintln(out, len(ans)-1)
		for _, v := range ans[1:] {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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


There is a grid, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered from $$$1$$$ to $$$n$$$ from bottom to top. The columns are numbered from $$$1$$$ to $$$m$$$ from left to right. The $$$i$$$-th column has the bottom $$$a_i$$$ cells blocked (the cells in rows $$$1, 2, \dots, a_i$$$), the remaining $$$n - a_i$$$ cells are unblocked.A robot is travelling across this grid. You can send it commands — move up, right, down or left. If a robot attempts to move into a blocked cell or outside the grid, it explodes.However, the robot is broken — it executes each received command $$$k$$$ times. So if you tell it to move up, for example, it will move up $$$k$$$ times ($$$k$$$ cells). You can't send it commands while the robot executes the current one.You are asked $$$q$$$ queries about the robot. Each query has a start cell, a finish cell and a value $$$k$$$. Can you send the robot an arbitrary number of commands (possibly, zero) so that it reaches the finish cell from the start cell, given that it executes each command $$$k$$$ times?The robot must stop in the finish cell. If it visits the finish cell while still executing commands, it doesn't count.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^9$$$; $$$1 \le m \le 2 \cdot 10^5$$$) — the number of rows and columns of the grid. The second line contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$0 \le a_i \le n$$$) — the number of blocked cells on the bottom of the $$$i$$$-th column. The third line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines contain five integers $$$x_s, y_s, x_f, y_f$$$ and $$$k$$$ ($$$a[y_s] < x_s \le n$$$; $$$1 \le y_s \le m$$$; $$$a[y_f] < x_f \le n$$$; $$$1 \le y_f \le m$$$; $$$1 \le k \le 10^9$$$) — the row and the column of the start cell, the row and the column of the finish cell and the number of times each your command is executed. The start and the finish cell of each query are unblocked.

For each query, print "YES" if you can send the robot an arbitrary number of commands (possibly, zero) so that it reaches the finish cell from the start cell, given that it executes each command $$$k$$$ times. Otherwise, print "NO".

package main

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

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

func main() {
	defer ww.Flush()
	var n, m int
	fmt.Fscan(rr, &n, &m)
	nums := make([]int, m)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
	}
	st := newLazySegmentTree(nums)
	var q int
	fmt.Fscan(rr, &q)
	outer:
	for qq:=0;qq<q;qq++ {
		var xs, ys, xf, yf, k int
		fmt.Fscan(rr, &xs, &ys, &xf, &yf, &k)
		if abs(ys - yf) % k != 0 || abs(xs - xf) %k != 0 {
			fmt.Fprintln(ww, "NO")
			continue outer
		}
		high := xs + (n - xs) / k * k
		if st.query(1, min(ys, yf), max(ys, yf)) >= high {
			fmt.Fprintln(ww, "NO")
		} else {
			fmt.Fprintln(ww, "YES")
		}
	}
}

type lazyST []struct {
	l, r int
	todo int
	lazy bool // 支持区间修改为某一个值
	sum  int // 根据需要修改
}

// 线段树定义的操作，可修改
func (lazyST) op(a, b int) int {
	return max(a, b)
}

// 根据子节点修改节点
func (t lazyST) maintain(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].sum = t.op(lo.sum, ro.sum)
}

// 根据数组构建线段树，下标从 1 开始
func (t lazyST) build(a []int, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t[o].sum = a[l-1]
		return
	}
	m := (l + r) >> 1
	t.build(a, o<<1, l, m)
	t.build(a, o<<1|1, m+1, r)
	t.maintain(o)
}

// 对节点 o 表示的区间的所有元素加上 add
// 如果要实现区间修改为某一个值而不是加上某一个值的话，将 += 变为 = 即可
func (t lazyST) do(o int, add int) {
	to := &t[o]
	to.todo += add                     // % mod
	to.lazy = true
	to.sum += add // % mod
}

// 懒标记下放
func (t lazyST) spread(o int) {
	if t[o].lazy {
		add := t[o].todo
		t.do(o<<1, add)
		t.do(o<<1|1, add)
		t[o].todo = 0
		t[o].lazy = false
	}
}

// 对 o 表示的区间中属于 [l, r] 的元素进行修改
func (t lazyST) update(o, l, r int, add int) {
	if l <= t[o].l && t[o].r <= r {
		// 是 [l, r] 的子集，全部修改
		t.do(o, add)
		return
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if l <= m {
		t.update(o<<1, l, r, add)
	}
	if m < r {
		t.update(o<<1|1, l, r, add)
	}
	t.maintain(o)
}

// o=1  [l,r] 1<=l<=r<=n
func (t lazyST) query(o, l, r int) int {
	if l <= t[o].l && t[o].r <= r {
		return t[o].sum
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	vl := t.query(o<<1, l, r)
	vr := t.query(o<<1|1, l, r)
	return t.op(vl, vr)
}

func (t lazyST) queryAll() int { return t[1].sum }

// a 从 0 开始
func newLazySegmentTree(a []int) lazyST {
	t := make(lazyST, 4*len(a))
	t.build(a, 1, 1, len(a))
	return t
}

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

package main

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

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

	n, m := readTwoNums(reader)

	A := readNNums(reader, m)

	q := readNum(reader)

	Q := make([][]int, q)
	for i := 0; i < q; i++ {
		Q[i] = readNNums(reader, 5)
	}

	res := solve(n, m, A, Q)

	var buf bytes.Buffer

	for i := 0; i < q; i++ {
		if res[i] {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(height int, m int, A []int, Q [][]int) []bool {

	arr := make([]int, 2*m)
	copy(arr[m:], A)

	for i := m - 1; i > 0; i-- {
		arr[i] = max(arr[2*i], arr[2*i+1])
	}

	get := func(l int, r int) int {
		var res int
		l += m
		r += m

		for l < r {
			if l&1 == 1 {
				res = max(res, arr[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	check := func(a, b []int, k int) bool {
		y1, x1 := a[0], a[1]
		x1--
		y2, x2 := b[0], b[1]
		x2--
		if x1%k != x2%k || y1%k != y2%k {
			return false
		}
		h := get(min(x1, x2), max(x1, x2)+1)

		// h >= min(y1, y2)
		y := max(y1, y2)
		// y + k * cnt <= height
		cnt := (height - y) / k
		y += cnt * k
		return y > h
	}

	ans := make([]bool, len(Q))

	for i, cur := range Q {
		ans[i] = check(cur[:2], cur[2:4], cur[4])
	}

	return ans
}

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var a [200005]int
type Node struct{
	v int
	l int
	r int
	left *Node
	right *Node
}
func max(x,y int)int{
	if x>y{
		return x
	}
	return y
}
func abs(x int)int{
	if x<0{
		return -x
	}
	return x
}
func build(x *Node, l, r int){
	x.l = l
	x.r = r
	mid := (l+r)>>1
	if l == r{
		x.v=a[mid]
		return
	}
	x.left = &Node{}
	x.right = &Node{}
	build(x.left,l,mid)
	build(x.right,mid+1,r)
	x.v = max(x.left.v,x.right.v)
}
func getMax(x *Node, l, r int) int{
	if(l<=x.l&&r>=x.r){
		return x.v
	}
	if r<x.l||l>x.r{
		return -1
	}
	lv := getMax(x.left,l,r)
	rv := getMax(x.right,l,r)
	return max(lv,rv)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, m int
	fmt.Fscan(in,&n,&m)
	for i:=1;i<=m;i++{
		fmt.Fscan(in,&a[i])
	}
	root := &Node{}
	build(root,1,m)
	var q int
	fmt.Fscan(in,&q)
	for i:=1;i<=q;i++{
		var x1,y1,x2,y2,k int
		fmt.Fscan(in,&x1,&y1,&x2,&y2,&k)
		yota := (n-x1)/k
		h := x1 + yota * k
		if abs(h-x2)%k!=0 || abs(y1-y2)%k!=0{
			fmt.Fprintln(out,"NO")
			continue
		}
		if y1==y2{
			fmt.Fprintln(out,"YES")
			continue
		}
		if y1>y2{
			tmp := y1
			y1 = y2
			y2 = tmp
		}
		if getMax(root,y1,y2) >= h{
			fmt.Fprintln(out,"NO")
		}else{
			fmt.Fprintln(out,"YES")
		}
	}
}

package main

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

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

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

func rw(in io.Reader, out io.Writer) {
	var t int = 1
	// fmt.Fscan(in, &t)
	for ti := 0; ti < t; ti++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		b := make([]int, m)
		for i := range b {
			fmt.Fscan(in, &b[i])
		}
		var q int
		fmt.Fscan(in, &q)
		c := make([][5]int, q)
		for i := range c {
			fmt.Fscan(in, &c[i][0], &c[i][1], &c[i][2], &c[i][3], &c[i][4])
		}
		w1 := do(n, m, b, q, c)
		for _, v := range w1 {
			fmt.Fprintln(out, v)
		}
	}
}

func do(n, m int, b []int, q int, c [][5]int) []string {
	t := build(1, m, b)
	do1 := func(x1, y1, x2, y2, k int) string {
		// log.Print(x1, y1, x2, y2, k)
		if y1 > y2 {
			x1, y1, x2, y2 = x2, y2, x1, y1
		}
		x1 += (n - x1) / k * k
		x2 += (n - x2) / k * k
		// log.Print(x1, x2)
		if (y2-y1)%k != 0 || x1 != x2 {
			return "NO"
		}
		v := query(t, y1, y2)
		// log.Print(v)
		if x1 <= v {
			return "NO"
		}
		return "YES"
	}
	ans := make([]string, q)
	for i, c := range c {
		ans[i] = do1(c[0], c[1], c[2], c[3], c[4])
	}
	return ans
}

type node struct {
	l, r   int
	ln, rn *node
	v      int
}

func build(l, r int, b []int) *node {
	n := &node{}
	n.l = l
	n.r = r
	if l == r {
		n.v = b[l-1]
		return n
	}
	m := (l + r) / 2
	n.ln = build(l, m, b)
	n.rn = build(m+1, r, b)
	n.v = n.ln.v
	if n.v < n.rn.v {
		n.v = n.rn.v
	}
	return n
}

func query(n *node, l, r int) int {
	if l <= n.l && n.r <= r {
		return n.v
	}
	m := (n.l + n.r) / 2
	if r <= m {
		return query(n.ln, l, r)
	} else if l >= m+1 {
		return query(n.rn, l, r)
	} else {
		lv := query(n.ln, l, m)
		rv := query(n.rn, m+1, r)
		if lv > rv {
			return lv
		}
		return rv
	}
}


You are given an undirected unweighted graph consisting of $$$n$$$ vertices and $$$m$$$ edges.You have to write a number on each vertex of the graph. Each number should be $$$1$$$, $$$2$$$ or $$$3$$$. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd.Calculate the number of possible ways to write numbers $$$1$$$, $$$2$$$ and $$$3$$$ on vertices so the graph becomes beautiful. Since this number may be large, print it modulo $$$998244353$$$.Note that you have to write exactly one number on each vertex.The graph does not have any self-loops or multiple edges.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^5$$$) — the number of tests in the input. The first line of each test contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 3 \cdot 10^5, 0 \le m \le 3 \cdot 10^5$$$) — the number of vertices and the number of edges, respectively. Next $$$m$$$ lines describe edges: $$$i$$$-th line contains two integers $$$u_i$$$, $$$ v_i$$$ ($$$1 \le u_i, v_i \le n; u_i \neq v_i$$$) — indices of vertices connected by $$$i$$$-th edge. It is guaranteed that $$$\sum\limits_{i=1}^{t} n \le 3 \cdot 10^5$$$ and $$$\sum\limits_{i=1}^{t} m \le 3 \cdot 10^5$$$.

For each test print one line, containing one integer — the number of possible ways to write numbers $$$1$$$, $$$2$$$, $$$3$$$ on the vertices of given graph so it becomes beautiful. Since answers may be large, print them modulo $$$998244353$$$.

NotePossible ways to distribute numbers in the first test:   the vertex $$$1$$$ should contain $$$1$$$, and $$$2$$$ should contain $$$2$$$;  the vertex $$$1$$$ should contain $$$3$$$, and $$$2$$$ should contain $$$2$$$;  the vertex $$$1$$$ should contain $$$2$$$, and $$$2$$$ should contain $$$1$$$;  the vertex $$$1$$$ should contain $$$2$$$, and $$$2$$$ should contain $$$3$$$. In the second test there is no way to distribute numbers.

package main

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

var (
	MOD int64 = int64(998244353)
)

func addEdge(g [][]int, from, to int) {
	if len(g[from]) <= 0 {
		g[from] = make([]int, 0)
	}
	g[from] = append(g[from], to)
}
func dfs(g [][]int, visit []int, root int, sum *int64, s *int64, f int) bool {
	visit[root] = f
	f++
	if f == 3 {
		f = 1
	}
	*sum = *sum + 1
	if f == 1 {
		*s = *s + 1
	}
	for _, next := range g[root] {
		if visit[next] == 0 {
			if dfs(g, visit, next, sum, s, f) == false {
				return false
			}
		} else if visit[next] != f {
			return false
		}
	}
	return true
}
func mi2(n int64) int64 {
	var d int64 = 2
	var ans int64 = 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = (ans * d) % MOD
		}
		n >>= 1
		d = (d * d) % MOD
	}
	return ans
}
func solve(sum, left int64) int64 {
	if sum == 1 {
		return int64(3)
	}
	ans1 := mi2(left)
	ans2 := mi2(sum - left)
	return (ans1 + ans2) % MOD
}
func main() {

	buf := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(buf, "%d\n", &t)
	for i := 1; i <= t; i++ {
		var n, m int
		fmt.Fscanf(buf, "%d %d\n", &n, &m)
		visit := make([]int, n+1)
		g := make([][]int, n+1)
		for j := 1; j <= m; j++ {
			var from, to int
			fmt.Fscanf(buf, "%d %d\n", &from, &to)
			addEdge(g, from, to)
			addEdge(g, to, from)
		}
		//	fmt.Println(g)
		var ans int64 = 0
		var sum int64 = 0
		var left int64 = 0
		for j := 1; j <= n; j++ {
			if visit[j] == 0 {
				sum = 0
				left = 0
				ok := dfs(g, visit, j, &sum, &left, 1)
				if ok == false {
					ans = 0
					break
				}
				var tmp int64 = solve(sum, left)
				if ans == 0 {
					ans = tmp
				} else {
					ans = (ans * tmp) % MOD
				}
			}
		}

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

/*
4 2
1 2
3 4
2 0

5 4
1 2
3 4
4 5
5 3
5 1
1 2
*/

package main

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

type Node struct {
	value int
	neighbor []int
}

func (n *Node) AddNeighbor(neighbor int) {
	n.neighbor = append(n.neighbor, neighbor)
}

var nodes []Node

const MOD = 998244353

func calculateWays() int64 {
	var ways int64 = 1
	for i, node := range nodes {
		if node.value == 0 {
			subgraphWays := getSubGraphWays(i)
			if subgraphWays == 0 {
				return 0
			}
			ways = (ways * subgraphWays) % MOD
		}
	}
	return ways
}

func getSubGraphWays(start int) int64 {
	oneCount := 0
	twoCount := 0
	valid := assignValue(start, 1, &oneCount, &twoCount)
	if !valid {
		return 0
	}
	// 2^b + 2^a
	return (powerTwo(oneCount) + powerTwo(twoCount)) % MOD
}

func assignValue(start int, value int, oneCount *int, twoCount *int) bool {
	nodes[start].value = value
	if value == 1 {
		*oneCount += 1
	} else {
		*twoCount += 1
	}
	for _, neighbor := range nodes[start].neighbor {
		n := nodes[neighbor]
		if n.value == value {
			return false
		}
		if n.value == 0 {
			if !assignValue(neighbor, 3 - value, oneCount, twoCount) {
				return false
			}
		}
	}
	return true
}

func powerTwo(a int) int64 {
	if a == 0 {
		return 1
	}
	res := powerTwo(a / 2)
	res = (res * res) % MOD
	if a % 2 == 1 {
		res = (res * 2) % MOD
	}
	return res
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)

	var t int
	for _, err := fmt.Fscan(stdin, &t); err == nil; _, err = fmt.Fscan(stdin, &t) {
		for ti := 0; ti < t; ti++ {
			var n, m int
			fmt.Fscan(stdin, &n, &m)

			nodes = make([]Node, n)
			for i := 0; i < m; i++ {
				var u, v int
				fmt.Fscan(stdin, &u, &v)
				u--
				v--
				nodes[u].AddNeighbor(v)
				nodes[v].AddNeighbor(u)
			}
			ways := calculateWays()
			fmt.Fprintf(stdout, "%d\n", ways)
			stdout.Flush()
		}
	}
}

package main

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

var (
	MOD int64 = int64(998244353)
)

func addEdge(g [][]int, from, to int) {
	if len(g[from]) <= 0 {
		g[from] = make([]int, 0)
	}
	g[from] = append(g[from], to)
}
func dfs(g [][]int,visit []int, root int, sum *int64, s *int64, f int)bool {
	visit[root] = f
	f++
	if f==3{
		f=1
	}
	*sum = *sum+1
	if f== 1{
		*s = *s+1
	}
	for _,next := range g[root]{
		if visit[next] == 0{
			if dfs(g,visit,next,sum,s,f) == false{
				return false
			}
		}else if visit[next] != f{
			return false
		}
	}
	return true
}
func mi2(n int64) int64 {
	var d int64 = 2
	var ans int64 = 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = (ans * d) % MOD
		}
		n >>= 1
		d = (d * d) % MOD
	}
	return ans
}
func solve(sum, left int64) int64 {
	if sum == 1 {
		return int64(3)
	}
	ans1 := mi2(left)
	ans2 := mi2(sum-left)
	return (ans1+ans2)%MOD
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(buf, "%d\n", &t)
	for i := 1; i <= t; i++ {
		var n, m int
		fmt.Fscanf(buf, "%d %d\n", &n, &m)
		visit := make([]int, n+1)
		g := make([][]int, n+1)
		for j := 1; j <= m; j++ {
			var from, to int
			fmt.Fscanf(buf, "%d %d\n", &from, &to)
			addEdge(g, from, to)
			addEdge(g, to, from)
		}
	//	fmt.Println(g)
		var ans int64 = 0
		var sum int64 = 0
		var left int64 = 0
		for j := 1; j <= n; j++ {
			if visit[j] == 0 {
				sum = 0
				left = 0
				ok := dfs(g,visit, j, &sum, &left, 1)
				if ok == false{
					continue
				}
				var tmp int64 = solve(sum, left)
				if ans == 0 {
					ans = tmp
				} else {
					ans = (ans * tmp) % MOD
				}
			}
		}

		fmt.Printf("%d\n", ans)
	}
}
/*
4 2
1 2
3 4
2 0
*/