You are given an array $$$a$$$ consisting of $$$n$$$ nonnegative integers. Let's define the prefix OR array $$$b$$$ as the array $$$b_i = a_1~\mathsf{OR}~a_2~\mathsf{OR}~\dots~\mathsf{OR}~a_i$$$, where $$$\mathsf{OR}$$$ represents the bitwise OR operation. In other words, the array $$$b$$$ is formed by computing the $$$\mathsf{OR}$$$ of every prefix of $$$a$$$.You are asked to rearrange the elements of the array $$$a$$$ in such a way that its prefix OR array is lexicographically maximum.An array $$$x$$$ is lexicographically greater than an array $$$y$$$ if in the first position where $$$x$$$ and $$$y$$$ differ, $$$x_i > y_i$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ nonnegative integers $$$a_1, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print $$$n$$$ integers — any rearrangement of the array $$$a$$$ that obtains the lexicographically maximum prefix OR array.

package main

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

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

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

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

		bb := make([]bool, n)
		var z int
		for i := 31; i > 0; i-- {
			if z&(1<<(i-1)) > 0 {
				continue
			}

			d := -1
			var idx int
			for j, v := range aa {
				if bb[j] {
					continue
				}

				if v|z > d {
					d = v | z
					idx = j
				}
			}

			if d < 0 {
				break
			}
			z = d
			bb[idx] = true
			fmt.Fprintf(out, "%d ", aa[idx])
		}

		for i := range bb {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; i < len(a); i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				if now|a[j] > newNow {
					maxPos = j
					newNow = now | a[j]
				}
			}

			if maxPos != -1 {
				a.Swap(i, maxPos)
			} else {
				break
			}

			now = newNow
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

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

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

		var n int
		fmt.Fscan(r, &n)

		a := make([]int, n)
		cnt := make(map[int]int)
		max_ := 0
		prev_max_ := 0
		max_t := 0
		for i := range a {
			fmt.Fscan(r, &a[i])
			if a[i] > max_ {
				max_ = a[i]
				max_t = a[i]
			}
			cnt[a[i]]++
		}

		fmt.Fprintf(w, "%d ", max_t)
		cnt[max_t]--

		for max_ != prev_max_ {
			prev_max_ = max_
			for _, v := range a {
				if cnt[v] > 0  && (prev_max_ | v) > max_ {
					max_ = prev_max_ | v
					max_t = v
				}
			}

			if cnt[max_t] > 0 {
				fmt.Fprintf(w, "%d ", max_t)
				cnt[max_t]--
			}
		}

		for _, v := range a {
			if cnt[v] > 0 {
				fmt.Fprintf(w, "%d ", v)
				cnt[v]--
			}
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

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

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

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

		var n int
		fmt.Fscan(r, &n)

		a := make([]int, n)
		cnt := make(map[int]int)
		max_ := 0
		prev_max_ := 0
		max_t := 0
		for i := range a {
			fmt.Fscan(r, &a[i])
			max_ = max(max_, a[i])
			max_t = max_
			cnt[a[i]]++
		}

		fmt.Fprintf(w, "%d ", max_t)
		cnt[max_t]--

		for max_ != prev_max_ {
			// fmt.Fprintf(w, "*** max_:%d prev_max_:%d\n", max_, prev_max_)
			prev_max_ = max_
			for _, v := range a {
				/*
				fmt.Fprintf(
					w,
					"--- v:%d cnt[v]:%d\n",
					v, cnt[v])
					*/
				if cnt[v] > 0  && (prev_max_ | v) > max_ {
					max_ = prev_max_ | v
					max_t = v
				}
			}

			if cnt[max_t] > 0 {
				fmt.Fprintf(w, "%d ", max_t)
				cnt[max_t]--
			}
		}

		for _, v := range a {
			if cnt[v] > 0 {
				fmt.Fprintf(w, "%d ", v)
				cnt[v]--
			}
		}
		fmt.Fprintln(w, "")

	}

}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		var n int
		Fscan(in, &n)
		var a, ok = []int{}, []int{}
		for i := 0; i < n; i++ {
			var x int
			Fscan(in, &x)
			a = append(a, x)
			ok = append(ok, 0)
		}
		var ans = []int{}
		now := 0
		for len(ans) < n {
			x, pos := 0, 0
			for i := 0; i < n; i++ {
				if ok[i] == 1 {
					continue
				}
				val := a[i] &^ now
				if val > x {
					x = val
					pos = i
				}
			}
			now |= x
			if x > 0 {
				ok[pos] = 1
				ans = append(ans, a[pos])
				continue
			}
			for i := 0; i < n; i++ {
				val := a[i] &^ now
				if val == x && ok[i] == 0 {
					ok[i] = 1
					ans = append(ans, a[i])
				}
			}
		}
		for i := 0; i < n; i++ {
			Fprintf(out, "%d ", ans[i])
		}
		Fprintf(out, "\n")
	}
}

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

package main

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

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

func readInt() int {
	var i int
	fmt.Fscan(reader, &i)
	return i
}

func readString() string {
	var s string
	fmt.Fscan(reader, &s)
	return s
}

