A bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person.You have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of $$$n$$$ ($$$n \ge 3$$$) positive distinct integers (i.e. different, no duplicates are allowed).Find the largest subset (i.e. having the maximum number of elements) of this array such that its sum is a composite number. A positive integer $$$x$$$ is called composite if there exists a positive integer $$$y$$$ such that $$$1 < y < x$$$ and $$$x$$$ is divisible by $$$y$$$.If there are multiple subsets with this largest size with the composite sum, you can output any of them. It can be proven that under the constraints of the problem such a non-empty subset always exists.

Each test consists of multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 100$$$) — the length of the array. The second line of each test case contains $$$n$$$ distinct integers $$$a_{1},a_{2},\dots,a_{n}$$$ ($$$1 \leq a_{i} \leq 200$$$) — the elements of the array.

Each test case should have two lines of output. The first line should contain a single integer $$$x$$$: the size of the largest subset with composite sum. The next line should contain $$$x$$$ space separated integers representing the indices of the subset of the initial array.

NoteIn the first test case, the subset $$$\{a_2, a_1\}$$$ has a sum of $$$9$$$, which is a composite number. The only subset of size $$$3$$$ has a prime sum equal to $$$11$$$. Note that you could also have selected the subset $$$\{a_1, a_3\}$$$ with sum $$$8 + 2 = 10$$$, which is composite as it's divisible by $$$2$$$.In the second test case, the sum of all elements equals to $$$21$$$, which is a composite number. Here we simply take the whole array as our subset.

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n int
		fmt.Fscan(r, &n)
		arr := make([]int, n)
		var total int
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
			total += int(arr[i])
		}
		found := 0
		for j := 2; j*j <= total; j++ {
			if total%j == 0 {
				found = 1
				break
			}
		}
		fmt.Fprintln(w, n+found-1)
		for i, v := range arr {
			if v%2 == 1 && found == 0 {
				found = 1
			} else {
				fmt.Fprint(w, i+1, " ")
			}
		}
		fmt.Fprintln(w)
	}
}

package main

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

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, sum := []int{}, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			o = append(o, p)
			sum += p
		}
		if !IsPrime(sum) {
			fmt.Fprint(w, n, "\n")
			for j := 0; j < n; j++ {
				fmt.Fprint(w, j+1, " ")
			}
		} else {
			for j := 0; j < n; j++ {
				if !IsPrime(sum - o[j]) {
					fmt.Fprint(w, n-1, "\n")
					for k := 0; k < n; k++ {
						if k != j {
							fmt.Fprint(w, k+1, " ")
						}
					}
					break
				}
			}
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

func solve(n int, a []int) {
	var sum, p int
	for i, x := range a {
		sum += x
		if x%2 == 1 {
			p = i
		}
	}
	if isPrime(sum) {
		fmt.Println(n - 1)
		for i := range a {
			if i != p {
				fmt.Print(i+1, " ")
			}
		}
		fmt.Println()
		return
	}
	fmt.Println(n)
	for i := range a {
		fmt.Print(i+1, " ")
	}
	fmt.Println()
	return
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		solve(n, a)
	}
}

package main
import (
  "C"
  "fmt"
)
var (
  x[600] int
  t =0
)
func main() {
  fmt.Scanf("%d\n",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    _,err:=fmt.Scanf("%d\n",&n)
    if err !=nil{
      fmt.Println("INPUT ERROR")
      return
    }
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    fmt.Scanln()
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var (
  x[600] int
  t =0
)
func main() {
  fmt.Scanf("%d\n",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    _,err:=fmt.Scanf("%d\n",&n)
    if err !=nil{
      fmt.Println("INPUT ERROR")
      return
    }
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    fmt.Scanln()
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var (
  x = make([]int,600)
  t =0
)
func main() {
  fmt.Scanf("%d\n",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    _,err:=fmt.Scanf("%d\n",&n)
    if err !=nil{
      fmt.Println("INPUT ERROR")
      return
    }
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    fmt.Scanln()
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main

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

/*
5
3
8 1 2
4
6 9 4 2
9
1 2 3 4 5 6 7 8 9
3
200 199 198
3
6 5 2
---
2
2 1
4
2 1 4 3
9
6 9 1 2 3 4 5 7 8
3
1 2 3
2
1 3
==========
1
4
4 5 8 6
---
3
1 2 4
*/

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

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

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var n int
		scanf("%d\n", &n)

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

		if !isPrime(sum) {
			fmt.Fprintf(&bld, "%d\n", n)
			for i := range a {
				fmt.Fprintf(&bld, "%d ", i+1)
			}
		} else {
			fmt.Fprintf(&bld, "%d\n", n-1)

			excluded := false
			for i, v := range a {
				if !excluded && v%2 == 1 {
					excluded = true
					continue
				}

				fmt.Fprintf(&bld, "%d ", i+1)
			}
		}
		fmt.Fprintf(&bld, "\n")
	}

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

func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

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

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

	return true
}

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

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

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 16 * 1024 * 1024)

	stdout := os.Stdout

	defer stdout.Close()

	writer := bufio.NewWriterSize(stdout, 16 * 1024 * 1024)

	tTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)
	t := int(tTemp)

	for t > 0 {
		nTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
		checkError(err)
		n := int(nTemp)

		arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")

		var ar []int

		for i := 0; i < n; i++ {
			arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
			checkError(err)
			arItem := int(arItemTemp)
			ar = append(ar, arItem)
		}

		var sum int
		var idx int
		for i, v := range ar {
			if v % 2 != 0 {
				idx = i
			}
			sum += v
		}

		var x = n - 1
		for s := 2; s <= int(math.Sqrt(float64(sum))) + 1; s++ {
			if sum % s == 0 {
				x = n
				break
			}
		}

		if x == n - 1 {
			fmt.Fprintln(writer, x)
			for i := 0; i < n; i++ {
				if i != idx {
					fmt.Fprintf(writer, "%d ", i+1)
				}
			}
		} else {
			fmt.Fprintf(writer, "%d\n", x)
			for i := 0; i < n; i++ {
				fmt.Fprintf(writer, "%d ", i+1)
			}
		}
		fmt.Fprintln(writer)

		t--
	}

	writer.Flush()
}

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

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

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

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

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

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

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

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    sum := 0
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
        sum += a[i]
    }
    if !isPrime(sum) {
        out(a)
        return
    }
    // find odd elem
    fmt.Fprintln(output, len(a) - 1)
    skipped := false
    for i := 0; i < len(a); i++ {
        if !skipped && a[i] % 2 == 1 {
            skipped = true
            continue
        }
        fmt.Fprint(output, i + 1, " ")
    }
    fmt.Fprintln(output)
}

func isPrime(x int) bool {
    for i := 2; i*i <= x; i++ {
        if x % i == 0 {
            return false
        }
    }
    return true
}
func out(a []int) {
    fmt.Fprintln(output, len(a))
    for i := 0; i < len(a); i++ {
        fmt.Fprint(output, i + 1, " ")
    }
    fmt.Fprintln(output)
}

package main

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

func main() {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		b := make([]int, n)
		var sum int = 0
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			sum += a[i]
		}
		for i := 0; i < len(b); i++ {
			b[i] = i
		}
		sort.Slice(b, func(l, r int) bool {
			return a[b[l]]%2 < a[b[r]]%2
		})
		var flag int = 1
		for i := 2; i*i <= sum; i++ {
			if sum%i == 0 {
				flag -= 1
			}
		}
		var n_len int = n
		if flag == 1 {
			n_len--
		}
		fmt.Fprint(out, n_len, "\n")
		for i := 0; i < n_len; i++ {
			fmt.Fprint(out, b[i]+1, " ")
		}
		fmt.Fprintln(out)
	}
}

