You are given a permutation $$$a$$$ consisting of $$$n$$$ numbers $$$1$$$, $$$2$$$, ..., $$$n$$$ (a permutation is an array in which each element from $$$1$$$ to $$$n$$$ occurs exactly once).You can perform the following operation: choose some subarray (contiguous subsegment) of $$$a$$$ and rearrange the elements in it in any way you want. But this operation cannot be applied to the whole array.For example, if $$$a = [2, 1, 4, 5, 3]$$$ and we want to apply the operation to the subarray $$$a[2, 4]$$$ (the subarray containing all elements from the $$$2$$$-nd to the $$$4$$$-th), then after the operation, the array can become $$$a = [2, 5, 1, 4, 3]$$$ or, for example, $$$a = [2, 1, 5, 4, 3]$$$.Your task is to calculate the minimum number of operations described above to sort the permutation $$$a$$$ in ascending order.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The first line of the test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$) — the number of elements in the permutation. The second line of the test case contains $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ — the given permutation $$$a$$$.

For each test case, output a single integer — the minimum number of operations described above to sort the array $$$a$$$ in ascending order.

NoteIn the explanations, $$$a[i, j]$$$ defines the subarray of $$$a$$$ that starts from the $$$i$$$-th element and ends with the $$$j$$$-th element.In the first test case of the example, you can select the subarray $$$a[2, 3]$$$ and swap the elements in it.In the second test case of the example, the permutation is already sorted, so you don't need to apply any operations.In the third test case of the example, you can select the subarray $$$a[3, 5]$$$ and reorder the elements in it so $$$a$$$ becomes $$$[2, 1, 3, 4, 5]$$$, and then select the subarray $$$a[1, 2]$$$ and swap the elements in it, so $$$a$$$ becomes $$$[1, 2, 3, 4, 5]$$$.

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

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

		p := make([]int, n)

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

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == len(p) && p[len(p) - 1] == 1 {
		return 3
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		a := make([]int, n)

		var posFirst int
		var posLast int
		flag := true

		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if a[i] == 1 {
				posFirst = i
			}
			if a[i] == n {
				posLast = i
			}
			if i != 0 && a[i] < a[i-1] {
				flag = false
			}
		}

		if flag {
			fmt.Println(0)
		} else if posFirst == 0 || posLast == n-1 {
			fmt.Println(1)
		} else if posFirst == n-1 && posLast == 0 {
			fmt.Println(3)
		} else {
			fmt.Println(2)
		}
	}
}

// 1525B. Permutation Sort
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				sorted = false
				break
			}
		}
		if sorted {
			fmt.Println(0)
		} else {
			if a[0] == n && a[n-1] == 1 {
				fmt.Println(3)
			} else if a[0] == 1 || a[n-1] == n {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		ARRAY := make([]int, n+1)
		contiuniopp := 0
		PlaceOfN := 0
		PlaceOfONe := 0
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
			if ARRAY[i] == i {
				contiuniopp++
			}
			if ARRAY[i] == n {
				PlaceOfN = i
			}
			if ARRAY[i] == 1 {
				PlaceOfONe = i
			}

		}
		if contiuniopp == n {
			fmt.Println(0)
		} else {
			if PlaceOfN == n || PlaceOfONe == 1 {
				fmt.Println(1)
			} else {
				if PlaceOfN == 1 && PlaceOfONe == n {
					fmt.Println(3)
				} else {
					fmt.Println(2)
				}
			}
		}

	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		if sort.IntsAreSorted(a) {
			Fprintln(out, 0)
			return
		}
		if a[0] == 1 || a[n-1] == n {
			Fprintln(out, 1)
		} else if a[0] == n && a[n-1] == 1 {
			Fprintln(out, 3)
		} else {
			Fprintln(out, 2)
		}
	}

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

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

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

package main

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

/*
2
3
3 2 1
3
1 3 2
---
3
1
*/

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

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

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

		if a[0] == n && a[n-1] == 1 {
			fmt.Fprintln(writer, 3)
			continue
		}

		if (a[0] == 1) != (a[n-1] == n) {
			fmt.Fprintln(writer, 1)
			continue
		}

		if a[0] != 1 && a[n-1] != n {
			fmt.Fprintln(writer, 2)
			continue
		}

		shouldSortCenter := false

		for i := 1; i < n-1; i++ {
			if a[i] != i+1 {
				shouldSortCenter = true
			}
		}

		if shouldSortCenter {
			fmt.Fprintln(writer, 1)
		} else {
			fmt.Fprintln(writer, 0)
		}
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