func main(){
	defer writer.Flush()
	T := readInt()
	for i := 1; i <= T; i++{
		n := readInt()
		a := make([]int, n)
		for j := 0; j < n; j++ {
			a[j] = readInt()
		}
		cur := 0
		for i := 0; i < n; i++ {
			change, p1 := 0, 0
			for j := 0; j < len(a); j++ {
				nCur := cur | a[j]
				if nCur > change {
					change = nCur
					p1 = j
				}
			}
			if change == cur {
				break
			}

			fmt.Fprint(writer, a[p1], " ")
			a = append(a[:p1], a[p1+1:]...)
			cur = change
		}
		for i := 0; i < len(a); i++ {
			fmt.Fprint(writer, a[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

const mod = 998244353
const mx = int64(1e9 + 7)

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([][]int64, n)
	for i := 0; i < n; i++ {
		var item int64
		Fscan(in, &item)
		arr[i] = []int64{item, item}
	}
	cur := int64(0)
	for i := 0; i < 30 && i < len(arr); i++ {
		sort.Slice(arr[i:], func(l, r int) bool {
			return arr[l+i][1] > arr[r+i][1]
		})
		cur |= arr[i][0]
		for j := i + 1; j < n; j++ {
			arr[j][1] -= arr[j][1] & cur
		}
	}
	for i := 0; i < len(arr); i++ {
		Fprintf(out, "%d ", arr[i][0])
	}
	Fprintln(out)
}

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

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

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

package main

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

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

func g1742(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		r := make([]int, n)
		ans := make([]int, n)
		mi := 0
		ua := map[int]bool{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r[i] = x
			if x > r[mi] {
				mi = i
			}
		}
		ans[0] = r[mi]
		ua[mi] = true

		mx := r[mi]
		mxi := 0
		for l := 1; l < 31; l++ {
			t := mx
			for i, v := range r {
				if v|mx > t {
					t = v | mx
					mxi = i
				}
			}
			if t == mx {
				break
			}
			mx = t
			ua[mxi] = true
			ans[l] = r[mxi]
		}

		idx := len(ua)
		for i, v := range r {
			if ua[i] {
				continue
			}
			ans[idx] = v
			idx++
		}

		for _, v := range ans {
			Fprintf(out, "%d ", v)
		}
		Fprintln(out, "")
	}
}

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		type pair struct{ ori, cur int }
		a := make([]pair, n)
		or := 0
		for i := range a {
			Fscan(in, &a[i].ori)
			a[i].cur = a[i].ori
			or |= a[i].ori
		}
		mask := 0
		pre := []int{}
		for mask != or {
			mxI := 0
			for i, p := range a {
				if p.cur > a[mxI].cur {
					mxI = i
				}
			}
			mask |= a[mxI].cur
			pre = append(pre, a[mxI].ori)
			a = append(a[:mxI], a[mxI+1:]...)
			for i := range a {
				a[i].cur &^=mask
			}
		}
		for _, v := range pre {
			Fprint(out, v, " ")
		}
		for _, v := range a {
			Fprint(out, v.ori, " ")
		}
		Fprintln(out)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

	// 如果是多组数据，请务必加上这段保险 —— 已经无法统计，有多少位竞赛选手在漏读数据上损失大把分数（包括我）
	// 此外，如果不小心写成了 scan(v) 而不是 scan(&v)，由于未传入指针，不会读入任何数据，这样本地运行一次就能立马发现错误
	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

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

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

package main

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

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

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

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

		bb := make([]bool, n)
		var z int
		for i := 31; i > 0; i-- {
			if z&(1<<(i-1)) > 0 {
				continue
			}

			d := -1
			var idx int
			for j, v := range aa {
				if bb[j] {
					continue
				}

				if v|z > d {
					d = v | z
					idx = j
				}
			}

			if d < 0 {
				break
			}
			z = d
			bb[idx] = true
			fmt.Fprintf(out, "%d ", aa[idx])
		}
		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)

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

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

		bb := make([]bool, n)
		fmt.Fprintf(out, "%d ", aa[0])
		z := aa[0]
		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}

			var d int
			var idx int
			for j := 1; j < n; j++ {
				if bb[j] {
					continue
				}

				if aa[j]|z > d {
					d = aa[j] | z
					idx = j
				}
			}
			z = d
			bb[idx] = true
			fmt.Fprintf(out, "%d ", aa[idx])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

		bb := make([]bool, n)
		bb[0] = true
		var z int
		for i := 0; i < bits.Len(uint(aa[0])); i++ {
			z = (z << 1) | 1
		}
		z = z ^ aa[0]
		fmt.Fprintf(out, "%d ", aa[0])
		stack := []int{}
		for i := 1; i < n; i++ {
			if aa[i] != aa[i-1] && aa[i]&z > 0 {
				bb[i] = true
				stack = append(stack, aa[i])
			}
		}

		sort.Slice(stack, func(i, j int) bool {
			return stack[i]|aa[0] > stack[j]|aa[0]
		})

		for _, v := range stack {
			fmt.Fprintf(out, "%d ", v)
		}
		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

		bb := make([]bool, n)
		bb[0] = true
		var z int
		for i := 0; i < bits.Len(uint(aa[0])); i++ {
			z = (z << 1) | 1
		}
		z = z ^ aa[0]
		fmt.Fprintf(out, "%d ", aa[0])
		for i := 1; i < n; i++ {
			if aa[i] != aa[i-1] && aa[i]&z > 0 {
				bb[i] = true
				fmt.Fprintf(out, "%d ", aa[i])
			}
		}

		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

		bb := make([]bool, n)
		bb[0] = true
		var z int
		for i := 0; i < bits.Len(uint(aa[0])); i++ {
			z = (z << 1) | 1
		}
		z = z ^ aa[0]
		fmt.Fprintf(out, "%d ", aa[0])
		for i := 1; i < n; i++ {
			if aa[i]&z > 0 {
				bb[i] = true
				fmt.Fprintf(out, "%d ", aa[i])
			}
		}

		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; ; i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				if newNow|a[j] > newNow {
					maxPos = j
					newNow |= a[j]
				}
			}

			if maxPos != -1 {
				a[i], a[maxPos] = a[maxPos], a[i]
			} else {
				break
			}

			now = newNow
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; ; i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				newNewNow := newNow | a[j]
				if newNewNow > newNow {
					maxPos = j
					newNow = newNewNow
				}
			}

			if maxPos != -1 {
				a[i], a[maxPos] = a[maxPos], a[i]
			} else {
				break
			}

			now = newNow
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; ; i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				newNewNow := now | a[j]
				if newNewNow > newNow {
					maxPos = j
					newNow = newNewNow
				}
			}

			if maxPos != -1 {
				a[i], a[maxPos] = a[maxPos], a[i]
			} else {
				break
			}
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

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

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

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

		var n int
		fmt.Fscan(r, &n)

		a := make([]int, n)
		cnt := make(map[int]int)
		max_ := 0
		prev_max_ := 0
		max_t := 0
		for i := range a {
			fmt.Fscan(r, &a[i])
			max_ = max(max_, a[i])
			max_t = max_
			cnt[a[i]]++
		}

		fmt.Fprintf(w, "%d ", max_t)
		cnt[max_t]--

		for max_ != prev_max_ {
			// fmt.Fprintf(w, "*** max_:%d prev_max_:%d\n", max_, prev_max_)
			prev_max_ = max_
			for _, v := range a {
				/*
				fmt.Fprintf(
					w,
					"--- v:%d cnt[v]:%d\n",
					v, cnt[v])
					*/
				if cnt[v] > 0  && (max_ | v) > max_ {
					max_ = max_ | v
					max_t = v
				}
			}

			if cnt[max_t] > 0 {
				fmt.Fprintf(w, "%d ", max_t)
				cnt[max_t]--
			}
		}

		for _, v := range a {
			if cnt[v] > 0 {
				fmt.Fprintf(w, "%d ", v)
				cnt[v]--
			}
		}
		fmt.Fprintln(w, "")

	}

}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		var n int
		Fscan(in, &n)
		var a, ok = []int{}, []int{}
		for i := 0; i < n; i++ {
			var x int
			Fscan(in, &x)
			a = append(a, x)
			ok = append(ok, 0)
		}
		var ans = []int{}
		now := 0
		for len(ans) < n {
			x, pos := 0, 0
			for i := 0; i < n; i++ {
				if ok[i] == 1 {
					continue
				}
				val := a[i] &^ now
				if val > x {
					x = val
					pos = i
				}
			}
			now = x
			if x > 0 {
				ok[pos] = 1
				ans = append(ans, a[pos])
				continue
			}
			for i := 0; i < n; i++ {
				val := a[i] &^ now
				if val == x && ok[i] == 0 {
					ok[i] = 1
					ans = append(ans, a[i])
				}
			}
		}
		for i := 0; i < n; i++ {
			Fprintf(out, "%d ", ans[i])
		}
		Fprintf(out, "\n")
	}
}

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