package main
import (
  "C"
  "fmt"
)
var (
  x[600] int
  t =0
)
func main() {
  fmt.Scanf("%d",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    _,err:=fmt.Scanf("%d",&n)
    if err !=nil{
      fmt.Println("INPUT ERROR")
      return
    }
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    //fmt.Scanln()
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var (
  x = make([]int,600)
  t =0
)
func main() {
  fmt.Scanf("%d\n",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    _,err:=fmt.Scanf("%d",&n)
    if err !=nil{
      fmt.Println("INPUT ERROR")
      return
    }
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var (
  x = make([]int,600)
  t =0
)
func main() {
  fmt.Scanf("%d",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    _,err:=fmt.Scanf("%d",&n)
    if err !=nil{
      fmt.Println("INPUT ERROR")
      return
    }
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var (
  x = make([]int,600)
  t =0
)
func main() {
  fmt.Scanf("%v",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    _,err:=fmt.Scanf("%v",&n)
    if err !=nil{
      fmt.Println("INPUT ERROR")
      return
    }
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%v",&x[i])
      sum += x[i]
    }
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var (
  x = make([]int,600)
  t =0
)
func main() {
  fmt.Scanf("%v",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    fmt.Scanf("%v",&n)
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%v",&x[i])
      sum += x[i]
    }
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var (
  x = make([]int,600)
  t =0
)
func main() {
  fmt.Scanf("%d",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    fmt.Scanf("%d",&n)
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main
import (
  "fmt"
)
var x[600] int
func main() {
  var t int
  fmt.Scanf("%d",&t)
  for ;t>0;t-- {
    n,f,sum:=0,0,0
    fmt.Scanf("%d",&n)
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Printf("%d\n",n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Printf("%d\n",n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Printf("\n")
  }

  //fmt.Println(t)
}

package main

import (
  "fmt"
)
var x[600] int
func main() {
  var t int
  fmt.Scanln(&t)
  for {
    if t == 0 {
      break
    }
    t--
    var n int
    fmt.Scanln(&n)
     sum := 0
    for  i := 1 ; i <= n ;i++ {
      fmt.Scanf("%d",&x[i])
      sum += x[i]
    }
    f := 0
    for i := 2 ; i * i <= sum ; i++ {
      if sum % i == 0 {
        f = 1
        break
      }
    }
    if f == 1 {
      fmt.Println(n)
      for  i := 1 ; i <= n ;i++ {
        fmt.Printf("%d ",i)

        //sum += x[i]
      }
    }else {
      fmt.Println(n - 1)
      f = 0
      for  i := 1 ; i <= n ;i++ {
        if x[i] % 2 == 0 {
          fmt.Printf("%d ",i)
        } else if f == 1 {
          fmt.Printf("%d ",i)
        }else {
          f = 1
        }
        //sum += x[i]
      }

    }
    fmt.Println()
  }

  //fmt.Println(t)
}

package main

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

/*
5
3
8 1 2
4
6 9 4 2
9
1 2 3 4 5 6 7 8 9
3
200 199 198
3
6 5 2
---
2
2 1
4
2 1 4 3
9
6 9 1 2 3 4 5 7 8
3
1 2 3
2
1 3
==========
1
4
4 5 8 6
---
3
1 2 4
*/

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

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

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var n int
		scanf("%d\n", &n)

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

		if isComposite(sum) {
			fmt.Fprintf(&bld, "%d\n", n)
			for i := range a {
				fmt.Fprintf(&bld, "%d ", i+1)
			}
		} else {
			excluded := false
			fmt.Fprintf(&bld, "%d\n", n-1)
			for i, v := range a {
				if !excluded && v%2 == 1 {
					excluded = true
					continue
				}

				fmt.Fprintf(&bld, "%d ", i+1)
			}
		}
		fmt.Fprintf(&bld, "\n")
	}

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

func isComposite(n int) bool {
	return (n%2 == 0 && n != 2) ||
		(n%3 == 0 && n != 3) ||
		(n%5 == 0 && n != 5) ||
		(n%7 == 0 && n != 7) ||
		(n%11 == 0 && n != 11) ||
		(n%13 == 0 && n != 13)
}

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

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

package main

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

/*
5
3
8 1 2
4
6 9 4 2
9
1 2 3 4 5 6 7 8 9
3
200 199 198
3
6 5 2
---
2
2 1
4
2 1 4 3
9
6 9 1 2 3 4 5 7 8
3
1 2 3
==========
1
3
6 5 2
---
1
3
*/

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

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

	bld := strings.Builder{}

	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			scanf("%d", &a[j])
		}
		scanf("\n")

		for j := 1; j < n; j++ {
			a[j] += a[j-1]
		}

		start := -1
		end := -2

		for j := 0; j < n; j++ {
			for k := j; k < n; k++ {
				snd := 0
				if j-1 >= 0 {
					snd = a[j-1]
				}
				sum := a[k] - snd
				if isComposite(sum) {
					if k-j > end-start {
						start = j
						end = k
					}
				}
			}
		}

		if start >= 0 {
			fmt.Fprintf(&bld, "%d\n", end-start+1)
			for j := start; j <= end; j++ {
				fmt.Fprintf(&bld, "%d ", j+1)
			}
			fmt.Fprintf(&bld, "\n")
		}
	}

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

func isComposite(n int) bool {
	return (n%2 == 0 && n != 2) ||
		(n%3 == 0 && n != 3) ||
		(n%5 == 0 && n != 5) ||
		(n%7 == 0 && n != 7) ||
		(n%11 == 0 && n != 11) ||
		(n%13 == 0 && n != 13)
}

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

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

package main

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

/*
5
3
8 1 2
4
6 9 4 2
9
1 2 3 4 5 6 7 8 9
3
200 199 198
3
1 1 1
---
2
2 1
4
2 1 4 3
9
6 9 1 2 3 4 5 7 8
3
1 2 3
==========
1
3
8 1 2
*/

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

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

	bld := strings.Builder{}

	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			scanf("%d", &a[j])
		}
		scanf("\n")

		for j := 1; j < n; j++ {
			a[j] += a[j-1]
		}

		start := -1
		end := -1

		for j := 0; j < n; j++ {
			for k := j + 1; k < n; k++ {
				snd := 0
				if j-1 >= 0 {
					snd = a[j-1]
				}
				sum := a[k] - snd
				if isComposite(sum) {
					if k-j > end-start {
						start = j
						end = k
					}
				}
			}
		}

		if start >= 0 {
			fmt.Fprintf(&bld, "%d\n", end-start+1)
			for j := start; j <= end; j++ {
				fmt.Fprintf(&bld, "%d ", j+1)
			}
			fmt.Fprintf(&bld, "\n")
		}
	}

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

func isComposite(n int) bool {
	return (n%2 == 0 && n != 2) ||
		(n%3 == 0 && n != 3) ||
		(n%5 == 0 && n != 5) ||
		(n%7 == 0 && n != 7) ||
		(n%11 == 0 && n != 11) ||
		(n%13 == 0 && n != 13)
}

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

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

package main

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

func main() {
	var t int
	_, _ = fmt.Scanf("%d\n", &t)

	for t > 0 {
		var n int
		_, _ = fmt.Scanf("%d\n", &n)

		var a = make([]int, n)
		_, _ = fmt.Fscan(os.Stdin, packAddrs(a)...)

		var sum int
		var idx int
		for i, v := range a {
			if v % 2 != 0 {
				idx = i
			}
			sum += v
		}

		var x = n - 1
		for s := 2; s <= int(math.Sqrt(float64(sum))) + 1; s++ {
			if sum % s == 0 {
				x = n
				break
			}
		}

		if x == n - 1 {
			fmt.Println(x)
			for i := 0; i < n; i++ {
				if i != idx {
					fmt.Print(i+1, " ")
				}
			}
		} else {
			fmt.Println(x)
			for i := 0; i < n; i++ {
				fmt.Print(i+1, " ")
			}
		}
		fmt.Println()

		t--
	}

}

func packAddrs(n []int) []interface{} {
	p := make([]interface{}, len(n))
	for i := range n {
		p[i] = &n[i]
	}
	return p
}

package main

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

func main() {
	var t int
	_, _ = fmt.Scanf("%d", &t)

	for t > 0 {
		var n int
		_, _ = fmt.Scanf("%d", &n)

		var a = make([]int, n)
		_, _ = fmt.Fscan(os.Stdin, packAddrs(a)...)

		var sum int
		var idx int
		for i, v := range a {
			if v % 2 != 0 {
				idx = i
			}
			sum += v
		}

		var x = n - 1
		for s := 2; s <= int(math.Sqrt(float64(sum))) + 1; s++ {
			if sum % s == 0 {
				x = n
				break
			}
		}

		if x == n - 1 {
			fmt.Println(x)
			for i := 0; i < n; i++ {
				if i != idx {
					fmt.Print(i+1, " ")
				}
			}
		} else {
			fmt.Println(x)
			for i := 0; i < n; i++ {
				fmt.Print(i+1, " ")
			}
		}
		fmt.Println()

		t--
	}

}

func packAddrs(n []int) []interface{} {
	p := make([]interface{}, len(n))
	for i := range n {
		p[i] = &n[i]
	}
	return p
}

package main

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

func main() {
	var t int
	_, _ = fmt.Scanf("%d", &t)

	for t > 0 {
		var n int
		_, _ = fmt.Scanf("%d", &n)

		var a = make([]int, n)
		_, _ = fmt.Fscan(os.Stdin, packAddrs(a)...)

		var sum int
		var idx int
		for i, v := range a {
			if v % 2 != 0 {
				idx = i
			}
			sum += v
		}

		var x = n
		for s := 2; s <= int(math.Sqrt(float64(sum))) + 1; s++ {
			if sum % s == 0 {
				x = n
				break
			}
		}

		if x == 0 {
			x--
			fmt.Println(x)
			for i := 0; i < n; i++ {
				if i != idx {
					fmt.Print(i+1, " ")
				}
			}
		} else {
			fmt.Println(x)
			for i := 0; i < n; i++ {
				fmt.Print(i+1, " ")
			}
		}
		fmt.Println()

		t--
	}

}

func packAddrs(n []int) []interface{} {
	p := make([]interface{}, len(n))
	for i := range n {
		p[i] = &n[i]
	}
	return p
}

package main

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

func main() {
	var t int
	_, _ = fmt.Scanf("%d", &t)

	for t > 0 {
		var n int
		_, _ = fmt.Scanf("%d", &n)

		var a = make([]int, n)
		_, _ = fmt.Fscan(os.Stdin, packAddrs(a)...)

		var sum int
		var idx int
		for i, v := range a {
			if v % 2 != 0 {
				idx = i
			}
			sum += v
		}

		var x int
		for s := 2; s <= int(math.Sqrt(float64(sum))) + 1; s++ {
			if sum % s == 0 {
				x = n
				break
			}
		}

		if x == 0 {
			x--
			fmt.Println(x)
			for i := 0; i < n; i++ {
				if i != idx {
					fmt.Print(i+1, " ")
				}
			}
		} else {
			fmt.Println(x)
			for i := 0; i < n; i++ {
				fmt.Print(i+1, " ")
			}
		}

		t--
	}

}

func packAddrs(n []int) []interface{} {
	p := make([]interface{}, len(n))
	for i := range n {
		p[i] = &n[i]
	}
	return p
}

package main

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

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

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

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

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    sum := 0
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
        sum += a[i]
    }
    if n % 2 == 0 || !isPrime(sum) {
        out(a)
        return
    }
    // find odd elem
    fmt.Fprintln(output, len(a) - 1)
    skipped := false
    for i := 0; i < len(a); i++ {
        if !skipped && a[i] % 2 == 1 {
            skipped = true
            continue
        }
        fmt.Fprint(output, i + 1, " ")
    }
    fmt.Fprintln(output)
}

func isPrime(x int) bool {
    for i := 2; i*i <= x; i++ {
        if x % i == 0 {
            return false
        }
    }
    return true
}
func out(a []int) {
    fmt.Fprintln(output, len(a))
    for i := 0; i < len(a); i++ {
        fmt.Fprint(output, i + 1, " ")
    }
    fmt.Fprintln(output)
}

package main

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

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

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

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

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    sum := 0
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
        sum += a[i]
    }
    if n % 2 == 0 || !isPrime(sum) {
        out(a)
        return
    }
    // find odd elem
    fmt.Fprintln(output, len(a) - 1)
    skipped := false
    for i := 0; i < len(a); i++ {
        if !skipped && a[i] % 2 == 1 {
            skipped = true
            continue
        }
        fmt.Fprint(output, i + 1, " ")
    }
    fmt.Fprintln(output)
}

func isPrime(x int) bool {
    for i := 2; i*i <= x; i++ {
        if x % i == 0 {
            return false
        }
    }
    return true
}
func out(a []int) {
    fmt.Fprintln(output, len(a))
    for i := 0; i < len(a); i++ {
        fmt.Fprint(output, a[i], " ")
    }
    fmt.Fprintln(output)
}

package main

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

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

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

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

func solve() {
    var n int
    fmt.Fscan(input, &n)
    a := make([]int, n)
    sum := 0
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
        sum += a[i]
    }
    if n % 2 == 0 || !isPrime(sum) {
        out(a)
        return
    }
    // find odd elem
    for i := 0; i < len(a); i++ {
        if a[i] % 2 == 1 {
            a[0], a[i] = a[i], a[0]
            out(a[1:])
        }
    }
}

func isPrime(x int) bool {
    for i := 2; i*i <= x; i++ {
        if x % i == 0 {
            return false
        }
    }
    return true
}
func out(a []int) {
    fmt.Fprintln(output, len(a))
    for i := 0; i < len(a); i++ {
        fmt.Fprint(output, a[i], " ")
    }
    fmt.Fprintln(output)
}

package main

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

func main() {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		b := make([]int, n)
		var sum int = 0
		for _, value := range a {
			fmt.Fscan(in, &value)
			sum += value
		}
		for i := 0; i < len(b); i++ {
			b[i] = i
		}
		sort.Slice(b, func(l, r int) bool {
			return a[l]%2 < a[r]%2
		})
		var flag int = 1
		for i := 2; i*i <= sum; i++ {
			if sum%i == 0 {
				flag -= 1
			}
		}
		var n_len int = n
		if flag == 1 {
			n_len--
		}
		fmt.Fprint(out, n_len, "\n")
		for i := 0; i < n_len; i++ {
			fmt.Fprint(out, b[i]+1, " ")
		}
		fmt.Fprintln(out)
	}
}

package main

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

func main() {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		b := make([]int, n)
		var sum int = 0
		for _, value := range a {
			fmt.Fscan(in, &value)
			sum += value
		}
		for i := 0; i < len(b); i++ {
			b[i] = i
		}
		sort.Slice(b, func(l, r int) bool {
			return a[l]%2 < a[r]%2
		})
		var flag int = 1
		for i := 2; i*i <= sum; i++ {
			if sum%i == 0 {
				flag = 0
			}
		}
		var n_len int = n - flag
		fmt.Fprint(out, n_len, "\n")
		for i := 0; i < n_len; i++ {
			fmt.Fprint(out, b[i]+1, " ")
		}
		fmt.Fprintln(out)
	}
}