func calc(n int, data []int) int {
	var res int
	if data[0] != 1 {
		res++
	}
	if data[n-1] != n {
		res++
	}
	switch res {
	case 2:
		if data[0] == n && data[n-1] == 1 {
			return 3
		}
		return 2
	case 1:
		return 1
	case 0:
	}
	for i, v := range data {
		if i+1 != v {
			return 1
		}
	}
	return 0
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var T int
	fmt.Fscanln(input, &T)
	for k := 0; k < T; k++ {
		var n int
		fmt.Fscanln(input, &n)
		data := make([]int, n)
		for i := range data {
			_, err := fmt.Fscan(input, &data[i])
			if err != nil {
				panic(err)
			}
		}
		fmt.Fscanf(input, "\n")
		fmt.Println(calc(n, data))
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

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

		p := make([]int, n)

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

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == len(p) - 1 && p[len(p) - 1] == 1 {
		return 3
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

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

		p := make([]int, n)

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

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	reverse := true

	for i := 0; i < len(p) - 1; i++ {
		if p[i] != len(p) - i {
			reverse = false
			break
		}
	}

	if reverse {
		return 3
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

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

		p := make([]int, n)

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

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == 1 || p[len(p) - 1] == len(p) {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

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

		p := make([]int, n)

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

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == 1 || p[len(p) - 1] == 5 {
		return 1
	} else {
		return 2
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

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

		p := make([]int, n)

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

func solve(p []int) int {
	bad := false
	for i := 0; i < len(p); i++ {
		if p[i] != i + 1 {
			bad = true
			break
		}
	}

	if !bad {
		return 0
	}

	if p[0] == 1 {
		return 1
	} else {
		return 2
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		a := make([]int, n)

		var posFirst int
		var posLast int
		flag := true

		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if a[i] == 1 {
				posFirst = i
			}
			if a[i] == n {
				posLast = i
			}
			if i != 0 && a[i] < a[i-1] {
				flag = false
			}
		}

		if flag {
			fmt.Println(0)
		} else if posFirst == 0 || posLast == n-1 {
			fmt.Println(1)
		} else if posFirst == n-1 || posLast == 0 {
			fmt.Println(3)
		} else {
			fmt.Println(2)
		}
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		a := make([]int, n)

		var posFirst int
		var posLast int
		flag := true

		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
			if a[i] == 1 {
				posFirst = i
			}
			if a[i] == n {
				posLast = i
			}
			if i != 0 && a[i] < a[i-1] {
				flag = false
			}
		}

		if flag {
			fmt.Println(0)
		} else if posFirst == 0 || posLast == n-1 {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

// 1525B. Permutation Sort
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] < a[i-1] {
				sorted = false
				break
			}
		}
		if sorted {
			fmt.Println(0)
		} else {
			if a[0] == 1 || a[n-1] == n {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		ARRAY := make([]int, n+1)
		contiuniopp := 0
		PlaceOfN := 0
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
			if ARRAY[i] == i {
				contiuniopp++
			}
			if ARRAY[i] == n {
				PlaceOfN = i
			}

		}
		if contiuniopp == n {
			fmt.Println(0)
		} else {
			if PlaceOfN == n {
				fmt.Println(1)
			}
			if PlaceOfN == 1 {
				fmt.Println(3)
			}
			if PlaceOfN != 1 && PlaceOfN != n {
				fmt.Println(2)
			}
		}

	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		if sort.IntsAreSorted(a) {
			Fprintln(out, 0)
			return
		}
		if a[0] == 1 || a[n-1] == n {
			Fprintln(out, 1)
		} else {
			Fprintln(out, 2)
		}
	}

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

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

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


Iahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is one which has all four vertices in the set of special points. Given the set of special points, please calculate the maximal area of a special quadrilateral.

The first line contains integer n (4 ≤ n ≤ 300). Each of the next n lines contains two integers: xi, yi ( - 1000 ≤ xi, yi ≤ 1000) — the cartesian coordinates of ith special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.

Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10 - 9.

NoteIn the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16.

package main

import (
	"fmt"
        "math"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < 0 {
						maxminus = math.Max(-a, maxminus)
					} else {
						maxplus = math.Max(a, maxplus)
					}
				}

			}
			if maxplus >= 0 && maxminus >= 0 {
				maxarea = math.Max(maxarea, maxplus + maxminus)
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
    "fmt"
)

var n int
type Point struct {
    x, y float32
}
var ps []Point

func xmult(p0, p1, p2 Point) float32 {
    return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x)
}

func main() {
    fmt.Scanln(&n)
    ps := make([]Point, n)
    for i := 0; i < n; i++ {
       fmt.Scanln(&ps[i].x, &ps[i].y)
    }
    var res float32
    for i := 0; i < n; i++ {
        p1 := ps[i]
        for  j := i + 1; j < n; j ++ {
            p2 := ps[j]
            var mx, mn float32
            mx = -1e9
            mn = 1e9
            for k, p3 := range ps {
                if k == i || k == j {
                    continue
                }
                tmp := xmult(p1, p2, p3)
                if tmp > mx {
                    mx = tmp
                }
                if tmp < mn {
                    mn = tmp
                }
            }
            if mx - mn > res {
                res = mx - mn
            }
        }
    }
    fmt.Println(res*0.5)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d %d\n", &a, &b)
		if err != nil {
			fmt.Println(err)
		}
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x))) / 2.0
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Printf("%f", maxarea)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
        "math"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 1; i <= n; i++ {
		for j := i+1; j <= n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 1; k <= n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < 0 {
						maxminus = math.Max(-a, maxminus)
					} else {
						maxplus = math.Max(a, maxplus)
					}
				}

			}
			if maxplus >= 0 && maxminus >= 0 {
				maxarea = maxplus + maxminus
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
	"fmt"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
        x := make(map[int]int)
        y := make(map[int]int)
	var a,b,n int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &a, &b)
                x[i] = a
                y[i] = b
	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d %d\n", &a, &b)
                if err != nil {
                   fmt.Println(err)
                }
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Println(maxarea)
}

package main

import (
	"fmt"
)

func area(x map[int]int, y map[int]int, A int, B int, C int) float64 {
	return float64(((x[B]-x[A])*(y[C]-y[B]) - (y[B]-y[A])*(x[C]-x[B])) / 2.0)
}

func main() {
	x := make(map[int]int)
	y := make(map[int]int)
	var a, b, n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d %d\n", &a, &b)
                if err != nil {
                   fmt.Println(err)
                }
		x[i] = a
		y[i] = b

	}
	var maxarea float64 = 0.0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 0; k < n; k++ {
				if k != i && k != j {
					var a float64 = area(x, y, i, j, k)
					if a < maxminus {
						maxminus = a
					} else if a > maxplus {
						maxplus = a
					}
				}

			}
			if maxplus >= 0 && maxminus < 0 && (maxplus-maxminus) > maxarea {
				maxarea = maxplus - maxminus
			}
		}
	}
	fmt.Printf("%f", maxarea)
}

package main

import (
	"fmt"
        "math"
)

func area(A Point, B Point, C Point) float64 {
	return float64(((B.x-A.x)*(C.y-B.y) - (B.y-A.y)*(C.x-B.x)))
}

type Point struct {
	x int
	y int
}

func main() {
	var points [301]Point
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d %d\n", &points[i].x, &points[i].y)

	}
	var maxarea float64 = 0.0
	for i := 1; i <= n; i++ {
		for j := i+1; j <= n; j++ {
			var maxplus, maxminus float64 = -1.0, -1.0
			for k := 1; k <= n; k++ {
				if k != i && k != j {
					var a float64 = area(points[i], points[j], points[k])
					if a < 0 {
						maxminus = math.Max(-a, maxminus)
					} else {
						maxplus = math.Max(a, maxminus)
					}
				}

			}
			if maxplus >= 0 && maxminus >= 0 {
				maxarea = maxplus + maxminus
			}
		}
	}
	fmt.Printf("%f", (maxarea / 2.0))
}

package main

import (
    "fmt"
)

var n int
type Point struct {
    x, y float32
}
var ps []Point

func xmult(p0, p1, p2 Point) float32 {
    return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x)
}

func main() {
    fmt.Scanln(&n)
    ps := make([]Point, n)
    for i := 0; i < n; i++ {
       fmt.Scanln(&ps[i].x, &ps[i].y)
    }
    var res float32
    for i := 0; i < n; i++ {
        p1 := ps[i]
        for  j := i + 1; j < n; j ++ {
            p2 := ps[j]
            var mx, mn float32
            for _, p3 := range ps {
                tmp := xmult(p1, p2, p3)
                if tmp > mx {
                    mx = tmp
                }
                if tmp < mn {
                    mn = tmp
                }
            }
            if mx - mn > res {
                res = mx - mn
            }
        }
    }
    fmt.Println(res*0.5)
}


Nastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.Two matrices $$$A$$$ and $$$B$$$ are given, each of them has size $$$n \times m$$$. Nastya can perform the following operation to matrix $$$A$$$ unlimited number of times:   take any square square submatrix of $$$A$$$ and transpose it (i.e. the element of the submatrix which was in the $$$i$$$-th row and $$$j$$$-th column of the submatrix will be in the $$$j$$$-th row and $$$i$$$-th column after transposing, and the transposed submatrix itself will keep its place in the matrix $$$A$$$). Nastya's task is to check whether it is possible to transform the matrix $$$A$$$ to the matrix $$$B$$$.    Example of the operation As it may require a lot of operations, you are asked to answer this question for Nastya.A square submatrix of matrix $$$M$$$ is a matrix which consist of all elements which comes from one of the rows with indeces $$$x, x+1, \dots, x+k-1$$$ of matrix $$$M$$$ and comes from one of the columns with indeces $$$y, y+1, \dots, y+k-1$$$ of matrix $$$M$$$. $$$k$$$ is the size of square submatrix. In other words, square submatrix is the set of elements of source matrix which form a solid square (i.e. without holes).

