You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Is it possible to arrange them on a circle so that each number is strictly greater than both its neighbors or strictly smaller than both its neighbors?In other words, check if there exists a rearrangement $$$b_1, b_2, \ldots, b_n$$$ of the integers $$$a_1, a_2, \ldots, a_n$$$ such that for each $$$i$$$ from $$$1$$$ to $$$n$$$ at least one of the following conditions holds: $$$b_{i-1} < b_i > b_{i+1}$$$ $$$b_{i-1} > b_i < b_{i+1}$$$To make sense of the previous formulas for $$$i=1$$$ and $$$i=n$$$, one shall define $$$b_0=b_n$$$ and $$$b_{n+1}=b_1$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 3\cdot 10^4$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$)  — the number of integers. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$2\cdot 10^5$$$.

For each test case, if it is not possible to arrange the numbers on the circle satisfying the conditions from the statement, output $$$\texttt{NO}$$$. You can output each letter in any case. Otherwise, output $$$\texttt{YES}$$$. In the second line, output $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$, which are a rearrangement of $$$a_1, a_2, \ldots, a_n$$$ and satisfy the conditions from the statement. If there are multiple valid ways to arrange the numbers, you can output any of them.

NoteIt can be shown that there are no valid arrangements for the first and the third test cases.In the second test case, the arrangement $$$[1, 8, 4, 9]$$$ works. In this arrangement, $$$1$$$ and $$$4$$$ are both smaller than their neighbors, and $$$8, 9$$$ are larger.In the fourth test case, the arrangement $$$[1, 11, 1, 111, 1, 1111]$$$ works. In this arrangement, the three elements equal to $$$1$$$ are smaller than their neighbors, while all other elements are larger than their neighbors.

package main

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

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

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

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

		if n%2 != 0 {
			fmt.Fprintln(out, "NO")
		} else {
			if n%2 == 0 {
				f := true
				sort.Ints(arr)
				g := make([]int, n)
				for i := 0; i < n/2; i++ {
					g[(2*i)%n] = arr[i]
				}
				for i := n / 2; i < n; i++ {
					g[(2*i+1)%n] = arr[i]
				}

				g = append(g[n-1:], g...)
				g = append(g, g[1])
				for i := 1; i <= n; i++ {
					if !((g[i] > g[i-1] && g[i] > g[i+1]) || (g[i] < g[i-1] && g[i] < g[i+1])) {
						f = false
						break
					}
				}
				if !f {
					fmt.Fprintln(out, "NO")
				} else {
					fmt.Fprintln(out, "YES")
					for i := 1; i <= n; i++ {
						fmt.Fprintf(out, "%d ", g[i])
					}
					fmt.Fprintln(out)
				}
			}
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
outer:
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slice := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slice[i])
		}
		if n%2 == 1 {
			fmt.Fprintln(writer, "NO")
			continue outer
		}
		sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] })
		//fmt.Println("!", slice)
		res := make([]int, n)
		fl := n / 2
		for i, j := 1, 0; j < fl; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!", res)
		//fr := n - fl
		for i, j := 2, fl; j < n-1; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!!", res)
		res[0] = slice[n-1]
		//fmt.Println("!!!", res)
		// check
		for i := 0; i < n-1; i++ {
			if i%2 == 1 {
				if res[i] >= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			} else {
				if res[i] <= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			}
		}
		if res[0] <= res[n-1] {
			if res[0] <= res[n-1] {
				fmt.Fprintln(writer, "NO")
				continue outer
			}
		}
		fmt.Fprintln(writer, "YES")
		for i := 0; i < n; i++ {
			fmt.Fprintf(writer, "%d ", res[i])
		}
		fmt.Fprintln(writer)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
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 tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); A := gis(N)
		if N % 2 == 1 { fmt.Fprintln(wrtr,"NO"); continue }
		sort.Slice(A,func(i,j int) bool { return A[i] < A[j] } )
		lidx,ridx := 0,N/2
		b := make([]int,0,N); for i:=0;i<N/2;i++ { b = append(b,A[lidx],A[ridx]); lidx++; ridx++ }
		// Now for the check
		good := true
		for i:=0;i<N;i++ {
			l := tern(i==0,N-1,i-1)
			r := tern(i==N-1,0,i+1)
			if !(b[i] > b[l] && b[i] > b[r] || b[i] < b[l] && b[i] < b[r]) { good = false; break }
		}
		if !good { fmt.Fprintln(wrtr,"NO"); } else { fmt.Fprintf(wrtr,"YES\n%v\n",vecintstring(b)) }
	}
}

package main

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

var T, N int
var A [200005]int

func solve() (f bool, res []int) {
	if N % 2 == 1 {
		f = false
		return
	}

	f = true
	sort.Ints(A[:N])
	res = make([]int, N)
	for i := 0; i < N / 2; i++ {
		res[i*2] = A[i]
	}
	for i := N / 2; i < N; i++ {
		res[(i - N/2) * 2 + 1] = A[i]
	}
	for i := 0; i<N; i+=2 {
		b, e := (i - 1 + N)%N, (i + 1) % N
		if res[i] < res[b] && res[i] < res[e] {

		}else{
			f = false
			return
		}
	}
	return
}

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

	fmt.Fscan(in, &T)

	for t := 1; t <= T; t++ {
		fmt.Fscan(in, &N)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &A[i])
		}

		f, res := solve()
		if f {
			fmt.Println("Yes")
			for i := 0; i < N; i++ {
				fmt.Print(res[i]," ")
			}
			fmt.Println("")
		}else {
			fmt.Println("NO")
			//fmt.Println(res)
		}
	}
}

package main

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

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

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

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

		if n%2 != 0 {
			fmt.Fprintln(out, "NO")
		} else {
			if n%2 == 0 {
				f := true
				sort.Slice(arr, func(i, j int) bool {
					return arr[i] < arr[j]
				})
				pos := (n / 2) - 1
				g := make([]int64, n)
				g[0] = arr[pos]
				x := 1
				for i := 1; i < n; i++ {
					if i%2 == 0 {
						g[i] = arr[pos-x]
						x++
					} else {
						g[i] = arr[pos+x]
					}
				}

				g = append(g[n-1:], g...)
				g = append(g, g[1])
				for i := 1; i <= n; i++ {
					if !((g[i] > g[i-1] && g[i] > g[i+1]) || (g[i] < g[i-1] && g[i] < g[i+1])) {
						f = false
						break
					}
				}
				if !f {
					fmt.Fprintln(out, "NO")
				} else {
					fmt.Fprintln(out, "YES")
					for i := 1; i <= n; i++ {
						fmt.Fprintf(out, "%d ", g[i])
					}
					fmt.Fprintln(out)
				}
			}
		}
	}
}

package main

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

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

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

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

		if n%2 != 0 {
			fmt.Fprintln(out, "NO")
		} else {
			if n%2 == 0 {
				f := true
				sort.Ints(arr)
				pos := (n / 2) - 1
				g := make([]int, n)
				g[0] = arr[pos]
				x := 1
				for i := 1; i < n; i++ {
					if i%2 == 0 {
						g[i] = arr[pos-x]
						x++
					} else {
						g[i] = arr[pos+x]
					}
				}

				g = append(g[n-1:], g...)
				g = append(g, g[1])
				for i := 1; i <= n; i++ {
					if !((g[i] > g[i-1] && g[i] > g[i+1]) || (g[i] < g[i-1] && g[i] < g[i+1])) {
						f = false
						break
					}
				}
				if !f {
					fmt.Fprintln(out, "NO")
				} else {
					fmt.Fprintln(out, "YES")
					for i := 1; i <= n; i++ {
						fmt.Fprintf(out, "%d ", g[i])
					}
					fmt.Fprintln(out)
				}
			}
		}
	}
}

