package main

import (
    "fmt"
    "sort"
)

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

    var T int

    fmt.Scan(&T)

    for t := 0; t < T; t++ {
        var n int
        fmt.Scan(&n)
        a := make([]int, n)

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

        sort.Ints(a)

        ans := 100000
        for i := 0; i < (n - 1); i++ {
            q := a[i+1] - a[i]
            if q < ans {
                ans = q
            }
        }

        fmt.Println(ans)
    }
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	cases, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < cases; i++ {
		scanner.Scan()
		text := scanner.Text()
		l, _ := strconv.Atoi(text)
		scanner.Scan()
		strength := scanner.Text()
		arr := strings.Split(strength, " ")
		arr_i := make([]int, 0, l)
		for i := 0; i < l; i++ {
			v, _ := strconv.Atoi(arr[i])
			arr_i = append(arr_i, v)
		}
		sort.Ints(arr_i)
		res := -1
		for i := 0; i < l-1; i++ {
			diff := int(math.Abs(float64(arr_i[i] - arr_i[i+1])))
			if res == -1 {
				res = diff
			} else if diff < res {
				res = diff
			}
			if res == 0 {
				break
			}
		}
		fmt.Println(res)
	}
}

package main

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

func main(){
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t,n int
	fmt.Scan(&t)
	for ;t>0;t--{
		fmt.Scan(&n)
		a := make([]int,n)
		for i:=0;i<len(a);i++{
			fmt.Scan(&a[i])
		}
		fmt.Fprintln(out,solve(a))
	}
}
func solve(a []int)int{
	sort.Ints(a)
	min := a[1]-a[0]
	for i:=0;i<len(a)-1;i++{
		temp := a[i+1]-a[i]
		if temp < min{
			min = temp
		}
	}
	return min
}

package main

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n:= reader.NextInt64()
		aa := make([]int, n)
		for i := 0; i < len(aa); i++ {
			aa[i] = reader.NextInt()
		}
		sort.Ints(aa)
		writer.Printf("%d\n", sol(aa))
	}
}

func sol(aa []int) int {
	minDiff:=aa[1]-aa[0]
	for i:=1;i<len(aa)-1;i++ {
		if(aa[i+1]-aa[i] < minDiff){
			minDiff = aa[i+1]-aa[i]
		}
	}
	return minDiff

}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

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

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int
	n int
	S []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		S = ReadIntSlice(n)
		solve(n, S)
	}
}

func solve(n int, S []int) {
	sort.Sort(sort.IntSlice(S))

	D := []int{}
	for i := 1; i < n; i++ {
		D = append(D, AbsInt(S[i]-S[i-1]))
	}

	fmt.Println(Min(D...))
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
  "fmt"
  "sort"
)

func main() {
  var t int
  fmt.Scan(&t)
  for t > 0 {
    t--
    var n int
    fmt.Scan(&n)
    var s []int
    s = make([]int, n)
    for i := 0; i < n; i++ {
      fmt.Scan(&s[i])
    }
    sort.Ints(s)
    ans := 1000
    for i := 1; i < n; i++ {
      if s[i] - s[i-1] < ans {
        ans = s[i] - s[i-1]
      }
    }
    fmt.Println(ans)
  }
}

package main

import "fmt"

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

func minDiff(arr []int, size int) int {
	if size < 1 {
		return -1
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	var res int
	fmt.Scanf("%d\n", &testCases)
	var result []int
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d\n", &sLen)
		s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			fmt.Scanf("%d", &s[j])
		}
		fmt.Scanf("\n")
		res = minDiff(s, sLen)
		result = append(result, res)
	}
	for _, val := range result {
		fmt.Println(val)
	}
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		sort.Ints(a)
		res := abs(a[0] - a[1])
		for i := 1; i < len(a); i++ {
			res = min(res, abs(a[i]-a[i-1]))
		}
		fmt.Println(res)
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		ans := int(1e9)
		for i := 1; i < n; i++ {
			if a[i]-a[i-1]<ans {
				ans = a[i]-a[i-1]
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

    var input io.Reader
    input = bufio.NewReader(os.Stdin)

    var T int
    fmt.Fscan(input, &T)

    for t := 0; t < T; t++ {
        var n int
        fmt.Fscan(input, &n)
        a := make([]int, n)

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

        sort.Ints(a)

        anss := 10000
        for i := 0; i < (n - 1); i++ {
            q := a[i+1] - a[i]
            if q < anss {
                anss = q
            }
        }

        fmt.Println(anss)
    }
}

package main

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

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

    var input io.Reader
    input = bufio.NewReader(os.Stdin)

    var T int
    fmt.Fscan(input, &T)

    for t := 0; t < T; t++ {
        var n int
        fmt.Fscan(input, &n)
        a := make([]int, n)

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

        sort.Ints(a)

        ans := 10000
        for i := 0; i < (n - 1); i++ {
            q := a[i+1] - a[i]
            if q < ans {
                ans = q
            }
        }

        fmt.Println(ans)
    }
}

package main

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

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

    var input io.Reader
    input = bufio.NewReader(os.Stdin)

    var T int
    fmt.Fscan(input, &T)

    for t := 0; t < T; t++ {
        var n int
        fmt.Fscan(input, &n)
        a := make([]int, n)

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

        sort.Ints(a)

        ans := 100000
        for i := 0; i < (n - 1); i++ {
            q := a[i+1] - a[i]
            if q < ans {
                ans = q
            }
        }

        fmt.Println(ans)
    }
}

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		s := ScanInts(n)
		sort.Ints(s)
		mnDiff := math.MaxInt32
		//mnIdx := 0
		i := 0
		for i < n-1 {
			if Abs(s[i]-s[i+1]) < mnDiff {
				mnDiff = Abs(s[i] - s[i+1])
				//mnIdx = i
			}
			i++
		}
		P(mnDiff)
	}
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scan(&t)
	for ; t != 0; t-- {
		var n int
		var a []int
		fmt.Scan(&n)
		for i, x := 0, 0; i < n; i++ {
			fmt.Scan(&x)
			a = append(a, x)
		}
		sort.Ints(a)
		var m = a[1] - a[0]
		for i := 1; i < n; i++ {
			if m > a[i]-a[i-1] {
				m = a[i] - a[i-1]
			}
		}
		fmt.Println(m)
	}
}

package main
import (
        "fmt"
        "os"
        "sort"
        "bufio"
)
func main(){
    var t, n, ans int
    var data [55]int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &n)
        for i := 0; i < n; i++ {
            fmt.Fscan(in, &data[i])
        }
        d := data[:n]
        sort.Ints(d)
        ans = 100000
        for i := 1; i < n; i++ {
            if ans > (d[i] - d[i-1]) {
                ans = d[i] - d[i-1]
            }
        }
        fmt.Println(ans)
    }
}

package main
import (
        "fmt"
        "os"
        "sort"
)
func main(){
    var t, n, ans int
    var data [55]int
    in := os.Stdin
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &n)
        for i := 0; i < n; i++ {
            fmt.Fscan(in, &data[i])
        }
        d := data[:n]
        sort.Ints(d)
        ans = 100000
        for i := 1; i < n; i++ {
            if ans > (d[i] - d[i-1]) {
                ans = d[i] - d[i-1]
            }
        }
        fmt.Println(ans)
    }
}

package main

import (
	"fmt"
	"sort"
)

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

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for tc := 0; tc < t; tc++ {
		var n int
		fmt.Scanf("%d\n", &n)
		s := make([]int, n)
		for i := 0; i < n; i++ {
		    fmt.Scanf("%d", &s[i])
		}
		fmt.Scanf("\n")
		sort.Ints(s)
		res := s[n - 1]
		for i := 0; i < n - 1; i++ {
		    res = min(res, s[i + 1] - s[i])
		}
		fmt.Println(res)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for tt := rd(); tt > 0; tt-- {
		n := rd()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = rd()
		}
		sort.Ints(a)
		ans := int(1e9)
		for i := 0; i < n-1; i++ {
			ans = min(ans, a[i+1]-a[i])
		}
		Fprintln(out, ans)
	}

}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}

package main