The first line contains two integers $$$n$$$ and $$$m$$$ separated by space ($$$1 \leq n, m \leq 500$$$) — the numbers of rows and columns in $$$A$$$ and $$$B$$$ respectively. Each of the next $$$n$$$ lines contains $$$m$$$ integers, the $$$j$$$-th number in the $$$i$$$-th of these lines denotes the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$A$$$ ($$$1 \leq A_{ij} \leq 10^{9}$$$). Each of the next $$$n$$$ lines contains $$$m$$$ integers, the $$$j$$$-th number in the $$$i$$$-th of these lines denotes the $$$j$$$-th element of the $$$i$$$-th row of the matrix $$$B$$$ ($$$1 \leq B_{ij} \leq 10^{9}$$$).

Print "YES" (without quotes) if it is possible to transform $$$A$$$ to $$$B$$$ and "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).

NoteConsider the third example. The matrix $$$A$$$ initially looks as follows.$$$$$$ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} $$$$$$Then we choose the whole matrix as transposed submatrix and it becomes$$$$$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 8\\ 3 & 6 & 9 \end{bmatrix} $$$$$$Then we transpose the submatrix with corners in cells $$$(2, 2)$$$ and $$$(3, 3)$$$. $$$$$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & \textbf{5} & \textbf{8}\\ 3 & \textbf{6} & \textbf{9} \end{bmatrix} $$$$$$So matrix becomes$$$$$$ \begin{bmatrix} 1 & 4 & 7\\ 2 & 5 & 6\\ 3 & 8 & 9 \end{bmatrix} $$$$$$and it is $$$B$$$.

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}

package main

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

type SA []int

func (s SA) Len() int {
	return len(s)
}

func (s SA) Swap(a, b int) {
	tmp := s[a]
	s[a] = s[b]
	s[b] = tmp
}
func (s SA) Less(i, j int) bool {
	if s[i] < s[j] {
		return true
	}
	return false
}
func turnC(n, m, i, j, v int) int64 {
	line := 0
	if i <= m-1-j{
		line = j+i
	}else{
		line = m-1+(i-(m-1-j))
	}
	var ret = int64(v)
	ret = ret*10000+int64(line)
	//fmt.Printf("i=%d j=%d %d ret=%d\n",i,j,v,ret)
	return ret
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m, v int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	mapp := make(map[int64]int)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(buf, "%d", &v)
			mapp[turnC(n, m, i, j, v)]++
		}
		fmt.Fscanf(buf, "\n")
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(buf, "%d", &v)
			key := turnC(n, m, i, j, v)
			cnt, ok := mapp[key]
			if ok && cnt > 0 {
				mapp[key]--
			} else {
				fmt.Printf("NO\n")
				return
			}
		}
		fmt.Fscanf(buf, "\n")
	}
	fmt.Printf("YES\n")
}

/**
0 0
0 1
3
UDD
 */

package main

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

type input struct {
  scanner *bufio.Scanner
}

func NewInput() input {
  in := input{scanner: bufio.NewScanner(os.Stdin)}
  in.scanner.Split(bufio.ScanWords)
  return in
}

func (in* input) Token() string {
  in.scanner.Scan()
  return in.scanner.Text()
}

func (in* input) IntToken() int {
  result, _ := strconv.Atoi(in.Token())
  return result
}

func ReadDiags(in input, N, M int) [][]int {
  result := make([][]int, N + M - 1)
  for r := 0; r < N; r++ {
    for c := 0; c < M; c++ {
      result[r + c] = append(result[r + c], in.IntToken())
    }
  }
  for i := 0; i < N + M - 1; i++ {
    sort.Slice(
      result[i],
      func(a, b int) bool { return result[i][a] < result[i][b] },
    )
  }
  return result
}

func main() {
  in := NewInput()
  N := in.IntToken()
  M := in.IntToken()

  A := ReadDiags(in, N, M)
  B := ReadDiags(in, N, M)

  if reflect.DeepEqual(A, B) {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}

// Author: sighduck
// URL: https://codeforces.com/contest/1136/problem/C

package main

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

func compareDiagonals(a [][]int, b [][]int, row int, column int, n int, m int) bool {
	aDiagonal := make(map[int]int)
	bDiagonal := make(map[int]int)
	count := 0
	for row+count < n && column-count >= 0 {
		aDiagonal[a[row+count][column-count]] += 1
		bDiagonal[b[row+count][column-count]] += 1
		count += 1
	}
	for elem, elemCount := range aDiagonal {
		if elemCount != bDiagonal[elem] {
			return false
		}
	}
	return true
}

func Solve(a [][]int, b [][]int, n int, m int) string {
	for j := 0; j < m; j++ {
		if !compareDiagonals(a, b, 0, j, n, m) {
			return "NO"
		}
	}
	for i := 1; i < n; i++ {
		if !compareDiagonals(a, b, i, m-1, n, m) {
			return "NO"
		}
	}
	return "YES"
}

func readMatrix(n int, m int, reader *bufio.Reader) [][]int {
	matrix := make([][]int, n)
	for i := 0; i < n; i++ {
		matrix[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &matrix[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}
	return matrix
}

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

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := readMatrix(n, m, reader)
	b := readMatrix(n, m, reader)

	fmt.Fprintf(writer, "%s\n", Solve(a, b, n, m))
}

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(newDiagA)
			        fmt.Println(newDiagB)
			    }
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(newDiagA)
			        fmt.Println(newDiagB)
			    }
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}

package main

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

func main() {
	var n, m int
	r := bufio.NewReader(os.Stdin)
	line, _ := r.ReadString('\n')
	intLine := parseInts(line)
	n, m = intLine[0], intLine[1]
	A := getNewMatrix(n, m, r)
	B := getNewMatrix(n, m, r)
	if isItPossibleToTransposeOneMatrixToAnother(A, B, n, m){
		fmt.Println("YES")
	} else{
		fmt.Println("NO")
	}
}