You are given a long decimal number $$$a$$$ consisting of $$$n$$$ digits from $$$1$$$ to $$$9$$$. You also have a function $$$f$$$ that maps every digit from $$$1$$$ to $$$9$$$ to some (possibly the same) digit from $$$1$$$ to $$$9$$$.You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in $$$a$$$, and replace each digit $$$x$$$ from this segment with $$$f(x)$$$. For example, if $$$a = 1337$$$, $$$f(1) = 1$$$, $$$f(3) = 5$$$, $$$f(7) = 3$$$, and you choose the segment consisting of three rightmost digits, you get $$$1553$$$ as the result.What is the maximum possible number you can obtain applying this operation no more than once?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of digits in $$$a$$$. The second line contains a string of $$$n$$$ characters, denoting the number $$$a$$$. Each character is a decimal digit from $$$1$$$ to $$$9$$$. The third line contains exactly $$$9$$$ integers $$$f(1)$$$, $$$f(2)$$$, ..., $$$f(9)$$$ ($$$1 \le f(i) \le 9$$$).

Print the maximum number you can get after applying the operation described in the statement no more than once.

package main

import (
    "fmt"
    "strings"
    "strconv"
)

var f [10]int

func main() {
    var N int
    fmt.Scan(&N)
    var in string
    fmt.Scan(&in)
    a := make([]int, N)

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

    for i := 1; i <= 9; i++ {
        fmt.Scan(&f[i])
    }

    for i := 0; i < N; i++ {
        if f[a[i]] <= a[i] {
            continue
        }
        for i < N && f[a[i]] >= a[i] {
            a[i] = f[a[i]]
            i++
        }
        break
    }
    for _, x := range a{
        fmt.Print(x)
    }
    fmt.Println()
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

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

	var in string
	fmt.Scan(&in)
	a := make([]int, n)
	for i, c := range strings.Split(in, "") {
		a[i], _ = strconv.Atoi(c)
	}

	var f [10]int
	for i := 1; i <= 9; i++ {
		fmt.Scan(&f[i])
	}

	for i := 0; i < n; i++ {
		if a[i] >= f[a[i]] {
			continue
		}

		for i < n && a[i] <= f[a[i]] {
			a[i] = f[a[i]]
			i++
		}

		break
	}

	for _, c := range a {
		fmt.Print(c)
	}
}

package main

import (
	"fmt"
	"strconv"
)

var n int
var tmp, num string
var f []int

func main() {
	f = make([]int, 10)

	fmt.Scanln(&tmp)
	n, _ = strconv.Atoi(tmp)

	fmt.Scanln(&num)

	for i := 1; i <= 9; i++ {
		fmt.Scanf("%d", &f[i])
	}

	num2 := []byte(num)

	flag := true

	for i := 0; i < n; i++ {
		old, _ := strconv.Atoi(string(num2[i]))
		new, _ := strconv.Atoi(string(num2[i]))

		new = f[old]

		if old > new {
			if flag == false {
				break
			}

			continue
		}

		if old < new {
			flag = false
		}

		b := []byte(strconv.Itoa(new))[0]
		num2[i] = b
	}

	fmt.Println(string(num2))
}

package main

import (
	"fmt"
)

func solve(a []uint8, f [10]uint8) []uint8 {
	started := false
	for i, cur := range a {
		if f[cur] < cur {
			if started {
				break
			}
			continue
		}

		if f[cur] > cur {
			a[i] = f[cur]
			started = true
		}
	}
	return a
}