import (
	"fmt"
	"sort"
)

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Scan(&n)
		A := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&A[i])
		}
		sort.Ints(A)
		ans := 100000
		for i := 0; i < n-1; i++ {
			tmp := A[i + 1] - A[i]
			if tmp < ans {
				ans = tmp
			}
		}
		fmt.Println(ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		s := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &s[j])
		}
		sort.Ints(s)
		min := 1001
		for j := 1; j < n; j++ {
			if min > s[j]-s[j-1] {
				min = s[j] - s[j-1]
			}
		}
		fmt.Fprintln(out, min)
	}
	out.Flush()
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(r, &a[j])
		}
		sort.Ints(a)
		m := a[1] - a[0]
		for j := 2; j < n; j++ {
			if a[j]-a[j-1] < m {
				m = a[j] - a[j-1]
			}
		}
		fmt.Fprintln(w, m)
	}
}

package main

import (
	"fmt"
	"sort"
	"strings"
)

type test struct {
	a []int
}

const TEST_MAX_SIZE = 50

// https://codeforces.com/problemset/problem/1360/B
// комментарий к решению
// Т.к. размер конечных команд не определен, то можно разделять спортсменов
// хоть как 1 vs n-1 , поэтому наша задача сводится к разделению на
// самых слабых vs самых сильных так, чтобы разница между max(слабых) и min(сильных)
// была минимальной. Т.е. сортируем всех спротсменов по силе и ищем минимальную
// разницу между любыми соседними - это и будет ответом
func taskSolution(in []test) string {
	ans := make([]int, len(in))
	for i := 0; i < len(in); i += 1 {
		a := in[i].a
		sort.Ints(a)
		ans[i] = a[1] - a[0]
		for j := 2; j < len(a); j += 1 {
			if a[j]-a[j-1] < ans[i] {
				ans[i] = a[j] - a[j-1]
			}
		}
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

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

	in := make([]test, 0, t)
	for i := 0; i < t; i += 1 {
		var n, ai int
		a := make([]int, 0, TEST_MAX_SIZE)
		if _, err := fmt.Scan(&n); err != nil {
			panic(err)
		}
		for j := 0; j < n; j += 1 {
			if _, err := fmt.Scan(&ai); err != nil {
				panic(err)
			}
			a = append(a, ai)
		}
		in = append(in, test{a})
	}

	fmt.Println(taskSolution(in))
}

package main

import (
	"fmt"
	"sort"
)

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

func solve() {
	var n int
	fmt.Scanf("%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	fmt.Scanf("\n")
	sort.Ints(a)
	ans := int(1e3)
	for i := 0; i < n - 1; i++ {
		ans = min(ans, a[i + 1] - a[i])
	}
	fmt.Println(ans)
}

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

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

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

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

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

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

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

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

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

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

func sol(s []int64) int64 {
	sort.Slice(s, func(a, b int) bool {
		return s[a] < s[b]
	})
	minSoFar := s[len(s)-1] - s[0]
	for i := 1; i < len(s); i++ {
		minSoFar = min(minSoFar, s[i]-s[i-1])
	}
	return minSoFar
}

package main

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

func main() {
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		aa := make([]int, 0)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			aa = append(aa, a)
		}
		sort.Slice(aa, func(i, j int) bool {
			return aa[i] < aa[j]
		})
		min := aa[n-1] - aa[0]
		for j := 0; j < n-1; j++ {
			if min > aa[j+1]-aa[j] {
				min = aa[j+1] - aa[j]
			}
		}
		fmt.Println(min)
	}
}

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		fmt.Println(solve(n, A))
	}
}

func solve(n int, A []int) int {
	sort.Ints(A)

	var best = math.MaxInt32

	for i := 0; i < n-1; i++ {
		if A[i+1]-A[i] < best {
			best = A[i+1] - A[i]
		}
	}
	return best
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n := s.NextInt()
		a := make([]int, n)
		for j := 0; j < n; j++ {
			a[j] = s.NextInt()
		}

		sort.Ints(a)

		min := 1001
		for j := 0; j < n-1; j++ {
			if a[j+1]-a[j] < min {
				min = a[j+1] - a[j]
			}
		}

		fmt.Println(min)
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

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

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

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1355/problem/B
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	sort.Ints(s)
	m := 10000
	for i := 1; i < n; i++ {
		m = min(m, s[i] - s[i - 1])
	}

	return m
}

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

// You can edit this code!
// Click here and start typing.
package main

import(
		"fmt"
		"sort"
	)

// Min returns the smaller of x or y.
func Min(x, y int) int {
    if x > y {
        return y
    }
    return x
}
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var t,n int

	//var array [] int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		array := make([]int, n)
		var dif int
		dif = 5000
		for y := 0; y < n; y++ {
			fmt.Scan(&array[y])
		}
		sort.Ints(array)
		for y := 1; y <n ; y++ {
			//if array[y] != array[y-1]{
			dif = Min(dif,AbsInt(array[y]-array[y-1]))
			//}
		}
		if dif == 5000{
			dif = 0
		}
		fmt.Println(dif)

	}

}

package main

import "fmt"

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

func minDiff(arr []int, size int) int {
	if size < 1 {
		return -1
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	var res int
	fmt.Scanf("%d\n", &testCases)
	var result []int
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d\n", &sLen)
		s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			fmt.Scanf("%d", &s[j])
		}
		res = minDiff(s, sLen)
		result = append(result, res)
	}
	for _, val := range result {
		fmt.Println(val)
	}
}

package main

import "fmt"

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	//var dummy int
	//var res int
	fmt.Scanf("%d\n", &testCases)
	fmt.Printf("testcases: %d\n", testCases)
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d\n", &sLen)
		fmt.Printf("Array Len: %d\n", sLen)
		//s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			var temp int
			fmt.Scanf("%d\n", &temp)
			fmt.Printf("%d ", temp)
		}
		// res = minDiff(s, sLen)
		// fmt.Printf("%d\n", res)
	}
}

package main

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

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

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

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	defer writer.Flush()
	var testCases int
	var sLen int
	//var res int
	fmt.Scanln(&testCases)
	fmt.Printf("testcases: %d\n", testCases)
	for i := 0; i < testCases; i++ {
		fmt.Scanln(&sLen)
		fmt.Printf("Array Len: %d\n", sLen)
		//s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			var temp int
			fmt.Scanln(&temp)
			fmt.Printf("%d ", temp)
		}
		// res = minDiff(s, sLen)
		// fmt.Printf("%d\n", res)
	}
}

package main

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

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

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

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	defer writer.Flush()
	var testCases int
	var sLen int
	var dummy int
	//var res int
	fmt.Scanf("%d%d", &testCases, &dummy)
	fmt.Printf("testcases: %d\n", testCases)
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d%d", &sLen, &dummy)
		fmt.Printf("Array Len: %d\n", sLen)
		//s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			var temp int
			fmt.Scanf("%d", &temp)
			fmt.Printf("%d ", temp)
		}
		fmt.Scanf("%d", &dummy)
		// res = minDiff(s, sLen)
		// fmt.Printf("%d\n", res)
	}
}

package main

import "fmt"

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	var res int
	fmt.Scan(&testCases)
	var result []int
	for i := 0; i < testCases; i++ {
		fmt.Scan(&sLen)
		s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			fmt.Scanf("%d", &s[j])
		}
		fmt.Println(s)
		res = minDiff(s, sLen)
		result = append(result, res)
	}
	for _, val := range result {
		fmt.Println(val)
	}
}

package main

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

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

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

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	defer writer.Flush()
	var testCases int
	var sLen int
	//var res int
	fmt.Scanf("%d", &testCases)
	fmt.Printf("testcases: %d\n", testCases)
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d", &sLen)
		fmt.Printf("Array Len: %d\n", sLen)
		//s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			var temp int
			fmt.Scanf("%d", &temp)
			fmt.Printf("%d ", temp)
		}
		// res = minDiff(s, sLen)
		// fmt.Printf("%d\n", res)
	}
}

package main

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

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

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

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	defer writer.Flush()
	var testCases int
	var sLen int
	//var dummy int
	//var res int
	fmt.Scanf("%d\n", &testCases)
	fmt.Printf("testcases: %d\n", testCases)
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d\n", &sLen)
		fmt.Printf("Array Len: %d\n", sLen)
		//s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			var temp int
			fmt.Scanf("%d\n", &temp)
			fmt.Printf("%d ", temp)
		}
		// res = minDiff(s, sLen)
		// fmt.Printf("%d\n", res)
	}
}