package main

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

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

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

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

		if n%2 != 0 {
			fmt.Fprintln(out, "NO")
		} else {
			if n%2 == 0 {
				f := true
				sort.Ints(arr)
				pos := (n / 2) - 1
				g := make([]int, n)
				g[0] = arr[pos]
				x := 1
				for i := 1; i < n; i++ {
					if i%2 == 0 {
						g[i] = arr[pos-x]
						x++
					} else {
						g[i] = arr[pos+x]
					}
				}

				g = append(g[n-1:], g...)
				g = append(g, g[1])
				for i := 1; i <= n; i++ {
					if (g[i] >= g[i-1] && g[i] <= g[i+1]) || (g[i] <= g[i-1] && g[i] >= g[i+1]) {
						f = false
						break
					}
				}
				if !f {
					fmt.Fprintln(out, "NO")
				} else {
					fmt.Fprintln(out, "YES")
					for i := 1; i <= n; i++ {
						fmt.Fprintf(out, "%d ", g[i])
					}
					fmt.Fprintln(out)
				}
			}
		}
	}
}

package main

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

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

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

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

		sort.Ints(arr)
		pos := n / 2
		if n%2 == 0 {
			pos--
		}
		g := make([]int, n)
		g[0] = arr[pos]
		x := 1
		for i := 1; i < n; i++ {
			if i%2 == 0 {
				g[i] = arr[pos-x]
				x++
			} else {
				g[i] = arr[pos+x]
			}
		}

		f := true
		g = append(g[n-1:], g...)
		g = append(g, g[1])
		for i := 1; i <= n; i++ {
			if i%2 != 0 && (g[i] >= g[i-1] || g[i] >= g[i+1]) {
				f = false
				break
			} else if i%2 == 0 && (g[i] <= g[i-1] || g[i] <= g[i+1]) {
				f = false
				break
			}
		}

		if !f {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
			for i := 1; i <= n; i++ {
				fmt.Fprintf(out, "%d ", g[i])
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

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

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

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

		sort.Ints(arr)
		pos := n / 2
		if n%2 == 0 {
			pos--
		}
		g := make([]int, n)
		g[0] = arr[pos]
		x := 1
		for i := 1; i < n; i++ {
			if i%2 == 0 {
				g[i] = arr[pos-x]
				x++
			} else {
				g[i] = arr[pos+x]
			}
		}

		f := true
		g = append(g[n-1:], g...)
		g = append(g, g[1])
		for i := 1; i < n; i++ {
			if i%2 != 0 && (g[i] >= g[i-1] || g[i] >= g[i+1]) {
				f = false
				break
			} else if i%2 == 0 && (g[i] <= g[i-1] || g[i] <= g[i+1]) {
				f = false
				break
			}
		}

		if !f {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
			for i := 1; i <= n; i++ {
				fmt.Fprintf(out, "%d ", g[i])
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
outer:
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slice := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slice[i])
		}
		if n%2 == 1 {
			fmt.Println("NO")
			continue outer
		}
		sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] })
		//fmt.Println("!", slice)
		res := make([]int, n)
		fl := n / 2
		for i, j := 1, 0; j < fl; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!", res)
		//fr := n - fl
		for i, j := 2, fl; j < n-1; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!!", res)
		res[0] = slice[n-1]
		//fmt.Println("!!!", res)
		// check
		for i := 0; i < n-1; i++ {
			if i%2 == 1 {
				if res[i] >= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			} else {
				if res[i] <= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			}
		}
		if res[0] <= res[n-1] {
			// res[3], res[n-1] = res[n-1], res[3]
			// for i := 0; i < n-1; i++ {
			// 	if i%2 == 1 {
			// 		if res[i] >= res[i+1] {
			// 			fmt.Fprintln(writer, "NO")
			// 			continue outer
			// 		}
			// 	} else {
			// 		if res[i] <= res[i+1] {
			// 			fmt.Fprintln(writer, "NO")
			// 			continue outer
			// 		}
			// 	}
			// }
			if res[0] <= res[n-1] {
				fmt.Fprintln(writer, "NO")
				continue outer
			}
		}
		fmt.Fprintln(writer, "YES")
		for i := 0; i < n; i++ {
			fmt.Fprintf(writer, "%d ", res[i])
		}
		fmt.Fprintln(writer)
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
outer:
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slice := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slice[i])
		}
		if n%2 == 1 {
			fmt.Println("NO")
			continue outer
		}
		sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] })
		//fmt.Println("!", slice)
		res := make([]int, n)
		fl := n / 2
		for i, j := 1, 0; j < fl; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!!!", res)
		//fr := n - fl
		for i, j := 0, fl; j < n; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!!!", res)
		// check
		for i := 0; i < n-1; i++ {
			if i%2 == 1 {
				if res[i] >= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			} else {
				if res[i] <= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			}
		}
		if res[0] <= res[n-1] {
			res[3], res[n-1] = res[n-1], res[3]
			for i := 0; i < n-1; i++ {
				if i%2 == 1 {
					if res[i] >= res[i+1] {
						fmt.Fprintln(writer, "NO")
						continue outer
					}
				} else {
					if res[i] <= res[i+1] {
						fmt.Fprintln(writer, "NO")
						continue outer
					}
				}
			}
			if res[0] <= res[n-1] {
				fmt.Fprintln(writer, "NO")
				continue outer
			}
		}
		fmt.Fprintln(writer, "YES")
		for i := 0; i < n; i++ {
			fmt.Fprintf(writer, "%d ", res[i])
		}
		fmt.Fprintln(writer)
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
outer:
	for iter := 0; iter < ntests; iter++ {
		var n int
		fmt.Fscan(scanner, &n)
		slice := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slice[i])
		}
		if n%2 == 1 {
			fmt.Println("NO")
			continue outer
		}
		sort.Slice(slice, func(i, j int) bool { return slice[i] < slice[j] })
		//fmt.Println("!", slice)
		res := make([]int, n)
		fl := n / 2
		for i, j := 1, 0; j < fl; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!!!", res)
		//fr := n - fl
		for i, j := 0, fl; j < n; i, j = i+2, j+1 {
			res[i] = slice[j]
		}
		//fmt.Println("!!!", res)
		// check
		for i := 0; i < n-1; i++ {
			if i%2 == 1 {
				if res[i] >= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			} else {
				if res[i] <= res[i+1] {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			}
		}
		if res[0] <= res[n-1] {
			fmt.Fprintln(writer, "NO")
			continue outer
		}
		fmt.Fprintln(writer, "YES")
		for i := 0; i < n; i++ {
			fmt.Fprintf(writer, "%d ", res[i])
		}
		fmt.Fprintln(writer)
	}
}


Alica and Bob are playing a game.Initially they have a binary string $$$s$$$ consisting of only characters 0 and 1.Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent characters of string $$$s$$$ and delete them. For example, if $$$s = 1011001$$$ then the following moves are possible:   delete $$$s_1$$$ and $$$s_2$$$: $$$\textbf{10}11001 \rightarrow 11001$$$;  delete $$$s_2$$$ and $$$s_3$$$: $$$1\textbf{01}1001 \rightarrow 11001$$$;  delete $$$s_4$$$ and $$$s_5$$$: $$$101\textbf{10}01 \rightarrow 10101$$$;  delete $$$s_6$$$ and $$$s_7$$$: $$$10110\textbf{01} \rightarrow 10110$$$. If a player can't make any move, they lose. Both players play optimally. You have to determine if Alice can win.

First line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Only line of each test case contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$), consisting of only characters 0 and 1.

For each test case print answer in the single line. If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register.

NoteIn the first test case after Alice's move string $$$s$$$ become empty and Bob can not make any move.In the second test case Alice can not make any move initially.In the third test case after Alice's move string $$$s$$$ turn into $$$01$$$. Then, after Bob's move string $$$s$$$ become empty and Alice can not make any move.

package main

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

var reader *bufio.Reader

func parseInt(s string) int {
	return int(parseInt64(s))
}

func parseInt64(s string) int64 {
	x, _ := strconv.ParseInt(s, 10, 64)
	return x
}