func main() {
	var n int

	fmt.Scanln(&n)

	a := make([]uint8, n)
	s := ""
	fmt.Scanln(&s)
	for i := range a {
		a[i] = s[i] - '0'
	}

	f := [10]uint8{}
	for i := 1; i < 10; i++ {
		fmt.Scan(&f[i])
	}

	ans := solve(a, f)
	for _, cur := range ans {
		fmt.Print(cur)
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var s []byte
	fmt.Scanf("%s\n", &s)
	// fmt.Printf("%d\n%s\n", n, s)
	arr := make([]int, 9, 9)
	for i, _ := range arr {
		fmt.Scanf("%d", &arr[i])
	}
	str := []byte(s)
	// fmt.Println(arr)
	ind := int(-1)
	for i, _ := range s {
		// fmt.Printf("%q ", s[i])
		if int(s[i]-'0') < arr[int(s[i]-'1')] {
			ind = i
			break
		}
	}
	if ind != -1 {
		for ind < len(s) && (int(s[ind]-'0') <= arr[int(s[ind]-'1')]) {
			str[ind] = byte(arr[int(s[ind]-'1')] + '0')
			ind += 1
		}
	}
	for _, kek := range str {
		fmt.Printf("%d", int(kek-'0'))
	}
	fmt.Printf("\n")
}

package main

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

func readInt(reader *bufio.Scanner) int {
	var result int
	reader.Scan()
	result,_ = strconv.Atoi(reader.Text())
	return result
}
func main() {

	var n int
	var number string
	reader:=bufio.NewScanner(os.Stdin)
	buf := make([]byte, 2)
	reader.Buffer(buf, 200001)
	reader.Split(bufio.ScanWords)
	var f [9]int
	n = readInt(reader)
	reader.Scan()
	number = reader.Text()
	numChars := []rune(number)
	for i:=0;i<9;i++ {
		f[i] = readInt(reader)
	}
	progress:=0
	for i:=0;i<n;i++ {
		num := (int) (numChars[i]-'0')
		if progress==0 && num < f[num-1]{
			progress = 1
		}
		if progress == 1 && num > f[num-1]{
			break
		}
		if progress == 1 {
			numChars[i] = (rune)(f[num-1] +'0')
		}
	}
	fmt.Println(string(numChars))
}

package main

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

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

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

func min(a ...int) int {
	min := -1
	for _, val := range a {
		if val < min {
			min = val
		}
	}
	return min
}

func max(a ...int) int {
	max := -1
	for _, val := range a {
		if val > max {
			max = val
		}
	}
	return max
}

func tr(n int) int {
	for n%10 == 0 {
		n = n / 10
	}
	return n
}

func main() {
	defer writer.Flush() // STDOUT MUST BE FLUSHED MANUALLY!!!
	var n int
	var s string
	m := [10]int{}
	scan(&n, &s)
	for i := 1; i < 10; i++ {
		scan(&m[i])
	}

	ns := ""
	con := false

	for idx := range s {
		dg, _ := strconv.Atoi(string(s[idx]))

		// start conv
		if m[dg] > dg {
			con = true
			ns += strconv.Itoa(m[dg])
			continue
		}

		// end conv
		if m[dg] < dg && con {
			con = false
			ns += s[idx:]
			break
		}

		ns += strconv.Itoa(dg)
	}
	print(ns)
}

package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	var a[10] int
	var i,x int
	for i = 1;i <= 9 ; i++{
		fmt.Scan(&x)
		a[i] = x
	}

	temp := []byte(s)
	var ok bool
	for index,chr := range temp{
		if(int(chr) - 48 < int(a[int(chr - 48)]) && !ok ){
			ok = true
			temp[index]  = byte(a[chr-48]) + 48
		}else if (ok && int(chr) - 48 < int(a[int(chr - 48)]) ){
			temp[index] = byte(a[chr - 48]) + 48
		} else if(ok && int(chr) - 48 > int(a[int(chr - 48)])){
			break;
		}
	}
	fmt.Print(string(temp))

}

package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	var a[10] int
	var i,x int
	for i = 1;i <= 9 ; i++{
		fmt.Scan(&x)
		a[i] = x
	}

	temp := []byte(s)
	var ok bool
	for index,chr := range temp{
		if(int(chr)  < int(a[int(chr - 48)] + 48) && !ok ){
			ok = true
			temp[index]  = byte(a[chr-48]) + 48
		}else if (ok && int(chr) < int(a[int(chr - 48)] + 48) ){
			temp[index] = byte(a[chr - 48]) + 48
		} else if(ok && int(chr) - 48 > int(a[int(chr - 48)])){
			break;
		}
	}
	fmt.Print(string(temp))

}

package main

import (
    "fmt"
    "strings"
    "strconv"
)

var f [10]int

func main() {
    var N int
    fmt.Scan(&N)
    var in string
    fmt.Scan(&in)
    a := make([]int, N)

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

    for i := 1; i <= 9; i++ {
        fmt.Scan(&f[i])
    }

    for i := 0; i < N; i++ {
        if f[a[i]] <= a[i] {
            continue
        }
        for i < N && f[a[i]] > a[i] {
            a[i] = f[a[i]]
            i++
        }
        break
    }
    for _, x := range a{
        fmt.Print(x)
    }
    fmt.Println()
}

package main

import (
	"fmt"
	"strconv"
)

var n int
var tmp, num string
var f []int

func main() {
	f = make([]int, 10)

	fmt.Scanln(&tmp)
	n, _ = strconv.Atoi(tmp)

	fmt.Scanln(&num)

	for i := 1; i <= 9; i++ {
		fmt.Scanf("%d", &f[i])
	}

	num2 := []byte(num)

	for i := 0; i < n; i++ {
		old, _ := strconv.Atoi(string(num2[i]))
		new, _ := strconv.Atoi(string(num2[i]))

		new = f[old]

		if old > new {
			break
		}

		b := []byte(strconv.Itoa(new))[0]
		num2[i] = b
	}

	fmt.Println(string(num2))
}

package main

import (
	"fmt"
	"strconv"
)

var n int
var num, t string
var f []int

func main() {
	f = make([]int, 10)

	fmt.Scanf("%d", &n)
	fmt.Scanln(&t)
	fmt.Scanln(&num)

	for i := 1; i <= 9; i++ {
		fmt.Scanf("%d", &f[i])
	}

	num2 := []byte(num)

	for i := 0; i < n; i++ {
		old, _ := strconv.Atoi(string(num2[i]))
		new, _ := strconv.Atoi(string(num2[i]))

		new = f[old]

		if old > new {
			break
		}

		b := []byte(strconv.Itoa(new))[0]
		num2[i] = b
	}

	fmt.Println(string(num2))
}

package main

import (
	"fmt"
)

func solve(a []uint8, f [10]uint8) []uint8 {
	started := true
	for i, cur := range a {
		if f[cur] < cur {
			if started {
				break
			}
			continue
		}

		a[i] = f[cur]
		started = true
	}
	return a
}