The only difference between easy and hard versions is on constraints. In this version constraints are higher. You can make hacks only if all versions of the problem are solved.Koa the Koala is at the beach!The beach consists (from left to right) of a shore, $$$n+1$$$ meters of sea and an island at $$$n+1$$$ meters from the shore.She measured the depth of the sea at $$$1, 2, \dots, n$$$ meters from the shore and saved them in array $$$d$$$. $$$d_i$$$ denotes the depth of the sea at $$$i$$$ meters from the shore for $$$1 \le i \le n$$$.Like any beach this one has tide, the intensity of the tide is measured by parameter $$$k$$$ and affects all depths from the beginning at time $$$t=0$$$ in the following way:  For a total of $$$k$$$ seconds, each second, tide increases all depths by $$$1$$$.  Then, for a total of $$$k$$$ seconds, each second, tide decreases all depths by $$$1$$$.  This process repeats again and again (ie. depths increase for $$$k$$$ seconds then decrease for $$$k$$$ seconds and so on ...).Formally, let's define $$$0$$$-indexed array $$$p = [0, 1, 2, \ldots, k - 2, k - 1, k, k - 1, k - 2, \ldots, 2, 1]$$$ of length $$$2k$$$. At time $$$t$$$ ($$$0 \le t$$$) depth at $$$i$$$ meters from the shore equals $$$d_i + p[t \bmod 2k]$$$ ($$$t \bmod 2k$$$ denotes the remainder of the division of $$$t$$$ by $$$2k$$$). Note that the changes occur instantaneously after each second, see the notes for better understanding. At time $$$t=0$$$ Koa is standing at the shore and wants to get to the island. Suppose that at some time $$$t$$$ ($$$0 \le t$$$) she is at $$$x$$$ ($$$0 \le x \le n$$$) meters from the shore:  In one second Koa can swim $$$1$$$ meter further from the shore ($$$x$$$ changes to $$$x+1$$$) or not swim at all ($$$x$$$ stays the same), in both cases $$$t$$$ changes to $$$t+1$$$.  As Koa is a bad swimmer, the depth of the sea at the point where she is can't exceed $$$l$$$ at integer points of time (or she will drown). More formally, if Koa is at $$$x$$$ ($$$1 \le x \le n$$$) meters from the shore at the moment $$$t$$$ (for some integer $$$t\ge 0$$$), the depth of the sea at this point  — $$$d_x + p[t \bmod 2k]$$$  — can't exceed $$$l$$$. In other words, $$$d_x + p[t \bmod 2k] \le l$$$ must hold always.  Once Koa reaches the island at $$$n+1$$$ meters from the shore, she stops and can rest.Note that while Koa swims tide doesn't have effect on her (ie. she can't drown while swimming). Note that Koa can choose to stay on the shore for as long as she needs and neither the shore or the island are affected by the tide (they are solid ground and she won't drown there). Koa wants to know whether she can go from the shore to the island. Help her!

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$)  — the number of test cases. Description of the test cases follows. The first line of each test case contains three integers $$$n$$$, $$$k$$$ and $$$l$$$ ($$$1 \le n \le 3 \cdot 10^5; 1 \le k \le 10^9; 1 \le l \le 10^9$$$) — the number of meters of sea Koa measured and parameters $$$k$$$ and $$$l$$$. The second line of each test case contains $$$n$$$ integers $$$d_1, d_2, \ldots, d_n$$$ ($$$0 \le d_i \le 10^9$$$)  — the depths of each meter of sea Koa measured. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case: Print Yes if Koa can get from the shore to the island, and No otherwise. You may print each letter in any case (upper or lower).

NoteIn the following $$$s$$$ denotes the shore, $$$i$$$ denotes the island, $$$x$$$ denotes distance from Koa to the shore, the underline denotes the position of Koa, and values in the array below denote current depths, affected by tide, at $$$1, 2, \dots, n$$$ meters from the shore.In test case $$$1$$$ we have $$$n = 2, k = 1, l = 1, p = [ 0, 1 ]$$$.Koa wants to go from shore (at $$$x = 0$$$) to the island (at $$$x = 3$$$). Let's describe a possible solution:  Initially at $$$t = 0$$$ the beach looks like this: $$$[\underline{s}, 1, 0, i]$$$.  At $$$t = 0$$$ if Koa would decide to swim to $$$x = 1$$$, beach would look like: $$$[s, \underline{2}, 1, i]$$$ at $$$t = 1$$$, since $$$2 > 1$$$ she would drown. So Koa waits $$$1$$$ second instead and beach looks like $$$[\underline{s}, 2, 1, i]$$$ at $$$t = 1$$$.  At $$$t = 1$$$ Koa swims to $$$x = 1$$$, beach looks like $$$[s, \underline{1}, 0, i]$$$ at $$$t = 2$$$. Koa doesn't drown because $$$1 \le 1$$$.  At $$$t = 2$$$ Koa swims to $$$x = 2$$$, beach looks like $$$[s, 2, \underline{1}, i]$$$ at $$$t = 3$$$. Koa doesn't drown because $$$1 \le 1$$$.  At $$$t = 3$$$ Koa swims to $$$x = 3$$$, beach looks like $$$[s, 1, 0, \underline{i}]$$$ at $$$t = 4$$$.  At $$$t = 4$$$ Koa is at $$$x = 3$$$ and she made it! We can show that in test case $$$2$$$ Koa can't get to the island.