func readLine() string {
	if reader == nil {
		reader = bufio.NewReader(os.Stdin)
	}
	s, _ := reader.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

func readFields() []string {
	return strings.Fields(readLine())
}

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

var t int

func main() {
	t := parseInt(readFields()[0])
	for tc := 0; tc < t; tc++ {
      f := readLine()
      ones, zeros := 0, 0
      for i := 0; i < len(f)-1; i++ {
        if f[i]=='1' {
            ones++
        } else {
            zeros++
        }
      }

      if ones == zeros {
          if ones % 2 == 0 {
              Println("NET")
          } else {
              Println("DA")
          }
          continue
      }

      if min(ones, zeros) % 2 == 0 {
          Println("NET")
      } else {
          Println("DA")
      }

    }
}

package main
import "fmt"

func min(a int, b int)int{
	if a >= b{
		return b;
	}else{
		return a;
	}
}
func main() {
    var t int;
    fmt.Scanln(&t);
    for kchk:=1; kchk<=t; kchk++{
    	var s string;
    	fmt.Scanln(&s);
    	var cnt0, cnt1 int;
    	for i:=0; i<len(s); i++{
    		if s[i] == '0' {
    			cnt0++;
    		}else{
    			cnt1++;
    		}
    	}
    	//fmt.Println(cnt0, cnt1, " ");
    	if min(cnt0, cnt1) % 2 == 0{
    		fmt.Println("NET");
    	}else{
    		fmt.Println("DA");
    	}
    }

}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		zeros := 0
		for _, c := range line {
			if c == '0' {
				zeros++
			}
		}
		ones := len(line) - zeros
		pairs := min(zeros, ones)
		if pairs % 2 == 0 {
			fmt.Println("NET")
		} else {
			fmt.Println("DA")
		}
	}
}

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

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/contest/1373/problem/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int
	S []rune
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	val := 0

	for {
		// PrintfDebug("S: %v\n", string(S))
		flag := false

		for i := 0; i < len(S)-1; i++ {
			if S[i] != S[i+1] {
				flag = true

				next := []rune{}
				for j := 0; j < i; j++ {
					next = append(next, S[j])
				}
				for j := i + 2; j < len(S); j++ {
					next = append(next, S[j])
				}

				val++
				S = next
				break
			}
		}

		if flag {
			continue
		} else {
			break
		}
	}
	// PrintfDebug("\n")

	if val%2 == 0 {
		fmt.Println("NET")
	} else {
		fmt.Println("DA")
	}
}

// func solve() {
// 	diff := make([]int, len(S)-1)
// 	for i := 0; i < len(S)-1; i++ {
// 		if S[i] != S[i+1] {
// 			diff[i] = 1
// 		} else {
// 			diff[i] = 0
// 		}
// 	}

// 	val := 0
// 	comp, cnts := RunLengthEncoding(diff)
// 	PrintfDebug("comp: %v\n", comp)
// 	for i := 0; i < len(comp); i++ {
// 		if comp[i] == 1 {
// 			val += Kiriage(cnts[i], 2)
// 		}
// 	}
// 	PrintfDebug("val: %d\n", val)

// 	if val%2 == 0 {
// 		fmt.Println("NET")
// 	} else {
// 		fmt.Println("DA")
// 	}
// }

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

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

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

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

	return runes, lengths
}

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

	res := []int{}

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

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

var nTest int
var s string

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

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

		cnt1 := 0
		cnt0 := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '0' {
				cnt0++
			} else {
				cnt1++
			}
		}

		min := cnt0
		if cnt1 < cnt0 {
			min = cnt1
		}

		var res string

		if min&1 == 0 {
			res = "NET"
		} else {
			res = "DA"
		}

		fmt.Fprintln(out, res)
	}

	out.Flush()
}

package main

import "fmt";

func main(){
    var t int;
    fmt.Scan(&t);
    for t > 0 {
        var n int;
        var a string;
        fmt.Scan(&a);
        var ar = make([]int,2);
        n = len(a);
        for i := 0;i < n;i++ {
            if a[i] == '0' {
                ar[1]++;
            } else {
                ar[0]++;
            }
        }

        if ar[1] < ar[0] {
            ar[0],ar[1] = ar[1],ar[0]
        }
        var ans string;
        if(ar[0]%2== 1){
            ans = "DA";
        } else {
            ans = "NET";
        }
        fmt.Println(ans);
        t--;
    }
}

package main

import "fmt"

func main() {
	var t int
	var str string

	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&str)
		l := len(str)
		var count0, count1 int

		for j := 0; j < l; j++ {
			if str[j] == '0' {
				count0++
			} else {
				count1++
			}
		}

		min := count0
		if count1 < count0 {
			min = count1
		}

		if min&1 == 1 {
			fmt.Println("DA")
		} else {
			fmt.Println("NET")
		}
	}
}

package main

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

func main() {
	t := NextInt()
	for t > 0 {
		t--
		s := Next()
		ones := 0
		for i := range s {
			if s[i] == '1' {
				ones++
			}
		}
		zeroes := len(s) - ones
		min := ones
		if zeroes < min {
			min = zeroes
		}

		if min % 2 == 1 {
			fmt.Println("DA")
		} else {
			fmt.Println("NET")
		}

	}
}

var sc = bufio.NewScanner(os.Stdin)

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

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

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

package main

import "fmt"

func main() {
	var t, l int
	var str string

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

		l = len(str)
		count := 0

		for j := 0; j < l-1; {
			tempJ := j
			if str[j] != str[j+1] {
				count++
				tempJ = j + 2
				if (j-1 >= 0 && j+2 < l) && str[j-1] != str[j+2] {
					count++
					tempJ = j + 3
				}

				j = tempJ
			} else {
				j++
			}
		}

		if count&1 == 1 {
			fmt.Println("DA")
			continue
		}

		fmt.Println("NET")
	}
}

package main

import "fmt"

func main() {
	var t, l int
	var str string

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

		l = len(str)
		if l == 1 {
			fmt.Println("NET")
			continue
		}

		count := 0
		i := 0
		j := 1
		for i >= 0 && j < l {
			if str[i] != str[j] {
				count++
				i--
				j++

				for (i >= 0 && j < l) && (str[i] != str[j]) {
					count++
					i--
					j++
				}

				i = j
				j++

			} else {
				i++
				j++
			}
		}

		if count&1 == 1 {
			fmt.Println("DA")
			continue
		}

		fmt.Println("NET")
	}
}

package main

import "fmt"

func main() {
	var t, l int
	var str string

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

		l = len(str)
		if l == 1 {
			fmt.Println("NET")
			continue
		}

		count := 0
		i := 0
		j := 1
		for i >= 0 && j < l {
			if str[i] != str[j] {
				count++
				i--
				j++

				for (i >= 0 && j < l) && (str[i] != str[j]) {
					count++
					i--
					j++
				}

				i = j
				j++

			} else {
				i++
				j++
			}
		}

		fmt.Println(count)
		if count&1 == 1 {
			fmt.Println("DA")
			continue
		}

		fmt.Println("NET")
	}
}

package main

import "fmt"

func main() {
	var t, l int
	var str string

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

		l = len(str)

		if l == 1 {
			fmt.Println("NET")
			continue
		}

		taken := make([]bool, l)

		count := 0
		i := 0
		j := 1
		for i >= 0 && j < l {
			if str[i] != str[j] {

				taken[i] = true
				taken[j] = true
				count++
				i--
				j++

				for (i >= 0 && j < l) && (str[i] != str[j]) {
					if taken[i] {
						i--
						continue
					}

					if taken[j] {
						j++
						continue
					}

					count++

					i--
					j++
				}

				i = j
				j++

			} else {
				i++
				j++
			}
		}
		if count&1 == 1 {
			fmt.Println("DA")
			continue
		}

		fmt.Println("NET")
	}
}

package main

import "fmt"

func main() {
	var t, l int
	var str string

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

		l = len(str)
		count := 0

		for j := 1; j < l; {
			if str[j-1] != str[j] {
				count++
				j = j + 2
			} else {
				j++
			}
		}

		if (count > 0) && (count&1 == 1) {
			fmt.Println("DA")
			continue
		}
		fmt.Println("NET")
	}
}