func main() {
	var n int

	fmt.Scanln(&n)

	a := make([]uint8, n)
	s := ""
	fmt.Scanln(&s)
	for i := range a {
		a[i] = s[i] - '0'
	}

	f := [10]uint8{}
	for i := 1; i < 10; i++ {
		fmt.Scan(&f[i])
	}

	ans := solve(a, f)
	for _, cur := range ans {
		fmt.Print(cur)
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func solve(a []uint8, f [10]uint8) []uint8 {
	for i, cur := range a {
		if f[cur] > cur {
			a[i] = f[cur]
		}
	}
	return a
}

func main() {
	var n int

	fmt.Scanln(&n)

	a := make([]uint8, n)
	s := ""
	fmt.Scanln(&s)
	for i := range a {
		a[i] = s[i] - '0'
	}

	f := [10]uint8{}
	for i := 1; i < 10; i++ {
		fmt.Scan(&f[i])
	}

	ans := solve(a, f)
	for _, cur := range ans {
		fmt.Print(cur)
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var s []byte
	fmt.Scanf("%s\n", &s)
	// fmt.Printf("%d\n%s\n", n, s)
	arr := make([]int, 9, 9)
	for i, _ := range arr {
		fmt.Scanf("%d", &arr[i])
	}
	str := []byte(s)
	// fmt.Println(arr)
	ind := int(-1)
	for i, _ := range s {
		// fmt.Printf("%q ", s[i])
		if int(s[i]-'0') < arr[int(s[i]-'1')] {
			ind = i
			break
		}
	}
	if ind != -1 {
		for ind < len(s) && (int(s[ind]-'0') < arr[int(s[ind]-'1')]) {
			str[ind] = byte(arr[int(s[ind]-'1')] + '0')
			ind += 1
		}
	}
	for _, kek := range str {
		fmt.Printf("%d", int(kek-'0'))
	}
	fmt.Printf("\n")
}

package main

import (
	"fmt"
)

func main() {

	var n int
	var number string

	var f int
	fmt.Scanf("%d", &n)
	replaced := make([]bool,n)
	fmt.Scanf("%s", &number)
	numChars := []rune(number)
	for i:=0;i<9;i++{
		fmt.Scanf("%d", &f)
		if f > i+1{
			for index, c := range numChars {
				if (int)(c-'0') == i+1 && !replaced[index]{
					numChars[index] = (rune)('0'+f)
					replaced[index] = true
				}
			}
		}
	}
		fmt.Println(string(numChars))
}

package main

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

func readInt(reader *bufio.Scanner) int {
	var result int
	reader.Scan()
	result,_ = strconv.Atoi(reader.Text())
	return result
}
func main() {

	var n int
	var number string
	reader:=bufio.NewScanner(os.Stdin)
	buf := make([]byte, 2)
	reader.Buffer(buf, 200001)
	reader.Split(bufio.ScanWords)
	var f int
	n = readInt(reader)
	replaced := make([]bool,n)
	reader.Scan()
	number = reader.Text()
	numChars := []rune(number)
	for i:=0;i<9;i++{
		f = readInt(reader)
		if f > i+1{
			for index, c := range numChars {
				if (int)(c-'0') == i+1 && !replaced[index]{
					numChars[index] = (rune)('0'+f)
					replaced[index] = true
				}
			}
		}
	}
		fmt.Println(string(numChars))
}

package main

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

func readInt(reader *bufio.Scanner) int {
	var result int
	reader.Scan()
	result,_ = strconv.Atoi(reader.Text())
	return result
}
func main() {

	var n int
	var number string
	reader:=bufio.NewScanner(os.Stdin)
	reader.Split(bufio.ScanWords)
	var f int
	n = readInt(reader)
	replaced := make([]bool,n)
	reader.Scan()
	number = reader.Text()
	numChars := []rune(number)
	for i:=0;i<9;i++{
		f = readInt(reader)
		if f > i+1{
			for index, c := range numChars {
				if (int)(c-'0') == i+1 && !replaced[index]{
					numChars[index] = (rune)('0'+f)
					replaced[index] = true
				}
			}
		}
	}
		fmt.Println(string(numChars))
}

package main

import (
	"fmt"
)

func main() {

	var n int
	var number string

	var f int
	fmt.Scanf("%d", &n)
	replaced := make([]bool,n)
	fmt.Scanf("%s", &number)
	numChars := []rune(number)
	for i:=0;i<9;i++{
		fmt.Scanf("%d", &f)
		if f > i+1{
			for index, c := range numChars {
				if (int)(c-'0') == i+1 && !replaced[index]{
					numChars[index] = (rune)('0'+f)
					replaced[index] = true
				}
			}
		}
	}
		fmt.Print(string(numChars))
}

package main

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

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

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

func min(a ...int) int {
	min := -1
	for _, val := range a {
		if val < min {
			min = val
		}
	}
	return min
}

func max(a ...int) int {
	max := -1
	for _, val := range a {
		if val > max {
			max = val
		}
	}
	return max
}

func tr(n int) int {
	for n%10 == 0 {
		n = n / 10
	}
	return n
}

func main() {
	defer writer.Flush() // STDOUT MUST BE FLUSHED MANUALLY!!!
	var n int
	var s string
	m := [10]int{}
	scan(&n, &s)
	for i := 1; i < 10; i++ {
		scan(&m[i])
	}

	ns := ""
	convd := -1

	for idx := range s {
		dg, _ := strconv.Atoi(string(s[idx]))

		if m[dg] > dg && convd == -1 {
			convd = dg
		}

		if convd == -1 {
			ns += strconv.Itoa(dg)
			continue
		}

		if dg == convd {
			ns += strconv.Itoa(m[dg])
		} else {
			ns += s[idx:]
			break
		}
	}
	print(ns)
}

package main

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

var input, inputerr = os.Open("./input")
var output, outputerr = os.Create("./output")
var reader = bufio.NewReader(input)
var writer = bufio.NewWriter(output)

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

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

func min(a ...int) int {
	min := -1
	for _, val := range a {
		if val < min {
			min = val
		}
	}
	return min
}

func max(a ...int) int {
	max := -1
	for _, val := range a {
		if val > max {
			max = val
		}
	}
	return max
}

func tr(n int) int {
	for n%10 == 0 {
		n = n / 10
	}
	return n
}

func main() {
	defer writer.Flush() // STDOUT MUST BE FLUSHED MANUALLY!!!
	var n int
	var s string
	m := [10]int{}
	scan(&n, &s)
	for i := 1; i < 10; i++ {
		scan(&m[i])
	}

	ns := ""
	con := false

	for idx := range s {
		dg, _ := strconv.Atoi(string(s[idx]))

		// start conv
		if m[dg] > dg {
			con = true
			ns += strconv.Itoa(m[dg])
			continue
		}

		// end conv
		if m[dg] < dg && con {
			con = false
			ns += s[idx:]
			break
		}

		ns += strconv.Itoa(dg)
	}
	print(ns)
}

package main

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

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

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

func min(a ...int) int {
	min := -1
	for _, val := range a {
		if val < min {
			min = val
		}
	}
	return min
}

func max(a ...int) int {
	max := -1
	for _, val := range a {
		if val > max {
			max = val
		}
	}
	return max
}

func tr(n int) int {
	for n%10 == 0 {
		n = n / 10
	}
	return n
}

func main() {
	defer writer.Flush() // STDOUT MUST BE FLUSHED MANUALLY!!!
	var n int
	var s string
	m := [10]int{}
	scan(&n, &s)
	for i := 1; i < 10; i++ {
		scan(&m[i])
	}

	ns := ""
	con := true

	for idx := range s {
		dg, _ := strconv.Atoi(string(s[idx]))

		// start conv
		if m[dg] > dg {
			con = true
			ns += strconv.Itoa(m[dg])
			continue
		}

		// end conv
		if m[dg] < dg && con {
			con = false
			ns += s[idx:]
			break
		}

		ns += strconv.Itoa(dg)
	}
	print(ns)
}


One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:a1, a2, ..., an → an, a1, a2, ..., an - 1. Help Twilight Sparkle to calculate: what is the minimum number of operations that she needs to sort the sequence?

The first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).

If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.

package main

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

type MyScanner struct {
	in *bufio.Scanner
}

var in = MyScanner{bufio.NewScanner(os.Stdin)}

func ScanInts(data []byte, atEOF bool) (advance int, token []byte, err error) {
	advance, token, err = bufio.ScanWords(data, atEOF)
	if err == nil && token != nil {
		_, err = strconv.Atoi(string(token))
	}
	return
}

func (m *MyScanner) innerNext(f bufio.SplitFunc) bool {
	m.in.Split(f)
	return m.in.Scan()
}

func (m *MyScanner) NextInt() (int, error) {
	if !m.innerNext(ScanInts) {
		return 0, m.in.Err()
	}
	return strconv.Atoi(m.in.Text())
}

func main() {
	n, _ := in.NextInt()
	a := make([]int, n)
	for i := range a {
		a[i], _ = in.NextInt()
	}
	r := 0
	for i := 1; i < n; i++ {
		if a[i-1] > a[i] {
			if r != 0 {
				fmt.Println("-1")
				return
			}
			r = i
		}
	}
	if r == 0 {
		fmt.Println("0")
	} else if a[0] < a[n-1] {
		fmt.Println("-1")
	} else {
		fmt.Println(n - r)
	}
}

package main

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

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

	s1 := -1
	e1p := 0
	s2 := -1
	e2 := -1
	has_s3 := false

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

		if has_s3 {
			continue
		}

		if i == 0 {
			s1 = a
		} else {
			if e2 > a {
				if s2 < 0 {
					e1p = i
					s2 = a
				} else {
					has_s3 = true
				}
			}
		}
		e2 = a
	}

	if s2 < 0 {
		fmt.Println(0)
	} else if has_s3 || e2 > s1 {
		fmt.Println(-1)
	} else {
		fmt.Println(n - e1p)
	}
}


Ralph is in the Binary Country. The Binary Country consists of n cities and (n - 1) bidirectional roads connecting the cities. The roads are numbered from 1 to (n - 1), the i-th road connects the city labeled  (here ⌊ x⌋ denotes the x rounded down to the nearest integer) and the city labeled (i + 1), and the length of the i-th road is Li.Now Ralph gives you m queries. In each query he tells you some city Ai and an integer Hi. He wants to make some tours starting from this city. He can choose any city in the Binary Country (including Ai) as the terminal city for a tour. He gains happiness (Hi - L) during a tour, where L is the distance between the city Ai and the terminal city.Ralph is interested in tours from Ai in which he can gain positive happiness. For each query, compute the sum of happiness gains for all such tours.Ralph will never take the same tour twice or more (in one query), he will never pass the same city twice or more in one tour.

The first line contains two integers n and m (1 ≤ n ≤ 106, 1 ≤ m ≤ 105). (n - 1) lines follow, each line contains one integer Li (1 ≤ Li ≤ 105), which denotes the length of the i-th road. m lines follow, each line contains two integers Ai and Hi (1 ≤ Ai ≤ n, 0 ≤ Hi ≤ 107).

Print m lines, on the i-th line print one integer — the answer for the i-th query.

NoteHere is the explanation for the second sample.Ralph's first query is to start tours from city 2 and Hi equals to 4. Here are the options:  He can choose city 5 as his terminal city. Since the distance between city 5 and city 2 is 3, he can gain happiness 4 - 3 = 1.  He can choose city 4 as his terminal city and gain happiness 3.  He can choose city 1 as his terminal city and gain happiness 2.  He can choose city 3 as his terminal city and gain happiness 1.  Note that Ralph can choose city 2 as his terminal city and gain happiness 4.  Ralph won't choose city 6 as his terminal city because the distance between city 6 and city 2 is 5, which leads to negative happiness for Ralph. So the answer for the first query is 1 + 3 + 2 + 1 + 4 = 11.

package main

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

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

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

func toInt(buf []byte) (o int) {
    for _, v := range buf {
        o = o*10 + int(v-'0')
    }
    return
}

type pair struct{
	a int
	b int
}

var n,m,l,r,c,sz_slc int
var ln,d [1000006]int
var slc [1000006]int
var ans int64
var g [1000006][]pair
var sum [1000006][2][]int64
var ver [1000006][2][]int

func cnt(v,h,side int){
	if len(ver[v][side]) == 0 {
		return
	}
	l = 0
	r = len(ver[v][side]) - 1
	c = d[v]
	//fmt.Println(v,h,side, ver[v][side])
	for ;r - l > 1; {
		mid := (l+r) >> 1
		if ver[v][side][mid] - c <= h {
			l = mid + 1
		}else{
			r = mid
		}
	}
	if l > r{
		l,r = r,l
	}
	idx := len(ver[v][side])
	if ver[v][side][l] - c > h {
		idx = l
	}else
		if ver[v][side][r] - c > h {
			idx = r
		}
	if idx > 0{
		ans += int64(c+h)*int64(idx) - sum[v][side][idx - 1]
	}
}

func goUp(v,h,side int){
	if h > 0{
		ans += int64(h)
		if side != -1{
			cnt(v,h,side)
		}
	}else{
		return
	}
	if v == 1 {
		return
	}
	goUp(v >> 1,h-ln[v],(v+1)&1)
}