func isItPossibleToTransposeOneMatrixToAnother(A, B [][]int, n,m int) bool {
	var currentRow, currentCol int
	for i:=0; i<n; i++{
		currentRow = i
		currentCol = 0
		newDiagA := make([]int, min(currentRow+1, m))
		newDiagB := make([]int, min(currentRow+1, m))
		for currentRow>=0 && currentCol<m {
			newDiagA[currentCol] = A[currentRow][currentCol]
			newDiagB[currentCol] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		sort.Sort(sort.IntSlice(newDiagA))
		sort.Sort(sort.IntSlice(newDiagB))
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(v)
			        fmt.Println(newDiagB[ind])
			    }
				return false
			}
		}
	}
	for i:=1; i<m; i++{
		currentRow = n-1
		currentCol = i
		newDiagA := make([]int, min(n, m-currentCol))
		newDiagB := make([]int, min(n, m-currentCol))
		for currentRow>=0 && currentCol<m{
			newDiagA[n-1-currentRow] = A[currentRow][currentCol]
			newDiagB[n-1-currentRow] = B[currentRow][currentCol]
			currentRow--
			currentCol++
		}
		for ind, v := range newDiagA {
			if newDiagB[ind] != v {
			    if n==50 && m==50{
			        fmt.Println(v)
			        fmt.Println(newDiagB[ind])
			    }
				return false
			}
		}
	}
	return true
}

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

func getNewMatrix(n, m int, r *bufio.Reader) [][]int{
	A := make([][]int, n)
	for i:=0; i<n; i++ {
		line, _ := r.ReadString('\n')
		A[i] = parseInts(line)
	}
	return A
}

func parseInts(s string) []int {
	var (
		fields = strings.Fields(s)
		ints   = make([]int, len(fields))
	)
	for i, f := range fields {
		ints[i], _ = strconv.Atoi(f)
	}
	return ints
}


There is a chess board of size $$$n \times m$$$. The rows are numbered from $$$1$$$ to $$$n$$$, the columns are numbered from $$$1$$$ to $$$m$$$.Let's call a cell isolated if a knight placed in that cell can't move to any other cell on the board. Recall that a chess knight moves two cells in one direction and one cell in a perpendicular direction:   Find any isolated cell on the board. If there are no such cells, print any cell on the board.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 64$$$) — the number of testcases. The only line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the number of rows and columns of the board.

For each testcase, print two integers — the row and the column of any isolated cell on the board. If there are no such cells, print any cell on the board.

NoteIn the first testcase, all cells are isolated. A knight can't move from any cell of the board to any other one. Thus, any cell on board is a correct answer.In the second testcase, there are no isolated cells. On a normal chess board, a knight has at least two moves from any cell. Thus, again, any cell is a correct answer.In the third testcase, only the middle cell of the board is isolated. The knight can move freely around the border of the board, but can't escape the middle.

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d ", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d ", &n, &m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n, m int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n, &m)
		fmt.Println((n+1)/2, (m+1)/2)
	}
}

package main

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

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

func (in *CF1739A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1739A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1739A
Date: 9/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1739/A
Problem: CF1739A
**/
func (in *CF1739A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		fmt.Println(int(math.Ceil(float64(n)/2.)), int(math.Ceil(float64(m)/2.)))
	}
}

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

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

package main

import "fmt"

func main() {
	var t int
	var n, m int
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&m)

		fmt.Println((n/2)+1, (m/2)+1)
		t--
	}
}

package main

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

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

	var n, m, t int

	for fmt.Fscan(r, &t); t > 0; t-- {
		fmt.Fscan(r, &n, &m)

		if n == 2 && m == 3 {
			fmt.Fprintln(w, 1, 2)
		} else if n == 3 && m == 2 {
			fmt.Fprintln(w, 2, 1)
		} else if n == 3 && m == 3 {
			fmt.Fprintln(w, 2, 2)
		} else {
			fmt.Fprintln(w, 1, 1)
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var y,x int
		fmt.Fscan(in,&y,&x)
		fmt.Fprintln(out,y/2+1,x/2+1)
	}
}

package main

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

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

	var n int
	Fscan(in, &n)
	for i := 1; i <= n; i++ {
		//fmt.Printf("%d/%d\n", i, n)
		var x int
		var y int
		//fmt.Scanf("%d %d\n", &n)
		Fscan(in, &x)
		Fscan(in, &y)

		if x <= 1 || y <= 1 {
			fmt.Printf("%d %d\n", 1, 1)
			continue
		}
		// if x >= 3 && y >= 3 {
		// 	fmt.Printf("%d %d\n", 1, 1)
		// 	continue
		// }
		fmt.Printf("%d %d\n", 2, 2)
	}
	// for i := 0; i < 9; i++ {
	// 	for j := 0; j < 9; j++ {
	// 		ans += cnt[i] * cnt[j] * cnt[i*j%9]
	// 	}
	// }
	//Fprint(out, ans)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	q, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; q > 0; q-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		m, _ := strconv.Atoi(arr[1])
		fmt.Println(n/2+1, m/2+1)
	}
}

package main

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

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

func solve(n, m int) (int, int) {
	if n == 1 || m == 1 {
		return 1, 1
	}
	if n < 4 && m < 4 {
		return 2, 2
	}
	return 1, 1
}

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

package main

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

func solve(n, m int) (int, int) {
	if n <= 3 && m <= 3 {
		return n / 2 + 1, m / 2 + 1
	}

	return 1, 1
}

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

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

	for ; t > 0; t-- {
		var n, m int
		fmt.Fscan(in, &n, &m)
		i, j := solve(n, m)
		fmt.Println(i, j)
	}
}

package main

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

func main() {
	var tc int

	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

	defer w.Flush()

	fmt.Fscan(r, &tc)

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

		o := solve(n, m)

		fmt.Fprintln(w, o[0], o[1])
	}
}

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

	ans := make([]int, 2)

	ans[0], ans[1] = n, m

	for cn := 1; cn <= n; cn++ {
		for cm := 1; cm <= m; cm++ {
			if (cn+2) > n && (cn-2) < 1 && (cm+2) > m && (cm-2) < 1 {

				ans[0] = cn
				ans[1] = cm
			}
		}
	}
	return ans
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()

	fmt.Fscan(reader, &testCases)

	for testCase := 0; testCase < testCases; testCase++ {
		var n, m int
		fmt.Fscan(reader, &n)
		fmt.Fscan(reader, &m)

		on, om := solveA(n, m)

		fmt.Fprintln(writer, on, om)
	}
}

func solveA(n, m int) (int, int) {

	on, om := n, m

	for cn := 1; cn <= n; cn++ {
		for cm := 1; cm <= m; cm++ {
			moveScore := 4
			if (cn + 2) > n {
				moveScore--
			}
			if (cn - 2) < 1 {
				moveScore--
			}
			if (cm + 2) > m {
				moveScore--
			}
			if (cm - 2) < 1 {
				moveScore--
			}

			if moveScore == 0 {
				on = cn
				om = cm
			}
		}
	}
	return on, om
}

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, m int
		fmt.Fscan(in, &n, &m)

		if n == 1 || m == 1 || n > 3 || m > 3 {
			fmt.Fprintln(out, 1, 1)
		} else {
			fmt.Fprintln(out, 2, 2)
		}
	}
}

package main

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

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

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