You are given an array $$$a_1, a_2, \dots, a_n$$$ where all $$$a_i$$$ are integers and greater than $$$0$$$. In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$). If $$$gcd(a_i, a_j)$$$ is equal to the minimum element of the whole array $$$a$$$, you can swap $$$a_i$$$ and $$$a_j$$$. $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$. Now you'd like to make $$$a$$$ non-decreasing using the operation any number of times (possibly zero). Determine if you can do this. An array $$$a$$$ is non-decreasing if and only if $$$a_1 \le a_2 \le \ldots \le a_n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.  The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of array $$$a$$$.  The second line of each test case contains $$$n$$$ positive integers $$$a_1, a_2, \ldots a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.  It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, output "YES" if it is possible to make the array $$$a$$$ non-decreasing using the described operation, or "NO" if it is impossible to do so.

Note In the first and third sample, the array is already non-decreasing. In the second sample, we can swap $$$a_1$$$ and $$$a_3$$$ first, and swap $$$a_1$$$ and $$$a_5$$$ second to make the array non-decreasing. In the forth sample, we cannot the array non-decreasing using the operation.

package main

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

// func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
// func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	var reader *bufio.Reader = bufio.NewReader(os.Stdin)
	var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var T int
	fmt.Scan(&T)
	var n int
outer:
	for t := 0; t < T; t++ {
		fmt.Fscan(reader, &n)
		as := make([]int, n)
		sas := make([]int, n)
		gmin := 1123456789
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &as[i])
			sas[i] = as[i]
			if as[i] < gmin {
				gmin = as[i]
			}
		}
		sort.Ints(sas)
		for i := 0; i < n; i++ {
			if sas[i] != as[i] {
				if as[i]%gmin != 0 || sas[i]%gmin != 0 {
					fmt.Fprintln(writer, "NO")
					continue outer
				}
			}
		}
		fmt.Fprintln(writer, "YES")
		// fmt.Fprintln(writer, ans)
	}
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		a := io.NextInts(n)
		m := a[0]
		for _, x := range a[1:] {
			if x < m {
				m = x
			}
		}

		var b, c []int
		for i, x := range a {
			if x%m == 0 {
				b = append(b, x)
				c = append(c, i)
			}
		}
		sort.Slice(b, func(i, j int) bool { return b[i] < b[j] })
		for i, x := range b {
			a[c[i]] = x
		}

		if sort.IntsAreSorted(a) {
			io.Println("YES")
		} else {
			io.Println("NO")
		}
	}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func sch(i int, a []int) int {
	s := 0
	e := len(a)-1

	for s <= e {
		m := (s+e)/2

		if a[m] == i {
			return m
		} else if a[m] < i {
			s = m+1
		} else {
			e = m-1
		}
	}

	if s < len(a) && a[s] == i {
		return s
	}

	return -1
}

func gcd(i, j int) int {
	if i == 0 {
		return j
	}

	t := i
	i = j%i
	j = t

	return gcd(i, j)
}

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

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

	for t := in(); t > 0; t-- {
		n := in()
		a := make([]int, n)
		b := make([]int, n)

		for i := range a {
			a[i] = in()
		}

		copy(b, a)

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

		okay := true

		for i := 1; i < n; i++ {
			if b[i] != a[i] && gcd(a[i], a[0]) != a[0] {
				okay = false
				break
			}
		}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		possible := true
		fmt.Fscan(in, &n)
		min := 1000000000
		a := make([]int, n)
		c := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
			if a[j] < min {
				min = a[j]
			}
		}
		var b []int
		for j := 0; j < n; j++ {
			if a[j]%min == 0 {
				b = append(b, a[j])
				c[j] = 0
			} else {
				c[j] = 1
			}
		}
		sort.Sort(sort.IntSlice(b))
		k := 0
		for j := 0; j < n; j++ {
			if c[j] == 0 {
				a[j] = b[k]
				k++
			}
		}

		prev := 0
		for j := 0; j < n; j++ {
			if a[j] < prev {
				possible = false
				break
			}
			prev = a[j]
		}
		if possible {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"

	"fmt"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()
		scanner.Text()

		scanner.Scan()
		a := MustParseFieldsC(scanner.Text())

		ans := solveC(a)

		fmt.Println(ans)
	}

}

type interval struct {
	l, h int
}

func solveC(a []int) string {
	var min = int(1e9 + 1)
	b := make([]int, len(a))
	mp := make(map[int]*interval)

	for i:= 0; i < len(a); i++ {
		if a[i] < min {
			min = a[i]
		}
		b[i] = a[i]
	}

	sort.Ints(b)

	for i := 1; i < len(b); i ++ {
		if b[i] % min != 0 {
			if b[i] != b[i - 1] {
				mp[b[i]] = &interval{i, i}
			} else {
				interval := mp[b[i]]
				interval.h = i
			}
		}
	}

	for i := 0; i < len(a); i++ {
		cur := a[i]
		if v, ok := mp[cur]; ok {
			if i < v.l || i > v.h {
				return "NO"
			}
		}
	}
	return "YES"
}

func MustParseFieldsC(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

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

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	nTest := 1
	nTest = rw.NextInt()
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.NextInt()
	a := rw.NextInts(n)
	min := -1
	for i, e := range a {
		if i == 0 || e < min {
			min = e
		}
	}
	pos := make([]int, 0)
	val := make([]int, 0)
	for i, e := range a {
		if e%min == 0 {
			pos = append(pos, i)
			val = append(val, e)
		}
	}
	sort.Ints(val)
	for j, i := range pos {
		a[i] = val[j]
	}
	if sort.IntsAreSorted(a) {
		rw.Println("YES")
	} else {
		rw.Println("NO")
	}
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

func main() {
    var i uint64 = 1<<18

    a := make([]uint64, i)

    for j := range a {
        a[j] = 178
    }
}

package main

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

func sch(i int, a []int) int {
	s := 0
	e := len(a)-1

	for s <= e {
		m := (s+e)/2

		if a[m] == i {
			return m
		} else if a[m] < i {
			s = m+1
		} else {
			e = m-1
		}
	}

	if s < len(a) && a[s] == i {
		return s
	}

	return -1
}

func gcd(i, j int) int {
	if i == 0 {
		return j
	}

	t := i
	i = j%i
	j = t

	return gcd(i, j)
}

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

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

	for t := in(); t > 0; t-- {
		n := in()
		a := make([]int, n)
		b := make([]int, n)

		for i := range a {
			a[i] = in()
		}

		copy(b, a)

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

		okay := true

		for i := range a {
			if b[i] != a[i] {
				j := sch(b[i], a)
				if gcd(b[i], b[j]) != a[0] {
					okay = false
					break
				}
			}
		}

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

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"

	"fmt"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()
		scanner.Text()

		scanner.Scan()
		a := MustParseFieldsC(scanner.Text())

		if j == 996 {
			fmt.Println(a)
		}

		ans := solveC(a)

		fmt.Println(ans)
	}

}

func solveC(a []int) string {
	var min = int(1e9 + 1)
	b := make([]int, len(a))
	mp := make(map[int]int)

	for i:= 0; i < len(a); i++ {
		if a[i] < min {
			min = a[i]
		}
		b[i] = a[i]
	}

	sort.Ints(b)

	for i := 1; i < len(b); i ++ {
		if b[i] % min != 0 {
			if b[i] != b[i - 1] {
				mp[b[i]] = i
			}
		}
	}

	for i := 0; i < len(a); i++ {
		cur := a[i]
		if v, ok := mp[cur]; ok {
			if v > i {
				return "NO"
			}
		}
	}
	return "YES"
}

func MustParseFieldsC(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

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

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"

	"fmt"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()
		scanner.Text()

		scanner.Scan()
		a := MustParseFieldsC(scanner.Text())

		ans := solveC(a)

		fmt.Println(ans)
	}

}

func solveC(a []int) string {
	var min = int(1e9 + 1)
	b := make([]int, len(a))
	mp := make(map[int]int)

	for i:= 0; i < len(a); i++ {
		if a[i] < min {
			min = a[i]
		}
		b[i] = a[i]
	}

	sort.Ints(b)

	for i := 1; i < len(b); i ++ {
		if b[i] % min != 0 {
			if b[i] != b[i - 1] {
				mp[b[i]] = i
			}
		}
	}

	for i := 0; i < len(a); i++ {
		cur := a[i]
		if v, ok := mp[cur]; ok {
			if v > i {
				return "NO"
			}
		}
	}
	return "YES"
}