package main

import "fmt"

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	//var dummy int
	//var res int
	fmt.Scanf("%d\n", &testCases)
	fmt.Printf("testcases: %d\n", testCases)
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d\n", &sLen)
		fmt.Printf("Array Len: %d\n", sLen)
		//s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			var temp int
			fmt.Scanf("%d", &temp)
			fmt.Printf("%d ", temp)
		}
		// res = minDiff(s, sLen)
		// fmt.Printf("%d\n", res)
	}
}

package main

import "fmt"

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	var res int
	fmt.Scan(&testCases)
	var result []int
	for i := 0; i < testCases; i++ {
		fmt.Scan(&sLen)
		s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			fmt.Scanf("%d", &s[j])
		}
		res = minDiff(s, sLen)
		result = append(result, res)
	}
	for _, val := range result {
		fmt.Println(val)
	}
}

package main

import "fmt"

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	//var dummy int
	//var res int
	fmt.Scanf("%d\n", &testCases)
	fmt.Printf("testcases: %d\n", testCases)
	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d\n", &sLen)
		fmt.Printf("Array Len: %d\n", sLen)
		//s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			var temp int
			fmt.Scanf("%d", &temp)
			fmt.Printf("%d ", temp)
		}
		fmt.Scanf("\n")
		// res = minDiff(s, sLen)
		// fmt.Printf("%d\n", res)
	}
}

package main

import (
	"fmt"
)

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	var res int
	// f, err := os.Open("a.txt")
	// if err != nil {
	// 	panic(err)
	// }
	// defer f.Close()

	// oldStdin := os.Stdin
	// defer func() { os.Stdin = oldStdin }()

	// os.Stdin = f
	fmt.Scan(&testCases)
	//var result []int
	for i := 0; i < testCases; i++ {
		fmt.Scan(&sLen)
		s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			fmt.Scanf("%d", &s[j])
		}
		//fmt.Println(s)
		res = minDiff(s, sLen)
		fmt.Printf("%d\n", res)
		//result = append(result, res)
	}
	// for _, val := range result {
	// 	fmt.Println(val)
	// }
}

package main

import (
	"fmt"
)

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

func minDiff(arr []int, size int) int {
	if size == 1 {
		return arr[0]
	}
	least := Abs(arr[1] - arr[0])
	for i := 0; i < size-1; i++ {
		for j := i + 1; j < size; j++ {
			diff := Abs(arr[j] - arr[i])
			if diff < least {
				least = diff
			}
		}
	}
	return least
}

func main() {
	var testCases int
	var sLen int
	var res int
	// f, err := os.Open("a.txt")
	// if err != nil {
	// 	panic(err)
	// }
	// defer f.Close()

	// oldStdin := os.Stdin
	// defer func() { os.Stdin = oldStdin }()

	// os.Stdin = f
	fmt.Scan(&testCases)
	fmt.Printf("testcases: %d\n", testCases)
	//var result []int
	for i := 0; i < testCases; i++ {
		fmt.Scan(&sLen)
		fmt.Println("Array Len: %d\n", sLen)
		s := make([]int, sLen)
		for j := 0; j < sLen; j++ {
			fmt.Scanf("%d", &s[j])
			fmt.Printf("%d ", s[j])
		}
		fmt.Println()
		//fmt.Println(s)
		res = minDiff(s, sLen)
		fmt.Printf("%d\n", res)
		//result = append(result, res)
	}
	// for _, val := range result {
	// 	fmt.Println(val)
	// }
}

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.Fscanf(reader, "%d\n", &t)

    for tt := 0; tt < t; tt++ {
        var n int
        fmt.Fscanf(reader, "%d\n", &n)
        a := make([]int, n)

        for i := 0; i < n; i++ {
            fmt.Fscanf(reader, "%d", &a[i])
        }

        sort.Ints(a)

        ans := 100000
        for i := 0; i < (n - 1); i++ {
            q := a[i+1] - a[i]
            if q < ans {
                ans = q
            }
        }

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


package main

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

const (
	T_MIN        = 1
	T_MAX        = int(1e4)
	N_MIN        = 1
	N_MAX        = int(1e6)
	M_MIN        = 1
	M_MAX        = int(1e6)
	S_LENGTH_MIN = 1
	S_LENGTH_MAX = int(1e6)
	LEFT         = 'L'
	UP           = 'U'
	RIGHT        = 'R'
	DOWN         = 'D'
)

var inputFile = os.Stdin
var outputFile = os.Stdout

var t int
var n, m [T_MAX]int
var s [T_MAX]string
var r, c [T_MAX]int

func in() {
	reader := bufio.NewReader(inputFile)
	fmt.Fscan(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(reader, &n[i], &m[i], &s[i])
	}
}

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

func solution(i int) {
	c[i] = 1
	r[i] = 1

	var left, up, right, down int
	var vertical, horizontal int
	for _, direction := range s[i] {
		switch direction {
		case LEFT:
			horizontal--
		case UP:
			vertical++
		case RIGHT:
			horizontal++
		case DOWN:
			vertical--
		}
		left = max(left, -horizontal)
		up = max(up, vertical)
		right = max(right, horizontal)
		down = max(down, -vertical)

		if left+right >= m[i] || up+down >= n[i] {
			return
		}

		c[i] = left + 1
		r[i] = up + 1
	}
	return
}

func out() {
	writer := bufio.NewWriter(outputFile)
	for i := 0; i < t; i++ {
		fmt.Fprintln(writer, r[i], c[i])
	}
	writer.Flush()
}

func main() {
	in()
	for i := 0; i < t; i++ {
		solution(i)
	}
	out()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1607E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	dir4 := []struct{ x, y int }{'L': {-1, 0}, 'R': {1, 0}, 'D': {0, -1}, 'U': {0, 1}}

	var T, n, m int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &s)
		var x, y, l, r, d, u int
		ansX, ansY := 1, 1
		for _, b := range s {
			x += dir4[b].x
			y += dir4[b].y
			if x < l {l = x} else if x > r {r = x}
			if y < d {d = y} else if y > u {u = y}
			if r-l >= m || u-d >= n {break}
			ansX, ansY = 1+u, 1-l
		}
		Fprintln(out, ansX, ansY)
	}
}

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

package main

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

const (
	T_MIN        = 1
	T_MAX        = int(1e4)
	N_MIN        = 1
	N_MAX        = int(1e6)
	M_MIN        = 1
	M_MAX        = int(1e6)
	S_LENGTH_MIN = 1
	S_LENGTH_MAX = int(1e6)
	LEFT         = 'L'
	UP           = 'U'
	RIGHT        = 'R'
	DOWN         = 'D'
)

var inputFile = os.Stdin
var outputFile = os.Stdout

var t int
var n, m [T_MAX]int
var s [T_MAX]string
var r, c [T_MAX]int

func in() {
	reader := bufio.NewReader(inputFile)
	fmt.Fscan(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(reader, &n[i], &m[i], &s[i])
	}
}

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

func solution(i int) {
	c[i] = m[i]
	r[i] = n[i]

	var left, up, right, down int
	var vertical, horizontal int
	for _, direction := range s[i] {
		switch direction {
		case LEFT:
			horizontal--
		case UP:
			vertical++
		case RIGHT:
			horizontal++
		case DOWN:
			vertical--
		}
		left = max(left, -horizontal)
		up = max(up, vertical)
		right = max(right, horizontal)
		down = max(down, -vertical)

		if 1+left+right >= m[i] || 1+up+down >= n[i] {
			return
		}

		c[i] = left + 1
		r[i] = up + 1
	}
	return
}

func out() {
	writer := bufio.NewWriter(outputFile)
	for i := 0; i < t; i++ {
		fmt.Fprintln(writer, r[i], c[i])
	}
	writer.Flush()
}

func main() {
	in()
	for i := 0; i < t; i++ {
		solution(i)
	}
	out()
}

package main

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

const (
	T_MIN        = 1
	T_MAX        = int(1e4)
	N_MIN        = 1
	N_MAX        = int(1e6)
	M_MIN        = 1
	M_MAX        = int(1e6)
	S_LENGTH_MIN = 1
	S_LENGTH_MAX = int(1e6)
	LEFT         = 'L'
	UP           = 'U'
	RIGHT        = 'R'
	DOWN         = 'D'
)