func solve() {
	var n, m int
	scan(&n, &m)
	if n == 1 || m == 1 {
		printf("%d %d\n", n, m)
	} else {
		printf("2 2\n")
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d ", &t)
	fmt.Println("t =", t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d ", &n, &m)
		fmt.Println("n =", n, "m =", m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d", &t)
	fmt.Println("t =", t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d", &n, &m)
		fmt.Println("n =", n, "m =", m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var (
		t int
		n int
		m int
	)

	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d", &n, &m)
		if n == 1 || m == 1 {
			fmt.Println("1 1")
		} else {
			fmt.Println("2 2")
		}
	}
}

package main

import "fmt"

func main() {
	var t, n, m int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n, &m)
		fmt.Println(1, 1)
	}
}

package main

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

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

func (in *CF1739A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1739A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1739A
Date: 9/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1739/A
Problem: CF1739A
**/
func (in *CF1739A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextString()
		fmt.Println(n, m)
	}
}

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

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

package main

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

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

func (in *CF1739A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1739A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1739A
Date: 9/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1739/A
Problem: CF1739A
**/
func (in *CF1739A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		_, _ = in.NextInt(), in.NextString()
		fmt.Println(1, 1)
	}
}

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

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

package main

import "fmt"

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

	fmt.Println((n/2)+1, (m/2)+1)
}

package main

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

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

	var n, m, t int

	for fmt.Fscan(r, &t); t > 0; t-- {
		fmt.Fscan(r, &n, &m)
		if m > n {
			temp := m
			m = n
			n = temp
		}

		if n == 2 && m == 3 {
			fmt.Fprintln(w, 1, 2)
		} else {
			fmt.Fprintln(w, 1, 1)
		}
	}
}


You are a game designer and want to make an obstacle course. The player will walk from left to right. You have $$$n$$$ heights of mountains already selected and want to arrange them so that the absolute difference of the heights of the first and last mountains is as small as possible. In addition, you want to make the game difficult, and since walking uphill or flat is harder than walking downhill, the difficulty of the level will be the number of mountains $$$i$$$ ($$$1 \leq i < n$$$) such that $$$h_i \leq h_{i+1}$$$ where $$$h_i$$$ is the height of the $$$i$$$-th mountain. You don't want to waste any of the mountains you modelled, so you have to use all of them. From all the arrangements that minimize $$$|h_1-h_n|$$$, find one that is the most difficult. If there are multiple orders that satisfy these requirements, you may find any.

The first line will contain a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of mountains. The second line of each test case contains $$$n$$$ integers $$$h_1,\ldots,h_n$$$ ($$$1 \leq h_i \leq 10^9$$$), where $$$h_i$$$ is the height of the $$$i$$$-th mountain. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output $$$n$$$ integers — the given heights in an order that maximizes the difficulty score among all orders that minimize $$$|h_1-h_n|$$$. If there are multiple orders that satisfy these requirements, you may output any.

NoteIn the first test case:The player begins at height $$$2$$$, next going up to height $$$4$$$ increasing the difficulty by $$$1$$$. After that he will go down to height $$$1$$$ and the difficulty doesn't change because he is going downhill. Finally the player will go up to height $$$2$$$ and the difficulty will increase by $$$1$$$. The absolute difference between the starting height and the end height is equal to $$$0$$$ and it's minimal. The difficulty is maximal.In the second test case:The player begins at height $$$1$$$, next going up to height $$$3$$$ increasing the difficulty by $$$1$$$. The absolute difference between the starting height and the end height is equal to $$$2$$$ and it's minimal as they are the only heights. The difficulty is maximal.

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		sort.Ints(nums)
		shortest, pos := int(1e9), 0
		for i := 0; i < n - 1; i++ {
			if abs(nums[i] - nums[i+1]) < shortest {
				shortest, pos = abs(nums[i] - nums[i+1]), i
			}
		}

		Fprint(out, nums[pos], " ")
		for i := pos + 2; i < n; i++ {
			Fprint(out, nums[i], " ")
		}
		for i := 0; i < pos; i++ {
			Fprint(out, nums[i], " ")
		}

		Fprintln(out, nums[pos+1], " ")
	}
}

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

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

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

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

package main

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

const inf int = 1<<31 - 1

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

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

func main() {
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		h := make([]int, n)
		for i := range h {
			scanf("%d", &h[i])
		}
		scanf("\n") // \n
		sort.Ints(h)
		offset := 0
		if n > 2 {
			d_min := inf
			for i := 1; i < n; i++ {
				if d_min > h[i]-h[i-1] {
					d_min = h[i] - h[i-1]
					offset = i
				}
			}
		}
		for i := range h {
			v := h[(offset+i)%n]
			if i == 0 {
				printf("%d", v)
			} else {
				printf(" %d", v)
			}
		}
		printf("\n")
	}

	writer.Flush()
}

package main

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

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

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

	var n int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		arr := make([]int, n)
		for i := range arr {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Ints(arr)

		if n == 2 {
			for _, num := range arr {
				fmt.Fprint(writer, num, " ")
			}
			fmt.Fprintln(writer)
			continue
		}

		mid, diff := 0, 1<<31-1
		for i := 0; i < n; i++ {
			if i+1 < n && arr[i+1]-arr[i] < diff {
				mid, diff = i+1, arr[i+1]-arr[i]
			}
		}
		for i := mid; i < n; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		for i := 0; i < mid; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

	var t int

	fmt.Fscan(r, &t)

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

		a := make([]int, n)

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

		ans := solve(a, n)

		for k := 0; k < len(ans); k++ {
			fmt.Fprint(w, ans[k])
			fmt.Fprint(w, " ")
		}
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

	sort.Ints(a)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		mp[a[i]]++
	}

	var b []int

	for k , v := range mp {
		if v > 1 {
			b = append(b, k)
		}
	}

	var s int
	var e int

	if len(b) > 0 {
		s = b[0]
		e = b[0]
	} else {

		var minD int = 1e9 + 5

		for k := 0; k < n - 1; k++ {
			if abs(a[k] - a[k + 1]) < minD {
				s = a[k]
				e = a[k + 1]
				minD = abs(a[k] - a[k + 1])
			}
		}

	}
	var ans []int
	ans = append(ans, s)

	startIndex := sort.Search(n, func(i int) bool {
		return a[i] >= s
	})

	for j := startIndex + 2 ; j < n; j++ {
		ans = append(ans, a[j])
	}

	for j := 0; j < startIndex; j++ {
		ans = append(ans, a[j])
	}

	ans = append(ans, e)
	return ans
}

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

	return x
}

package main

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

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

*/

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

	bld := strings.Builder{}

	var t int
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		h := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &h[i])
		}
		scanf("\n")

		sort.Ints(h)

		fstIdx := 0
		lstIdx := n - 1

		for i := 0; i < n-1; i++ {
			if h[i+1]-h[i] < h[lstIdx]-h[fstIdx] {
				fstIdx = i
				lstIdx = i + 1
			}
		}

		fmt.Fprintf(&bld, "%d ", h[fstIdx])

		for i := fstIdx + 1; i < n; i++ {
			if i != lstIdx {
				fmt.Fprintf(&bld, "%d ", h[i])
			}
		}
		for i := 0; i < fstIdx; i++ {
			fmt.Fprintf(&bld, "%d ", h[i])
		}

		fmt.Fprintf(&bld, "%d\n", h[lstIdx])
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

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

	return true
}

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

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