func dfs(v,dist int) {
	d[v] = dist
	for i:=0;i<len(g[v]);i++{
		dfs(g[v][i].a, dist + g[v][i].b)
		for j:=0;j<sz_slc;j++ {
			ver[v][i] = append(ver[v][i], slc[j])
		}
		//fmt.Println(v,i,ver[v][i])
		//fmt.Println(v,i,ver[v][i])
	}
	//fmt.Println(">>>",v,ver[v][0],ver[v][1])
	if len(ver[v][0]) != 0 {
		sum[v][0] = append(sum[v][0], int64(ver[v][0][0]))
	}
	for i:=1;i<len(ver[v][0]);i++{
		sum[v][0] = append(sum[v][0], sum[v][0][i-1] + int64(ver[v][0][i]))
	}

	if len(ver[v][1]) != 0 {
		sum[v][1] = append(sum[v][1], int64(ver[v][1][0]))
	}
	for i:=1;i<len(ver[v][1]);i++{
		sum[v][1] = append(sum[v][1], sum[v][1][i-1] + int64(ver[v][1][i]))
	}
	sz_slc = 0;
	slc[sz_slc] = dist
	sz_slc++;
	i := 0
	j := 0
	for ;i<len(ver[v][0]) || j < len(ver[v][1]); {
		if i == len(ver[v][0]) {
			slc[sz_slc] = ver[v][1][j]
			sz_slc++
			j++
			continue
		}
		if j == len(ver[v][1]) {
			slc[sz_slc] = ver[v][0][i]
			sz_slc++
			i++
			continue
		}
		if ver[v][0][i] <= ver[v][1][j] {
			slc[sz_slc] = ver[v][0][i]
			sz_slc++
			i++
		}else{
			slc[sz_slc] = ver[v][1][j]
			sz_slc++
			j++
		}
	}
}

func main() {
	fmt.Scanf("%d%d",&n,&m)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i:=2;i<=n;i++ {
		var x int
		scanner.Scan()
		x = toInt(scanner.Bytes())
		g[i >> 1] = append(g[i >> 1], pair{i,x})
		ln[i] = x
		//g[i] = append(pair{i/2,x})
	}
	dfs(1,0)
	var city,h int
	for ;m>0;m--{
		ans = 0
		scanner.Scan()
		city = toInt(scanner.Bytes())
		scanner.Scan()
		h = toInt(scanner.Bytes())
		cnt(city, h, 0)
		cnt(city, h, 1)
		goUp(city,h,-1)
		fmt.Println(ans)
	}

}


This problem is a complicated version of D1, but it has significant differences, so read the whole statement.Polycarp has an array of $$$n$$$ ($$$n$$$ is even) integers $$$a_1, a_2, \dots, a_n$$$. Polycarp conceived of a positive integer $$$k$$$. After that, Polycarp began performing the following operations on the array: take an index $$$i$$$ ($$$1 \le i \le n$$$) and reduce the number $$$a_i$$$ by $$$k$$$.After Polycarp performed some (possibly zero) number of such operations, it turned out that at least half of the numbers in the array became the same. Find the maximum $$$k$$$ at which such a situation is possible, or print $$$-1$$$ if such a number can be arbitrarily large.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains an even integer $$$n$$$ ($$$4 \le n \le 40$$$) ($$$n$$$ is even). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots a_n$$$ ($$$-10^6 \le a_i \le 10^6$$$). It is guaranteed that the sum of all $$$n$$$ specified in the given test cases does not exceed $$$100$$$.

For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 1$$$) — the maximum possible number that Polycarp used in operations on the array, or $$$-1$$$, if such a number can be arbitrarily large.

package main

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

const (
	INIT = -1
	INF  = 1e18
)

func die(v ...interface{}) {
	_, file, line, _ := runtime.Caller(1)
	fmt.Printf("die %s line %d: %v", file, line, v)
	os.Exit(-1)
}

type scanner struct {
	sc  *bufio.Scanner
	buf []byte
	max int
}

func newScanner() *scanner {
	rv := &scanner{max: bufio.MaxScanTokenSize} // default
	rv.sc = bufio.NewScanner(os.Stdin)
	rv.sc.Split(bufio.ScanWords)
	rv.buf = make([]byte, rv.max)
	rv.sc.Buffer(rv.buf, rv.max)
	return rv
}

func (s *scanner) nextInt() int {
	if !s.sc.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	rv, err := strconv.Atoi(s.sc.Text())
	if err != nil {
		die(err)
	}
	return rv
}

func (s *scanner) nextInt64() int64 {
	if !s.sc.Scan() {
		die(io.ErrUnexpectedEOF)
	}
	rv, err := strconv.ParseInt(s.sc.Text(), 10, 64)
	if err != nil {
		die(err)
	}
	return rv
}

func (s *scanner) nextStr() string {
	if !s.sc.Scan() {
		die("parse error")
	}
	return s.sc.Text()
}

var (
	a []int
	n int
)

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

func same() bool {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[a[i]]++
		if cnt[a[i]]*2 >= n {
			return true
		}
	}
	return false
}