var inputFile = os.Stdin
var outputFile = os.Stdout

var t int
var n, m [T_MAX]int
var s [T_MAX]string
var r, c [T_MAX]int

func in() {
	reader := bufio.NewReader(inputFile)
	fmt.Fscan(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(reader, &n[i], &m[i], &s[i])
	}
}

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

func solution(i int) {
	c[i] = n[i]
	r[i] = m[i]

	var left, up, right, down int
	var vertical, horizontal int
	for _, direction := range s[i] {
		switch direction {
		case LEFT:
			horizontal--
		case UP:
			vertical++
		case RIGHT:
			horizontal++
		case DOWN:
			vertical--
		}
		left = max(left, -horizontal)
		up = max(up, vertical)
		right = max(right, horizontal)
		down = max(down, -vertical)

		if left+right >= m[i] || up+down >= n[i] {
			return
		}

		c[i] = left + 1
		r[i] = up + 1
	}
	return
}

func out() {
	writer := bufio.NewWriter(outputFile)
	for i := 0; i < t; i++ {
		fmt.Fprintln(writer, r[i], c[i])
	}
	writer.Flush()
}

func main() {
	in()
	for i := 0; i < t; i++ {
		solution(i)
	}
	out()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1607E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	dir4 := []struct{ x, y int }{'L': {-1, 0}, 'R': {1, 0}, 'D': {0, -1}, 'U': {0, 1}}

	var T, n, m int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &s)
		var x, y, l, r, d, u int
		ansX, ansY := 1, 1
		for _, b := range s {
			x += dir4[b].x
			y += dir4[b].y
			if x < l {l = x} else if x > r {r = x}
			if y < d {d = y} else if y > u {u = y}
			if r-l >= m || u-d >= n {break}
			ansX, ansY = 1-d, 1-l
		}
		Fprintln(out, ansX, ansY)
	}
}

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


package main

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

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

	n := readNum(reader)
	A := readNNums(reader, n)

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

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

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

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

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

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

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

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

	return i
}

func solve(n int, A []int) int64 {
	cnt := make([]int, 21)

	for i := 0; i < 21; i++ {
		for j := 0; j < n; j++ {
			if A[j]&(1<<uint(i)) > 0 {
				cnt[i]++
			}
		}
	}

	B := make([]int, n)

	for i := 0; i < 21; i++ {
		for x := 0; x < cnt[i]; x++ {
			B[x] = B[x] | (1 << uint(i))
		}
	}

	var res int64

	for i := 0; i < n; i++ {
		res += int64(B[i]) * int64(B[i])
	}

	return res
}

package main

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

var nn int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 1
	//fmt.Println(len(primes))
	for ii := 0; ii < q; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		tmp := 0
		a := make([]int, 21)
		weight := make([]int, 21)
		weight[0] = 1
		for i := 1; i < 21; i++ {
			weight[i] = weight[i-1] * 2
		}
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &tmp)
			id := 0
			for tmp > 0 {
				a[id] += tmp % 2
				tmp /= 2
				id++
			}
		}
		fmt.Fscanf(in, "\n")
		ans := int64(0)
		for true {
			cur := 0
			for i := 20; i >= 0; i-- {
				if a[i] > 0 {
					a[i]--
					cur += weight[i]
				}
			}
			if cur == 0 {
				break
			}
			ans += int64(cur) * int64(cur)
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func gcd(a, b int) int {
	//fmt.Println(a, b)
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

package main

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

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

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

	n := in()

	a := make([]uint64, n)

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

	var mask, sum uint64
	for i := 0; i < 20; i++ {
		st := 0
		mask = 1 << i

		for j := range a {
			if mask&a[j] == mask {
				st++
			}
		}

		for j := range a {
			if st != 0 {
				a[j] |= mask
				st--
			} else {
				a[j] &^= (mask)
			}
		}
	}

	for i := range a {
		sum += a[i] * a[i]
	}

	fmt.Println(sum)
}

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	n int
	A []int

	cnts [60]int
)

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	for _, a := range A {
		for i := 0; i < 30; i++ {
			if NthBit(a, i) == 1 {
				cnts[i]++
			}
		}
	}

	B := make([]int, n)
	for i := 0; i < n; i++ {
		val := 0
		for j := 0; j < 30; j++ {
			if cnts[j] > 0 {
				val = OnBit(val, j)
				cnts[j]--
			}
		}

		B[i] = val
	}

	ans := int64(0)
	for _, b := range B {
		ans += int64(b) * int64(b)
	}
	fmt.Println(ans)
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num int, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num int, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num int, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	a := [200000]int{}
	bit := [20][]bool{}
	fmt.Fscan(in, &n)

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

	for i := 0; i < 20; i++ {
		for j := 0; j < n; j++ {
			b := (a[j] & (1 << i)) != 0
			// fmt.Println(a[j])
			bit[i] = append(bit[i], b)
		}

		sort.Slice(bit[i], func(x, y int) bool {
			return bit[i][x] && !bit[i][y]
		})

		// for j := 0; j < n; j++ {
		// 	fmt.Printf("%v ", bit[i][j])
		// }

		// fmt.Println("")
	}

	sum := int64(0)
	for i := 0; i < n; i++ {
		val := int64(0)
		for j := 0; j < 20; j++ {
			if bit[j][i] {
				val += 1 << j
			}
		}

		sum += val * val
	}

	fmt.Fprint(out, sum)
	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1368D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	cnt := [20]int{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		for j := range cnt {
			cnt[j] += v >> j & 1
		}
	}
	s := int64(0)
	for ; n > 0; n-- {
		v = 0
		for i, c := range cnt {
			if c > 0 {
				cnt[i]--
				v |= 1 << i
			}
		}
		s += int64(v) * int64(v)
	}
	Fprint(out, s)
}

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

package main
import (
        "fmt"
        "os"
        "bufio"
)
func main(){
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    d := make([]int, 20)
    b := make([]int, 20)
    for i := 0; i < 20; i++ {
        d[i] = 1 << i
        b[i] = 0
    }
    for ; n > 0; n-- {
        var tmp int
        fmt.Fscan(in, &tmp)
        for j := 0; j < 20; j++ {
            if d[j] & tmp != 0 {
                b[j]++
            }
        }
    }
    var ans int64 = 0
    for true {
        var v int64 = 0
        for j := 0; j < 20; j++ {
            if b[j] != 0 {
                v += int64(d[j])
                b[j]--
            }
        }
        if v == 0 {
            break;
        } else {
            ans += v * v
        }
    }

    fmt.Fprintln(out, ans)
}

package main

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

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

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

	n := in()

	a := make([]uint64, n)

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

	var mask, i, sum uint64
	for i := 0; i < 20; i++ {
		st := 0
		mask = 1 << i
		for j := range a {
			if mask&a[j] == 0 {
				a[j], a[st] = a[st], a[j]
				st++
			}
		}
	}

	for i = 1; i < n; i++ {
		a[i-1], a[i] = a[i]&a[i-1], a[i]|a[i-1]
	}

	for i := range a {
		sum += a[i] * a[i]
	}

	fmt.Println(sum)
}

package main

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

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

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

	n := in()

	a := make([]uint64, n)

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

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

	var sum uint64

	for i := range a {
		a[i], a[0] = a[i]&a[0], a[0]|a[i]
	}

	for i := range a {
		sum += a[i] * a[i]
	}

	fmt.Println(sum)
}

package main

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

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

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

	n := in()

	a := make([]uint64, n)

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

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

	var sum uint64

	for i := range a {
		a[i], a[n-1] = a[i]&a[n-1], a[n-1]|a[i]
	}

	// fmt.Println(a)

	for i := range a {
		sum += a[i] * a[i]
	}

	fmt.Println(sum)
}