func digitAt(num, pos int64) int64 {
	rem := num % int64(math.Pow(10, float64(pos)))
	return rem / int64(math.Pow(10, float64(pos-1)))
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		if n == 2 {
			Fprintln(out, a[0],a[1])
			return
		}
		miI :=1
		for i := 1; i < n; i++ {
			if a[i]-a[i-1] < a[miI]-a[miI-1] {
				miI = i
			}
		}
		for _, v := range a[miI:] {
			Fprint(out, v, " ")
		}
		for _, v := range a[:miI] {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

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

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

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	cases()
	// solve()
}

/* --- Solution C --- */
func solve() {
	n := in.nextInt()

	heights := make([]int, n)
	for i := 0; i < n; i++ {
		h := in.nextInt()
		heights[i] = h
	}

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

	var pos int
	var diff int = 1e9 + 7
	for i := 0; i < n-1; i++ {
		if heights[i+1]-heights[i] < diff {
			diff = heights[i+1] - heights[i]
			pos = i + 1
		}
	}

	if n == 2 {
		out.printf("%d %d\n", heights[0], heights[1])
		return
	}
	for i, j := 0, pos; i < n; i, j = i+1, (j+1)%n {
		out.printf("%d ", heights[j])
	}
	out.println()

}

func cases() {
	tt := in.nextInt()
	for ; tt > 0; tt-- {
		solve()
	}
}

/* --- I/O --- */
const BUF_MAX_CAP int = 2e5 + 43

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

func (in *In) nextByte() byte {
	in.scanner.Scan()
	return in.scanner.Text()[0]
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

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) 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 main() {
	io := NewIO(os.Stdin, os.Stdout)
	for t := io.ReadInt(); t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)
		a.Sort()

		if len(a) == 2 {
			io.PrintlnIntSlice(a)
			continue
		}

		minDist := a[1] - a[0]
		for i := 2; i < a.Len(); i++ {
			minDist = min(minDist, a[i]-a[i-1])
		}

		i := 1
		for ; i < a.Len(); i++ {
			if a[i] - a[i-1] == minDist	{
				break
			}
		}

		io.PrintIntSlice(a[i:])
		io.PrintlnIntSlice(a[:i])
	}
}

package main

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

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

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

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

		sort.Ints(h)

		index := low(h)

		ans := order(h, index)

		if n == 2 {
			ans = h
		}

		for i := 0; i < n; i++ {
			fmt.Printf("%d ", ans[i])
		}
		fmt.Println()
	}
}

func order(a []int, j int) (b []int) {
	b = a[j:]
	b = append(b, a[:j]...)

	return
}

func low(a []int) (index int) {
	n := len(a)
	diff := a[n-1]

	for i := 1; i < n; i++ {
		if a[i]-a[i-1] < diff {
			diff = a[i] - a[i-1]
			index = i
		}
	}

	return
}

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		sort.Ints(nums)
		shortest, pos := int(1e9), 0
		for i := 0; i < n - 1; i++ {
			if abs(nums[i] - nums[i+1]) < shortest {
				shortest, pos = abs(nums[i] - nums[i+1]), i
			}
		}

		Fprint(out, nums[pos], " ")
		for i := 0; i < pos; i++ {
			Fprint(out, nums[i], " ")
		}
		for i := pos + 2; i < n; i++ {
			Fprint(out, nums[i], " ")
		}
		Fprintln(out, nums[pos+1], " ")
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		smallest := int(1e9) + 1
		for k, v := range mp {
			if v > 1 {
				smallest = min(smallest, k)
			}
		}

		sort.Ints(nums)
		if smallest == int(1e9) + 1 {
			Fprint(out, nums[0], " ")
			for i := 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, nums[1])

		} else {
			pos := sort.SearchInts(nums, smallest)
			Fprint(out, smallest, " ")
			for i := pos + 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			for i := 0; i < pos; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, smallest)
		}
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		smallest := int(1e9) + 1
		for k, v := range mp {
			if v > 1 {
				smallest = min(smallest, k)
			}
		}

		sort.Ints(nums)
		if smallest == int(1e9) + 1 {
			Fprint(out, nums[0], " ")
			for i := 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, nums[n - 1])

		} else {
			pos := sort.SearchInts(nums, smallest)
			Fprint(out, smallest, " ")
			for i := pos + 2; i < n; i++ {
				Fprint(out, nums[i], " ")
			}
			for i := 0; i < pos; i++ {
				Fprint(out, nums[i], " ")
			}
			Fprintln(out, smallest)
		}
	}
}

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

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

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

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

package main

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

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

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

	var n int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		arr := make([]int, n)
		for i := range arr {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Ints(arr)

		if n == 2 {
			for _, num := range arr {
				fmt.Fprint(writer, num, " ")
			}
			fmt.Fprintln(writer)
			return
		}

		mid, diff := 0, 1<<31-1
		for i := 0; i < n; i++ {
			if i+1 < n && arr[i+1]-arr[i] < diff {
				mid, diff = i+1, arr[i+1]-arr[i]
			}
		}
		for i := mid; i < n; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		for i := 0; i < mid; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

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

	var n int
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		arr := make([]int, n)
		for i := range arr {
			fmt.Fscan(reader, &arr[i])
		}
		sort.Ints(arr)
		mid := 0
		for ; mid+1 < n; mid++ {
			if arr[mid] == arr[mid+1] {
				break
			}
		}
		for i := mid + 1; i < n; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		for i := 0; i <= mid; i++ {
			fmt.Fprint(writer, arr[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

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

	var t int

	fmt.Fscan(r, &t)

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

		a := make([]int, n)

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

		ans := solve(a, n)

		for k := 0; k < len(ans); k++ {
			fmt.Fprint(w, ans[k])
			fmt.Fprint(w, " ")
		}
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

	sort.Ints(a)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		mp[a[i]]++
	}

	var b []int

	for k , v := range mp {
		if v > 1 {
			b = append(b, k)
		}
	}

	var s int
	var e int

	if len(b) > 0 {
		s = b[0]
		e = b[0]
	} else {

		var minD int = 1e9 + 5

		for k := 0; k < n - 1; k++ {
			if abs(a[k] - a[k + 1]) < minD {
				s = a[k]
				e = a[k + 1]
			}
		}

	}
	var ans []int
	ans = append(ans, s)

	startIndex := sort.Search(n, func(i int) bool {
		return a[i] >= s
	})

	for j := startIndex + 2 ; j < n; j++ {
		ans = append(ans, a[j])
	}

	for j := 0; j < startIndex; j++ {
		ans = append(ans, a[j])
	}

	ans = append(ans, e)
	return ans
}

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

	return x
}

package main

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

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

	var t int

	fmt.Fscan(r, &t)

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

		a := make([]int, n)

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

		ans := solve(a, n)

		for k := 0; k < len(ans); k++ {
			fmt.Fprint(w, ans[k])
			fmt.Fprint(w, " ")
		}
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

	//4 2 1 5 3 6 5 7 8

	// 1 2 3 4 5 5 6 7 8

	//5 6 7 8 1 2 3 4 5

	sort.Ints(a)

	mp := make(map[int]int)
	for i := 0; i < n; i++ {
		mp[a[i]]++
	}

	var b []int

	for k , v := range mp {
		if v > 1 {
			b = append(b, k)
		}
	}

	var s int
	var e int

	if len(b) > 0 {
		s = b[0]
		e = b[0]
	} else {
		s = a[0]
		e = a[1]
	}
	var ans []int
	ans = append(ans, s)

	startIndex := sort.Search(n, func(i int) bool {
		return a[i] >= s
	})

	for j := startIndex + 2 ; j < n; j++ {
		ans = append(ans, a[j])
	}

	for j := 0; j < startIndex; j++ {
		ans = append(ans, a[j])
	}

	ans = append(ans, e)
	return ans
}