func MustParseFieldsC(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

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

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"

	"fmt"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()
		scanner.Text()

		scanner.Scan()
		a := MustParseFieldsC(scanner.Text())

		if j == 995 {
			fmt.Println(a)
		}

		ans := solveC(a)

		fmt.Println(ans)
	}

}

func solveC(a []int) string {
	var min = int(1e9 + 1)
	b := make([]int, len(a))
	mp := make(map[int]int)

	for i:= 0; i < len(a); i++ {
		if a[i] < min {
			min = a[i]
		}
		b[i] = a[i]
	}

	sort.Ints(b)

	for i := 1; i < len(b); i ++ {
		if b[i] % min != 0 {
			if b[i] != b[i - 1] {
				mp[b[i]] = i
			}
		}
	}

	for i := 0; i < len(a); i++ {
		cur := a[i]
		if v, ok := mp[cur]; ok {
			if v > i {
				return "NO"
			}
		}
	}
	return "YES"
}

func MustParseFieldsC(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

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


According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.You are given a jacket with n buttons. Determine if it is fastened in a right way.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket. The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.

In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".

package main

import (
	"fmt"
)

func main(){
	var n int
	var a [1024]int
	sum := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++{
		if i == n - 1{
			fmt.Scanf("%d\n", &a[i])
		}else {
			fmt.Scanf("%d", &a[i])
		}
		sum += a[i]
	}
	flag := false
	if n == 1{
		if a[0] == 1{
			flag = true
		}
	}else{
		if sum == n - 1 {
				flag = true
			}
	}
	if flag {
		fmt.Println("YES")
	}else{
		fmt.Println("NO")
	}
}

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	log.SetOutput(ioutil.Discard)
	// log.SetOutput(os.Stderr)

	n := nextInt()
	cntZero := 0

	for i := 0; i < n; i++ {
		if nextInt() == 0 {
			cntZero++
		}
	}

	if (cntZero == 1 && n == 1) || (n > 1 && cntZero != 1) {
		println("NO")
	} else {
		println("YES")
	}
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import (
    "fmt"
)

func main () {
    var size int
    var button []int
    fmt.Scanf("%d\n", &size)
    button = make([]int, size)
    for i :=0 ; i<size; i++ {
        t := 0
        if i == size -1 {
            fmt.Scanf("%d\n", &t)
        } else {
            fmt.Scanf("%d", &t)
        }

        button[i] =t
    }

    badCnt := 0
    for _, val := range button {
        if val == 0{
            badCnt += 1
        }
    }

    if size == 1 {
        if badCnt == 0 {
            fmt.Print("YES")
        }else {
            fmt.Print("NO")
        }
        return
    }

    if badCnt == 1{
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }

}

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

func main(){
	scanner := bufio.NewScanner(os.Stdin)
	var botton string
	var state string
	scanner.Scan()
	botton = scanner.Text()
	scanner.Scan()
	state = scanner.Text()
	if botton == "1"{
		if state == "1"{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}else{
		arrState := strings.Split(state," ")
		count := 0
		for i := 0; i < len(arrState); i++ {
			a,_ := strconv.Atoi(arrState[i])
			if a == 0{
				count += 1
			}
		}
		if count == 1{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
    var n int
    var arr [1001]int
    fmt.Scanf("%d\n", &n)
    i := 0
    cnt_zero := 0
    for i < n {
        fmt.Scanf("%d", &arr[i])
        if arr[i] == 0 {
            cnt_zero++
        }
        i++
    }
    var flag bool
    flag = true
    if n == 1 {
        if cnt_zero == 1 {
            flag = false
        }
    } else {
        if cnt_zero != 1 {
            flag = false
        }
    }
    if flag {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

func solve(n int, arr []int) string {
	if n == 1 {
		if arr[0] == 0 {
			return "NO"
		}
		return "YES"
	}

	open := 0

	for i := range arr {
		if arr[i] == 0 {
			if open == 1 {
				return "NO"
			}
			open++
		}
	}

	if open == 0 {
		return "NO"
	}
	return "YES"
}

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

	var n int
	fmt.Fscanf(r, "%d\n", &n)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%s\n", solve(n, arr))
}

// MIT License
//
// Copyright (c) 2017 Nobi Hoang <nobi.hoa@gmail.com>
//
// http://codeforces.com/problemset/problem/691/A
//

package main

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

// ReadLine reads a line from the command line.
// It returns the line and an error if that fails.
func ReadLine() (string, error) {
  line, err := bufio.NewReader(os.Stdin).ReadString('\n')
  if err != nil {
    return "", err
  }
  return strings.TrimSpace(string(line)), nil
}

// Execute run
func Execute() {
  var n int
  fmt.Scanf("%d\n", &n)

  var a = make([]int, n)
  var s string
  s, _ = ReadLine()

  for i, str := range strings.Split(s, " ") {
    num, _ := strconv.Atoi(str)
    a[i] = num
  }

  count := 0
  for i := 0; i < n; i++ {
    if a[i] == 1 {
      count++
    }
  }

  if len(a) == 1 {
    if count == 1 {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  } else {
    if count == n - 1 {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  }
}

func main() {
  Execute()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	cnt := 0
	for i:= 0; i < n; i++ {
	    var val int
		fmt.Scanf("%d", &val)
		if val == 0 {
			cnt++;
		}
	}
	if (n == 1 && cnt == 0) || (n != 1 && cnt == 1) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

package main

import(
	"fmt"
)

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

	var a int
	var s int

	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		s += a
	}
	if (n > 1 && s == n-1) || (n == 1 && s == 1) {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

import(
	"fmt"
)

func main() {
	var n int
	var ele int
	fmt.Scanf("%d\n", &n)
	if n == 1 {
		fmt.Scanf("%d", &ele)
		if ele == 1 {
			fmt.Print("YES")
		} else {
			fmt.Print("NO")
		}
	} else {
		flaten := 0
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &ele)
			if ele == 0 {
				flaten++
				if flaten > 1 {
					fmt.Print("NO")
					return
				}
			}
		}
		if flaten == 1 {
			fmt.Print("YES")
		} else {
			fmt.Print("NO")
		}
	}
}

package main

import "fmt"

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

	var a int

	s := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		s += a
	}

	if (n > 1 && s == n-1) || (n == 1 && s == 1) {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

import (
	"fmt"
)

func main(){
	var n int
	var a [1024]int
	sum := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++{
		if i == n - 1{
			fmt.Scanf("%d\n", &a[i])
		}else {
			fmt.Scanf("%d", &a[i])
		}
		sum += a[i]
	}
	flag := false
	if n == 1{
		if a[0] == 1{
			flag = true
		}
	}else{
		if sum == n - 1 && a[n - 1] != 0 {
				flag = true
			}
	}
	if flag {
		fmt.Println("YES")
	}else{
		fmt.Println("NO")
	}
}

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	log.SetOutput(ioutil.Discard)
	// log.SetOutput(os.Stderr)

	n := nextInt()
	cntZero := 0

	for i := 0; i < n; i++ {
		if nextInt() == 0 {
			cntZero++
		}
	}

	if (cntZero == 0 && n == 1) || (n > 1 && cntZero != 1) {
		println("NO")
	} else {
		println("YES")
	}

}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import (
    "fmt"
)

func main () {
    var size int
    var button []int
    fmt.Scanf("%d", &size)
    button = make([]int, size)
    for i :=0 ; i<size; i++ {
        t := 0
        if i == size -1 {
            fmt.Scanf("%d\n", &t)
        } else {
            fmt.Scanf("%d", &t)
        }

        button[i] =t
    }

    badCnt := 0
    for _, val := range button {
        if val == 0{
            badCnt += 1
        }
    }

    if size == 1 {
        if badCnt == 0 {
            fmt.Print("YES")
        }else {
            fmt.Print("NO")
        }
        return
    }

    if badCnt == 1{
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }

}

package main

import (
    "fmt"
)

func main () {
    var size int
    var button []int
    fmt.Scanf("%d", &size)
    button = make([]int, size)
    for i :=0 ; i<size; i++ {
        if i == size -1 {
            fmt.Scanf("%d\n", &button[i])
        } else {
            fmt.Scanf("%d", &button[i])
        }
    }

    fmt.Println(button)

    badCnt := 0
    for _, val := range button {
        if val == 0{
            badCnt += 1
        }
    }

    if size == 1 {
        if badCnt == 0 {
            fmt.Print("YES")
        }else {
            fmt.Print("NO")
        }
        return
    }

    if badCnt == 1{
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }

}

package main

import (
    "fmt"
)

func main () {
    var size int
    var button []int64
    fmt.Scanf("%d", &size)
    button = make([]int64, size)
    for i :=0 ; i<size; i++ {
        if i == size -1 {
            fmt.Scanf("%d\n", &button[i])
        } else {
            fmt.Scanf("%d", &button[i])
        }
    }

    badCnt := 0
    for _, val := range button {
        if val == 0{
            badCnt += 1
        }
    }

    if size == 1 {
        if badCnt == 0 {
            fmt.Print("YES")
        }else {
            fmt.Print("NO")
        }
        return
    }

    if badCnt == 1{
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }

}

package main

import (
    "fmt"
)

func main () {
    var size int
    var button []int
    fmt.Scanf("%d", &size)
    button = make([]int, size)
    for i :=0 ; i<size; i++ {
        if i == size -1 {
            fmt.Scanf("%d\n", &button[i])
        } else {
            fmt.Scanf("%d", &button[i])
        }
    }

    badCnt := 0
    for _, val := range button {
        if val == 0{
            badCnt += 1
        }
    }

    if size == 1 {
        if badCnt == 0 {
            fmt.Print("YES")
        }else {
            fmt.Print("NO")
        }
        return
    }

    if badCnt == 1{
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }

}

package main

import (
	"fmt"
)

func main () {
	var size int
	var button []int64
	fmt.Scanf("%d", &size)
	button = make([]int64, size)
	for i :=0 ; i<size; i++ {
		fmt.Scanf("%d", &button[i])
	}

	badCnt := 0
	for _, val := range button {
		if val == 0{
			badCnt += 1
		}
	}

	if size == 1 {
		if badCnt == 0 {
			fmt.Print("YES")
		}else {
			fmt.Print("NO")
		}
		return
	}

	if badCnt == 1{
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}

}

package main

import "fmt"

func main() {
    var n int
    var arr [1001]int
    fmt.Scanf("%d", &n)
    i := 0
    cnt_zero := 0
    for i < n {
        fmt.Scanf("%d", &arr[i])
        if arr[i] == 0 {
            cnt_zero++
        }
        i++
    }
    var flag bool
    flag = true
    if n == 1 {
        if cnt_zero == 1 {
            flag = false
        }
    } else {
        if cnt_zero != 1 {
            flag = false
        }
    }
    if flag {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

// MIT License
//
// Copyright (c) 2017 Nobi Hoang <nobi.hoa@gmail.com>
//
// http://codeforces.com/problemset/problem/691/A
//

package main

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

// ReadLine reads a line from the command line.
// It returns the line and an error if that fails.
func ReadLine() (string, error) {
  line, err := bufio.NewReader(os.Stdin).ReadString('\n')
  if err != nil {
    return "", err
  }
  return strings.TrimSpace(string(line)), nil
}

// Execute run
func Execute() {
  var n int
  fmt.Scanf("%d", &n)

  var a = make([]int, n)
  var s string
  s, _ = ReadLine()

  for i, str := range strings.Split(s, " ") {
    num, _ := strconv.Atoi(str)
    a[i] = num
  }

  fmt.Println(a)

  count := 0
  for i := 0; i < n; i++ {
    if a[i] == 1 {
      count++
    }
  }

  if len(a) == 1 {
    if count == 1 {
      fmt.Println("YES")
    }
  } else {
    if count == n - 1 {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  }
}

func main() {
  Execute()
}

// MIT License
//
// Copyright (c) 2017 Nobi Hoang <nobi.hoa@gmail.com>
//
// http://codeforces.com/problemset/problem/691/A
//

package main

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

// ReadLine reads a line from the command line.
// It returns the line and an error if that fails.
func ReadLine() (string, error) {
  line, err := bufio.NewReader(os.Stdin).ReadString('\n')
  if err != nil {
    return "", err
  }
  return strings.TrimSpace(string(line)), nil
}

// Execute run
func Execute() {
  var n int
  fmt.Scanf("%d\n", &n)

  var a = make([]int, n)
  var s string
  s, _ = ReadLine()

  for i, str := range strings.Split(s, " ") {
    num, _ := strconv.Atoi(str)
    a[i] = num
  }

  count := 0
  for i := 0; i < n; i++ {
    if a[i] == 1 {
      count++
    }
  }

  if len(a) == 1 {
    if count == 1 {
      fmt.Println("YES")
    }
  } else {
    if count == n - 1 {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  }
}

func main() {
  Execute()
}

// MIT License
//
// Copyright (c) 2017 Nobi Hoang <nobi.hoa@gmail.com>
//
// http://codeforces.com/problemset/problem/691/A
//

package main

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

// ReadLine reads a line from the command line.
// It returns the line and an error if that fails.
func ReadLine() (string, error) {
  line, err := bufio.NewReader(os.Stdin).ReadString('\n')
  if err != nil {
    return "", err
  }
  return strings.TrimSpace(string(line)), nil
}

// Execute run
func Execute() {
  var n int
  fmt.Scanf("%d", &n)

  var a = make([]int, n)
  var s string
  s, _ = ReadLine()

  for i, str := range strings.Split(s, " ") {
    num, _ := strconv.Atoi(str)
    a[i] = num
  }

  count := 0
  for i := 0; i < n; i++ {
    if a[i] == 1 {
      count++
    }
  }

  if len(a) == 1 {
    if count == 1 {
      fmt.Println("YES")
    }
  } else {
    if count == n - 1 {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
  }
}

func main() {
  Execute()
}

package main

import(
	"fmt"
)

func main() {
	var n int
	var ele int
	fmt.Scanf("%d", &n)
	if n == 1 {
		fmt.Scanf("%d", &ele)
		if ele == 1 {
			fmt.Print("YES")
		} else {
			fmt.Print("NO")
		}
	} else {
		flaten := 0
		a := []int{}
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &ele)
			a = append(a, ele)
			if ele == 0 {
				flaten++
				if flaten > 1 {
					fmt.Print("NO")
					return
				}
			}
		}
		fmt.Print("YES")
	}
}

package main

import(
	"fmt"
)

func main() {
	var n int
	var ele int
	fmt.Scanf("%d\n", &n)
	if n == 1 {
		fmt.Scanf("%d", &ele)
		if ele == 1 {
			fmt.Print("YES")
		} else {
			fmt.Print("NO")
		}
	} else {
		flaten := 0
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &ele)
			if ele == 0 {
				flaten++
				if flaten > 1 {
					fmt.Print("NO")
					return
				}
			}
		}
		fmt.Print("YES")
	}
}

package main

import(
	"fmt"
)

func main() {
	var n int
	var ele int
	fmt.Scanf("%d", &n)
	if n == 1 {
		fmt.Scanf("%d", &ele)
		if ele == 1 {
			fmt.Print("YES")
		} else {
			fmt.Print("NO")
		}
	} else {
		flaten := 0
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &ele)
			if ele == 0 {
				flaten++
				if flaten > 1 {
					fmt.Print("NO")
					return
				}
			}
		}
		fmt.Print("YES")
	}
}

package main

import "fmt"

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

	var a int

	s := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		s += a
	}

	if s == n-1 || (n == 1 && s == 1) {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}


People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied:  every integer from 1 to n2 appears in the table exactly once;  in each row numbers are situated in increasing order;  the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right.

The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum.

First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any.

package main

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

type intArray []int
type intArrayArray []intArray

func main() {
    stin := bufio.NewScanner(os.Stdin)
    stin.Scan()
    ss := strings.Fields(stin.Text())
    n,_ := strconv.Atoi(ss[0])
    k,_ := strconv.Atoi(ss[1])

    var a intArrayArray = make(intArrayArray,0)
    for i := 0; i < n; i++ {
        var q intArray = make(intArray,0)
        for j := 0; j < n; j++ {
            q = append(q, i+j)
        }
        a = append(a, q)
    }

    init := n*n
    for i := 0; i < n; i++ {
        for j := n-1; j >= k-1; j-- {
            a[i][j] = init
            init -= 1
        }
    }

    if k > 1 {
        for i := 0; i < n; i++ {
            for j := k-2; j >= 0; j-- {
                a[i][j] = init
                init -= 1
            }
        }
    }

    s := 0
    for i := 0; i < n; i++ {
        s += a[i][k-1]
    }
    fmt.Printf("%d\n", s)
    for i := 0; i < n; i++ {
        for j := 0; j < n; j++ {
            fmt.Printf("%d ", a[i][j])
        }
        fmt.Printf("\n")
    }
}


You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query.

For each test case, print $$$q$$$ integers — the answers to the queries of this test case in the order they appear.

// https://codeforces.com/contest/1342/problem/C
package main

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

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

func main() {
	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n)

	for i := 0; i < n; i++ {
		var a, b, q int64
		fmt.Fscan(input, &a, &b, &q)
		solve(input, a, b, q)
	}
}

func solve(input io.Reader, a, b, q int64) {
	ab := a * b
	pref := make([]int64, ab + 1)
	for i := int64(1); i <= ab; i++ {
		pref[i] += pref[i - 1]
		if i % a % b != i % b % a {
			pref[i]++
		}
	}

	calc := func(last int64) int64 {
		cnt := last / ab
		r := last % ab
		return cnt * pref[ab] + pref[r]
	}

	for i := int64(0); i < q; i++ {
		var l, r int64
		fmt.Fscan(input, &l, &r)
		ans := calc(r) - calc(l - 1)
		if i == 0 {
			fmt.Print(ans)
		} else {
			fmt.Print(" ", ans)
		}
	}

	fmt.Println()
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 3*1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return i
	}

	for t := input(); t > 0; t-- {
		a, b, q := input(), input(), input()

		p := make([]uint64, a*b+1)
		var i uint64
		for i = 1; i <= a*b; i++ {
			p[i] = p[i-1]
			if (i%a)%b != (i%b)%a {
				p[i]++
			}
		}

		query := func(n uint64) uint64 {
			num := n / (a * b)
			rem := n % (a * b)
			return num*p[a*b] + p[rem]
		}

		for i = 0; i < q; i++ {
			l, r := input(), input()
			fmt.Print(query(r)-query(l-1), " ")
		}
		fmt.Println()
	}

}

/*
URL:
https://codeforces.com/problemset/problem/1342/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	a, b int64
	q    int
	l, r int64

	L    int64
	memo []int64
	msum []int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		a, b = ReadInt64_2()
		q = ReadInt()

		solve()
	}
}

func solve() {
	L = Lcm(a, b)

	// 前処理
	memo = make([]int64, L)
	msum = make([]int64, L+1)
	for i := int64(0); i < L; i++ {
		if (i%a)%b != (i%b)%a {
			memo[i] = 1
		}
	}
	for i := int64(0); i < L; i++ {
		msum[i+1] = msum[i] + memo[i]
	}

	// PrintfDebug("memo: %v\n", memo)
	// PrintfDebug("msum: %v\n", msum)

	answers := make([]int64, q)
	for i := 0; i < q; i++ {
		l, r = ReadInt64_2()
		answers[i] = calc()
	}
	fmt.Println(PrintInts64Line(answers...))
}

// [l, r] の個数を求める
func calc() int64 {
	return sub(r) - sub(l-1)
}

// [0, r] の個数を求める
func sub(r int64) int64 {
	segNum := r / L
	unit := msum[L]
	res := segNum * unit

	// 端数の計算
	s := segNum * L
	t := r
	length := t - s + 1
	res += msum[length]

	return res
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int64) int64 {
	return (a + (b - 1)) / b
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int64) int64 {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int64) int64 {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int64) int64 {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int64) int64 {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1342C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}
	lcm := func(a, b int64) int64 { return a / gcd(a, b) * b }

	var t, q int
	var a, b, l, r int64
	cnt := func(x int64) int64 {
		l := lcm(a, b)
		if l == b {
			return 0
		}
		ans := x / l * (l - b)
		x %= l
		if x >= b {
			ans += x - b + 1
		}
		return ans
	}
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fscan(in, &a, &b, &q)
		if a > b {
			a, b = b, a
		}
		for ; q > 0; q-- {
			Fscan(in, &l, &r)
			Fprint(out, cnt(r)-cnt(l-1), " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}
	lcm := func(a, b int64) int64 { return a / gcd(a, b) * b }
	solve := func(_case int) {
		var a, b, l, r int64
		var q int

		// <=x
		cnt := func(x int64) int64 {
			l := lcm(a, b)
			if l == b {
				return 0
			}

			cnt := x / l
			ans := cnt * (l - b)
			x %= l
			if x >= b {
				ans += x - b + 1
			}
			return ans

			//if x <b {
			//	return 0
			//}
			//if x==b {
			//	if x%a!=0 {
			//		return 1
			//	}
			//}
		}

		Fscan(in, &a, &b, &q)

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

		ans := make([]interface{}, q)
		for i := 0; i < q; i++ {
			Fscan(in, &l, &r)
			ans[i] = cnt(r) - cnt(l-1)
		}
		Fprintln(out, ans...)
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		solve(_case)
	}
}

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

package main

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

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

    var t int
    Fscan(in, &t)

    for test := 0; test < t; test++ {
        var a, b, q int
        Fscan(in, &a, &b, &q)
        var reminders []int64
        n := int64(a * b)

        for i := 1; i < int(n); i++ {
            if (i % a) % b != (i % b) % a {
                reminders = append(reminders, int64(i))
            }
        }

        length := len(reminders)

        var l, r, L, R, ans int64

        for subtest := 0; subtest < q; subtest++ {
            Fscan(in, &l, &r)
            l--
            L = l / n
            R = r / n
            l = l % n
            r = r % n
            ans = (R - L) * int64(length)
            left := 0
            right := length - 1
            mid := 0
            lBigger := 0
            rBigger := 0
            for ; left <= right; {
                mid = (left + right) / 2
                if reminders[mid] <= l {
                    lBigger = mid + 1
                    left = mid + 1
                } else {
                    right = mid - 1
                }
            }

            left = 0
            right = length - 1
            for ; left <= right ; {
                mid = (left + right) / 2
                if reminders[mid] <= r {
                    rBigger = mid + 1
                    left = mid + 1
                } else {
                    right = mid - 1
                }
            }

            ans += int64(rBigger - lBigger)

            Fprint(out, ans, " ")
        }
        Fprint(out, "\n")
    }

}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for T := stdin.ReadInt(); T > 0; T-- {
		a := stdin.ReadInt64()
		b := stdin.ReadInt64()

		if a > b {
			a, b = b, a
		}
		lcm := Lcm64(a, b)

		ans := []int64{}
		for q := stdin.ReadInt(); q > 0; q-- {
			l := stdin.ReadInt64() - 1
			r := stdin.ReadInt64()

			x := l/lcm*(lcm-b) + Max64(int64(0), l%lcm-b+1)
			y := r/lcm*(lcm-b) + Max64(int64(0), r%lcm-b+1)
			ans = append(ans, y-x)
		}
		stdout.Println(strings.Join(ToStringSlice(ans), " "))
	}
}

type Deque struct {
	head []interface{}
	tail []interface{}
}

func NewDeque() *Deque {
	return &Deque{
		head: []interface{}{},
		tail: []interface{}{},
	}
}

func (d *Deque) AppendLast(v interface{}) {
	d.tail = append(d.tail, v)
}

func (d *Deque) AppendFirst(v interface{}) {
	d.head = append(d.head, v)
}

func (d *Deque) PopLast() interface{} {
	if len(d.tail) == 0 {
		v := d.head[0]
		d.head = d.head[1:]
		return v
	} else {
		v := d.tail[len(d.tail)-1]
		d.tail = d.tail[:len(d.tail)-1]
		return v
	}
}

func (d *Deque) PopFirst() interface{} {
	if len(d.head) == 0 {
		v := d.tail[0]
		d.tail = d.tail[1:]
		return v
	} else {
		v := d.head[len(d.head)-1]
		d.head = d.head[:len(d.head)-1]
		return v
	}
}

func (d *Deque) IsEmpty() bool {
	return len(d.head) == 0 && len(d.tail) == 0
}

func (d *Deque) PeekFirst() interface{} {
	if len(d.head) == 0 {
		return d.tail[0]
	} else {
		return d.head[len(d.head)-1]
	}
}

func (d *Deque) PeekLast() interface{} {
	if len(d.tail) == 0 {
		return d.head[0]
	} else {
		return d.tail[len(d.tail)-1]
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

// ========================================
//      FOR int64
// ========================================

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

package main

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

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

    n := 100000

    arr := make([]int, 0)
    for i := 0; i < n; i++ {
        arr = append(arr, 1)
    }
    sum := 0
    for i := 0; i < n; i++ {
        sum += arr[i]
    }
    Fprint(out, sum)
}


In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another.Note that in this problem you do not have to minimize the number of swaps — your task is to find any sequence that is no longer than n.

The first line of the input contains integer n (1 ≤ n ≤ 3000) — the number of array elements. The second line contains elements of array: a0, a1, ..., an - 1 ( - 109 ≤ ai ≤ 109), where ai is the i-th element of the array. The elements are numerated from 0 to n - 1 from left to right. Some integers may appear in the array more than once.

In the first line print k (0 ≤ k ≤ n) — the number of swaps. Next k lines must contain the descriptions of the k swaps, one per line. Each swap should be printed as a pair of integers i, j (0 ≤ i, j ≤ n - 1), representing the swap of elements ai and aj. You can print indices in the pairs in any order. The swaps are performed in the order they appear in the output, from the first to the last. It is allowed to print i = j and swap the same pair of elements multiple times. If there are multiple answers, print any of them. It is guaranteed that at least one answer exists.

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	a := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		_a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		a[i] = _a
	}

	swap := 0
	var swaps [][2]int

	for i := n - 1; i > 0; i-- {
		max := -1
		max_idx := -1
		for j := 0; j < i; j++ {
			if max_idx < 0 || a[j] > max {
				max = a[j]
				max_idx = j
			}
		}
		if max > a[i] {
			swap++
			swaps = append(swaps, [2]int{max_idx, i})
			a[max_idx], a[i] = a[i], a[max_idx]
		}
	}

	fmt.Println(swap)
	for i := 0; i < swap; i++ {
		fmt.Println(swaps[i][0], swaps[i][1])
	}
}

package main

import (
	"fmt"
	"math"
)

type pair struct {
	i, j int
}

func minOfInts(a []int) (int, int) {
	value := math.MaxInt32
	var index int
	for i, v := range a {
		if v < value {
			index = i
			value = v
		}
	}
	return index, value
}

func main() {
	var n, k int

	fmt.Scan(&n)

	a := make([]int, n)
	var res []pair

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	for i := 0; i < n; i++ {
		j, _ := minOfInts(a[i:])
		j += i
		if j != i {
			p := pair{i: i, j: j}
			res = append(res, p)
			k++
			a[i], a[j] = a[j], a[i]
		}
	}

	fmt.Println(k)

	for i := 0; i < k; i++ {
		fmt.Println(res[i].i, res[i].j)
	}
}

package main

import (
	"fmt"
	"sort"
)

type pair struct {
	i, j int
}

func main() {
	var n, k int

	fmt.Scan(&n)

	a := make([]int, n)
	sortedA := make([]int, n)
	var swaps []pair

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	copy(sortedA, a)
	sort.Ints(sortedA)

	for i := n - 1; i >= 0; i-- {
		if a[i] != sortedA[i] {
			var j int
			for j = 0; j < i; j++ {
				if a[j] == sortedA[i] {
					break
				}
			}
			p := pair{i: i, j: j}
			swaps = append(swaps, p)
			k++
			a[i], a[j] = a[j], a[i]
		}
	}

	fmt.Println(k)

	for i := 0; i < k; i++ {
		fmt.Println(swaps[i].i, swaps[i].j)
	}
}

package main

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

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

func main() {
	defer writer.Flush()

	scanner.Split(bufio.ScanWords)
	n := ReadInt32()
	data := make([]int, n)
	for i := 0; i < n; i += 1 {
		data[i] = ReadInt32()
	}
	swaps := 0
	swapIndex := make([][]int, 0)
	for i := 0; i < n-1; i += 1 {
		minValue := 1000000001
		minIndex := -1
		for j := i + 1; j < n; j += 1 {
			if data[j] < minValue {
				minValue = data[j]
				minIndex = j
			}
		}
		if minValue < data[i] {
			swaps += 1
			data[i], data[minIndex] = data[minIndex], data[i]
			swapIndex = append(swapIndex, []int{i, minIndex})
		}
	}
	PrintInts(swaps)
	writer.WriteByte('\n')
	for _, indexs := range swapIndex {
		PrintInts(indexs...)
		writer.WriteByte('\n')
	}
}

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}

func PrintInts(ints ...int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a, b := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		b[i] = a[i]
	}
	sort.Ints(b)
	var z [][]int
	for i := 0; i < n; i++ {
		if a[i] == b[i] {
			continue
		}
		for j := i + 1; j < n; j++ {
			if a[j] == b[i] {
				a[i], a[j] = a[j], a[i]
				z = append(z, []int{i, j})
				break
			}
		}
	}
	k := len(z)
	fmt.Println(k)
	for i := 0; i < k; i++ {
		fmt.Printf("%d %d\n", z[i][0], z[i][1])
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int64, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	r := make([][2]int, 0)
	for i := 0; i < n; i++ {
		min := i
		for j := i + 1; j < n; j++ {
			if a[j] < a[min] {
				min = j
			}
		}
		if min != i {
			tmp := [2]int{i, min}
			a[i], a[min] = a[min], a[i]
			r = append(r, tmp)
		}
	}
	fmt.Println(len(r))
	for _, i := range r {
		fmt.Println(i[0], i[1])
	}
}

package main

import "fmt"

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

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

	ans := make([]int, n*2, n*2)
	index := 0

	for i := 0; i < n; i++ {
		t := i
		for j := i + 1; j < n; j++ {
			if an[t] > an[j] {
				t = j
			}
		}

		if t != i {
			an[i], an[t] = an[t], an[i]
			ans[index] = i
			index++
			ans[index] = t
			index++
		}
	}

	cnt := index / 2
	fmt.Println(cnt)
	for i := 0; i < cnt; i++ {
		fmt.Println(ans[i*2], ans[i*2+1])
	}
}

package main

import (
	"fmt"
	"sort"
)

type pair struct {
	i, j int
}

func main() {
	var n, k int

	fmt.Scan(&n)

	a := make([]int, n)
	sortedA := make([]int, n)
	var swaps []pair

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	copy(sortedA, a)
	sort.Ints(sortedA)

	for i := n - 1; i >= 0; i-- {
		if a[i] != sortedA[i] {
			j := sort.SearchInts(a, sortedA[i])
			p := pair{i: i, j: j}
			swaps = append(swaps, p)
			k++
		}
	}

	fmt.Println(k)

	for i := 0; i < k; i++ {
		fmt.Println(swaps[i].i, swaps[i].j)
	}
}

package main

import (
	"fmt"
)

type pair struct {
	i, j int
}

func main() {
	var n, k int

	fmt.Scan(&n)

	a := make([]int64, n)
	var swaps []pair

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	for i := n - 1; i >= 0; i-- {
		for j := 0; j < i; j++ {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
				p := pair{i: j, j: j + 1}
				swaps = append(swaps, p)
				k++
			}
		}
	}

	fmt.Println(k)

	for i := 0; i < k; i++ {
		fmt.Println(swaps[i].i, swaps[i].j)
	}
}