package main
import (
        "fmt"
        "os"
        "bufio"
)
func main(){
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n int
    fmt.Fscan(in, &n)
    d := make([]int, 20)
    b := make([]int, 20)
    for i := 0; i < 20; i++ {
        d[i] = 1 << i
        b[i] = 0
    }
    for ; n > 0; n-- {
        var tmp int
        fmt.Fscan(in, &tmp)
        for j := 0; j < 20; j++ {
            if d[j] & tmp != 0 {
                b[j]++
            }
        }
    }
    var ans int64 = 0
    for true {
        v := 0
        for j := 0; j < 20; j++ {
            if b[j] != 0 {
                v += d[j]
                b[j]--
            }
        }
        if v == 0 {
            break;
        } else {
            ans += int64(v * v)
        }
    }

    fmt.Fprintln(out, ans)
}


package main

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

func main() {
	//var read, _ = os.Open("dat.txt")
	//var write, _ = os.Create("result.txt")
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	defer write.Flush()
	var n int
	var s string
	fmt.Fscan(read, &n)
	fmt.Fscan(read, &s)
	var a = make([][]int, 26)
	for i := 0; i < n; i++ {
		var ai = int(s[i]) - 97
		a[ai] = append(a[ai], i)
	}
	for i := 0; i < 26; i++ {
		if len(a[i]) > 0 {
			sort.Ints(a[i])
		}
	}
	var m int
	fmt.Fscan(read, &m)
	for i := 0; i < m; i++ {
		var t string
		fmt.Fscan(read, &t)
		var tm = map[int]int{}
		for j := 0; j < len(t); j++ {
			var id = int(t[j]) - 97
			if val, ok := tm[id]; ok {
				tm[id] = val + 1
			} else {
				tm[id] = 1
			}
		}
		//Ищем максимальный префикс
		var nmax = -1
		for key, value := range tm {
			var nm = a[key][value-1]
			if nm > nmax {
				nmax = nm
			}
		}
		fmt.Fprintln(write, nmax+1)

	}

	//read.Close()
	//write.Close()
}

package main

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

func main() {
	// var a, b string
	var n, d int
	var t, s string
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	fmt.Fscanln(scr, &s)
	fmt.Fscanln(scr, &d)

	m := make(map[rune][]int)

	for x, y := range s {
		m[y] = append(m[y], x+1)
	}

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

		m1 := make(map[rune]int)

		fmt.Fscanln(scr, &t)

		arr := make([]int, 0)

		for _, y := range t {
			arr = append(arr, m[y][m1[y]])
			m1[y]++
		}

		sort.Ints(arr)
		fmt.Println(arr[len(arr)-1])
	}
}

package main

import "fmt"

func convertIndex(c int) int {
	return c - 97
}

type inputType struct {
	poses        []int
	currentIndex int
}

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

	}

	return b
}

func main() {
	var n, m int
	var s string
	var a [26]inputType
	fmt.Scanf("%d\n%s\n%d\n", &n, &s, &m)

	for i := 0; i < n; i++ {
		c := convertIndex(int(s[i]))
		a[c].poses = append(a[c].poses, i)
	}

	var ans int
	var tmp string
	for m > 0 {
		m--
		fmt.Scanf("%s\n", &tmp)

		for i := 0; i < 26; i++ {
			a[i].currentIndex = 0
		}

		ans = -1
		for _, c := range tmp {
			pos := convertIndex(int(c))
			currentIndex := a[pos].currentIndex

			ans = max(ans, a[pos].poses[currentIndex])
			a[pos].currentIndex++
		}

		fmt.Println(ans + 1)
	}
}

package main

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

var DEBUG = true

func main() {
	defer Flush()
	n := readi()
	_ = n
	s := readb()
	x := make([][]int, 26)
	for i, c := range s {
		j := int(c - 'a')
		x[j] = append(x[j], i+1)
	}

	m := readi()
	for i := 0; i < m; i++ {
		t := readb()
		y := make(map[int]int)
		for _, c := range t {
			y[int(c-'a')]++
		}

		var ans int
		for c, k := range y {
			ans = max(ans, x[c][k-1])
		}
		println(ans)
	}

}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func dbgf(f string, args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintf(os.Stderr, f, args...)
}

func dbg(args ...interface{}) {
	if !DEBUG {
		return
	}
	fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

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

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

const nmax = 200000 + 1

 var writer = bufio.NewWriter(os.Stdout)

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

func toInt(buf []byte) (n uint32) {
	for _, v := range buf {
		if v >= '0' && v <= '9' {
			n = n*10 + uint32(v-'0')
		}
	}
	return
}

func solve(m []uint32, t string) uint32 {
	a := [30]uint32{}

	var max uint32

	for _, ch := range t {
		c := ch - 'a'
		a[c]++

		t := (m[a[c]*30+uint32(c)])
		if t > max {
			max = t
		}
	}

	return max
}

/*
type index struct {
	ch    rune
	count uint32
}
*/
func main() {
	reader := bufio.NewReaderSize(os.Stdin, nmax)

	reader.ReadLine()

	m := make([]uint32, nmax*30)

	a := [30]uint32{}

	for isPrefix := true; isPrefix; {
		var str []byte
		str, isPrefix, _ = reader.ReadLine()

		for i, ch := range str {
			c := ch - 'a'
			a[c]++

			m[a[c]*30+uint32(c)] = uint32(i)
		}
	}

	bytes, _ := reader.ReadBytes('\n')
	n := toInt(bytes)

	for i := uint32(0); i < n; i++ {
		t, _ := reader.ReadString('\n')

		t = strings.Trim(t, "\r\n")
		if len(t) > 0 {
			r := solve(m, t) + 1

			printf("%d\n",r)
		}
	}

		writer.Flush()
}

package main

import "fmt"

func convertIndex(c int) int {
	return c - 97
}

type inputType struct {
	poses        []int
	currentIndex int
}

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

	}

	return b
}

func main() {
	var n, m int
	var s string
	var a [26]inputType
	fmt.Scanf("%d\n%s\n%d", &n, &s, &m)

	for i := 0; i < n; i++ {
		c := convertIndex(int(s[i]))
		a[c].poses = append(a[c].poses, i)
	}

	var ans int
	var tmp string
	for m > 0 {
		m--
		fmt.Scanf("%s\n", &tmp)

		for i := 0; i < 26; i++ {
			a[i].currentIndex = 0
		}

		ans = -1
		for _, c := range tmp {
			pos := convertIndex(int(c))
			currentIndex := a[pos].currentIndex

			ans = max(ans, a[pos].poses[currentIndex])
			a[pos].currentIndex++
		}

		fmt.Println(ans + 1)
	}
}


package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func print(a ...interface{})            { fmt.Println(a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f+"\n", a...) }

func main() {
	defer writer.Flush()

	var testcases int64
	scanf("%d", &testcases)
  var i int64
	for i = 0; i < testcases; i++ {
		var n, x, y int64
		scanf("%d %d %d", &n, &x, &y)
    var a, b string
    scanf("%s", &a)
    scanf("%s", &b)

		print(solve(n, x, y, a, b))
	}
}

func max(nums ...int64) int64 {
  result := nums[0]
	for _, num := range nums {
		if num > result {
			result = num
		}
	}
	return result
}

func min(nums ...int64) int64 {
  result := nums[0]
  for _, num := range nums {
    if num < result {
      result = num
    }
  }
  return result
}

func solve(n, x, y int64, a, b string) int64 {
  diffs := make([]int64, 0, n)
  var i int64
  for i = 0; i < n; i++ {
    if a[i] != b[i] {
      diffs = append(diffs, i)
    }
  }

  m := int64(len(diffs))

  if m % 2 == 1 {
    return -1
  }

  if x >= y {
    if m == 2 && diffs[0] + 1 == diffs[1] {
      return min(x, y*2)
    }
    return y * m / 2
  }

  dp := make([][]int64, m)
  for i = 0; i < m; i++ {
    dp[i] = make([]int64, m)
    var j int64
    for j = 0; j < m; j++ {
      dp[i][j] = -1
    }
  }
  var dfs func(i, drop int64) int64
  dfs = func(i, drop int64) int64 {
    if i >= m {
      if drop == 0 {
        return 0
      }
      return math.MaxInt64
    }
    if dp[i][drop] != -1 {
      return dp[i][drop]
    }
    result := dfs(i+1, drop+1)
    if drop > 0 {
      this := dfs(i+1, drop-1)
      if this != math.MaxInt64 {
        result = min(result, this + y)
      }
    }
    if i < m-1 {
      this := dfs(i+2, drop)
      if this != math.MaxInt64 {
        result = min(result, this + min(y, x * (diffs[i+1] - diffs[i])))
      }
    }
    dp[i][drop] = result
    return result
  }
  res := dfs(0, 0)
  return res
}