package main

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

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

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

	bld := strings.Builder{}

	var t int
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		h := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &h[i])
		}
		scanf("\n")

		sort.Ints(h)

		fstIdx := 0
		lstIdx := n - 1

		for i, j := 0, n-2; i <= j; i, j = i+1, j-1 {
			if h[i+1]-h[i] < h[lstIdx]-h[fstIdx] {
				fstIdx = i
				lstIdx = i + 1
			}

			if h[j+1]-h[j] < h[lstIdx]-h[fstIdx] {
				fstIdx = j
				lstIdx = j + 1
			}
		}

		fmt.Fprintf(&bld, "%d ", h[fstIdx])

		if n == 4 {
			c := make([]int, 0)
			for i := 0; i < n; i++ {
				if i != fstIdx && i != lstIdx {
					c = append(c, h[i])
				}
			}
			if h[fstIdx] <= c[1] && c[0] <= h[lstIdx] {
				fmt.Fprintf(&bld, "%d %d ", c[1], c[0])
			} else {
				fmt.Fprintf(&bld, "%d %d ", c[0], c[1])
			}
		} else {
			for i := 0; i < n; i++ {
				if i != fstIdx && i != lstIdx {
					fmt.Fprintf(&bld, "%d ", h[i])
				}
			}
		}

		fmt.Fprintf(&bld, "%d\n", h[lstIdx])
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

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

	return true
}

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

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

func digitAt(num, pos int64) int64 {
	rem := num % int64(math.Pow(10, float64(pos)))
	return rem / int64(math.Pow(10, float64(pos-1)))
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		miI :=1
		for i := 1; i < n; i++ {
			if a[i]-a[i-1] < a[miI]-a[miI-1] {
				miI = i
			}
		}
		for _, v := range a[miI:] {
			Fprint(out, v, " ")
		}
		for _, v := range a[:miI] {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

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

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


$$$n$$$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map. You are the game master and want to organize a tournament. There will be a total of $$$n-1$$$ battles. While there is more than one player in the tournament, choose any map and any two remaining players to fight on it. The player who loses will be eliminated from the tournament. In the end, exactly one player will remain, and he is declared the winner of the tournament. For each player determine if he can win the tournament.

The first line 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 10^5$$$) — the number of players. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$, $$$a_i \neq a_j$$$ for $$$i \neq j$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th player on the first map.  The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^9$$$, $$$b_i \neq b_j$$$ for $$$i \neq j$$$), where $$$b_i$$$ is the strength of the $$$i$$$-th player on the second map.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print a string of length $$$n$$$. $$$i$$$-th character should be "1" if the $$$i$$$-th player can win the tournament, or "0" otherwise.

NoteIn the first test case, the $$$4$$$-th player will beat any other player on any game, so he will definitely win the tournament.In the second test case, everyone can be a winner. In the third test case, there is only one player. Clearly, he will win the tournament.

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

type pair struct {a, b int}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]pair, n)
    aa := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i].a)
        aa[i] = a[i].a
        a[i].b = i
    }

    b := make([]pair, n)
    bb := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &b[i].a)
        bb[i] = b[i].a
        b[i].b = i
    }

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

    ans := make([]int, n)
    i := n - 1
    mina := min(a[i].a, aa[b[i].b])
    minb := min(b[i].a, bb[a[i].b])

    //var dfs func(int)
    //fmt.Println(a)
    //dfs = func(index int) {
    //    fmt.Println(index, mina, minb)
    //    if index >= n || ans[index] == 1 { return }
    //    if aa[index] < mina && bb[index] < minb { return }
    //    ans[index] = 1
    //
    //    mina = min(mina, aa[index])
    //    minb = min(minb, bb[index])
    //
    //    l, r := -1, n
    //    for (r - l) > 1 {
    //        m := (l + r) / 2
    //        if a[m].a <= mina {
    //            l = m
    //        } else {
    //            r = m
    //        }
    //    }
    //    dfs(a[r].b)
    //
    //    l, r = -1, n
    //    for (r - l) > 1 {
    //        m := (l + r) / 2
    //        if b[m].a <= minb {
    //            l = m
    //        } else {
    //            r = m
    //        }
    //    }
    //    dfs(b[r].b)
    //}
    //dfs(a[n - 1].b)
    //dfs(b[n - 1].b)

    for i >= 0 {
        if a[i].a >= mina || bb[a[i].b] > minb {
            ans[a[i].b] = 1
            mina = min(mina, a[i].a)
            minb = min(minb, bb[a[i].b])
        }
        if b[i].a >= minb || aa[b[i].b] > mina {
            ans[b[i].b] = 1
            minb = min(minb, b[i].a)
            mina = min(mina, aa[b[i].b])
        }
        i--
    }

    for _, v := range ans {
        fmt.Fprint(output, v)
    }
    fmt.Fprintln(output)
}

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 isPrime(v int) bool {
    if v == 1 { return false }
    for i := 2; i * i <= v; i++ {
        if v % i == 0 { return false }
    }
    return true
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

type pair struct {a, b int}

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]pair, n)
    aa := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i].a)
        aa[i] = a[i].a
        a[i].b = i
    }

    b := make([]pair, n)
    bb := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &b[i].a)
        bb[i] = b[i].a
        b[i].b = i
    }

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

    ans := make([]int, n)
    i := n - 1
    mina := a[i].a
    minb := b[i].a

    for i >= 0 {
        if a[i].a >= mina || bb[a[i].b] > minb {
            ans[a[i].b] = 1
            mina = min(mina, a[i].a)
            minb = min(minb, bb[a[i].b])
        }
        if b[i].a >= minb || aa[b[i].b] > mina {
            ans[b[i].b] = 1
            minb = min(minb, b[i].a)
            mina = min(mina, aa[b[i].b])
        }
        i--
    }

    for _, v := range ans {
        fmt.Fprint(output, v)
    }
    fmt.Fprintln(output)
}

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 isPrime(v int) bool {
    if v == 1 { return false }
    for i := 2; i * i <= v; i++ {
        if v % i == 0 { return false }
    }
    return true
}


Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve.The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos.Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up.Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients.