/*
Attempting https://codeforces.com/contest/1384/problem/B2
which will take care of B1 also, if works
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line1, _ := reader.ReadString('\n')
	line1_arr := strings.Fields(line1)
	// fmt.Println(line1_arr)
	T, _ := strconv.Atoi(line1_arr[0])
	//fmt.Println("T:", T)
	for t := 0; t < T; t++ {
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		N, _ := strconv.Atoi(line2_arr[0])
		K, _ := strconv.Atoi(line2_arr[1])
		L, _ := strconv.Atoi(line2_arr[2])
		// fmt.Println(N, K, L)
		line3, _ := reader.ReadString('\n')
		Astr := strings.Fields(line3)
		A := make([]int, N)
		var safe []int
		soln_possible := true
		for i:=0; i<N; i++ {
			A[i], _ = strconv.Atoi(Astr[i])
			if A[i] + K <= L {
				safe = append(safe, i)
			} else if A[i] > L {
				fmt.Println("No")
				soln_possible = false
				break
			}
		}
		//fmt.Println("A:", A)
		//fmt.Println("safe:", safe)

		if !soln_possible {
			continue
		}

		safe_ind := 0
		lower_bound := -1
		upper_bound := N
		if len(safe) > 0 {
			upper_bound = safe[safe_ind]
		}
		res := "Yes"
		for true {

			retval := is_path_safe(lower_bound, upper_bound, K, L, A)
			//fmt.Println("is_path_safe() beg: ", lower_bound, "end: ", upper_bound, "retval: ", retval)
			if !retval {
				res = "No"
				break
			} else {
				if safe_ind > len(safe) -1 {
					break
				}

				lower_bound = safe[safe_ind]
				safe_ind++
				if safe_ind > len(safe) -1 {
					upper_bound = N
				} else {
					upper_bound = safe[safe_ind]
				}
			}
		}

		fmt.Println(res)
	}
}

func is_path_safe(beg, end, K, L int, A []int) bool {
	abeg := beg + 1
	aend := end - 1
	if abeg >= aend {
		return true
	}

	t := 0
	for i:=abeg; i<=aend; i++ {
		t = get_time_to_enter(K, L, t, A[i])
		//fmt.Println("t: ", t)
		if t < 0 {
			return false
		}
	}

	// last step
	t++

	//fmt.Println("t: ", t)
	if t > 2*K {
		return false
	}

	return true
}

/*
The precise time pos, where we can enter that position
*/
func get_time_to_enter(K, L, t, d int) int {

	t++
	x := d + K - L
	if t >= x && t <= 2 * K - x {
		return t
	} else if t < x {
		return x
	} else {
		return -1
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

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

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

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

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

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

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

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

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

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

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

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

type tide struct {
	d int64 // delta
	i bool  // increasing - false by default
}

// Next adjusts the tide level to the next most optimal value
// Returns false if unable to do so
func (t *tide) Next(currDepth int64, k, l int64) bool {
	// rest spot -> reset params
	if currDepth + k <= l {
		t.d = k
		t.i = false
		return true
	}

	// tide decreasing -> check min
	if !t.i {
		t.d--
		if currDepth + t.d > l {
			t.d = l - currDepth
		}
		if t.d < 0 {
			return false
		}
		if t.d == 0 {
			t.i = true
		}
		return true
	}

	// tide increasing
	t.d++
	if currDepth + t.d > l {
		return false
	}
	if t.d == k {
		t.i = false
	}
	return true
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		k := sint64()
		l := sint64()
		d := make([]int64, n)
		for i := range d {
			d[i] = sint64()
		}
		printf("%s\n", sol(d, n, k, l))
	}
}

func sol(d []int64, n, k, l int64) string {
	t := &tide{
		d: k,
		i: false,
	}
	for _, di := range d {
		if !t.Next(di, k, l) {
			return "No"
		}
	}
	return "Yes"
}

/*
Attempting https://codeforces.com/contest/1384/problem/B2
which will take care of B1 also, if works
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line1, _ := reader.ReadString('\n')
	line1_arr := strings.Fields(line1)
	// fmt.Println(line1_arr)
	T, _ := strconv.Atoi(line1_arr[0])
	//fmt.Println("T:", T)
	for t := 0; t < T; t++ {
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		N, _ := strconv.Atoi(line2_arr[0])
		K, _ := strconv.Atoi(line2_arr[1])
		L, _ := strconv.Atoi(line2_arr[2])
		// fmt.Println(N, K, L)
		line3, _ := reader.ReadString('\n')
		Astr := strings.Fields(line3)
		A := make([]int, N)
		var safe []int
		soln_possible := true
		for i:=0; i<N; i++ {
			A[i], _ = strconv.Atoi(Astr[i])
			if A[i] + K <= L {
				safe = append(safe, i)
			} else if A[i] > L {
				fmt.Println("No")
				soln_possible = false
				break
			}
		}
		//fmt.Println("A:", A)
		//fmt.Println("safe:", safe)

		if !soln_possible {
			continue
		}

		safe_ind := 0
		lower_bound := -1
		upper_bound := N
		if len(safe) > 0 {
			upper_bound = safe[safe_ind]
		}
		res := "Yes"
		for true {

			retval := is_path_safe(lower_bound, upper_bound, K, L, A)
			//	fmt.Println("is_path_safe() beg: ", lower_bound, "end: ", upper_bound, "retval: ", retval)
			if !retval {
				res = "No"
				break
			} else {
				if safe_ind > len(safe) -1 {
					break
				}

				lower_bound = safe[safe_ind]
				safe_ind++
				if safe_ind > len(safe) -1 {
					upper_bound = N
				} else {
					upper_bound = safe[safe_ind]
				}
			}
		}

		fmt.Println(res)
	}
}

func is_path_safe(beg, end, K, L int, A []int) bool {
	abeg := beg + 1
	aend := end - 1
	if abeg >= aend {
		return true
	}

	t := 0
	k := K
	for i:=abeg; i<=aend; i++ {
		x := A[i] + k - L
		if x > 0 {
			t += x
			k = get_k_phase(K, k, t)
		} else {
			t++
		}

	}

	// fmt.Println("t: ", t)
	if t >= 2*K {
		return false
	}

	return true
}

func get_k_phase(K, k, t int) int {
	t %= 2*K
	if t <= K {
		return k - t
	} else {
		return k
	}
}


You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).

For each test case, print the answer:   "NO" in the only line of the output if a solution doesn't exist;  or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		a := make([]int, 3)
		for i := 0; i < 3; i++ {
			a[i] = NextInt()
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		if a[0] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[0])
		} else if a[1] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[1])
		} else {
			Println("NO")
		}
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

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

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

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

func main() {
	defer out.Flush()
	var nTest int
	fmt.Fscanf(in, "%d\n", &nTest)
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}
func solveCase() {
	var a [3]int
	fmt.Fscanf(in, "%d %d %d\n", &a[0], &a[1], &a[2])
	sort.Ints(a[:])
	if a[1] != a[2] {
		fmt.Fprint(out, "NO\n")
	} else {
		fmt.Fprint(out, "YES\n")
		fmt.Fprintf(out, "%d %d %d\n", a[0], a[0], a[1])
	}
}

package main

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

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

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

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

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

	for _case := 1; _case <= T; _case++ {
		input := readInts()
		sort.Ints(input)
		if input[0] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0], input[0], input[0])
		} else if input[1] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0], input[0], input[1])
		} else {
			fmt.Println("NO")
		}
		//fmt.Fprintf(writer, "Case #%d: %d %d\n", _case, x, y)
	}

	writer.Flush()
}

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

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

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

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

package main

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

func main() {
	var t int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)
	fmt.Fscanln(scr, &t)

	for i := 0; i < t; i++ {
		a := make([]int, 3)
		fmt.Fscanln(scr, &a[0], &a[1], &a[2])

		sort.Ints(a)
		if a[2] != a[1] {
			fmt.Fprintln(ocr, "NO")
		} else {
			fmt.Fprintln(ocr, "YES")
			fmt.Fprintln(ocr, a[2], 1, a[0])
		}
		ocr.Flush()
	}
}

package main

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

func main() {
	var t int
	var a [3]int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		m := max(a[0], a[1])
		m = max(m, a[2])
		min := a[0]
		count := 0
		for j := 0; j < 3; j++ {
			if m == a[j] {
				count++
			} else {
				min = a[j]
			}
		}
		if count >= 2 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", m, min, min)
		} else {
			fmt.Println("NO")
		}
	}
}

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

package main
// https://codeforces.com/contest/1380/submission/87050098
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

import (
	"sort"
)

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadText() string {
	fi.scanner.Scan()
	return fi.scanner.Text()
}

func (fi *FastIn) ReadInt() int {
	ret, err := strconv.Atoi(fi.ReadText())
	if err != nil {
		panic(err)
	}
	return ret
}

func (fi *FastIn) ReadInts(arr []int) {
	for i := 0; i < len(arr); i++ {
		arr[i] = fi.ReadInt()
	}
}
func Min (a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func (fi *FastIn) ReadInt64() int64 {
	ret, err := strconv.ParseInt(fi.ReadText(), 10, 64)
	if err != nil {
		panic(err)
	}
	return ret
}

var x,k,y int64

func GetCost(arr []int, left_b int, right_b int) (int64, bool) {
	any_gt := false
	max_bound := left_b
	if max_bound < right_b {
		max_bound = right_b
	}
	for _,v := range arr {
		if  v > max_bound {
			any_gt = true
		}
	}

	len := int64(len(arr))
	if any_gt {
		if len < k {
			return 0, false
		}
		return Min((len/k)*x+(len%k)*y,x+(len-k)*y), true
	} else {
		return Min((len/k)*x+(len%k)*y, len * y), true
	}
}

func main() {
	fin := MakeFastIn()
	T := fin.ReadInt()
	for ;T>0;T--{
		a:= make([]int, 3)
		fin.ReadInts(a)

		sort.Ints(a[:])
		if a[1]==a[2] {
			fmt.Println("YES")
			fmt.Println(a[0],a[1],1)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	testCountStr, _ := reader.ReadString('\n')
	testCountStr = strings.Trim(testCountStr, " \r\n")
	testCountVal64, _ := strconv.ParseInt(testCountStr, 10, 32)
	testCountVal := int(testCountVal64)

	for i := 0; i < testCountVal; i++ {
		val1Str, _ := reader.ReadString(' ')
		val2Str, _ := reader.ReadString(' ')
		val3Str, _ := reader.ReadString('\n')

		val1, _ := strconv.ParseInt(strings.Trim(val1Str, " \r\n"), 10, 32)
		val2, _ := strconv.ParseInt(strings.Trim(val2Str, " \r\n"), 10, 32)
		val3, _ := strconv.ParseInt(strings.Trim(val3Str, " \r\n"), 10, 32)

		switch {
		case val1 == val2 && val2 == val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val1)
			}
		case val1 == val2 && val3 < val1:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val3, val3)
			}
		case val3 == val2 && val1 < val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val3)
			}
		case val1 == val3 && val2 < val1:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val2, val2)
			}
		default:
			{
				fmt.Println("NO")
			}
		}
	}
}

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-- {
		a := []int{io.nextInt(), io.nextInt(), io.nextInt()}
		sort.Ints(a)
		if a[1] == a[2] {
			io.println("YES")
			io.println(a[0], a[0], a[1])
		} else {
			io.println("NO")
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p []byte
}

func newFastIO(r io.Reader, w io.Writer) fastIO {
	return fastIO{bufio.NewReader(r), bufio.NewWriter(w), make([]byte, 1)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p)
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p)
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p)
	}
	return n
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

// https://codeforces.com/contest/x/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

var x, y, z int
func solver() {
	fmt.Fscan(input, &x, &y, &z)

	if x == y && z <= x {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else if x == z && y <= z {
		fmt.Println("YES")
		fmt.Println(x, y, y)
	} else if z == y && x <= z {
		fmt.Println("YES")
		fmt.Println(z, x, x)
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

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

func solve(a []int) {

	max := 0
	sndMax := 0
	for _, v := range a {
		if v > max {
			sndMax = max
			max = v
		} else if v > sndMax && v != max {
			sndMax = v
		}
	}

	count := 0
	for _, v := range a {
		if v == max {
			count++
		}
	}

	if count == 2 {
		printf("YES\n")
		printf("%d %d %d\n", max, sndMax, 1)
	} else if count == 3 {
		printf("YES\n")
		printf("%d %d %d\n", max, max, max)
	} else {
		printf("NO\n")
	}

}

func main() {
	defer writer.Flush()

	var testCases int
	scanf("%d\n", &testCases)
	for i := 0; i < testCases; i++ {
		var x, y, z int
		scanf("%d %d %d", &x, &y, &z)
		// printf("%d %d %d\n", x, y, z)
		scanf("\n")
		solve([]int{x, y, z})
	}
}

package main

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

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

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

	for t := input(); t > 0; t-- {
		arr := make([]int, 3)

		for i := range arr {
			arr[i] = input()
		}

		sort.Ints(arr)

		if arr[2] == arr[1] {
			fmt.Println("YES")
			fmt.Println(arr[0], arr[0], arr[2])
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var x, y, z int
		fmt.Fscan(in, &x)
		fmt.Fscan(in, &y)
		fmt.Fscan(in, &z)

		if x == y && x == z {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", x, x, x)
		} else if x == y && x > z {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", z, z, x)
		} else if x == z && x > y {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", y, y, x)
		} else if y == z && y > x {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", x, x, y)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var x, y, z int64
		line := readLine(reader)
		strs := strings.Split(string(line), " ")
		x, _ = strconv.ParseInt(strs[0], 10, 64)
		y, _ = strconv.ParseInt(strs[1], 10, 64)
		z, _ = strconv.ParseInt(strs[2], 10, 64)
		if x != y && x != z && y != z {
			fmt.Println("NO")
			continue
		}
		if x == y && z > x || (x == z && y > x) || (y == z && x > y) {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		if x == y && x == z {
			fmt.Println(x, y, z)
			continue
		}
		if x == y {
			fmt.Println(x, z, z)
		} else if x == z {
			fmt.Println(y, x, y)
		} else {
			fmt.Println(x, x, z)
		}
	}
}

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
}

package main

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

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

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

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

package main

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

func solve() {
	x, y, z := readInt(), readInt(), readInt()

	if x == y && y == z {
		fmt.Println("YES")
		fmt.Println(x, x, x)
		return
	}

	if x != y && y != z && z != x {
		fmt.Println("NO")
		return
	}

	if x == y {
		if x > z {
			fmt.Println("YES")
			fmt.Println(x, z, z)
		} else {
			fmt.Println("NO")
		}
	} else if y == z {
		if y > x {
			fmt.Println("YES")
			fmt.Println(x, x, z)
		} else {
			fmt.Println("NO")
		}
	} else if z == x {
		if x > y {
			fmt.Println("YES")
			fmt.Println(y, x, y)
		} else {
			fmt.Println("NO")
		}
	}
}

func main() {
	k := readInt()
	for i := 0; i < k; i++ {
		solve()
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

func readInt() int {
	return int(readInt64())
}

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

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

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

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

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

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}

package main

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

func main() {
	var t uint16
	var x, y, z uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &t)
	for i := uint16(0); i < t; i++ {
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		if x == y {
			if z <= x {
				fmt.Println("YES")
				fmt.Println(z, z, y)
			} else {
				fmt.Println("NO")
			}
		} else if x == z {
			if y <= x {
				fmt.Println("YES")
				fmt.Println(y, y, x)
			} else {
				fmt.Println("NO")
			}
		} else if y == z {
			if x <= y {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var t, x, y, z int
	scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		scanf("%d %d %d\n", &x, &y, &z)
		cnt, max := 1, 0
		if x > max {
			max = x
			cnt = 1
		}
		if y > max {
			max = y
			cnt = 1
		} else if y == max {
			cnt++
		}

		if z > max {
			max = z
			cnt = 1
		} else if z == max {
			cnt++
		}

		if cnt == 1 {
			printf("NO\n")
		} else if cnt == 3 {
			printf("YES\n%d %d %d\n", x, y, z)
		} else {
			printf("YES\n")
			if x != max {
				printf("%d %d %d\n", x, x, max)
			} else if y != max {
				printf("%d %d %d\n", y, max, y)
			} else {
				printf("%d %d %d\n", max, z, z)
			}
		}
	}

}

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		a := make([]int, 3)
		for i := 0; i < 3; i++ {
			a[i] = NextInt()
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		if a[0] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[0])
		} else if a[1] == a[2] {
			Println("YES")
			Print(a[1]-1)
			Print(" ")
			Print(a[1])
			Print(" ")
			Println(a[2])
		} else {
			Println("NO")
		}
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

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

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		a := make([]int, 3)
		for i := 0; i < 3; i++ {
			a[i] = NextInt()
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		if a[0] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[0])
		} else if a[1] == a[2] {
			Println("YES")
			Print(a[0]-1)
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[1])
		} else {
			Println("NO")
		}
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

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

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

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

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

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

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

	for _case := 1; _case <= T; _case++ {
		input := readInts()
		sort.Ints(input)
		if input[0] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0], input[0], input[0])
		} else if input[1] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0]-1, input[0], input[1])
		} else {
			fmt.Println("NO")
		}
		//fmt.Fprintf(writer, "Case #%d: %d %d\n", _case, x, y)
	}

	writer.Flush()
}

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

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

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

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

package main

import (
	"fmt"
	"sort"
)

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

	for i := 0; i < t; i++ {
		a := make([]int, 3)
		fmt.Scanln(&a[0], &a[1], &a[2])

		m := make(map[int]int)
		m[a[0]]++
		m[a[1]]++
		m[a[2]]++

		sort.Ints(a)

		if len(m) == 3 {
			fmt.Println("NO")
		} else {
			if m[a[2]] >= 2 {
				fmt.Println("YES")
				fmt.Println(a[2], a[2]-1, a[0])
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var T int
	fmt.Scanf("%d", &T)
	for ;T>0;T--{
		var a[3] int
		for i:=0 ;i<3;i++{
			fmt.Scanf("%d", &a[i])
		}
		sort.Ints(a[:])
		if a[1]==a[2] {
			fmt.Println("YES")
			fmt.Println(a[0],a[1],1)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"
import "math"

func main() {
	var testCount int

	fmt.Scanf("%d", &testCount)

	for i := 0; i < testCount; i++ {
		inputCount := 3
		vals := make([]int, 3)

		for j := 0; j < inputCount; j++ {
			fmt.Scanf("%d", &vals[j])
		}

		var max = -999
		var min = 2000000000
		for j := 0; j < inputCount; j++ {
			max = int(math.Max(float64(max), float64(vals[j])))
			min = int(math.Min(float64(min), float64(vals[j])))
		}
		var maxAppearTimes = 0
		for j := 0; j < inputCount; j++ {
			if vals[j] == max {
				maxAppearTimes++
			}
		}

		switch {
		case maxAppearTimes == 2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d", max, min, min)
			}
		case maxAppearTimes == 3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d", max, max, max)
			}
		default:
			{
				fmt.Println("NO")
			}
		}

		// 1 2 3: 2 3 3
		// 1 1 3: 1 3 3
		// 1 3 3: 3 3 3
		// 3 3 3: 3 3 3
	}
}

package main

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

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

	testCountStr, _ := reader.ReadString('\n')
	testCountVal64, _ := strconv.ParseInt(testCountStr, 10, 32)
	testCountVal := int(testCountVal64)

	for i := 0; i < testCountVal; i++ {
		val1Str, _ := reader.ReadString(' ')
		val2Str, _ := reader.ReadString(' ')
		val3Str, _ := reader.ReadString('\n')

		val1, _ := strconv.ParseInt(val1Str, 10, 32)
		val2, _ := strconv.ParseInt(val2Str, 10, 32)
		val3, _ := strconv.ParseInt(val3Str, 10, 32)

		switch {
		case val1 == val2 && val2 == val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val1)
			}
		case val1 == val2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val3)
			}
		case val3 == val2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val3, val3)
			}
		case val1 == val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val2)
			}
		default:
			{
				fmt.Println("NO")
			}
		}
	}
}

package main

import "fmt"
import "math"

func main() {
	var testCount int

	fmt.Scanf("%d", &testCount)

	for i := 0; i < testCount; i++ {
		inputCount := 3
		vals := make([]int, 3)

		for j := 0; j < inputCount; j++ {
			fmt.Scanf("%d", &vals[j])
		}

		var max = -999
		var min = 2000000000
		for j := 0; j < inputCount; j++ {
			max = int(math.Max(float64(max), float64(vals[j])))
			min = int(math.Min(float64(min), float64(vals[j])))
		}
		var maxAppearTimes = 0
		for j := 0; j < inputCount; j++ {
			if vals[j] == max {
				maxAppearTimes++
			}
		}

		switch {
		case maxAppearTimes == 2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", max, min, min)
			}
		case maxAppearTimes == 3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", max, max, max)
			}
		default:
			{
				fmt.Println("NO")
			}
		}

		// 1 2 3: 2 3 3
		// 1 1 3: 1 3 3
		// 1 3 3: 3 3 3
		// 3 3 3: 3 3 3
	}
}

// https://codeforces.com/contest/x/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

var x, y, z int
func solver() {
	fmt.Fscan(input, &x, &y, &z)

	if x == y && z <= x {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else if x == z && y <= z {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else if z == y && x <= z {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var x, y, z int64
		fmt.Scanf("%d %d %d\n", &x, &y, &z)
		if x != y && x != z && y != z {
			fmt.Println("NO")
			continue
		}
		if x == y && z > x || (x == z && y > x) || (y == z && x > y) {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		if x==y && x == z {
			fmt.Println(x, y, z)
			continue
		}
		if x == y {
			fmt.Println(x, z, z)
		} else if x == z {
			fmt.Println(x, y, y)
		} else  {
			fmt.Println(x, z, z)
		}
	}
}

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
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var x, y, z int64
		line := readLine(reader)
		strs := strings.Split(string(line), " ")
		x, _ = strconv.ParseInt(strs[0], 10, 64)
		y, _ = strconv.ParseInt(strs[1], 10, 64)
		z, _ = strconv.ParseInt(strs[2], 10, 64)
		if x != y && x != z && y != z {
			fmt.Println("NO")
			continue
		}
		if x == y && z > x || (x == z && y > x) || (y == z && x > y) {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		if x == y && x == z {
			fmt.Println(x, y, z)
			continue
		}
		if x == y {
			fmt.Println(x, z, z)
		} else if x == z {
			fmt.Println(y, x, y)
		} else {
			fmt.Println(x, z, z)
		}
	}
}

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
}

package main

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

func main() {
	var t uint16
	var x, y, z uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &t)
	for i := uint16(0); i < t; i++ {
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		if x == y {
			if z <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else if x == z {
			if y <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else if y == z {
			if x <= y {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var t uint16
	var x, y, z uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &t)
	for i := uint16(0); i < t; i++ {
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		if x == y {
			if z <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else if x == z {
			if y <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else {
			// y == z
			if x <= y {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

import "fmt"

func main() {
	var t, x, y, z int
	fmt.Scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		fmt.Scanf("%d %d %d\n", &x, &y, &z)
		cnt, max := 1, 0
		if x > max {
			max = x
			cnt = 1
		}
		if y > max {
			max = y
			cnt = 1
		} else if y == max {
			cnt = 2
		}

		if z > max {
			max = z
			cnt = 1
		} else if z == max {
			cnt++
		}

		if cnt == 1 {
			fmt.Println("NO")
		} else if cnt == 2 {
			fmt.Println("YES")
			fmt.Println(x, y, z)
		} else {
			fmt.Println("YES")
			if x != max {
				fmt.Println(x, x, max)
			} else if y != max {
				fmt.Println(y, max, y)
			} else {
				fmt.Println(max, z, z)
			}
		}
	}

}


Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!When building the graph, he needs four conditions to be satisfied:   It must be a simple undirected graph, i.e. without multiple (parallel) edges and self-loops.  The number of vertices must be exactly $$$n$$$ — a number he selected. This number is not necessarily prime.  The total number of edges must be prime.  The degree (i.e. the number of edges connected to the vertex) of each vertex must be prime. Below is an example for $$$n = 4$$$. The first graph (left one) is invalid as the degree of vertex $$$2$$$ (and $$$4$$$) equals to $$$1$$$, which is not prime. The second graph (middle one) is invalid as the total number of edges is $$$4$$$, which is not a prime number. The third graph (right one) is a valid answer for $$$n = 4$$$.   Note that the graph can be disconnected.Please help Bob to find any such graph!

The input consists of a single integer $$$n$$$ ($$$3 \leq n \leq 1\,000$$$) — the number of vertices.

If there is no graph satisfying the conditions, print a single line containing the integer $$$-1$$$. Otherwise, first print a line containing a prime number $$$m$$$ ($$$2 \leq m \leq \frac{n(n-1)}{2}$$$) — the number of edges in the graph. Then, print $$$m$$$ lines, the $$$i$$$-th of which containing two integers $$$u_i$$$, $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$) — meaning that there is an edge between vertices $$$u_i$$$ and $$$v_i$$$. The degree of each vertex must be prime. There must be no multiple (parallel) edges or self-loops. If there are multiple solutions, you may print any of them. Note that the graph can be disconnected.

NoteThe first example was described in the statement.In the second example, the degrees of vertices are $$$[7, 5, 2, 2, 3, 2, 2, 3]$$$. Each of these numbers is prime. Additionally, the number of edges, $$$13$$$, is also a prime number, hence both conditions are satisfied.

/*
URL:
https://codeforces.com/problemset/problem/1178/D
*/

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 (
	n int

	A [][2]int
)

func main() {
	n = ReadInt()

	p := n
	for i := 0; ; i++ {
		if IsPrime(p) {
			break
		}
		p++
	}

	for i := 1; i <= n; i++ {
		var e [2]int
		if i == n {
			e = [2]int{n, 1}
		} else {
			e = [2]int{i, i + 1}
		}

		A = append(A, e)
	}

	nokori := p - n
	for i := 0; i < nokori; i++ {
		s := 1 + i
		t := s + n/2
		A = append(A, [2]int{s, t})
	}

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

// IsPrime judges whether an argument integer is a prime number or not.
func IsPrime(n int) bool {
	if n == 1 {
		return false
	}

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

	return true
}

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

/*********** 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 reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func next(n int) int {
	for isPrime(n) == false {
		n++
	}
	return n
}
func main() {
	defer writer.Flush()

	var n int
	scanf("%d", &n)
	nxt := next(n)
	printf("%d\n", nxt)
	for i := 0; i < n; i++ {
		printf("%d %d\n", i+1, (i+1)%n+1)
	}
	p1 := 2
	p2 := n
	for i := 0; i < nxt-n; i++ {
		printf("%d %d\n", p1, p2)
		p1++
		p2--
	}
}

package main
import "fmt"
func check(x int) bool{
	for i:=2;i*i<=x;i++{
		if x%i==0{
			return false
		}
	}
	return true
}
func main() {
	var n int
	fmt.Scanf("%d",&n)
	num:=0
	for i:=n;i<=2*n;i++{
		if check(i){
			num=i
			break
		}
	}
	fmt.Printf("%d\n",num)
	for i:=1;i<n;i++{
		fmt.Printf("%d %d\n",i,i+1)
	}
	fmt.Printf("%d 1\n",n)
	num=num-n
	for i:=1;i<=num;i++{
		fmt.Printf("%d %d\n",i,n-i)
	}
}


After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it N rows with M trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the j-th tree in the i-th row would have the coordinates of (i, j). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation.The burning began in K points simultaneously, which means that initially K trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1.Find the tree that will be the last to start burning. If there are several such trees, output any.

The first input line contains two integers N, M (1 ≤ N, M ≤ 2000) — the size of the forest. The trees were planted in all points of the (x, y) (1 ≤ x ≤ N, 1 ≤ y ≤ M) type, x and y are integers. The second line contains an integer K (1 ≤ K ≤ 10) — amount of trees, burning in the beginning.  The third line contains K pairs of integers: x1, y1, x2, y2, ..., xk, yk (1 ≤ xi ≤ N, 1 ≤ yi ≤ M) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide.

Output a line with two space-separated integers x and y — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any.

package main

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

type Empty struct{}
type pair struct {
	X int32
	Y int32
}

func neighbors(x, y, n, m int32) []*pair {
	res := make([]*pair, 0)
	if y-1 > 0 {
		res = append(res, &pair{X: x, Y: y - 1})
	}
	if y+1 <= m {
		res = append(res, &pair{X: x, Y: y + 1})
	}
	if x+1 <= n {
		res = append(res, &pair{X: x + 1, Y: y})
	}
	if x-1 > 0 {
		res = append(res, &pair{X: x - 1, Y: y})
	}
	return res

}

func main() {
	iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 0777)
	oFile, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_RDWR, 0777)
	reader := bufio.NewReader(iFile)
	writer := bufio.NewWriter(oFile)
	//reader := bufio.NewReader(os.Stdin)
	//writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, m, k, x, y, i int32
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	fmt.Fscanf(reader, "%d\n", &k)
	var visited [2001][2001]int8
	queue := make([]*pair, 0)
	for i = 0; i < k; i++ {
		fmt.Fscanf(reader, "%d %d", &x, &y)
		queue = append(queue, &pair{X: x, Y: y})
		visited[x][y] = 1
	}
	fmt.Fscanf(reader, "\n")
	var last *pair
	for len(queue) != 0 {
		p := queue[0]
		//fmt.Println(p)
		last = p
		queue = queue[1:]
		for _, q := range neighbors(p.X, p.Y, n, m) {
			if visited[q.X][q.Y] == 0 {
				visited[q.X][q.Y] = 1
				queue = append(queue, q)
			}
		}
	}
	fmt.Fprintf(writer, "%d %d\n", last.X, last.Y)
}

package main

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

type Empty struct{}
type pair struct {
	X int16
	Y int16
}

func neighbors(x, y, n, m int16) []pair {
	res := make([]pair, 0)
	if y-1 > 0 {
		res = append(res, pair{X: x, Y: y - 1})
	}
	if y+1 <= m {
		res = append(res, pair{X: x, Y: y + 1})
	}
	if x+1 <= n {
		res = append(res, pair{X: x + 1, Y: y})
	}
	if x-1 > 0 {
		res = append(res, pair{X: x - 1, Y: y})
	}
	return res

}
func main() {
	// iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 0777)
	// oFile, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_RDWR, 0777)
	// reader := bufio.NewReader(iFile)
	// writer := bufio.NewWriter(oFile)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, m, k, x, y, i int16
	var idx int32
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	fmt.Fscanf(reader, "%d\n", &k)
	visited := make(map[int32]Empty)
	queue := make([]pair, 0)
	for i = 0; i < k; i++ {
		fmt.Fscanf(reader, "%d %d", &x, &y)
		queue = append(queue, pair{X: x, Y: y})
		visited[int32(y)*int32(m)+int32(x)] = Empty{}
	}
	fmt.Fscanf(reader, "\n")
	var last pair
	for len(queue) != 0 {
		p := queue[0]
		//fmt.Println(p)
		last = p
		queue = queue[1:]
		for _, q := range neighbors(p.X, p.Y, n, m) {
			idx = int32(q.Y)*int32(m) + int32(q.X)
			if _, ok := visited[idx]; !ok {
				visited[idx] = Empty{}
				queue = append(queue, q)
			}
		}
	}
	fmt.Fprintf(writer, "%d %d\n", last.X, last.Y)

}

package main

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

type Empty struct{}
type pair struct {
	X int16
	Y int16
}

func neighbors(x, y, n, m int16) []pair {
	res := make([]pair, 0)
	if y-1 > 0 {
		res = append(res, pair{X: x, Y: y - 1})
	}
	if y+1 <= m {
		res = append(res, pair{X: x, Y: y + 1})
	}
	if x+1 <= n {
		res = append(res, pair{X: x + 1, Y: y})
	}
	if x-1 > 0 {
		res = append(res, pair{X: x - 1, Y: y})
	}
	return res

}
func main() {
	iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 0777)
	oFile, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_RDWR, 0777)
	reader := bufio.NewReader(iFile)
	writer := bufio.NewWriter(oFile)
	//reader := bufio.NewReader(os.Stdin)
	//writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, m, k, x, y, i int16
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	fmt.Fscanf(reader, "%d\n", &k)
	visited := make(map[int16]Empty)
	queue := make([]pair, 0)
	for i = 0; i < k; i++ {
		fmt.Fscanf(reader, "%d %d", &x, &y)
		queue = append(queue, pair{X: x, Y: y})
		visited[y*m+x] = Empty{}
	}
	fmt.Fscanf(reader, "\n")
	var last pair
	for len(queue) != 0 {
		p := queue[0]
		last = p
		queue = queue[1:]
		for _, q := range neighbors(p.X, p.Y, n, m) {
			idx := q.Y*m + q.X
			if _, ok := visited[idx]; !ok {
				visited[idx] = Empty{}
				queue = append(queue, q)
			}
		}
	}
	fmt.Fprintf(writer, "%d %d\n", last.X, last.Y)

}


Ilya lives in a beautiful city of Chordalsk.There are $$$n$$$ houses on the street Ilya lives, they are numerated from $$$1$$$ to $$$n$$$ from left to right; the distance between every two neighboring houses is equal to $$$1$$$ unit. The neighboring houses are $$$1$$$ and $$$2$$$, $$$2$$$ and $$$3$$$, ..., $$$n-1$$$ and $$$n$$$. The houses $$$n$$$ and $$$1$$$ are not neighboring.The houses are colored in colors $$$c_1, c_2, \ldots, c_n$$$ so that the $$$i$$$-th house is colored in the color $$$c_i$$$. Everyone knows that Chordalsk is not boring, so there are at least two houses colored in different colors.Ilya wants to select two houses $$$i$$$ and $$$j$$$ so that $$$1 \leq i < j \leq n$$$, and they have different colors: $$$c_i \neq c_j$$$. He will then walk from the house $$$i$$$ to the house $$$j$$$ the distance of $$$(j-i)$$$ units.Ilya loves long walks, so he wants to choose the houses so that the distance between them is the maximum possible.Help Ilya, find this maximum possible distance.

The first line contains a single integer $$$n$$$ ($$$3 \leq n \leq 300\,000$$$) — the number of cities on the street. The second line contains $$$n$$$ integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \leq c_i \leq n$$$) — the colors of the houses. It is guaranteed that there is at least one pair of indices $$$i$$$ and $$$j$$$ so that $$$1 \leq i < j \leq n$$$ and $$$c_i \neq c_j$$$.

Print a single integer — the maximum possible distance Ilya can walk.

NoteIn the first example the optimal way is to walk from the first house to the last one, where Ilya can walk the distance of $$$5-1 = 4$$$ units.In the second example the optimal way is to either walk from the first house to the second or from the second to the third. Both these ways have the distance of $$$1$$$ unit.In the third example the optimal way is to walk from the third house to the last one, where Ilya can walk the distance of $$$7-3 = 4$$$ units.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0
	fmt.Fscan(in, &n)
	houseColor := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &houseColor[i])
	}
	for i := 1; i < n; i++ {
		if houseColor[0] != houseColor[n-i] {
			fmt.Println(n - i)
			break
		}
		if houseColor[n-1] != houseColor[i-1] {
			fmt.Println(n - i)
			break
		}
	}
}

package main

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

func main() {
	var n, cnt int
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	M := make(map[int][]int)
	B := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(scr, "%d", &B[i])
		if i == 0 {
			M[B[i]] = append(M[B[i]], i)
		} else if i == n-1 {
			M[B[i]] = append(M[B[i]], i)
		}
	}

	if len(M) == 2 {
		fmt.Println(n - 1)
	} else {
		for i := 1; i < n-1; i++ {
			if B[i] != B[0] {
				cnt = M[B[0]][1] - i
				break
			}
		}
		for i := n - 2; i >= 1; i-- {
			if B[i] != B[0] {
				if cnt < (i - M[B[0]][0]) {
					cnt = M[B[0]][0] - i
					break
				}
			}
		}
		fmt.Println(math.Abs(float64(cnt)))
	}
}

package main

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

const N = 300300
var n int
var a[N] int

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	var ret = 0
	for i := 1; i <= n; i++ {

		if a[i] != a[1] {
			ret = max(ret, i - 1)
		}

		if a[i] != a[n] {
			ret = max(ret, n - i)
		}
	}
	fmt.Fprintf(writer, "%d", ret)
}

package main

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

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

	var n int
	fmt.Fscanln(in, &n)

	minIndex1 := 1
	var minColor1 int
	fmt.Fscan(in, &minColor1)

	minIndex2 := -1

	maxIndex1 := -1
	maxColor1 := 0

	maxIndex2 := -1

	for i := 2; i <= n; i++ {
		var color int
		fmt.Fscan(in, &color)

		if minIndex2 == -1 && color != minColor1  {
			minIndex2 = i
		}

		if color != maxColor1 {
			maxIndex2 = maxIndex1

			maxColor1 = color
		}
		maxIndex1 = i
	}

	if minColor1 != maxColor1 {
		fmt.Println(maxIndex1 - minIndex1)
	} else if maxIndex1 - minIndex2 > maxIndex2 - minIndex1 {
		fmt.Println(maxIndex1 - minIndex2)
	} else {
		fmt.Println(maxIndex2 - minIndex1)
	}
}

package main

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

func main() {
	var n, cnt int
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	M := make(map[int][]int)
	B := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(scr, "%d", &B[i])
		if i == 0 {
			M[B[i]] = append(M[B[i]], i)
		} else if i == n-1 {
			M[B[i]] = append(M[B[i]], i)
		}
	}

	if len(M) == 2 {
		fmt.Println(n - 1)
	} else {
		for i := 1; i < n-1; i++ {
			if B[i] != B[0] {
				cnt = M[B[0]][1] - i
				break
			}
		}
		for i := n - 2; i >= 1; i-- {
			if B[i] != B[0] {
				if cnt < (i - M[B[0]][0]) {
					cnt = M[B[0]][0] - i
					break
				}
			}
		}
		fmt.Println(cnt)
	}
}

package main

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

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

	var n int
	fmt.Fscanln(in, &n)

	minIndex1 := 1
	var minColor1 int
	fmt.Fscan(in, &minColor1)

	minIndex2 := -1

	maxIndex1 := -1
	maxColor1 := 0

	maxIndex2 := -1
	maxColor2 := 0

	for i := 2; i <= n; i++ {
		var color int
		fmt.Fscan(in, &color)

		if minIndex2 == -1 && color != minColor1  {
			minIndex2 = i
		}

		if color != maxColor1 {
			maxIndex2 = maxIndex1
			maxColor2 = maxColor1

			maxColor1 = color
			maxIndex1 = i
		} else if color != maxColor2 {
			maxIndex2 = i
			maxColor2 = color
		}
	}

	if minColor1 != maxColor1 {
		fmt.Println(maxIndex1 - minIndex1)
	} else if maxIndex1 - minIndex2 > maxIndex2 - minIndex1 {
		fmt.Println(maxIndex1 - minIndex2)
	} else {
		fmt.Println(maxIndex2 - minIndex1)
	}
}