package main

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

func min(i, j float64) float64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.ParseFloat(arr[1], 64)
		y, _ := strconv.ParseFloat(arr[2], 64)
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		d := 0
		c := make([]bool, n, n)
		for i := 0; i < n; i++ {
			c[i] = a[i] != b[i]
			if c[i] {
				d++
			}
		}

		// если нужно поменять нечетное количество элементов, то решения нет
		if d%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if d == 2 {
			var l, r int
			for l = 0; !c[l]; {
				l++
			}
			for r = n - 1; !c[r]; {
				r--
			}

			if l+1 == r {
				fmt.Println(int(min(2*y, x)))
			} else {
				fmt.Println(int(min(float64(r-l)*x, y)))
			}

			continue
		}

		if d == 0 || x >= y {
			fmt.Println(int(float64(d/2) * y))
			continue
		}
		z0 := make([][]float64, n, n)
		z1 := make([][]float64, n, n)
		for i := 0; i < n; i++ {
			z0[i] = make([]float64, n+1, n+1)
			z1[i] = make([]float64, n+1, n+1)
			for j := 0; j <= n; j++ {
				z0[i][j] = math.Inf(1)
				z1[i][j] = math.Inf(1)
			}
		}
		if c[0] {
			z1[0][1] = 0
		} else {
			z0[0][0] = 0
		}
		for i := 1; i < n; i++ {
			if c[i] {
				for j := i + 1; j >= 0; j-- {
					if j <= i {
						z0[i][j] = min(z0[i-1][j+1]+y, z1[i-1][j+1]+x)
					}
					if j > 0 {
						z0[i][j] = min(min(z0[i][j], z0[i-1][j-1]+x), z1[i-1][j-1]+y)
						z1[i][j] = min(z0[i-1][j-1], z1[i-1][j-1])
					}
				}
			} else {
				for j := i + 1; j >= 0; j-- {
					z0[i][j] = min(z0[i-1][j], z1[i-1][j])
					z1[i][j] = min(z0[i-1][j]+y, z1[i-1][j]+x)
					if j > 1 {
						z1[i][j] = min(min(z1[i][j], z0[i-1][j-2]+x), z1[i-1][j-2]+y)
					}
				}
			}
		}
		fmt.Printf("%d\n", int(z0[n-1][0]))
	}
}

package main

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

func min(i, j float64) float64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.ParseFloat(arr[1], 64)
		y, _ := strconv.ParseFloat(arr[2], 64)
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		d := 0
		c := make([]bool, n, n)
		for i := 0; i < n; i++ {
			c[i] = a[i] != b[i]
			if c[i] {
				d++
			}
		}

		// если нужно поменять нечетное количество элементов, то решения нет
		if d%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if d == 2 {
			var l, r int
			for l = 0; !c[l]; {
				l++
			}
			for r = n - 1; !c[r]; {
				r--
			}

			if l+1 == r {
				fmt.Println(min(2*y, x))
			} else {
				fmt.Println(min(float64(r-l)*x, y))
			}

			continue
		}

		if d == 0 || x >= y {
			fmt.Println(float64(d/2) * y)
			continue
		}
		z0 := make([][]float64, n, n)
		z1 := make([][]float64, n, n)
		for i := 0; i < n; i++ {
			z0[i] = make([]float64, n+1, n+1)
			z1[i] = make([]float64, n+1, n+1)
			for j := 0; j <= n; j++ {
				z0[i][j] = math.Inf(1)
				z1[i][j] = math.Inf(1)
			}
		}
		if c[0] {
			z1[0][1] = 0
		} else {
			z0[0][0] = 0
		}
		for i := 1; i < n; i++ {
			if c[i] {
				for j := i + 1; j >= 0; j-- {
					if j <= i {
						z0[i][j] = min(z0[i-1][j+1]+y, z1[i-1][j+1]+x)
					}
					if j > 0 {
						z0[i][j] = min(min(z0[i][j], z0[i-1][j-1]+x), z1[i-1][j-1]+y)
						z1[i][j] = min(z0[i-1][j-1], z1[i-1][j-1])
					}
				}
			} else {
				for j := i + 1; j >= 0; j-- {
					z0[i][j] = min(z0[i-1][j], z1[i-1][j])
					z1[i][j] = min(z0[i-1][j]+y, z1[i-1][j]+x)
					if j > 1 {
						z1[i][j] = min(min(z1[i][j], z0[i-1][j-2]+x), z1[i-1][j-2]+y)
					}
				}
			}
		}
		fmt.Printf("%d\n", int(z0[n-1][0]))
	}
}

package main

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

func min(i, j float64) float64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.ParseFloat(arr[1], 64)
		y, _ := strconv.ParseFloat(arr[2], 64)
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		d := 0
		c := make([]bool, n, n)
		for i := 0; i < n; i++ {
			c[i] = a[i] != b[i]
			if c[i] {
				d++
			}
		}

		// если нужно поменять нечетное количество элементов, то решения нет
		if d%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if d == 2 {
			var l, r int
			for l = 0; !c[l]; {
				l++
			}
			for r = n - 1; !c[r]; {
				r--
			}

			if l+1 == r {
				fmt.Println(min(2*y, x))
			} else {
				fmt.Println(min(float64(r-l)*x, y))
			}

			continue
		}

		if d == 0 || x >= y {
			fmt.Println(float64(d/2) * y)
			continue
		}
		z0 := make([][]float64, n, n)
		z1 := make([][]float64, n, n)
		for i := 0; i < n; i++ {
			z0[i] = make([]float64, n+1, n+1)
			z1[i] = make([]float64, n+1, n+1)
			for j := 0; j <= n; j++ {
				z0[i][j] = math.Inf(1)
				z1[i][j] = math.Inf(1)
			}
		}
		if c[0] {
			z1[0][1] = 0
		} else {
			z0[0][0] = 0
		}
		for i := 1; i < n; i++ {
			if c[i] {
				for j := i + 1; j >= 0; j-- {
					if j <= i {
						z0[i][j] = min(z0[i-1][j+1]+y, z1[i-1][j+1]+x)
					}
					if j > 0 {
						z0[i][j] = min(min(z0[i][j], z0[i-1][j-1]+x), z1[i-1][j-1]+y)
						z1[i][j] = min(z0[i-1][j-1], z1[i-1][j-1])
					}
				}
			} else {
				for j := i + 1; j >= 0; j-- {
					z0[i][j] = min(z0[i-1][j], z1[i-1][j])
					z1[i][j] = min(z0[i-1][j]+y, z1[i-1][j]+x)
					if j > 1 {
						z1[i][j] = min(min(z1[i][j], z0[i-1][j-2]+x), z1[i-1][j-2]+y)
					}
				}
			}
		}
		fmt.Println(int(z0[n-1][0]))
	}
}

package main

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