The first line contains two integers n and d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 ≤ a ≤ b ≤ 104) — the size of one low quality photo and of one high quality photo, correspondingly.  Next n lines describe the clients. The i-th line contains two integers xi and yi (0 ≤ xi, yi ≤ 105) — the number of low quality photos and high quality photos the i-th client wants, correspondingly.  All numbers on all lines are separated by single spaces.

On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data.

package main

import "os"
import "bufio"
import "strconv"
import "sort"

type int64arr []int64
func (a int64arr) Len() int { return len(a) }
func (a int64arr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a int64arr) Less(i, j int) bool { return a[i] < a[j] }

func sel(x []int64, count int64) []int64 {
	var pos int64
	var temp int64
	for i:=0; int64(i)<count-1; i++ {
		pos = int64(i)
		for j:=i+1; int64(j)<count; j++ {
			if x[pos] > x[j] {
				pos = int64(j)
			}
		}
		if pos != int64(i) {
			temp = x[i]
			x[i] = x[pos]
			x[pos] = temp
		}
	}
	return x
}

func main(){
	var n, d, a, b, x, y, sum int64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	d, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	a, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	b, _ = strconv.ParseInt(r.Text(), 0, 64)
	arr := make([]int64, n)
	arr2 := make([]int64, n)
	var i int
	for i=0; int64(i)<n; i++ {
		r.Scan()
		x, _ = strconv.ParseInt(r.Text(), 0, 64)
		r.Scan()
		y, _ = strconv.ParseInt(r.Text(), 0, 64)
		arr[i] = x*a+y*b
		arr2[i] = arr[i]
	}
	sort.Sort(int64arr(arr))
	for i=0; int64(i)<n; i++ {
		if sum+arr[i] > d {
			break
		}
		sum += arr[i]
	}
	count := i
	count1 := 0
	var limit int64
	w.WriteString(strconv.Itoa(count)+"\n")
	if count != 0 {
		limit = arr[count-1]
	}
	for i=0; int64(i)<n; i++ {
		if arr2[i] < limit {
			w.WriteString(strconv.Itoa(i+1)+" ")
			count1 += 1
		}
	}
	i = 0
	for count1 != count {
		if arr2[i] == limit {
			w.WriteString(strconv.Itoa(i+1)+" ")
			count1 += 1
		}
		i++
	}
	w.WriteString("\n")
	w.Flush()
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

type Person struct {
	Need, Rank int
}
type People []Person
func (people People) Len() int {
	return len(people)
}
func (people People) Swap(i, j int) {
	people[i], people[j] = people[j], people[i]
}
func (people People) Less(i, j int) bool {
	return people[i].Need < people[j].Need
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, d := scanInt(scanner), scanInt(scanner)
	a, b := scanInt(scanner), scanInt(scanner)
	people := make(People, n)
	for i, _ := range people {
		x, y := scanInt(scanner), scanInt(scanner)
		people[i].Need = a*x + b*y
		people[i].Rank = i+1
	}
	sort.Sort(people)
	pos := 0
	for {
		d -= people[pos].Need
		if d < 0 {
			break
		}
		pos++
		if pos == n {
			break
		}
	}
	writer.WriteString(fmt.Sprintf("%d\n", pos))
	if pos != 0 {
		writer.WriteString(fmt.Sprintf("%d", people[0].Rank))
	}
	for i := 1; i < pos; i++ {
		writer.WriteString(fmt.Sprintf(" %d", people[i].Rank))
	}
	writer.WriteString("\n")
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	y := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		y[i] *= b
	}
	count := 0
	client := make([]int, n)
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			client[count] = j+1
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	xa := make([]int, n)
	y := make([]int, n)
	ya := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		xa[i] = x[i]*a
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		ya[i] = y[i]*b
		y[i] *= b
	}
	for i:=0; i<n-1; i++ {
		for j:=i+1; j<n; j++ {
			if x[j] + y[j] < x[i] + y[i] {
				x[i], y[i], x[j], y[j] = x[j], y[j], x[i], y[i]

			}
		}
	}
	count := 0
	client := make([]int, n)
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			for k:=0; k<n; k++ {
				if x[j] == xa[k] && y[j] == ya[k] {
					client[count] = k+1

					break
				}
			}
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	xa := make([]int, n)
	y := make([]int, n)
	ya := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		xa[i] = x[i]*a
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		ya[i] = y[i]*b
		y[i] *= b
	}
	for i:=0; i<n-1; i++ {
		for j:=i+1; j<n; j++ {
			if x[j] + y[j] < x[i] + y[i] {
				x[i], y[i], x[j], y[j] = x[j], y[j], x[i], y[i]

			}
		}
	}
	count := 0
	client := make([]int, n)
	prev := 0
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			for k:=0; k<n; k++ {
				if x[j] == xa[k] && y[j] == ya[k] {
					client[count] = k+1
					if client[count] == prev {
						client[count] += 1
					}
					prev = client[count]
					break
				}
			}
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
import "strconv"

func main(){
	var n, d int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	d, _ = strconv.Atoi(r.Text())
	var a, b int
	r.Scan()
	a, _ = strconv.Atoi(r.Text())
	r.Scan()
	b, _ = strconv.Atoi(r.Text())
	x := make([]int, n)
	y := make([]int, n)
	for i:=0; i<n; i++ {
		r.Scan()
		x[i], _ = strconv.Atoi(r.Text())
		x[i] *= a
		r.Scan()
		y[i], _ = strconv.Atoi(r.Text())
		y[i] *= b
	}
	for i:=0; i<n-1; i++ {
		for j:=i+1; j<n; j++ {
			if x[j] + y[j] < x[i] + y[i] {
				x[i], y[i], x[j], y[j] = x[j], y[j], x[i], y[i]
			}
		}
	}
	count := 0
	client := make([]int, n)
	for j:=0; j<n; j++ {
		if x[j] + y[j] <= d {
			d -= x[j]+y[j]
			client[count] = j+1
			count += 1
		}
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	for k:=0; k<count; k++ {
		w.WriteString(strconv.Itoa(client[k])+" ")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

type Person struct {
	Need, Rank int
}
type People []Person
func (people People) Len() int {
	return len(people)
}
func (people People) Swap(i, j int) {
	people[i], people[j] = people[j], people[i]
}
func (people People) Less(i, j int) bool {
	return people[i].Need < people[j].Need
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, d := scanInt(scanner), scanInt(scanner)
	a, b := scanInt(scanner), scanInt(scanner)
	people := make(People, n)
	for i, _ := range people {
		x, y := scanInt(scanner), scanInt(scanner)
		people[i].Need = a*x + b*y
		people[i].Rank = i+1
	}
	sort.Sort(people)
	var pos int
	for pos = 0; pos != n && d >= 0; pos++ {
		d -= people[pos].Need
	}
	writer.WriteString(fmt.Sprintf("%d\n", pos))
	if pos != 0 {
		writer.WriteString(fmt.Sprintf("%d", people[0].Rank))
	}
	for i := 1; i < pos; i++ {
		writer.WriteString(fmt.Sprintf(" %d", people[i].Rank))
	}
	writer.WriteString("\n")
}