func main() {
	sc := newScanner()
	tc := sc.nextInt()

	for ; tc > 0; tc-- {
		n = sc.nextInt()

		a = make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = sc.nextInt()
		}
		if same() {
			fmt.Println(-1)
			continue
		}

		// fmt.Printf("a\n")
		// for _, k := range a {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		div := []int{}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				diff := abs(a[i] - a[j])
				if diff == 0 {
					continue
				}
				for k := 1; k*k <= diff; k++ {
					if (diff % k) == 0 {
						div = append(div, diff/k)
						div = append(div, k)
					}
				}
			}
		}

		uniq := []int{}
		sort.Ints(div)
		for i := 0; i < len(div); i++ {
			if i == 0 || div[i] != div[i-1] {
				uniq = append(uniq, div[i])
			}
		}
		div = uniq

		// fmt.Printf("div\n")
		// for _, k := range div {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		ans := 0
		for _, k := range div {
			for i := 0; i < n; i++ {
				cnt := 0
				for j := 0; j < n; j++ {
					diff := abs(a[i] - a[j])
					if (diff % k) == 0 {
						cnt++
					}
				}
				if cnt*2 >= n {
					if ans < k {
						ans = k
					}
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

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

const (
	INIT = -1
	INF  = 1e18
)

func die(s ...string) {
	_, file, line, _ := runtime.Caller(1)
	fmt.Printf("die %q file %s line %d", s, file, line)
	os.Exit(-1)
}

type scanner struct {
	sc  *bufio.Scanner
	buf []byte
	max int
}

func newScanner() *scanner {
	rv := &scanner{max: bufio.MaxScanTokenSize} // default
	rv.sc = bufio.NewScanner(os.Stdin)
	rv.sc.Split(bufio.ScanWords)
	rv.buf = make([]byte, rv.max)
	rv.sc.Buffer(rv.buf, rv.max)
	return rv
}

func (s *scanner) fastParse(buf []byte) (x int64, y int) {
	neg := false
	if buf[0] == '-' {
		neg = true
		buf = buf[1:]
	}
	for _, b := range buf {
		x = x*10 + int64(b-'0')
		y = y*10 + int(b-'0')
	}
	if neg {
		x = -x
		y = -y
	}
	return
}

func (s *scanner) nextInt() int {
	if !s.sc.Scan() {
		die("parse error")
	}
	_, rv := s.fastParse(s.sc.Bytes())
	return rv
}

func (s *scanner) nextInt64() int64 {
	if !s.sc.Scan() {
		die("parse error")
	}
	rv, _ := s.fastParse(s.sc.Bytes())
	return rv
}

func (s *scanner) nextStr() string {
	if !s.sc.Scan() {
		die("parse error")
	}
	return s.sc.Text()
}

var (
	a []int
	n int
)

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

func same() bool {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[a[i]]++
		if cnt[a[i]]*2 >= n {
			return true
		}
	}
	return false
}

func main() {
	sc := newScanner()
	tc := sc.nextInt()

	for ; tc > 0; tc-- {
		n = sc.nextInt()

		a = make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = sc.nextInt()
		}
		if same() {
			fmt.Println(-1)
			continue
		}

		// fmt.Printf("a\n")
		// for _, k := range a {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		div := []int{}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				diff := abs(a[i] - a[j])
				if diff == 0 {
					continue
				}
				for k := 1; k*k <= diff; k++ {
					if (diff % k) == 0 {
						div = append(div, diff/k)
						div = append(div, k)
					}
				}
			}
		}

		uniq := []int{}
		sort.Ints(div)
		for i := 0; i < len(div); i++ {
			if i == 0 || div[i] != div[i-1] {
				uniq = append(uniq, div[i])
			}
		}
		div = uniq

		// fmt.Printf("div\n")
		// for _, k := range div {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		ans := 0
		for _, k := range div {
			for i := 0; i < n; i++ {
				cnt := 0
				for j := 0; j < n; j++ {
					diff := abs(a[i] - a[j])
					if (diff % k) == 0 {
						cnt++
					}
				}
				if cnt*2 >= n {
					if ans < k {
						ans = k
					}
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

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

const (
	INIT = -1
	INF  = 1e18
)

func check(t bool, s ...string) {
	if t {
		return
	}
	_, file, line, _ := runtime.Caller(1)
	fmt.Println("Check failed file", file, "line", line, s)
	os.Exit(-1)
}

var (
	a []int
	n int
)

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

func same() bool {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[a[i]]++
		if cnt[a[i]]*2 >= n {
			return true
		}
	}
	return false
}

func main() {
	var tc int
	r := bufio.NewReader(os.Stdin)
	//	fmt.Scan(&tc)
	fmt.Fscan(r, &tc)

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		//		fmt.Scan(&n)

		a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
			//			fmt.Scan(&a[i])
		}
		if same() {
			fmt.Println(-1)
			continue
		}

		// fmt.Printf("a\n")
		// for _, k := range a {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		div := []int{}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				diff := abs(a[i] - a[j])
				if diff == 0 {
					continue
				}
				for k := 1; k*k <= diff; k++ {
					if (diff % k) == 0 {
						div = append(div, diff/k)
						div = append(div, k)
					}
				}
			}
		}

		uniq := []int{}
		sort.Ints(div)
		for i := 0; i < len(div); i++ {
			if i == 0 || div[i] != div[i-1] {
				uniq = append(uniq, div[i])
			}
		}
		div = uniq

		// fmt.Printf("div\n")
		// for _, k := range div {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		ans := 0
		for _, k := range div {
			for i := 0; i < n; i++ {
				cnt := 0
				for j := 0; j < n; j++ {
					diff := abs(a[i] - a[j])
					if (diff % k) == 0 {
						cnt++
					}
				}
				if cnt*2 >= n {
					if ans < k {
						ans = k
					}
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"os"
	"runtime"
	"sort"
)

const (
	INIT = -1
	INF  = 1e18
)

func check(t bool, s ...string) {
	if t {
		return
	}
	_, file, line, _ := runtime.Caller(1)
	fmt.Println("Check failed file", file, "line", line, s)
	os.Exit(-1)
}

var (
	a []int
	n int
)

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

func same() bool {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[a[i]]++
		if cnt[a[i]]*2 >= n {
			return true
		}
	}
	return false
}

func main() {
	var tc int
	fmt.Fscan(os.Stdin, &tc)

	for ; tc > 0; tc-- {
		fmt.Fscan(os.Stdin, &n)

		a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(os.Stdin, &a[i])
		}
		if same() {
			fmt.Println(-1)
			continue
		}

		// fmt.Printf("a\n")
		// for _, k := range a {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		div := []int{}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				diff := abs(a[i] - a[j])
				if diff == 0 {
					continue
				}
				for k := 1; k*k <= diff; k++ {
					if (diff % k) == 0 {
						div = append(div, diff/k)
						div = append(div, k)
					}
				}
			}
		}

		uniq := []int{}
		sort.Ints(div)
		for i := 0; i < len(div); i++ {
			if i == 0 || div[i] != div[i-1] {
				uniq = append(uniq, div[i])
			}
		}
		div = uniq

		// fmt.Printf("div\n")
		// for _, k := range div {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		ans := 0
		for _, k := range div {
			for i := 0; i < n; i++ {
				cnt := 0
				for j := 0; j < n; j++ {
					diff := abs(a[i] - a[j])
					if (diff % k) == 0 {
						cnt++
					}
				}
				if cnt*2 >= n {
					if ans < k {
						ans = k
					}
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

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

const (
	INIT = -1
	INF  = 1e18
)

func check(t bool, s ...string) {
	if t {
		return
	}
	_, file, line, _ := runtime.Caller(1)
	fmt.Println("Check failed file", file, "line", line, s)
	os.Exit(-1)
}

type scanner struct {
	sc  *bufio.Scanner
	buf []byte
	max int
}

func newScanner() *scanner {
	rv := &scanner{max: bufio.MaxScanTokenSize} // default
	rv.sc = bufio.NewScanner(os.Stdin)
	rv.sc.Split(bufio.ScanWords)
	rv.buf = make([]byte, rv.max)
	rv.sc.Buffer(rv.buf, rv.max)
	return rv
}

func (s *scanner) nextInt() int {
	return int(s.nextInt64())
}

func (s *scanner) nextInt64() int64 {
	check(s.sc.Scan(), "parse error")
	rv, _ := strconv.ParseInt(string(s.sc.Bytes()), 10, 64)
	return rv
}

func (s *scanner) nextStr() string {
	check(s.sc.Scan(), "parse error")
	return s.sc.Text()
}

var (
	a []int
	n int
)

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

func same() bool {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[a[i]]++
		if cnt[a[i]]*2 >= n {
			return true
		}
	}
	return false
}

func main() {
	sc := newScanner()
	tc := sc.nextInt()
	for ; tc > 0; tc-- {
		n = sc.nextInt()
		a = make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = sc.nextInt()
		}
		if same() {
			fmt.Println(-1)
			continue
		}

		// fmt.Printf("a\n")
		// for _, k := range a {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		div := []int{}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				diff := abs(a[i] - a[j])
				if diff == 0 {
					continue
				}
				for k := 1; k*k <= diff; k++ {
					if (diff % k) == 0 {
						div = append(div, diff/k)
						div = append(div, k)
					}
				}
			}
		}

		uniq := []int{}
		sort.Ints(div)
		for i := 0; i < len(div); i++ {
			if i == 0 || div[i] != div[i-1] {
				uniq = append(uniq, div[i])
			}
		}
		div = uniq

		// fmt.Printf("div\n")
		// for _, k := range div {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		ans := 0
		for _, k := range div {
			for i := 0; i < n; i++ {
				cnt := 0
				for j := 0; j < n; j++ {
					diff := abs(a[i] - a[j])
					if (diff % k) == 0 {
						cnt++
					}
				}
				if cnt*2 >= n {
					if ans < k {
						ans = k
					}
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

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

const (
	INIT = -1
	INF  = 1e18
)

func check(t bool, s ...string) {
	if t {
		return
	}
	_, file, line, _ := runtime.Caller(1)
	fmt.Println("Check failed file", file, "line", line, s)
	os.Exit(-1)
}

type scanner struct {
	sc  *bufio.Scanner
	buf []byte
	max int
}

func newScanner() *scanner {
	rv := &scanner{max: bufio.MaxScanTokenSize} // default
	rv.sc = bufio.NewScanner(os.Stdin)
	rv.sc.Split(bufio.ScanWords)
	rv.buf = make([]byte, rv.max)
	rv.sc.Buffer(rv.buf, rv.max)
	return rv
}

// TODO: does this actually make any difference vs strconv?
func (s *scanner) fastParse(buf []byte) (x int64, y int) {
	neg := false
	for _, b := range buf {
		if b == '-' {
			neg = true
			continue
		}
		x = x*10 + int64(b-'0')
		y = y*10 + int(b-'0')
	}
	if neg {
		x *= -1
		y *= -1
	}
	return
}

func (s *scanner) nextInt() int {
	check(s.sc.Scan(), "parse error")
	_, ans := s.fastParse(s.sc.Bytes())
	return ans
}

func (s *scanner) nextInt64() int64 {
	check(s.sc.Scan(), "parse error")
	ans, _ := s.fastParse(s.sc.Bytes())
	return ans
}

func (s *scanner) nextStr() string {
	check(s.sc.Scan(), "parse error")
	return s.sc.Text()
}

var (
	a []int
	n int
)

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

func same() bool {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[a[i]]++
		if cnt[a[i]]*2 >= n {
			return true
		}
	}
	return false
}

func main() {
	sc := newScanner()
	tc := sc.nextInt()
	for ; tc > 0; tc-- {
		n = sc.nextInt()
		a = make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = sc.nextInt()
		}
		if same() {
			fmt.Println(-1)
			continue
		}

		// fmt.Printf("a\n")
		// for _, k := range a {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		div := []int{}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				diff := abs(a[i] - a[j])
				if diff == 0 {
					continue
				}
				for k := 1; k*k <= diff; k++ {
					if (diff % k) == 0 {
						div = append(div, diff/k)
						div = append(div, k)
					}
				}
			}
		}

		uniq := []int{}
		sort.Ints(div)
		for i := 0; i < len(div); i++ {
			if i == 0 || div[i] != div[i-1] {
				uniq = append(uniq, div[i])
			}
		}
		div = uniq

		// fmt.Printf("div\n")
		// for _, k := range div {
		// 	fmt.Printf("%d ", k)
		// }
		// fmt.Println()

		ans := 0
		for _, k := range div {
			for i := 0; i < n; i++ {
				cnt := 0
				for j := 0; j < n; j++ {
					diff := abs(a[i] - a[j])
					if (diff % k) == 0 {
						cnt++
					}
				}
				if cnt*2 >= n {
					if ans < k {
						ans = k
					}
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

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

var N int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		a = make([]int, N)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int {
	var max int
	var min int = 1e6 + 5

	mp := make(map[int]int)

	for i := 0; i < N; i++ {
		if a[i] > max {
			max = a[i]
		}
		if a[i] < min {
			min = a[i]
		}
		mp[a[i]]++
	}

	for _, v := range mp {
		if v >= N/2 {
			return -1
		}
	}

	if N == 4 {
		return max - min
	}

	var maxKey int = 2

	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {

			d := abs(a[i] - a[j])

			mp := make(map[int]int)

			for k := 0; k < N; k++ {
				if k == i  || k == j {
					continue
				}

				d1 := abs(a[i] - a[k])
				d2 := abs(a[j] - a[k])

				g1 := GCD(d1, d2)

				g := GCD(g1, d)

				mp[g]++
			}

			var localMax int

			var arr []int

			for k, _ := range mp {
				arr = append(arr, k)
			}
			sort.Ints(arr)

			for p := len(arr) - 1; p >= 0; p-- {

				curKey := arr[p]
				v1 := mp[curKey]

				if v1 >= N/2 - 2 {
					localMax = maxF(localMax, curKey)
					continue
				}

				c := v1

				var g int = -1
				done := false

				for z := p - 1; z >= 0; z-- {
					thisKey := arr[z]
					v2 := mp[thisKey]

					if g == -1 {
						g = GCD(curKey, thisKey)
					} else {
						g = GCD(g, thisKey)
					}
					if c + v2 >= N/2 - 2 {
						done = true
						break
					}
				}

				if done {
					localMax = maxF(localMax, g)
				}
			}

			maxKey = maxF(maxKey, localMax)
		}
	}

	return maxKey
}

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

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

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

package main

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

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

	_, _ = fmt.Fscan(r, &t)

	TestLoop: for ; t > 0; t-- {
		_, _ = fmt.Fscan(r, &n)
		var a []int

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

		result := -1
		for _, value := range origCnt {
			if 2 * value >= n {
				fmt.Println(result)
				continue TestLoop
			}
		}

		sort.Ints(a)
		for i := 0; i < n; i++ {
			equal := 1
			cntDiv := make(map[int]int)
			for j := i + 1; j < n; j++ {
				if a[i] == a[j] {
					equal++
				} else {
					diff := a[j] - a[i]
					for d := 1; d * d <= diff; d++ {
						if diff % d == 0 {
							cntDiv[d]++
							if diff / d != d {
								cntDiv[diff / d]++
							}
						}
					}
				}
			}

			for key, value := range cntDiv {
				if 2 * (value + equal) >= n && result < key {
					result = key
				}
			}
		}

		fmt.Println(result)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1593D2(in io.Reader, out io.Writer) {
	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		c := map[int]int{}
		for i := range a {
			Fscan(in, &a[i])
			c[a[i]]++
		}
		for _, c := range c {
			if c >= n/2 {
				Fprintln(out, -1)
				continue o
			}
		}

		sort.Ints(a)
		ans := 0
		f := func(base, d int) bool {
			c := 0
			for _, v := range a {
				if abs(v-base)%d == 0 {
					c++
				}
			}
			return c >= n/2
		}
		for i, v := range a {
			for _, w := range a[:i] {
				for d, m := 1, v-w; d*d <= m; d++ {
					if m%d == 0 {
						if f(w, m/d) {
							ans = max(ans, m/d)
							break
						}
						if f(w, d) {
							ans = max(ans, d)
						}
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}
func main() {CF1593D2(os.Stdin, os.Stdout)}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1593D2(in io.Reader, out io.Writer) {
	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		c := map[int]int{}
		for i := range a {
			Fscan(in, &a[i])
			c[a[i]]++
		}
		for _, c := range c {
			if c >= n/2 {
				Fprintln(out, -1)
				continue o
			}
		}

		sort.Ints(a)
		ans := 0
		f := func(base, d int) bool {
			c := 0
			for _, v := range a {
				if abs(v-base)%d == 0 {
					c++
				}
			}
			return c >= n/2
		}
		for i, v := range a {
			for _, w := range a[:i] {
				for d, m := 1, v-w; d*d <= m; d++ {
					if m%d == 0 {
						if f(w, m/d) {
							ans = max(ans, m/d)
							break
						}
						if f(w, d) {
							ans = max(ans, d)
						}
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

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

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

package main

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

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

	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		c := map[int]int{}
		for i := range a {
			Fscan(in, &a[i])
			c[a[i]]++
		}
		for _, c := range c {
			if c >= n/2 {
				Fprintln(out, -1)
				continue o
			}
		}

		sort.Ints(a)
		ans := 0
		f := func(base, d int) bool {
			c := 0
			for _, v := range a {
				if abs(v-base)%d == 0 {
					c++
				}
			}
			return c >= n/2
		}
		for i, v := range a {
			for _, w := range a[:i] {
				for d, m := 1, v-w; d*d <= m; d++ {
					if m%d == 0 {
						if f(w, m/d) {
							ans = max(ans, m/d)
							break
						}
						if f(w, d) {
							ans = max(ans, d)
						}
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

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

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

package main

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

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

  var t int
  fmt.Fscan(reader, &t)
  for ; t > 0; t-- {
    var n int
    fmt.Fscan(reader, &n)
    arr := make([]int, n)
    m := make(map[int]int)
    z := false
    for i := 0; i < n; i++ {
      fmt.Fscan(reader, &arr[i])
      m[arr[i]]++
      if m[arr[i]] >= n/2 {
        z = true
      }
    }
    if z {
      fmt.Fprint(writer, "-1\n")
      continue
    }

    ans := 1
    check := func (k int) {
      if k <= ans {
        return
      }
      freqs := make(map[int]int)
      for i := 0; i < n; i++ {
        rem := arr[i] % k
        if rem < 0 {
          rem += k
        }
        freqs[rem]++
        if freqs[rem] >= n/2 {
          ans = k
          return
        }
      }
      return
    }

    for i := 0; i < n; i++ {
      for j := 0; j < n; j++ {
        d := arr[i]-arr[j]
        if (d < 0) {
          d = -d
        }
        if (d <= ans) {
          continue
        }
        for k := 1; k*k <= d; k++ {
          if d % k == 0 {
            check(k)
            check(d/k)
          }
        }
      }
    }

    fmt.Fprint(writer, ans, "\n")
  }
}

package main

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

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

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int
	fmt.Fscanf(r, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(r, "%d", &arr[i])
		}
		fmt.Fscanf(r, "\n")

		sort.Ints(arr)

		diff := 1
		c := 1
		for i := 1; i < n; i++ {
			if arr[i] != arr[i-1] {
				c = 1
			} else {
				c++
			}
			if c > diff {
				diff = c
			}
		}

		if diff >= n/2 {
			fmt.Println(-1)
			continue
		}

		res := 0
		for l := 0; l < len(arr); l++ {
			f := [22]map[int]bool{}
			for i := 0; i < 22; i++ {
				f[i] = make(map[int]bool)
			}

			for i := 0; i < len(arr); i++ {
				for j := n/2 - 1; j >= 1; j-- {
					for k, _ := range f[j] {
						//	fmt.Println(k, arr[l]-arr[i])
						f[j+1][gcd(k, abs(arr[l]-arr[i]))] = true
					}
				}
				f[1][abs(arr[l]-arr[i])] = true
			}

			//	fmt.Println(f[1:(n/2 + 1)])

			for k, _ := range f[n/2] {
				if k > res {
					res = k
				}
			}
		}

		fmt.Println(res)
	}
}

package main

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

var N int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		a = make([]int, N)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int {
	var max int
	var min int = 1e6 + 5

	mp := make(map[int]int)

	for i := 0; i < N; i++ {
		if a[i] > max {
			max = a[i]
		}
		if a[i] < min {
			min = a[i]
		}
		mp[a[i]]++
	}

	for _, v := range mp {
		if v >= N/2 {
			return -1
		}
	}

	if N == 4 {
		return max - min
	}

	var maxKey int = 2

	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {

			d := abs(a[i] - a[j])

			mp := make(map[int]int)

			for k := 0; k < N; k++ {
				if k == i  || k == j {
					continue
				}

				d1 := abs(a[i] - a[k])
				d2 := abs(a[j] - a[k])

				g1 := GCD(d1, d2)

				g := GCD(g1, d)

				mp[g]++
			}

			for k, v := range mp {
				if v >= N/2 - 2 {
					maxKey = maxF(maxKey, k)
				}
			}
		}
	}

	return maxKey
}

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

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

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

package main

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

var N int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		a = make([]int, N)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int {
	var max int
	var min int = 1e6 + 5

	mp := make(map[int]int)

	for i := 0; i < N; i++ {
		if a[i] > max {
			max = a[i]
		}
		if a[i] < min {
			min = a[i]
		}
		mp[a[i]]++
	}

	for _, v := range mp {
		if v >= N/2 {
			return -1
		}
	}

	var maxKey int = 2

	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {

			d := abs(a[i] - a[j])

			mp := make(map[int]int)

			for k := 0; k < N; k++ {
				if k == i  || k == j {
					continue
				}

				d1 := abs(a[i] - a[k])
				d2 := abs(a[j] - a[k])

				g1 := GCD(d1, d2)

				g := GCD(g1, d)

				mp[g]++
			}

			for k, v := range mp {
				if v >= N/2 - 2 {
					maxKey = maxF(maxKey, k)
				}
			}
		}
	}

	return maxKey
}

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

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

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

package main

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

var N int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		a = make([]int, N)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int {
	var max int
	var min int = 1e6 + 5

	mp := make(map[int]int)

	for i := 0; i < N; i++ {
		if a[i] > max {
			max = a[i]
		}
		if a[i] < min {
			min = a[i]
		}
		mp[a[i]]++
	}

	for _, v := range mp {
		if v >= N/2 {
			return -1
		}
	}

	var  i int
	for i = max - min; i >= 2; i-- {

		mp := make(map[int]int)

		for j := 0; j < N; j++ {
			var r int
			if a[j] >= 0 {
				r = a[j] % i

			} else {
				r = i + (a[j] % i)
			}

			mp[r]++
		}

		for _, v := range mp {
			if v >= N/2 {
				return i
			}
		}
	}

	return 1
}

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

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