func min(i, j float64) float64 {
	if i < j {
		return i
	}
	return j
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.ParseFloat(arr[1], 64)
		y, _ := strconv.ParseFloat(arr[2], 64)
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		d := 0
		c := make([]bool, n, n)
		for i := 0; i < n; i++ {
			c[i] = a[i] != b[i]
			if c[i] {
				d++
			}
		}

		// если нужно поменять нечетное количество элементов, то решения нет
		if d%2 == 1 {
			fmt.Println(-1)
			continue
		}

		if d == 2 {
			var l, r int
			for l = 0; !c[l]; {
				l++
			}
			for r = n - 1; !c[r]; {
				r--
			}

			if l+1 == r {
				fmt.Println(min(2*y, x))
			} else {
				fmt.Println(min(float64(r-l)*x, y))
			}

			continue
		}

		if d == 0 || x >= y {
			fmt.Println(float64(d/2) * y)
			continue
		}
		z0 := make([][]float64, n, n)
		z1 := make([][]float64, n, n)
		for i := 0; i < n; i++ {
			z0[i] = make([]float64, n+1, n+1)
			z1[i] = make([]float64, n+1, n+1)
			for j := 0; j <= n; j++ {
				z0[i][j] = math.Inf(1)
				z1[i][j] = math.Inf(1)
			}
		}
		if c[0] {
			z1[0][1] = 0
		} else {
			z0[0][0] = 0
		}
		for i := 1; i < n; i++ {
			if c[i] {
				for j := i + 1; j >= 0; j-- {
					if j <= i {
						z0[i][j] = min(z0[i-1][j+1]+y, z1[i-1][j+1]+x)
					}
					if j > 0 {
						z0[i][j] = min(min(z0[i][j], z0[i-1][j-1]+x), z1[i-1][j-1]+y)
						z1[i][j] = min(z0[i-1][j-1], z1[i-1][j-1])
					}
				}
			} else {
				for j := i + 1; j >= 0; j-- {
					z0[i][j] = min(z0[i-1][j], z1[i-1][j])
					z1[i][j] = min(z0[i-1][j]+y, z1[i-1][j]+x)
					if j > 1 {
						z1[i][j] = min(min(z1[i][j], z0[i-1][j-2]+x), z1[i-1][j-2]+y)
					}
				}
			}
		}
		fmt.Println(z0[n-1][0])
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.Atoi(arr[1])
		y, _ := strconv.Atoi(arr[2])
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		indexes := make([]int, 0)
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				indexes = append(indexes, i)
			}
		}
		ln := len(indexes)
		if ln%2 > 0 {
			fmt.Println(-1)
			continue
		}
		if x >= y {
			if ln == 2 {
				if indexes[1]-indexes[0] == 1 {
					min := x
					if 2*y < min {
						min = 2 * y
					}
					fmt.Println(min)
				} else {
					fmt.Println(y)
				}
			} else {
				fmt.Println(ln / 2 * y)
			}
		} else {
			completed := make(map[int]bool)
			prevMinDistance := 0
			minDistance := n
			distances := make(map[int]int)
			for {
				for first, last := 0, 1; last < ln; first, last = last, last+1 {
					if completed[indexes[first]] {
						continue
					}
					for completed[indexes[last]] {
						last++
					}
					d := indexes[last] - indexes[first]
					if d > prevMinDistance && d < minDistance {
						minDistance = d
					}
				}
				if prevMinDistance == minDistance {
					break
				}
				for first, last := 0, 1; last < ln; first, last = last, last+1 {
					if completed[indexes[first]] {
						continue
					}
					for completed[indexes[last]] {
						last++
					}
					d := indexes[last] - indexes[first]
					if d == minDistance {
						completed[indexes[first]] = true
						completed[indexes[last]] = true
						first++
						last++
						distances[minDistance]++
					}
				}
				prevMinDistance = minDistance
				minDistance = n
			}

			min := 0
			for k, v := range distances {
				if k*x < y {
					min += k * x * v
				} else {
					min += v * y
				}
			}
			fmt.Println(min)
		}

	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	txt, _ := reader.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(txt))
	for ; t > 0; t-- {
		txt, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(txt), " ")
		n, _ := strconv.Atoi(arr[0])
		x, _ := strconv.Atoi(arr[1])
		y, _ := strconv.Atoi(arr[2])
		txt, _ = reader.ReadString('\n')
		a := strings.TrimSpace(txt)
		txt, _ = reader.ReadString('\n')
		b := strings.TrimSpace(txt)
		indexes := make([]int, 0)
		for i := 0; i < n; i++ {
			if a[i] != b[i] {
				indexes = append(indexes, i)
			}
		}
		ln := len(indexes)
		if ln%2 > 0 {
			fmt.Println(-1)
			continue
		}
		if x >= y {
			if ln == 2 {
				if indexes[1]-indexes[0] == 1 {
					min := x
					if 2*y < min {
						min = 2 * y
					}
					fmt.Println(min)
				} else {
					fmt.Println(y)
				}
			} else {
				fmt.Println(ln / 2 * y)
			}
		} else {
			cntX := 0
			for i := 1; i < ln; i++ {
				if indexes[i]-indexes[i-1] == 1 {
					cntX++
					i++
				}
			}
			fmt.Println(cntX*x + (ln-cntX*2)/2*y)
		}

	}
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func print(a ...interface{})            { fmt.Println(a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f+"\n", a...) }

func main() {
	defer writer.Flush()

	var testcases int64
	scanf("%d", &testcases)
  var i int64
	for i = 0; i < testcases; i++ {
		var n, x, y int64
		scanf("%d %d %d", &n, &x, &y)
    var a, b string
    scanf("%s", &a)
    scanf("%s", &b)

		print(solve(n, x, y, a, b))
	}
}

func max(nums ...int64) int64 {
  result := nums[0]
	for _, num := range nums {
		if num > result {
			result = num
		}
	}
	return result
}

func min(nums ...int64) int64 {
  result := nums[0]
  for _, num := range nums {
    if num < result {
      result = num
    }
  }
  return result
}

func solve(n, x, y int64, a, b string) int64 {
  diffs := make([]int64, 0, n)
  var i int64
  for i = 0; i < n; i++ {
    if a[i] != b[i] {
      diffs = append(diffs, i)
    }
  }

  m := int64(len(diffs))

  if m % 2 == 1 {
    return -1
  }

  if x >= y {
    if m == 2 && diffs[0] + 1 == diffs[1] {
      return min(x, y*2)
    }
    return y * m / 2
  }

  dp := make([][]int64, m)
  for i = 0; i < m; i++ {
    dp[i] = make([]int64, m)
    var j int64
    for j = 0; j < m; j++ {
      dp[i][j] = -1
    }
  }
  var dfs func(i, drop int64) int64
  dfs = func(i, drop int64) int64 {
    if i >= m {
      if drop == 0 {
        return 0
      }
      return math.MaxInt32
    }
    if dp[i][drop] != -1 {
      return dp[i][drop]
    }
    result := dfs(i+1, drop+1)
    if drop > 0 {
      result = min(result, dfs(i+1, drop-1) + y)
    }
    if i < m-1 {
      result = min(result, dfs(i+2, drop) + min(y, x * (diffs[i+1] - diffs[i])))
    }
    dp[i][drop] = result
    return result
  }
  res := dfs(0, 0)
  return res
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func print(a ...interface{})            { fmt.Println(a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f+"\n", a...) }

func main() {
	defer writer.Flush()

	var testcases int
	scanf("%d", &testcases)
	for i := 0; i < testcases; i++ {
		var n, x, y int
		scanf("%d %d %d", &n, &x, &y)
    var a, b string
    scanf("%s", &a)
    scanf("%s", &b)

		print(solve(n, x, y, a, b))
	}
}

func max(nums ...int) int {
	result := math.MinInt32
	for _, num := range nums {
		if num > result {
			result = num
		}
	}
	return result
}

func min(nums ...int) int {
  result := nums[0]
  for _, num := range nums {
    if num < result {
      result = num
    }
  }
  return result
}

func solve(n, x, y int, a, b string) int {
  diffs := make([]int, 0, n)
  for i := 0; i < n; i++ {
    if a[i] != b[i] {
      diffs = append(diffs, i)
    }
  }

  m := len(diffs)

  if m % 2 == 1 {
    return -1
  }

  if x >= y {
    if m == 2 && diffs[0] + 1 == diffs[1] {
      return min(x, y*2)
    }
    return y * m / 2
  }

  dp := make([][]int, m)
  for i := 0; i < m; i++ {
    dp[i] = make([]int, m)
    for j := 0; j < m; j++ {
      dp[i][j] = -1
    }
  }
  var dfs func(i, drop int) int
  dfs = func(i, drop int) int {
    if i >= m {
      if drop == 0 {
        return 0
      }
      return math.MaxInt32
    }
    if dp[i][drop] != -1 {
      return dp[i][drop]
    }
    result := dfs(i+1, drop+1)
    if drop > 0 {
      result = min(result, dfs(i+1, drop-1) + y)
    }
    if i < m-1 {
      result = min(result, dfs(i+2, drop) + min(y, x * (diffs[i+1] - diffs[i])))
    }
    dp[i][drop] = result
    return result
  }
  res := dfs(0, 0)
  return res
}


package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, m := read(), uint(read())
	mat := make([][]int, n)
	for i := range mat {
		mat[i] = make([]int, m)
		for j := range mat[i] {
			mat[i][j] = read()
		}
	}
	var ansI, ansJ int
	sort.Search(1e9+1, func(min int) bool {
		id := make([]int, 1<<m)
		for i, mi := range mat {
			v := 0
			for j, a := range mi {
				if a >= min {
					v |= 1 << uint(j)
				}
			}
			id[v] = i + 1
		}
		for i := range id {
			if id[i] > 0 {
				for j := i; j < 1<<m; j++ {
					if i|j == 1<<m-1 && id[j] > 0 {
						ansI, ansJ = id[i], id[j]
						return false
					}
				}
			}
		}
		return true
	})
	Print(ansI, ansJ)
}

package main

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

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

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

func scanInt64() int64 {
	sc.Scan()
	a, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return a
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 {
			fmt.Fprint(wr, " ")
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

const mod = 1000000007

var (
	n      int
	m      int
	a      [][]int
	single int
	ans1   int
	ans2   int
	MX     uint
)

func check(value int) (bool, int, int) {
	cnt := make([]int, MX)
	sum := make([]int, MX)
	for i := 0; i < n; i++ {
		mask := uint(0)
		for j := uint(0); j < uint(m); j++ {
			if a[i][j] >= value {
				mask |= (1 << j)
			}
		}
		cnt[mask] = i + 1
		sum[mask] = i + 1
	}
	for i := uint(0); i < uint(m); i++ {
		for j := uint(0); j < MX; j++ {
			if (j>>i&1) == 1 && sum[j] != 0 {
				sum[j^(1<<i)] = sum[j]
			}
		}
	}
	maskMax := uint(MX - 1)
	for mask := uint(1); mask < MX; mask++ {
		if cnt[mask] == 0 {
			continue
		}
		if sum[maskMax^mask] != 0 {
			return true, cnt[mask], sum[maskMax^mask]
		}
	}
	return false, 0, 0
}

func main() {
	sc.Split(bufio.ScanWords)
	n = scanInt()
	m = scanInt()
	a = make([][]int, n)
	MX = uint(1) << uint(m)
	for i := range a {
		a[i] = make([]int, m)
	}
	for i := 0; i < n; i++ {
		rowMin := 0
		for j := 0; j < m; j++ {
			a[i][j] = scanInt()
			if a[i][j] < rowMin {
				rowMin = a[i][j]
			}
			if rowMin >= single {
				single = rowMin
				ans1 = i + 1
				ans2 = i + 1
			}
		}
	}
	low, high, mid := single+1, 1000000000, 0
	for low <= high {
		mid = (low + high) >> 1
		judge, row1, row2 := check(mid)
		if judge {
			ans1, ans2 = row1, row2
			low = mid + 1
		} else {
			high = mid - 1
		}
	}
	fmt.Println(ans1, " ", ans2)
}

package main

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

const (
	mod = 998244353
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Fscanf(in, "%d", &a[i][j])
		}
		fmt.Fscanf(in, "\n")
	}
	//fmt.Println(a)
	l := 0
	r := int(1e9)
	for l < r {
		mid := (l + r + 1) / 2
		x, _ := find(a, mid)
		if x != -1 {
			l = mid
		} else {
			r = mid - 1
		}
	}
	x, y := find(a, l)
	fmt.Fprintf(out, "%d %d\n", x+1, y+1)
	return
}

func find(a [][]int, find int) (int, int) {
	//fmt.Println("try to find ", find, a)
	ansMap := make([]int, 256)
	for i := 0; i < 256; i++ {
		ansMap[i] = -1
	}
	n := len(a)
	m := len(a[0])
	for i := 0; i < n; i++ {
		weight := 1
		state := 0
		for j := 0; j < m; j++ {
			if a[i][j] >= find {
				state += weight
			}
			weight *= 2
		}
		if ansMap[state] == -1 {
			ansMap[state] = i
		}
	}
	wantedState := 1<<uint(m) - 1
	//fmt.Println("debug wantedState", wantedState, ansMap[:32])
	for i := 0; i <= wantedState; i++ {
		for j := 0; j <= wantedState; j++ {
			if i|j == wantedState && ansMap[i] != -1 && ansMap[j] != -1 {
				return ansMap[i], ansMap[j]
			}
		}
	}
	return -1, -1
}

package main

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

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

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

func scanInt64() int64 {
	sc.Scan()
	a, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return a
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 {
			fmt.Fprint(wr, " ")
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

const mod = 1000000007

var (
	n      int
	m      int
	a      [][]int
	single int
	ans1   int
	ans2   int
	MX     uint
)

func check(value int) (bool, int, int) {
	cnt := make([]int, MX)
	sum := make([]int, MX)
	for i := 0; i < n; i++ {
		mask := uint(0)
		for j := uint(0); j < uint(m); j++ {
			if a[i][j] >= value {
				mask |= (1 << j)
			}
		}
		cnt[mask] = i + 1
		sum[mask] = i + 1
	}
	for i := uint(0); i < uint(m); i++ {
		for j := uint(0); j < MX; j++ {
			if (j>>i&1) == 1 && sum[j] != 0 {
				sum[j^(1<<i)] = sum[j]
			}
		}
	}
	maskMax := uint(MX - 1)
	for mask := uint(1); mask < MX; mask++ {
		if cnt[mask] == 0 {
			continue
		}
		if sum[maskMax^mask] != 0 {
			return true, cnt[mask], sum[maskMax^mask]
		}
	}
	return false, 0, 0
}

func main() {
	sc.Split(bufio.ScanWords)
	n = scanInt()
	m = scanInt()
	a = make([][]int, n)
	MX = uint(1) << uint(m)
	for i := range a {
		a[i] = make([]int, m)
	}
	for i := 0; i < n; i++ {
		rowMin := 0
		for j := 0; j < m; j++ {
			a[i][j] = scanInt()
			if a[i][j] < rowMin {
				rowMin = a[i][j]
			}
			if rowMin > single {
				single = rowMin
				ans1 = i + 1
				ans2 = i + 1
			}
		}
	}
	low, high, mid := single+1, 1000000000, 0
	for low <= high {
		mid = (low + high) >> 1
		judge, row1, row2 := check(mid)
		if judge {
			ans1, ans2 = row1, row2
			low = mid + 1
		} else {
			high = mid - 1
		}
	}
	println(ans1, " ", ans2)
}

package main

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

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

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

func scanInt64() int64 {
	sc.Scan()
	a, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return a
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 {
			fmt.Fprint(wr, " ")
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

const mod = 1000000007

var (
	n      int
	m      int
	a      [][]int
	single int
	ans1   int
	ans2   int
	MX     uint
)

func check(value int) (bool, int, int) {
	cnt := make([]int, MX)
	sum := make([]int, MX)
	for i := 0; i < n; i++ {
		mask := uint(0)
		for j := uint(0); j < uint(m); j++ {
			if a[i][j] >= value {
				mask |= (1 << j)
			}
		}
		cnt[mask] = i + 1
		sum[mask] = i + 1
	}
	for i := uint(0); i < uint(m); i++ {
		for j := uint(0); j < MX; j++ {
			if (j>>i&1) == 1 && sum[j] != 0 {
				sum[j^(1<<i)] = sum[j]
			}
		}
	}
	maskMax := uint(MX - 1)
	for mask := uint(1); mask < MX; mask++ {
		if cnt[mask] == 0 {
			continue
		}
		if sum[maskMax^mask] != 0 {
			return true, cnt[mask], sum[maskMax^mask]
		}
	}
	return false, 0, 0
}

func main() {
	sc.Split(bufio.ScanWords)
	n = scanInt()
	m = scanInt()
	a = make([][]int, n)
	MX = uint(1) << uint(m)
	for i := range a {
		a[i] = make([]int, m)
	}
	for i := 0; i < n; i++ {
		rowMin := 0
		for j := 0; j < m; j++ {
			a[i][j] = scanInt()
			if a[i][j] < rowMin {
				rowMin = a[i][j]
			}
			if rowMin > single {
				single = rowMin
				ans1 = i + 1
				ans2 = i + 1
			}
		}
	}
	low, high, mid := single+1, 1000000000, 0
	for low <= high {
		mid = (low + high) >> 1
		judge, row1, row2 := check(mid)
		if judge {
			ans1, ans2 = row1, row2
			low = mid + 1
		} else {
			high = mid - 1
		}
	}
	fmt.Println(ans1, " ", ans2)
}