Along the railroad there are stations indexed from $$$1$$$ to $$$10^9$$$. An express train always travels along a route consisting of $$$n$$$ stations with indices $$$u_1, u_2, \dots, u_n$$$, where ($$$1 \le u_i \le 10^9$$$). The train travels along the route from left to right. It starts at station $$$u_1$$$, then stops at station $$$u_2$$$, then at $$$u_3$$$, and so on. Station $$$u_n$$$ — the terminus.It is possible that the train will visit the same station more than once. That is, there may be duplicates among the values $$$u_1, u_2, \dots, u_n$$$.You are given $$$k$$$ queries, each containing two different integers $$$a_j$$$ and $$$b_j$$$ ($$$1 \le a_j, b_j \le 10^9$$$). For each query, determine whether it is possible to travel by train from the station with index $$$a_j$$$ to the station with index $$$b_j$$$.For example, let the train route consist of $$$6$$$ of stations with indices [$$$3, 7, 1, 5, 1, 4$$$] and give $$$3$$$ of the following queries:   $$$a_1 = 3$$$, $$$b_1 = 5$$$It is possible to travel from station $$$3$$$ to station $$$5$$$ by taking a section of the route consisting of stations [$$$3, 7, 1, 5$$$]. Answer: YES.  $$$a_2 = 1$$$, $$$b_2 = 7$$$You cannot travel from station $$$1$$$ to station $$$7$$$ because the train cannot travel in the opposite direction. Answer: NO.  $$$a_3 = 3$$$, $$$b_3 = 10$$$It is not possible to travel from station $$$3$$$ to station $$$10$$$ because station $$$10$$$ is not part of the train's route. Answer: NO.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case is empty. The second line of each test case contains two integers: $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5$$$) —the number of stations the train route consists of and the number of queries. The third line of each test case contains exactly $$$n$$$ integers $$$u_1, u_2, \dots, u_n$$$ ($$$1 \le u_i \le 10^9$$$). The values $$$u_1, u_2, \dots, u_n$$$ are not necessarily different. The following $$$k$$$ lines contain two different integers $$$a_j$$$ and $$$b_j$$$ ($$$1 \le a_j, b_j \le 10^9$$$) describing the query with index $$$j$$$. It is guaranteed that the sum of $$$n$$$ values over all test cases in the test does not exceed $$$2 \cdot 10^5$$$. Similarly, it is guaranteed that the sum of $$$k$$$ values over all test cases in the test also does not exceed $$$2 \cdot 10^5$$$

For each test case, output on a separate line:   YES, if you can travel by train from the station with index $$$a_j$$$ to the station with index $$$b_j$$$ NO otherwise.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

NoteThe first test case is explained in the problem statement.

package main

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

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

func main() {
	defer out.Flush()

	var testNum int

	fmt.Fscan(in, &testNum)
	for i := 0; i < testNum; i++ {
		n, k := 1, 1
		fmt.Fscan(in, &n, &k)

		stations := make(map[int][]int)
		for ii := 0; ii < n; ii++ {
			x := 1
			fmt.Fscan(in, &x)
			stations[x] = append(stations[x], ii)
		}

		for ii := 0; ii < k; ii++ {
			a, b := 1, 1
			fmt.Fscan(in, &a, &b)

			if _, ok := stations[a]; !ok {
				fmt.Fprintln(out, "no")
				continue
			}

			if _, ok := stations[b]; !ok {
				fmt.Fprintln(out, "no")
				continue
			}

			v1 := stations[a][0]
			v2 := stations[b][len(stations[b])-1]

			if v1 < v2 {
				fmt.Fprintln(out, "yes")
			} else {
				fmt.Fprintln(out, "no")
			}
		}
	}
}

package main

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

var reader *bufio.Reader

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

	reader = bufio.NewReader(os.Stdin)

	fmt.Fscanln(reader, &t)

	for i := 0; i < t; i++ {
		fmt.Fscanln(reader)
		fmt.Fscanln(reader, &n, &k)

		// log.Printf("n=%d, k=%d", n, k)

		solve(n, k)
	}
}

func solve(n, k int) {
	left := make(map[int]int)
	right := make(map[int]int)

	for i := 0; i < n; i++ {
		var u int
		fmt.Fscan(reader, &u)
		// log.Printf("read i=%d value=%d", i, u)

		if _, exists := left[u]; !exists {
			left[u] = i
			right[u] = i
		} else {
			right[u] = i
		}
	}
	fmt.Fscanln(reader)

	routeExists := func(a, b int) bool {
		l, ok := left[a]
		if !ok {
			return false
		}

		r, ok := right[b]
		if !ok {
			return false
		}

		return l <= r
	}

	// requests
	for k > 0 {
		k--

		var (
			a int
			b int
		)
		fmt.Fscanln(reader, &a, &b)
		// log.Printf("a = %d, b = %d", a, b)
		if routeExists(a, b) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

type Pair struct {
	First  int
	Second int
}

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

	return b
}

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

	return a
}

func main() {
	var t, n, k, v, a, b int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &t)
	for tt := 0; tt < t; tt++ {
		fmt.Fscan(reader, &n, &k)
		data := map[int]Pair{}
		exist := map[int]bool{}
		dd := []int{}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &v)
			dd = append(dd, v)
			exist[v] = true
			data[v] = Pair{
				First:  200005,
				Second: -1,
			}
		}

		for i := 0; i < n; i++ {
			val, _ := data[dd[i]]
			val.First = Min(val.First, i+1)
			val.Second = Max(val.Second, i+1)
			data[dd[i]] = val
		}

		for i := 0; i < k; i++ {
			fmt.Fscan(reader, &a, &b)
			if !exist[a] || !exist[b] {
				fmt.Println("NO")
				continue
			}
			// cout << "first" << data[a].first << endl;
			// cout << "second" << data[b].second << endl;
			if data[a].First <= data[b].Second {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, k int
	fmt.Fscan(rr, &n, &k)
	nums := make([]int, n)
	left, right := make(map[int]int), make(map[int]int)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
		right[nums[i]] = i
	}
	for i:=n-1;i>=0;i-- {
		left[nums[i]] = i
	}
	for kk:=0;kk<k;kk++ {
		var a, b int
		fmt.Fscan(rr, &a, &b)
		l, ok1 := left[a]
		r, ok2 := right[b]
		if !ok1 || !ok2 || l > r {
			fmt.Fprintln(ww, "NO")
		} else {
			fmt.Fprintln(ww, "YES")
		}
	}
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

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

func main() {

	defer writer.Flush()
	var tc int
	var n, k int
	var a, b int
	var mn [200005]int
	var mx [200005]int

	scanws(&tc)
	for t := 1; t <= tc; t++ {
		scanws(&n, &k)
		mp := map[int]int{}
		cnt := 1
		for i := 1; i <= n; i++ {
			scanws(&a)
			indx, isExist := mp[a]
			if isExist == false {
				indx = cnt
				mp[a] = cnt
				mn[indx] = i
				cnt++
			}
			mx[indx] = i
		}
		for q := 0; q < k; q++ {
			scanws(&a, &b)
			ia, ba := mp[a]
			ib, bb := mp[b]
			if ba == false || bb == false {
				printf("NO\n")
				continue
			}
			if mn[ia] >= mx[ib] {
				printf("NO\n")
				continue
			}
			if mn[ia] < mx[ib] {
				printf("YES\n")
			}
		}
	}
}

package main

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

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

	numCases := 0
	fmt.Fscan(in, &numCases)

	for ; numCases > 0; numCases-- {
		n, k := 0, 0
		fmt.Fscan(in, &n, &k)

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

		for ; k > 0; k-- {
			a, b := 0, 0
			fmt.Fscan(in, &a, &b)

			aIdx, ok := stations[a]
			if !ok {
				fmt.Fprintln(out, "NO")
				continue
			}

			bIdx, ok := stations[b]
			if !ok {
				fmt.Fprintln(out, "NO")
				continue
			}

			if aIdx[0] < bIdx[len(bIdx)-1] {
				fmt.Fprintln(out, "YES")
			} else {
				fmt.Fprintln(out, "NO")
			}
		}
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		readString(reader)

		n, k := readTwoNums(reader)
		stations := readNNums(reader, n)
		queries := make([][]int, k)
		for i := 0; i < k; i++ {
			queries[i] = readNNums(reader, 2)
		}
		res := solve(stations, queries)
		for _, cur := range res {
			if cur {
				buf.WriteString("YES\n")
			} else {
				buf.WriteString("NO\n")
			}
		}
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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
	var bs []byte

	for {
		bs, _ = reader.ReadBytes('\n')
		if len(bs) > 1 {
			break
		}
	}

	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(stations []int, queries [][]int) []bool {
	n := len(stations)
	first_occ := make(map[int]int)
	last_occ := make(map[int]int)

	for i := 0; i < n; i++ {
		if _, ok := first_occ[stations[i]]; !ok {
			first_occ[stations[i]] = i + 1
		}
		last_occ[stations[i]] = i + 1
	}

	ans := make([]bool, len(queries))

	for i, qry := range queries {
		a, b := qry[0], qry[1]
		if first_occ[a] > 0 && first_occ[b] > 0 {
			ans[i] = first_occ[a] < last_occ[b]
		}
	}

	return ans
}

package main

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

type node struct {
	max, min int
}

func solve(in io.Reader, out io.Writer) {
	var n, k int
	fmt.Fscan(in, &n, &k)
	mp := make(map[int]node)
	for i := 0; i < n; i++ {
		var num int
		fmt.Fscan(in, &num)
		if v, ok := mp[num]; ok {
			mp[num] = node{
				max: max(v.max, i+1),
				min: min(v.min, i+1),
			}
		} else {
			mp[num] = node{
				max: i + 1,
				min: i + 1,
			}
		}
	}
	for i := 0; i < k; i++ {
		var lo, hi int
		fmt.Fscan(in, &lo, &hi)
		v1, ok := mp[lo]
		if !ok {
			fmt.Fprintln(out, "NO")
			continue
		}
		v2, ok := mp[hi]
		if !ok {
			fmt.Fprintln(out, "NO")
			continue
		}
		if v1.min <= v2.max {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		solve(in, os.Stdout)
		t--
	}
}

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
}

package main

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

const cf = true

func solve() {
	var n, k int
	fmt.Fscan(in, &n, &k)
	first := make(map[int]int)
	last := make(map[int]int)
	var num int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &num)
		last[num] = i
		if _, ok := first[num]; !ok {
			first[num] = i
		}
	}
	var a, b int
	for i := 0; i < k; i++ {
		fmt.Fscan(in, &a, &b)
		f, fOk := first[a]
		l, lOk := last[b]
		if !fOk || !lOk || f > l {
			fmt.Fprintln(out, "NO")
			continue
		}
		fmt.Fprintln(out, "YES")
	}
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

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

	var T int
	var n int
	var k int
	var x int
	var y int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &k)

		st, que := make([]int, n), make([][]int, k)
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			st[i] = x
		}
		for i := 0; i < k; i++ {
			Fscan(in, &x, &y)
			que[i] = []int{x, y}
		}

		m := map[int][]int{}
		for i, v := range st {
			if len(m[v]) == 0 {
				m[v] = []int{i, i}
			} else {
				m[v][1] = i
			}
		}

		for _, v := range que {
			x, y := v[0], v[1]
			ans := "NO"
			if len(m[x]) > 0 && len(m[y]) > 0 {
				if m[x][0] < m[y][1] {
					ans = "YES"
				}
			}
			Fprintln(out, ans)
		}
	}
}

package main

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

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

func tos(i int64) string {
  return strconv.FormatInt(i, 10)
}

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  sc.Scan()
  n := toi(sc.Text())
  sc.Scan()
  k := toi(sc.Text())
  a := map[int64][]int64{}
  for i := int64(0); i < n; i++ {
    sc.Scan()
    x := toi(sc.Text())
    if _, in := a[x]; in {
      a[x] = append(a[x], i)
    } else {
      a[x] = []int64{i}
    }
  }
  for cnt := int64(0); cnt < k; cnt++ {
    sc.Scan()
    x := toi(sc.Text())
    sc.Scan()
    y := toi(sc.Text())
    i, in := a[x]
    j, jn := a[y]
    if in && jn && i[0] <= j[len(j) - 1] {
      wr.WriteString("YES\n")
      continue
    }
    wr.WriteString("NO\n")
  }
}

const (
  once = false
  maxBufSize = 10000000
)

func main() {
  sc := bufio.NewScanner(bufio.NewReader(os.Stdin))
  sc.Split(bufio.ScanWords)
  sc.Buffer(make([]byte, maxBufSize), maxBufSize)

  wr := bufio.NewWriter(os.Stdout)
  defer wr.Flush()

  if once {
    solve(sc, wr)
  } else {
    sc.Scan()
    times, _ := strconv.Atoi(sc.Text())
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

package main

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

var (
	_r = bufio.NewReader(os.Stdin)
	_w = bufio.NewWriter(os.Stdout)
)

type Tint interface {
	int | int32 | int64
}

func min[T Tint](x, y T) T {
	if x <= y {
		return x
	}
	return y
}
func max[T Tint](x, y T) T {
	if x >= y {
		return x
	}
	return y
}
func main() {
	defer _w.Flush()

	var _t int
	// n = 1
	fmt.Fscan(_r, &_t)
	for ; _t > 0; _t-- {
		n, k := 1, 1
		fmt.Fscan(_r, &n, &k)
		id := make(map[int][]int)
		for i := 0; i < n; i++ {
			x := 1
			fmt.Fscan(_r, &x)
			id[x] = append(id[x], i)
		}
		for i := 0; i < k; i++ {
			a, b := 1, 1
			fmt.Fscan(_r, &a, &b)
			if _, ok := id[a]; !ok {
				fmt.Fprintln(_w, "NO")
				continue
			}
			if _, ok := id[b]; !ok {
				fmt.Fprintln(_w, "NO")
				continue
			}
			if id[a][0] >= id[b][len(id[b])-1] {
				fmt.Fprintln(_w, "NO")
				continue
			}
			fmt.Fprintln(_w, "YES")
		}
	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n, m int
		fmt.Fscan(r, &n, &m)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		b := make([][2]int, m)
		for j := 0; j < m; j++ {
			fmt.Fscan(r, &b[j][0], &b[j][1])
		}
		w1 := do(a, b)
		for _, w1 := range w1 {
			fmt.Fprintln(w, w1)
		}
	}
}

func do(a []int, b [][2]int) []string {
	c := make([]string, 0, len(b))
	ml := map[int]int{}
	mr := map[int]int{}
	for i, v := range a {
		if j, ok := ml[v]; !ok || j > i {
			ml[v] = i
		}
		if j, ok := mr[v]; !ok || j < i {
			mr[v] = i
		}
	}
	for _, v := range b {
		a := v[0]
		b := v[1]
		if check(ml, mr, a, b) {
			c = append(c, "YES")
		} else {
			c = append(c, "NO")
		}
	}
	return c
}

func check(ml, mr map[int]int, a, b int) bool {
	if _, ok := ml[a]; !ok {
		return false
	}
	if _, ok := ml[b]; !ok {
		return false
	}
	return ml[a] <= mr[b]
}

// 1702C. Train and Queries
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k, curr int
		fmt.Fscan(reader, &n, &k)
		max := make(map[int]int)
		min := make(map[int]int)
		for i := 1; i <= n; i++ {
			fmt.Fscan(reader, &curr)
			if val, ok := max[curr]; ok {
				if i > val {
					max[curr] = i
				}
			} else {
				max[curr] = i
			}
			if val, ok := min[curr]; ok {
				if i < val {
					min[curr] = i
				}
			} else {
				min[curr] = i
			}
		}
		for i := 1; i <= k; i++ {
			var a, b int
			fmt.Fscan(reader, &a, &b)
			if val1, ok1 := max[b]; ok1 {
				if val2, ok2 := min[a]; ok2 {
					if val1 > val2 {
						fmt.Println("YES")
					} else {
						fmt.Println("NO")
					}
				} else {
					fmt.Println("NO")
				}
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

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

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

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

		mm := make(map[int][2]int, n)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			e, ok := mm[v]
			if !ok {
				mm[v] = [2]int{i, i}
			} else {
				e[1] = i
				mm[v] = e
			}

		}

		for i := 0; i < k; i++ {
			var a, b int
			fmt.Fscan(in, &a, &b)
			e1, ok := mm[a]
			if !ok {
				fmt.Fprintln(out, "NO")
				continue
			}
			e2, ok := mm[b]
			if !ok {
				fmt.Fprintln(out, "NO")
				continue
			}

			if e1[0] <= e2[1] {
				fmt.Fprintln(out, "YES")
			} else {
				fmt.Fprintln(out, "NO")
			}

		}
	}
}

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, q int

		Fscan(in, &n, &q)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		first, last := map[int]int{}, map[int]int{}
		for i := 0; i < n; i++ {
			last[a[i]] = i + 1
		}
		for i := n - 1; i >= 0; i-- {
			first[a[i]] = i + 1
		}
		for i := 0; i < q; i++ {
			var x, y int
			Fscan(in, &x, &y)
			lx, ry := first[x], last[y]

			if (lx == 0 || ry == 0) || lx > ry {
				Fprintln(out, "No")

			} else {
				Fprintln(out, "Yes")
			}
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }

package main

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

type Pos struct {
	mi int
	ma int
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		fmt.Fscanln(inp)
		var n, k int
		fmt.Fscanln(inp, &n, &k)

		mapping := map[int]*Pos{}

		var tmp int
		for i := 1; i <= n; i++ {
			if i < n {
				fmt.Fscan(inp, &tmp)
			} else {
				fmt.Fscanln(inp, &tmp)
			}

			if _, ok := mapping[tmp]; !ok {
				mapping[tmp] = &Pos{mi: i, ma: i}
			} else {
				if i < mapping[tmp].mi {
					mapping[tmp].mi = i
				}
				if i > mapping[tmp].ma {
					mapping[tmp].ma = i
				}
			}
		}

		for i := 0; i < k; i++ {
			var res bool
			var s, e int
			fmt.Fscanln(inp, &s, &e)

			if ts, ok := mapping[s]; !ok {
				res = false
			} else if te, ok := mapping[e]; !ok {
				res = false
			} else if ts.mi > te.ma {
				res = false
			} else {
				res = true
			}

			if res {
				fmt.Fprintln(out, "YES")
			} else {
				fmt.Fprintln(out, "NO")
			}
		}

	}

	out.Flush()
}

package main

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

var maxSize int

func init() {
	maxSize = 2*int(math.Pow(10, 5)) + 3
}

func main() {
	defer func() {
		if err := recover(); err != nil {
			fmt.Println(err)
		}
	}()

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, maxSize), maxSize)

	scanner.Scan()

	testNum, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < testNum; i++ {
		var t string
		for {
			scanner.Scan()
			t = scanner.Text()
			if t != "" {
				break
			}
		}

		nk := strings.Split(t, " ") //n k
		n, _ := strconv.ParseInt(nk[0], 10, 64)
		k, _ := strconv.ParseInt(nk[1], 10, 64)

		scanner.Scan()
		ns := strings.Split(scanner.Text(), " ")

		stations := make([]int64, 0, n)
		for _, nn := range ns {
			nm, _ := strconv.ParseInt(nn, 10, 64)
			stations = append(stations, nm)
		}

		for ii := int64(0); ii < k; ii++ {
			scanner.Scan()
			stationsDest := strings.Split(scanner.Text(), " ")
			a, _ := strconv.ParseInt(stationsDest[0], 10, 64)
			b, _ := strconv.ParseInt(stationsDest[1], 10, 64)

			var found bool
			var lastIndex int
			for l, iii := range stations {
				if iii == a {
					found = true
					lastIndex = l
					break
				}
			}

			var foundB bool
			if found {
				for _, iii := range stations[lastIndex:] {
					if iii == b {
						foundB = true
						break
					}
				}
			}

			if foundB {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		}
	}
}

package main

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

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

	fmt.Scanln(&t)

	for i := 0; i < t; i++ {
		fmt.Scanln()
		fmt.Scanln(&n, &k)

		// log.Printf("n=%d, k=%d", n, k)

		solve(n, k)
	}
}

func solve(n, k int) {
	left := make(map[int]int)
	right := make(map[int]int)

	reader := bufio.NewReader(os.Stdin)

	for i := 0; i < n; i++ {
		var u int
		fmt.Fscan(reader, &u)
		// log.Printf("read i=%d value=%d", i, u)

		if _, exists := left[u]; !exists {
			left[u] = i
			right[u] = i
		} else {
			right[u] = i
		}
	}
	fmt.Fscanln(reader)

	routeExists := func(a, b int) bool {
		l, ok := left[a]
		if !ok {
			return false
		}

		r, ok := right[b]
		if !ok {
			return false
		}

		return l <= r
	}

	// requests
	for k > 0 {
		k--

		var (
			a int
			b int
		)
		fmt.Fscanln(reader, &a, &b)
		// log.Printf("a = %d, b = %d", a, b)
		if routeExists(a, b) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

type Pair struct {
	First  int
	Second int
}

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

	return b
}

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

	return a
}

func main() {
	var t, n, k, v, a, b int
	fmt.Scanf("%d", &t)
	for tt := 0; tt < t; tt++ {
		fmt.Scanf("%d %d", &n, &k)
		data := map[int]Pair{}
		exist := map[int]bool{}
		dd := []int{}
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &v)
			dd = append(dd, v)
			exist[v] = true
			data[v] = Pair{
				First:  200005,
				Second: -1,
			}
		}

		for i := 0; i < n; i++ {
			val, _ := data[dd[i]]
			val.First = Min(val.First, i+1)
			val.Second = Max(val.Second, i+1)
			data[dd[i]] = val
		}

		for i := 0; i < k; i++ {
			fmt.Scanf("%d%d", &a, &b)
			if !exist[a] || !exist[b] {
				fmt.Println("NO")
				continue
			}
			// cout << "first" << data[a].first << endl;
			// cout << "second" << data[b].second << endl;
			if data[a].First <= data[b].Second {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

import "fmt"

type Pair struct {
	First  int
	Second int
}

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

	return b
}

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

	return a
}

func main() {
	var t, n, k, v, a, b int
	fmt.Scanf("%d", &t)
	for tt := 0; tt < t; tt++ {
		fmt.Scanf("%d", &n)
		fmt.Scanf("%d %d", &n, &k)
		data := map[int]Pair{}
		exist := map[int]bool{}
		dd := []int{}
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &v)
			dd = append(dd, v)
			exist[v] = true
			data[v] = Pair{
				First:  200005,
				Second: -1,
			}
		}

		for i := 0; i < n; i++ {
			val, _ := data[dd[i]]
			val.First = Min(val.First, i+1)
			val.Second = Max(val.Second, i+1)
			data[dd[i]] = val
		}

		for i := 0; i < k; i++ {
			fmt.Scanf("%d%d", &a, &b)
			if !exist[a] || !exist[b] {
				fmt.Println("NO")
				continue
			}
			// cout << "first" << data[a].first << endl;
			// cout << "second" << data[b].second << endl;
			if data[a].First <= data[b].Second {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, k int
	fmt.Fscan(rr, &n, &k)
	nums := make([]int, n)
	left, right := make(map[int]int), make(map[int]int)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
		right[nums[i]] = i
	}
	for i:=n-1;i>=0;i-- {
		left[nums[i]] = i
	}
	for kk:=0;kk<k;kk++ {
		var a, b int
		fmt.Fscan(rr, &a, &b)
		if left[a] < right[b] {
			fmt.Fprintln(ww, "YES")
		} else {
			fmt.Fprintln(ww, "NO")
		}
	}
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.In one move, you can choose some index $$$i$$$ ($$$1 \le i \le n - 2$$$) and shift the segment $$$[a_i, a_{i + 1}, a_{i + 2}]$$$ cyclically to the right (i.e. replace the segment $$$[a_i, a_{i + 1}, a_{i + 2}]$$$ with $$$[a_{i + 2}, a_i, a_{i + 1}]$$$). Your task is to sort the initial array by no more than $$$n^2$$$ such operations or say that it is impossible to do that.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 500$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 500$$$), where $$$a_i$$$ is the $$$i$$$-th element $$$a$$$. It is guaranteed that the sum of $$$n$$$ does not exceed $$$500$$$.

For each test case, print the answer: -1 on the only line if it is impossible to sort the given array using operations described in the problem statement, or the number of operations $$$ans$$$ on the first line and $$$ans$$$ integers $$$idx_1, idx_2, \dots, idx_{ans}$$$ ($$$1 \le idx_i \le n - 2$$$), where $$$idx_i$$$ is the index of left border of the segment for the $$$i$$$-th operation. You should print indices in order of performing operations.

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		cnt, res := solve(n, A)
		fmt.Println(cnt)
		if cnt < 0 {
			continue
		}
		var buf bytes.Buffer
		for i := 0; i < cnt; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		fmt.Println(buf.String())
	}
}

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 cycle(a, b, c *int) {
	*a, *b, *c = *c, *a, *b
}

func solve(n int, A []int) (int, []int) {
	ps := make([]Pair, n)
	for i := 0; i < n; i++ {
		ps[i] = Pair{A[i], i}
	}

	sort.Sort(Pairs(ps))

	for i := 0; i < n; i++ {
		A[ps[i].second] = i
	}

	var cnt int

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

	if cnt&1 == 1 {
		var ok = false
		for i := 0; i < n-1 && !ok; i++ {
			if ps[i].first == ps[i+1].first {
				A[ps[i].second], A[ps[i+1].second] = A[ps[i+1].second], A[ps[i].second]
				ok = true
			}
		}
		if !ok {
			return -1, nil
		}
	}
	res := make([]int, 0, n)
	for i := 0; i < n-2; i++ {
		var pos = i
		for j := i + 1; j < n; j++ {
			if A[j] < A[pos] {
				pos = j
			}
		}

		for pos > i+1 {
			cycle(&A[pos-2], &A[pos-1], &A[pos])
			res = append(res, pos-2+1)
			pos -= 2
		}

		if pos != i {
			// pos = i + 1
			// 3, 1, 2, the only way
			j := pos + 1
			cycle(&A[j-2], &A[j-1], &A[j])
			res = append(res, j-2+1)
			cycle(&A[j-2], &A[j-1], &A[j])
			res = append(res, j-2+1)
			pos = i
		}
	}

	if !sort.IntsAreSorted(A) {
		// 2, 3, 1 the only way
		cycle(&A[n-3], &A[n-2], &A[n-1])
		res = append(res, n-3+1)
	}

	if !sort.IntsAreSorted(A) {
		return -1, nil
	}

	return len(res), res
}

type Pair struct {
	first, second int
}

func (this Pair) Less(that Pair) bool {
	if this.first < that.first {
		return true
	}
	if this.first == that.first && (this.second < that.second) {
		return true
	}
	return false
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].Less(ps[j])
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

package main

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

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

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

	var t, n int

	t = input()

	for ; t > 0; t-- {
		n = input()

		arr := make([]int, n)
		moves := make([]int, 0)

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

		rotate := func(i int) {
			tmp := arr[i+2]
			arr[i+2] = arr[i+1]
			arr[i+1] = arr[i]
			arr[i] = tmp
		}

		minInd := func(i, n int) int {
			min := i

			for j := i + 1; j < n; j++ {
				if arr[j] < arr[min] {
					min = j
				}
			}
			return min
		}

		for i := 0; i < n-2; i++ {
			k := minInd(i, n)

			for k != i {
				if k > i+2 {
					rotate(k - 2)
					k = k - 2
					moves = append(moves, k)
				} else {
					rotate(i)
					k = minInd(i, i+3)
					moves = append(moves, i)
				}
			}
		}

		sorted := false

		if arr[n-2] <= arr[n-1] {
			sorted = true
		} else {
			for i := n - 3; i >= 0; i-- {
				rotate(i)
				moves = append(moves, i)
				if sort.IntsAreSorted(arr) {
					sorted = true
					break
				}
			}
		}

		if sorted {
			fmt.Println(len(moves))
			for i := 0; i < len(moves); i++ {
				fmt.Print(moves[i]+1, " ")
			}
			fmt.Print("\n")
		} else {
			fmt.Println(-1)
		}

	}
}

package main

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

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

	var t, n int

	fmt.Fscanf(reader, "%d\n", &t)

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

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

		res, sum := cacul(a, n)
		fmt.Println(sum)

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

func cacul(a []int, n int) ([]int, int) {
	res := make([]int, 0, n*(n+1))
	for i := 2; i < n; i++ {

		for j, k := i, 1; j > 1 && j > k; j-- {
			if a[j] < a[j-1] || a[j] < a[j-2] {
				res = append(res, j-2)
				a[j-2], a[j-1], a[j] = a[j], a[j-2], a[j-1]
				k = j - 3
				j++
			}

			if len(res) > n*n {
				return nil, -1
			}
		}
	}

	for i, k := 0, 1; i < n-2 && i < k; i++ {
		if a[i] > a[i+1] || a[i] > a[i+2] {
			res = append(res, i)
			a[i], a[i+1], a[i+2] = a[i+2], a[i], a[i+1]
			k = i + 3
			i--
		}

		if len(res) > n*n {
			return nil, -1
		}
	}
	//fmt.Println(a)
	if sort.IntsAreSorted(a) {
		return res, len(res)
	} else {
		return nil, -1
	}
}

package main

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

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

	var t, n int

	fmt.Fscanf(reader, "%d\n", &t)

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

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

		s := make([]int, n)
		copy(s, a)
		sort.Ints(s)

		res, sum := cacul(s, a, n)
		fmt.Println(sum)

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

func cacul(s []int, a []int, n int) ([]int, int) {
	res := make([]int, 0, n*n)
	for i := 0; i < n-2; i++ {
		if s[i] == a[i] {
			continue
		}

		j := i + 1
		for ; j < n; j++ {
			if s[i] == a[j] {
				break
			}
		}

		k := j - 2
		for ; k >= i; k -= 2 {
			res = append(res, k)
			a[k], a[k+1], a[k+2] = a[k+2], a[k], a[k+1]
		}

		if k+2 == i {
			continue
		}

		if k+1 == i && i > 0 && a[k] == a[k+2] {
			res = append(res, k)
			a[k], a[k+1], a[k+2] = a[k+2], a[k], a[k+1]
			continue
		}

		res = append(res, i, i)
		a[i], a[i+1], a[i+2] = a[i+1], a[i+2], a[i]
	}

	if a[n-2] > a[n-1] {
		d := n - 3
		for ; d >= 0; d-- {
			if s[d] == s[d+1] {
				break
			}
		}

		if d >= 0 {
			for i := n - 3; i >= d; i-- {
				res = append(res, i)
				a[i], a[i+1], a[i+2] = a[i+2], a[i], a[i+1]
			}
		} else {
			return nil, -1
		}

	}

	if len(res) > n*n {
		return nil, -1
	}

	return res, len(res)
}

package main

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

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

	var t, n int

	fmt.Fscanf(reader, "%d\n", &t)

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

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

		res, sum := cacul(a, n)
		fmt.Println(sum)

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

func cacul(a []int, n int) ([]int, int) {
	res := make([]int, 0, n*(n+1))
	for i := 2; i < n; i++ {

		for j := i; j > 1; j-- {
			if a[j] < a[j-1] || a[j] < a[j-2] {
				res = append(res, j-2)
				a[j-2], a[j-1], a[j] = a[j], a[j-2], a[j-1]
				j++
			}

			if len(res) > n*n {
				return nil, -1
			}
		}
	}

	for i := 0; i < n-2; i++ {
		if a[i] > a[i+1] || a[i] > a[i+2] {
			res = append(res, i)
			a[i], a[i+1], a[i+2] = a[i+2], a[i], a[i+1]
			i--
		}

		if len(res) > n*n {
			return nil, -1
		}
	}
	//fmt.Println(a)
	if sort.IntsAreSorted(a) {
		return res, len(res)
	} else {
		return nil, -1
	}
}

package main

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

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

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

	var t, n int

	t = input()

	for ; t > 0; t-- {
		n = input()

		arr := make([]int, n)
		moves := make([]int, 0)

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

		rotate := func(i int) {
			tmp := arr[i+2]
			arr[i+2] = arr[i+1]
			arr[i+1] = arr[i]
			arr[i] = tmp
		}

		minInd := func(i, n int) int {
			min := i

			for j := i + 1; j < n; j++ {
				if arr[j] < arr[min] {
					min = j
				}
			}
			return min
		}

		for i := 0; i < n-2; i++ {
			k := minInd(i, n)

			for k != i {
				if k > i+2 {
					rotate(k - 2)
					k = k - 2
					moves = append(moves, k)
				} else {
					rotate(i)
					k = minInd(i, i+3)
					moves = append(moves, i)
				}
			}
		}

		sorted := false

		if arr[n-2] <= arr[n-1] {
			sorted = true
		} else {
			for i := n - 3; i >= 0; i-- {
				rotate(i)
				moves = append(moves, i)
				if sort.IntsAreSorted(arr) {
					sorted = true
					break
				}
			}
		}

		if sorted {
			fmt.Println(len(moves))
			for i := 0; i < len(moves); i++ {
				fmt.Print(moves[i], " ")
			}
			fmt.Print("\n")
		} else {
			fmt.Println(-1)
		}

	}
}

package main

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

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

	var t, n int

	fmt.Fscanf(reader, "%d\n", &t)

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

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

		res, sum := cacul(a, n)
		fmt.Println(sum)

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

func cacul(a []int, n int) ([]int, int) {
	res := make([]int, 0, n*(n+1))
	for i := 2; i < n; i++ {

		for j := i; j > 1; j-- {
			if a[j] < a[j-1] || a[j] < a[j-2] || (a[j] == a[j-2] && a[j-1] < a[j-2]) {
				res = append(res, j-2)
				a[j-2], a[j-1], a[j] = a[j], a[j-2], a[j-1]
				j++
			}

			if len(res) > n*n {
				return nil, -1
			}
		}
	}

	if sort.IntsAreSorted(a) {
		return res, len(res)
	} else {
		return nil, -1
	}
}

package main

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

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

	var t, n int

	fmt.Fscanf(reader, "%d\n", &t)

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

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

		res, sum := cacul(a, n)
		fmt.Println(sum)

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

func cacul(a []int, n int) ([]int, int) {
	res := make([]int, 0, n*(n+1))
	for i := 2; i < n; i++ {

		for j := i; j > 1; j-- {
			if a[j] < a[j-1] || a[j] < a[j-2] {
				res = append(res, j-2)
				a[j-2], a[j-1], a[j] = a[j], a[j-2], a[j-1]
				j++
			}

			if len(res) > n*n {
				return nil, -1
			}
		}
	}

	if sort.IntsAreSorted(a) {
		return res, len(res)
	} else {
		return nil, -1
	}
}


Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers. A sequence a1, a2, ..., an, consisting of n integers, is Hungry if and only if:   Its elements are in increasing order. That is an inequality ai < aj holds for any two indices i, j (i < j).  For any two indices i and j (i < j), aj must not be divisible by ai. Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

The input contains a single integer: n (1 ≤ n ≤ 105).

Output a line that contains n space-separated integers a1 a2, ..., an (1 ≤ ai ≤ 107), representing a possible Hungry sequence. Note, that each ai must not be greater than 10000000 (107) and less than 1. If there are multiple solutions you can output any one.

package main

import (
	"fmt"
)

func main() {
	var p int
	fmt.Scan(&p)
	for i:=p; i<2*p;i++ {
		fmt.Print(i," ")
	}
}

package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  notPrime := make([]bool, 1299710)
  primes := []int{}
  pos := 2
  for pos < len(notPrime) {
    primes = append(primes, pos)
    for seek := 2*pos; seek < len(notPrime); seek += pos {
      notPrime[seek] = true
    }
    for pos++; pos < len(notPrime) && notPrime[pos]; pos++ {
    }
  }

  n := getI()
  writer.WriteString(fmt.Sprintf("%d", primes[0]))
  for i := 1; i < n; i++ {
    writer.WriteString(fmt.Sprintf(" %d", primes[i]))
  }
  writer.WriteString("\n")
}

package main

import (
	"fmt"
)

func main() {
	const max int = 10000000

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

	start := max - n + 1
	for i := 0; i < n; i++ {
		fmt.Printf("%d ", start+i)
	}
	fmt.Printf("\n")
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    len := 2*n
    for i := n; i < len; i++ {
        writer.WriteString(strconv.Itoa(i))
        if i == (len-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

package main

import (
	"fmt"
)

// 1200
// 25.05.2020
// https://codeforces.com/problemset/problem/327/B

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

	g := 10000000 - n - 1
	for i := 0; i < n; i++ {
		fmt.Printf("%d ", g+i)
	}
}

// 327B-mic
package main

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

func main() {
    var n int
    a := bufio.NewWriter(os.Stdout)
    fmt.Scan(&n)
    for i := 0; i <= n-1; i++ {
        fmt.Fprint(a, n+i)
        if i != n-1 {
            fmt.Fprint(a, " ")
        } else {
            fmt.Fprintln(a)
        }
    }
    a.Flush()
}

package main
import (
  "bufio"
  "fmt"
  "strconv"
  "os"
)
func main() {
  reader:=bufio.NewReader(os.Stdin)
  str,_,_:= reader.ReadLine()
  n,_:=strconv.Atoi(string(str))
  for i:=0;i<n;i++{
    fmt.Print(100000+i," ");
  }
}

package main

import (
	"fmt"
)

func main() {
	var p int
	fmt.Scan(&p)
	for i := p; i < 2*p; i++ {
		fmt.Print(i, " ")
	}
}

package main

import "fmt"

const MAX_VAL = 10000000
var notPrime []bool = make([]bool, MAX_VAL+1)

func sieve() {
  for i := int64(2); i <= MAX_VAL; i++ {
    if !notPrime[i] {
      for j := i * i; j <= MAX_VAL; j += i {
        notPrime[j] = true
      }
    }
  }
}

func main() {
  var n int
  fmt.Scanf("%d", &n)
  sieve()
  written := 0
  for i := 2; i <= MAX_VAL && written < n; i++ {
    if !notPrime[i] {
      if written == 0 {
        fmt.Print(i)
      } else {
        fmt.Print(" ", i)
      }
      written++
    }
  }
  fmt.Println()
}

package main

import "fmt"

const MAX_VAL = 10000000
var notPrime []bool = make([]bool, MAX_VAL+1)

func sieve() {
  for i := 2; i <= MAX_VAL; i++ {
    if !notPrime[i] {
      for j := i + i; j <= MAX_VAL; j += i {
        notPrime[j] = true
      }
    }
  }
}

func main() {
  var n int
  fmt.Scanf("%d", &n)
  sieve()
  written := 0
  for i := 2; i <= MAX_VAL && written < n; i++ {
    if !notPrime[i] {
      if written == 0 {
        fmt.Print(i)
      } else {
        fmt.Print(" ", i)
      }
      written++
    }
  }
  fmt.Println()
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdin)
    var n int
    fmt.Scan(&n)
    len := 2*n
    for i := n; i < len; i++ {
        writer.WriteString(strconv.Itoa(i))
        if i == (len-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

package main

import (
	"fmt"
	"math"
)

// 1200
// 25.05.2020
// https://codeforces.com/problemset/problem/327/B

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

	k := int(math.Ceil(float64(n) / float64(math.Log(float64(n)))))

	a := make([]bool, k)

	for i := range a {
		if a[i] {
			continue
		}
		n--
		fmt.Printf("%d ", 2+i)
		if n == 0 {
			return
		}
		for j := range a[i:] {
			a[j] = a[j] || (2+j)%(2+i) == 0
		}
	}
}

package main

import "fmt"

// 1200
// 25.05.2020
// https://codeforces.com/problemset/problem/327/B

func main() {
	var n int
	fmt.Scanln(&n)
	var a [10000]bool

	for i := range a {
		if a[i] {
			continue
		}
		n--
		fmt.Printf("%d ", 2+i)
		if n == 0 {
			return
		}
		for j := range a[i:] {
			if (2+j)%(2+i) == 0 {
				a[j] = true
			}
		}
	}
}

// 327B-mic
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    for i := 2; i <= n+1; i++ {
        fmt.Print(i)
        if i != n {
            fmt.Print(" ")
        } else {
            fmt.Println()
        }
    }
}

// 327B-mic
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    for i := 1; i <= n; i++ {
        fmt.Print(i)
        if i != n {
            fmt.Print(" ")
        } else {
            fmt.Println()
        }
    }
}

// 327B-mic
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    for i := n; i <= n*2; i++ {
        fmt.Println(i)
    }
}

package main

import (
  "fmt"
  "math/big"
)

func main() {
  var n int
  fmt.Scanf("%d", &n)
  for i := 2; i <= n; i++ {
    if big.NewInt(int64(i)).ProbablyPrime(20) {
      if i == 2 {
        fmt.Print(i)
      } else {
        fmt.Print(" ", i)
      }
    }
  }
  fmt.Println()
}


Acacius is studying strings theory. Today he came with the following problem.You are given a string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks. It is possible to replace question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once?Each question mark should be replaced with exactly one lowercase English letter. For example, string "a?b?c" can be transformed into strings "aabbc" and "azbzc", but can't be transformed into strings "aabc", "a?bbc" and "babbc".Occurrence of a string $$$t$$$ of length $$$m$$$ in the string $$$s$$$ of length $$$n$$$ as a substring is a index $$$i$$$ ($$$1 \leq i \leq n - m + 1$$$) such that string $$$s[i..i+m-1]$$$ consisting of $$$m$$$ consecutive symbols of $$$s$$$ starting from $$$i$$$-th equals to string $$$t$$$. For example string "ababa" has two occurrences of a string "aba" as a substring with $$$i = 1$$$ and $$$i = 3$$$, but there are no occurrences of a string "aba" in the string "acba" as a substring.Please help Acacius to check if it is possible to replace all question marks with lowercase English letters in such a way that a string "abacaba" occurs as a substring in a resulting string exactly once.

First line of input contains an integer $$$T$$$ ($$$1 \leq T \leq 5000$$$), number of test cases. $$$T$$$ pairs of lines with test case descriptions follow. The first line of a test case description contains a single integer $$$n$$$ ($$$7 \leq n \leq 50$$$), length of a string $$$s$$$. The second line of a test case description contains string $$$s$$$ of length $$$n$$$ consisting of lowercase English letters and question marks.

For each test case output an answer for it. In case if there is no way to replace question marks in string $$$s$$$ with a lowercase English letters in such a way that there is exactly one occurrence of a string "abacaba" in the resulting string as a substring output "No". Otherwise output "Yes" and in the next line output a resulting string consisting of $$$n$$$ lowercase English letters. If there are multiple possible strings, output any. You may print every letter in "Yes" and "No" in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answer).

6
7
abacaba
7
???????
11
aba?abacaba
11
abacaba?aba
15
asdf???f???qwer
11
abacabacaba

Yes
abacaba
Yes
abacaba
Yes
abadabacaba
Yes
abacabadaba
No
No

NoteIn first example there is exactly one occurrence of a string "abacaba" in the string "abacaba" as a substring.In second example seven question marks can be replaced with any seven lowercase English letters and with "abacaba" in particular.In sixth example there are two occurrences of a string "abacaba" as a substring.

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		S, _ := reader.ReadBytes('\n')
		ok := solve(n, S)
		if !ok {
			buf.WriteString("No\n")
		} else {
			buf.WriteString("Yes\n")
			buf.WriteString(string(S))
		}
	}
	fmt.Print(buf.String())
}

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
}

const PAT = "abacaba"
const N = 100

var BUF []byte
var lps []int
var tmp []byte

func init() {
	BUF = make([]byte, N)
	lps = make([]int, N)
	tmp = make([]byte, len(PAT))
}

func solve(n int, S []byte) bool {
	// let's find whether there is already a abacaba already
	for i := 0; i+len(PAT) <= n; i++ {
		// if we make S[i:i + len(PAT)] as PAT
		var j int
		for j < len(PAT) && (S[i+j] == PAT[j] || S[i+j] == '?') {
			j++
		}
		if j < len(PAT) {
			continue
		}
		copy(tmp, S[i:i+j])
		copy(S[i:i+j], PAT)
		var cnt int
		p := kmp(n, S)
		for k := len(PAT) - 1; k < n; k++ {
			if p[k] == len(PAT) {
				cnt++
			}
		}
		if cnt == 1 {
			for k := 0; k < n; k++ {
				if S[k] == '?' {
					S[k] = 'd'
				}
			}
			return true
		}
		//revert
		copy(S[i:i+j], tmp)
	}

	return false
}

func kmp(n int, S []byte) []int {
	copy(BUF, PAT)
	BUF[len(PAT)] = '#'
	copy(BUF[len(PAT)+1:], S)
	n += len(PAT) + 1
	//lps := make([]int, n)
	for i := 1; i < n; i++ {
		j := lps[i-1]

		for j > 0 && BUF[i] != BUF[j] {
			j = lps[j-1]
		}

		lps[i] = j
		if BUF[i] == BUF[j] {
			lps[i]++
		}
	}

	return lps[len(PAT)+1 : n]
}

package main

import (
	"bufio"
	"fmt"
	"os"
    "bytes"
    "strings"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewReader(os.Stdout)
)

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

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

func main() {
    var t int
	fmt.Fscanln(input, &t)
    for i := 0; i < t; i++ {
        solve()
    }
}

const p = "abacaba"
var s string

func solve() {
    var d int
    fmt.Fscanln(input, &d)
    fmt.Fscanln(input, &s)
    m := make([]int, 0)
    for i := 0; i + len(p) <= len(s); i++ {
        l := 0
        for l < len(p) && (s[i + l] == '?' || s[i + l] == p[l]) {l++}
        if l == len(p) {m = append(m, i)}
    }
    for _, pos := range m {
        str := printStr(pos)
        f, l := strings.Index(str, p), strings.LastIndex(str, p)
        if f == l {
            fmt.Println("Yes")
            fmt.Println(str)
            return
        }
    }
    fmt.Println("No")
}

func printStr(index int) string {
    var buf bytes.Buffer
    for i := 0; i < len(s); i++ {
        if i >= index && i < index + len(p) {
            buf.WriteByte(p[i - index])
            continue
        }
        if s[i] != '?' {
            buf.WriteByte(s[i])
        } else {
            buf.WriteByte('z')
        }
    }
    return buf.String()
}

package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

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

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

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

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

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

func CheckLocation(r []rune) bool {
	target := "abacaba"
	ok := true
	for k := 0; k < 7 && ok; k++ {
		if r[k] != rune(target[k]) && r[k] != '?' {
			ok = false
		}
	}
	if !ok {
		return false
	}
	return true
}

func CheckIndex(r []rune, pos int) bool {
	if pos < 0 || pos + 6 >= len(r) {
		return false
	}
	return CheckLocation(r[pos:(pos+7)])
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		fin.ReadInt()
		str := fin.ReadText()
		r := []rune(str)
		r2 := append([]rune(nil), r...)
		for j := 0; j < len(r2); j++{
			if r2[j] == '?' {
				r2[j] = 'z'
			}
		}

		cnt_orig := 0
		for j := 0; j < len(r2); j++{
			if CheckIndex(r2, j){
				cnt_orig++
			}
		}
		if cnt_orig > 1 {
			fmt.Printf("No\n")
			continue
		}
		if cnt_orig == 1 {
			fmt.Printf("Yes\n%s\n", string(r2))
			continue
		}
		target := "abacaba"
		answer := false
		for j := 0; j < len(r); j++{
			if !CheckIndex(r, j) {
				continue
			}
			for k := 0; k < 7; k++ {
				r2[j+k] = rune(target[k])
			}
			cnt_orig = 0
			for k := (j-10); k <= (j+10); k++{
				if CheckIndex(r2, k){
					cnt_orig += 1
				}
			}

			if cnt_orig == 1 {
				answer = true
				break
			} else {
				for k := 0; k < 7; k++ {
					r2[j+k] = r[j+k]
					if r2[j+k] == '?' {
						r2[j+k] = 'z'
					}
				}
			}

		}
		if answer {
			fmt.Printf("Yes\n%s\n", string(r2))
		} else {
			fmt.Printf("No\n")
		}
	}
}

package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

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

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

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

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

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

func CheckLocation(r []rune) bool {
	target := "abacaba"
	ok := true
	for k := 0; k < 7 && ok; k++ {
		if r[k] != rune(target[k]) && r[k] != '?' {
			ok = false
		}
	}
	if !ok {
		return false
	}
	return true
}

func CheckIndex(r []rune, pos int) bool {
	if pos < 0 || pos + 6 >= len(r) {
		return false
	}
	return CheckLocation(r[pos:(pos+7)])
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		fin.ReadInt()
		str := fin.ReadText()
		r := []rune(str)
		r2 := append([]rune(nil), r...)
		for j := 0; j < len(r2); j++{
			if r2[j] == '?' {
				r2[j] = 'z'
			}
		}

		cnt_orig := 0
		for j := 0; j < len(r2); j++{
			if CheckIndex(r2, j){
				cnt_orig++
			}
		}

		answer := false
		if cnt_orig > 1 {
			fmt.Printf("No\n")
			continue
		}
		target := "abacaba"
		for j := 0; j < len(r) && !answer; j++{
			if !CheckIndex(r, j) {
				continue
			}
			for k := 0; k < 7; k++ {
				r2[j+k] = rune(target[k])
			}
			cnt_orig = 0
			for k := 0; k < len(r); k++{
				if CheckIndex(r2, k){
					cnt_orig += 1
				}
			}

			if cnt_orig == 1 {
				answer = true
				break
			} else {
				for k := 0; k < 7; k++ {
					r2[j+k] = r[j+k]
					if r2[j+k] == '?' {
						r2[j+k] = 'z'
					}
				}
			}

		}
		if answer {
			fmt.Printf("Yes\n%s\n", string(r2))
		} else {
			fmt.Printf("No\n")
		}
	}
}

package main

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

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

	const a = "abacaba"
	var T, n int
	var s string
O:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
	o:
		for r := 7; r <= n; r++ {
			for l := r - 7; l < r; l++ {
				if s[l] != '?' && s[l] != a[l-r+7] {
					continue o
				}
			}
			t, f := s[:r-7]+a+s[r:], false
			for i := 7; i <= n; i++ {
				if t[i-7:i] == a {
					if f {
						continue o
					}
					f = true
				}
			}
			if f {
				Fprintln(out, "Yes")
				Fprintln(out, strings.ReplaceAll(t, "?", "d"))
				continue O
			}
		}
		Fprintln(out, "No")
	}
}

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

package main

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

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

	const a = "abacaba"
	check := func(s string) (f bool) {
		for i := range s {
			if strings.HasPrefix(s[i:], a) {
				if f {
					return false
				}
				f = true
			}
		}
		return
	}
	var t, n int
	var s string
O:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &s)
	o:
		for i := 7; i <= n; i++ {
			for j := i - 7; j < i; j++ {
				if s[j] != '?' && s[j] != a[j-i+7] {
					continue o
				}
			}
			if c := s[:i-7] + a + s[i:]; check(c) {
				Fprintln(out, "Yes")
				Fprintln(out, strings.ReplaceAll(c, "?", "d"))
				continue O
			}
		}
		Fprintln(out, "No")
	}
}

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

package main

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

func main() {

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

	var s string
	var t, n int

	src := "abacaba"

	fmt.Fscanf(in, "%d\n", &t)

	for t != 0 {

		t--

		fmt.Fscanf(in, "%d\n", &n)

		fmt.Fscanf(in, "%s\n", &s)

		l := true

		for i := 0; i < n-7+1; i++ {

			k := 0

			s1 := []rune(s)

			barlag := true

			for j := 0; j < 7; j++ {

				if s1[i+j] == rune(src[j]) || s1[i+j] == '?' {

					s1[i+j] = rune(src[j])

				} else {
					barlag = false
					break
				}

			}

			if !barlag {
				continue
			}

			s2 := string(s1)

			for j := 0; j < n-7+1; j++ {

				if s2[j:j+7] == src {

					k++

				}

			}

			if k == 1 {

				fmt.Fprintln(out, "Yes")

				s2 = strings.ReplaceAll(s2, "?", "z")

				fmt.Fprintln(out, s2)

				l = false

				break
			}

		}

		if l {

			fmt.Fprintln(out, "No")

		}

	}

	out.Flush()
}

package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

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

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

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

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

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

func CheckLocation(r []rune) bool {
	target := "abacaba"
	ok := true
	for k := 0; k < 7 && ok; k++ {
		if r[k] != rune(target[k]) && r[k] != '?' {
			ok = false
		}
	}
	if !ok {
		return false
	}
	return true
}

func CheckIndex(r []rune, pos int) bool {
	if pos < 0 || pos + 6 >= len(r) {
		return false
	}
	return CheckLocation(r[pos:(pos+7)])
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		fin.ReadInt()
		str := fin.ReadText()
		r := []rune(str)
		r2 := append([]rune(nil), r...)
		for j := 0; j < len(r2); j++{
			if r2[j] == '?' {
				r2[j] = 'z'
			}
		}

		cnt_orig := 0
		for j := 0; j < len(r2); j++{
			if CheckIndex(r2, j){
				cnt_orig++
			}
		}
		if cnt_orig > 1 {
			fmt.Printf("No\n")
			continue
		}
		if cnt_orig == 1 {
			fmt.Printf("Yes\n%s\n", string(r2))
			continue
		}
		target := "abacaba"
		answer := false
		for j := 0; j < len(r); j++{
			if !CheckIndex(r, j) {
				continue
			}
			for k := 0; k < 7; k++ {
				r2[j+k] = rune(target[k])
			}
			cnt_orig = 0
			for k := (j-10); k <= (j+10); k++{
				if CheckIndex(r2, k){
					cnt_orig += 1
				}
			}

			if cnt_orig == 1 {
				answer = true
				break
			} else {
				for k := 0; k < 7; k++ {
					r2[j+k] = r[k]
					if r2[j+k] == '?' {
						r2[j+k] = 'z'
					}
				}
			}

		}
		if answer {
			fmt.Printf("Yes\n%s\n", string(r2))
		} else {
			fmt.Printf("No\n")
		}
	}
}

package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

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

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

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

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

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

func CheckLocation(r []rune) bool {
	target := "abacaba"
	ok := true
	for k := 0; k < 7 && ok; k++ {
		if r[k] != rune(target[k]) && r[k] != '?' {
			ok = false
		}
	}
	if !ok {
		return false
	}
	return true
}

func CheckIndex(r []rune, pos int) bool {
	if pos < 0 || pos + 6 >= len(r) {
		return false
	}
	return CheckLocation(r[pos:(pos+7)])
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		fin.ReadInt()
		str := fin.ReadText()
		r := []rune(str)
		r2 := append([]rune(nil), r...)
		for j := 0; j < len(r2); j++{
			if r2[j] == '?' {
				r2[j] = 'z'
			}
		}

		cnt_orig := 0
		for j := 0; j < len(r2); j++{
			if CheckIndex(r2, j){
				cnt_orig++
			}
		}

		answer := false
		if cnt_orig > 1 {
			fmt.Printf("No\n")
			continue
		}
		target := "abacaba"
		for j := 0; j < len(r) && !answer; j++{
			if !CheckIndex(r, j) {
				continue
			}
			for k := 0; k < 7; k++ {
				r2[j+k] = rune(target[k])
			}
			cnt_orig = 0
			for k := (j-10); k <= (j+10); k++{
				if CheckIndex(r2, k){
					cnt_orig += 1
				}
			}

			if cnt_orig == 1 {
				answer = true
				break
			} else {
				for k := 0; k < 7; k++ {
					r2[j+k] = r[j+k]
					if r2[j+k] == '?' {
						r2[j+k] = 'z'
					}
				}
			}

		}
		if answer {
			fmt.Printf("Yes\n%s\n", string(r2))
		} else {
			fmt.Printf("No\n")
		}
	}
}

package main

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

func main() {

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

	var s string
	var t, n int

	src := "abacaba"

	fmt.Fscanf(in, "%d\n", &t)

	for t != 0 {

		t--

		fmt.Fscanf(in, "%d\n", &n)

		fmt.Fscanf(in, "%s\n", &s)

		l := true

		for i := 0; i < n-7+1; i++ {

			k := 0

			s1 := []rune(s)

			barlag := true

			for j := 0; j < 7; j++ {

				if s1[i+j] == rune(src[j]) || s1[i+j] == '?' {

					s1[i+j] = rune(src[j])

				} else {
					barlag = false
					break
				}

			}

			if !barlag {
				continue
			}

			s2 := string(s1)

			for j := 0; j < n-7+1; j++ {

				if s2[j:j+7] == src {

					k++

				}

			}

			if k == 1 {

				fmt.Fprintln(out, "Yes")

				s2 = strings.ReplaceAll(s2, "?", "z")

				fmt.Fprintln(out, s2)

				l = false

			}

		}

		if l {

			fmt.Fprintln(out, "No")

		}

	}

	out.Flush()
}


Chef Monocarp has just put $$$n$$$ dishes into an oven. He knows that the $$$i$$$-th dish has its optimal cooking time equal to $$$t_i$$$ minutes.At any positive integer minute $$$T$$$ Monocarp can put no more than one dish out of the oven. If the $$$i$$$-th dish is put out at some minute $$$T$$$, then its unpleasant value is $$$|T - t_i|$$$ — the absolute difference between $$$T$$$ and $$$t_i$$$. Once the dish is out of the oven, it can't go back in.Monocarp should put all the dishes out of the oven. What is the minimum total unpleasant value Monocarp can obtain?

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of testcases. Then $$$q$$$ testcases follow. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of dishes in the oven. The second line of the testcase contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le n$$$) — the optimal cooking time for each dish. The sum of $$$n$$$ over all $$$q$$$ testcases doesn't exceed $$$200$$$.

Print a single integer for each testcase — the minimum total unpleasant value Monocarp can obtain when he puts out all the dishes out of the oven. Remember that Monocarp can only put the dishes out at positive integer minutes and no more than one dish at any minute.

NoteIn the first example Monocarp can put out the dishes at minutes $$$3, 1, 5, 4, 6, 2$$$. That way the total unpleasant value will be $$$|4 - 3| + |2 - 1| + |4 - 5| + |4 - 4| + |6 - 5| + |2 - 2| = 4$$$.In the second example Monocarp can put out the dishes at minutes $$$4, 5, 6, 7, 8, 9, 10$$$.In the third example Monocarp can put out the dish at minute $$$1$$$.In the fourth example Monocarp can put out the dishes at minutes $$$5, 1, 2, 4, 3$$$.In the fifth example Monocarp can put out the dishes at minutes $$$1, 3, 4, 5$$$.

package main

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

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...) }

const inf = 100000

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

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

func solve() {
	var n int
	scanf("%d\n", &n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &v[i])
		} else {
			scanf("%d ", &v[i])
		}
	}
	sort.Ints(v)
	d := make([][]int, n + 1)
	for i := range d {
		d[i] = make([]int, 2 * n + 1)
		for j := 0; j < len(d[i]); j++ {
			d[i][j] = inf
		}
	}
	for j := 1; j <= n; j++ {
		d[0][j] = abs(j - v[0])
	}
	for i := 0; i + 1 < n; i++ {
		for j := 1; j + 1 <= 2 * n; j++ {
			//d[i][j]->
			d[i][j + 1] = min(d[i][j + 1], d[i][j])
			d[i + 1][j + 1] = min(d[i + 1][j + 1],
				d[i][j] + abs(j + 1 - v[i + 1]))
		}
	}
	mn := d[n - 1][1]
	for j := 1; j <= 2 * n; j++ {
		if d[n - 1][j] < mn {
			mn = d[n - 1][j]
		}
	}
	//fmt.Println(d)
	printf("%d\n", mn)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

import (
	"fmt"
	"sort"
)

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func min(T []int) int {
	r := -1
	for _, t := range T {
		if t != -1 {
			if r == -1 {
				r = t
			}
			if t < r {
				r = t
			}
		}
	}
	return r
}

func main() {
	// Write your solution here
	var q int
	fmt.Scanf("%d\n", &q)

	for ; q > 0; q-- {
		var n int
		fmt.Scanf("%d\n", &n)

		var t = make([]int, n)
		for i := range t {
			if i < len(t)-1 {
				fmt.Scanf("%d", &t[i])
			} else {
				fmt.Scanf("%d\n", &t[i])
			}
		}
		sort.Ints(t)

		var T = make([][]int, n)
		for i := range T {
			T[i] = make([]int, 2*n+1)
			for j := range T[i] {
				T[i][j] = -1 // 把下标到 i 这几个菜（下标从0开始）取出，最后一个菜在 j 时刻取出(时刻从 1 开始)
			}
		}

		// init
		for time := 0 + 1; time <= t[0]+0; time++ {
			T[0][time] = abs(time - t[0])
		}

		// update
		for k := 1; k < n; k++ {
			for time := k + 1; time <= t[k]+k; time++ { // 到第k个元素为止（下标从0开始），共k+1个元素，t[k]>=1, t[k]+k>=k+1, 无需更新到 2n
				T[k][time] = min(T[k-1][:time]) + abs(time-t[k])
			}
		}

		fmt.Println(min(T[n-1]))
	}
}

package main

import (
	"fmt"
	"sort"
)

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func min(T []int) int {
	r := -1
	for _, t := range T {
		if t != -1 {
			if r == -1 {
				r = t
			}
			if t < r {
				r = t
			}
		}
	}
	return r
}

func main() {
	// Write your solution here
	var q int
	fmt.Scanf("%d\n", &q)

	for ; q > 0; q-- {
		var n int
		fmt.Scanf("%d\n", &n)

		var t = make([]int, n)
		for i := range t {
			if i < len(t)-1 {
				fmt.Scanf("%d", &t[i])
			} else {
				fmt.Scanf("%d\n", &t[i])
			}
		}
		sort.Ints(t)

		var T = make([][]int, n)
		for i := range T {
			T[i] = make([]int, 2*n+1)
			for j := range T[i] {
				T[i][j] = -1 // 把下标到 i 这几个菜（下标从0开始）取出，最后一个菜在 j 时刻取出(时刻从 1 开始)
			}
		}

		// init
		for time := 0 + 1; time <= 2*n; time++ {
			T[0][time] = abs(time - t[0])
		}

		// update
		for k := 1; k < n; k++ {
			for time := k + 1; time <= 2*n; time++ {
				T[k][time] = min(T[k-1][:time]) + abs(time-t[k])
			}
		}

		fmt.Println(min(T[n-1]))
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1437C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 1e9
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	var T, n, t int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		type neighbor struct{ to, rid, cap, cost int }
		g := make([][]neighbor, 3*n+2)
		addEdge := func(from, to, cap, cost int) {
			g[from] = append(g[from], neighbor{to, len(g[to]), cap, cost})
			g[to] = append(g[to], neighbor{from, len(g[from]) - 1, 0, -cost})
		}
		st, end := 0, 3*n+1
		for i := 1; i <= n; i++ {
			addEdge(st, i, 1, 0)
		}
		for i := 1; i <= n; i++ {
			Fscan(in, &t)
			for j := 1; j <= 2*n; j++ {
				addEdge(i, n+j, inf, abs(t-j))
			}
		}
		for i := n + 1; i <= 3*n; i++ {
			addEdge(i, end, 1, 0)
		}

		n = 3*n + 2
		dist := make([]int, n)
		type pair struct{ v, i int }
		fa := make([]pair, n)
		spfa := func() bool {
			for i := range dist {
				dist[i] = inf
			}
			dist[st] = 0
			inQ := make([]bool, n)
			inQ[st] = true
			q := []int{st}
			for len(q) > 0 {
				v := q[0]
				q = q[1:]
				inQ[v] = false
				for i, e := range g[v] {
					if e.cap == 0 {
						continue
					}
					w := e.to
					if newD := dist[v] + e.cost; newD < dist[w] {
						dist[w] = newD
						fa[w] = pair{v, i}
						if !inQ[w] {
							q = append(q, w)
							inQ[w] = true
						}
					}
				}
			}
			return dist[end] < inf
		}
		minCost := 0
		for spfa() {
			for v := end; v != st; {
				p := fa[v]
				e := &g[p.v][p.i]
				e.cap--
				g[v][e.rid].cap++
				v = p.v
			}
			minCost += dist[end]
		}
		Fprintln(out, minCost)
	}
}

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

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
type vdPair struct{ v, dis int }
type vdHeap []vdPair

func (h vdHeap) Len() int              { return len(h) }
func (h vdHeap) Less(i, j int) bool    { return h[i].dis < h[j].dis }
func (h vdHeap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *vdHeap) Push(v interface{})   { *h = append(*h, v.(vdPair)) }
func (h *vdHeap) Pop() (v interface{}) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; return }
func (h *vdHeap) push(v vdPair)        { heap.Push(h, v) }
func (h *vdHeap) pop() vdPair          { return heap.Pop(h).(vdPair) }

func CF1437C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 1e9
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	var T, n, t int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		type neighbor struct{ to, rid, cap, cost int }
		g := make([][]neighbor, 3*n+2)
		addEdge := func(from, to, cap, cost int) {
			g[from] = append(g[from], neighbor{to, len(g[to]), cap, cost})
			g[to] = append(g[to], neighbor{from, len(g[from]) - 1, 0, -cost})
		}
		st, end := 0, 3*n+1
		for i := 1; i <= n; i++ {
			addEdge(st, i, 1, 0)
		}
		for i := 1; i <= n; i++ {
			Fscan(in, &t)
			for j := 1; j <= 2*n; j++ {
				addEdge(i, n+j, inf, abs(t-j))
			}
		}
		for i := n + 1; i <= 3*n; i++ {
			addEdge(i, end, 1, 0)
		}

		n = 3*n + 2
		const inf int = 1e9
		h := make([]int, n)
		dist := make([]int, n)
		type pair struct{ v, i int }
		fa := make([]pair, n)
		dijkstra := func() bool {
			for i := range dist {
				dist[i] = inf
			}
			dist[st] = 0
			q := vdHeap{{st, 0}}
			for len(q) > 0 {
				p := q.pop()
				v := p.v
				if dist[v] < p.dis {
					continue
				}
				for i, e := range g[v] {
					if e.cap == 0 {
						continue
					}
					w := e.to
					if newD := dist[v] + int(e.cost) + h[v] - h[w]; newD < dist[w] {
						dist[w] = newD
						fa[w] = pair{v, i}
						q.push(vdPair{w, newD})
					}
				}
			}
			return dist[end] < inf
		}
		minCost := 0
		for dijkstra() {
			for i, d := range dist {
				h[i] += d
			}
			for v := end; v != st; {
				p := fa[v]
				e := &g[p.v][p.i]
				e.cap--
				g[v][e.rid].cap++
				v = p.v
			}
			minCost += h[end]
		}
		Fprintln(out, minCost)
	}
}

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

package main
import (
	"fmt"
	"math"
	"sort"
)
func abs (a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}
func min(a int, b int) int {
	if a <= b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Scan(&q)
	for t := 0; t < q; t++ {
		n := 0
		fmt.Scan(&n)
		a := make([]int, n)
		for i := range a {
			fmt.Scan(&a[i])
		}
		sort.Ints(a)
		dp := make([][]int, n)
		for i := range dp {
			dp[i] = make([]int, 2 * n + 1)
		}
		for j := 1; j <= 2 * n; j++ {
			dp[0][j] = abs(a[0] - j)
		}
		for i := 1; i < n; i++ {
			for j := 1; j <= 2 * n; j++ {
				dp[i][j] = math.MaxInt32
			}
		}
		for i := 1; i < n; i++ {
			for j := i + 1; j <= 2 * n; j++ {
				for k := i; k < j; k++ {
					dp[i][j] = min(dp[i][j], dp[i - 1][k] + abs(a[i] - j))
				}
			}
		}
		res := math.MaxInt32
		for j := 1; j <= 2 * n; j++ {
			if res > dp[n - 1][j] {
				res = dp[n - 1][j]
			}
		}
		fmt.Println(res)
	}
}

// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools

package main

import (
	"fmt"
)

func main() {
	// Write your solution here
	var q int
	fmt.Scanf("%d\n", &q)

	for ; q > 0; q-- {
		var n int
		fmt.Scanf("%d\n", &n)

		var t = make([]int, n)
		var T = make([]int, 2*n+1)
		for i := range t {
			fmt.Scanf("%d", &t[i])
			T[t[i]] += 1
		}

		ans := 0
		for tn := range T {
			if T[tn] > 1 {
				p := T[tn] - 1
				for d := 1; d < n; d++ {
					if tn-d > 0 && T[tn-d] == 0 && p > 0 {
						T[tn-d] = 1
						p -= 1
						ans += d
					}
					if tn+d <= 2*n && T[tn+d] == 0 && p > 0 {
						T[tn+d] = 1
						p -= 1
						ans += d
					}
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"sort"
)

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func min(T []int) int {
	r := -1
	for _, t := range T {
		if t != -1 {
			if r == -1 {
				r = t
			}
			if t < r {
				r = t
			}
		}
	}
	return r
}

func main() {
	// Write your solution here
	var q int
	fmt.Scanf("%d\n", &q)

	for ; q > 0; q-- {
		var n int
		fmt.Scanf("%d\n", &n)

		var t = make([]int, n)
		for i := range t {
			if i < len(t)-1 {
				fmt.Scanf("%d", &t[i])
			} else {
				fmt.Scanf("%d\n", &t[i])
			}
		}
		sort.Ints(t)

		var T = make([][]int, n)
		for i := range T {
			T[i] = make([]int, n+n/2+1)
			for j := range T[i] {
				T[i][j] = -1 // 把下标到 i 这几个菜（下标从0开始）取出，最后一个菜在 j 时刻取出(时刻从 1 开始)
			}
		}

		// init
		for time := 0 + 1; time <= t[0]+t[0]/2; time++ {
			T[0][time] = abs(time - t[0])
		}

		// update
		for k := 1; k < n; k++ {
			for time := k + 1; time <= t[k]+t[k]/2; time++ {
				T[k][time] = min(T[k-1][:time]) + abs(time-t[k])
			}
		}

		fmt.Println(min(T[n-1]))
	}
}


Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai + 1, ..., aj is equal to k.

The first line of the input contains integers n, m and k (1 ≤ n, m ≤ 100 000, 0 ≤ k ≤ 1 000 000) — the length of the array, the number of queries and Bob's favorite number respectively. The second line contains n integers ai (0 ≤ ai ≤ 1 000 000) — Bob's array. Then m lines follow. The i-th line contains integers li and ri (1 ≤ li ≤ ri ≤ n) — the parameters of the i-th query.

Print m lines, answer the queries in the order they appear in the input.

NoteIn the first sample the suitable pairs of i and j for the first query are: (1, 2), (1, 4), (1, 5), (2, 3), (3, 6), (5, 6), (6, 6). Not a single of these pairs is suitable for the second query.In the second sample xor equals 1 for all subarrays of an odd length.

package main

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

const BLOCK_SIZE int = 316

type query struct {
    Left int
    Right int
    Number int
}

func (q query) Less(other query) bool {
    return q.Right < other.Right
}

type queryArray []query
type queryArrayArray []queryArray

func (q queryArray) Len() int {
    return len(q)
}

func (q queryArray) Swap(i, j int) {
    q[i], q[j] = q[j], q[i]
}

func (q queryArray) Less(i, j int) bool {
    if q[i].Less(q[j]) {
        return true
    } else {
        return false
    }
}

var cnt [1<<20]int
var result int64 = 0
var favourite int

func vadd(v int) {
    result += int64(cnt[v ^ favourite])
    cnt[v] += 1
}

func vdel(v int) {
    cnt[v] -= 1
    result -= int64(cnt[v ^ favourite])
}

func main() {
    var n, m int
    stin := bufio.NewReader(os.Stdin)
    ns,_ := stin.ReadBytes('\n')
    nss := strings.Fields(string(bytes.Trim(ns,"\n\r ")))
    n,_ = strconv.Atoi(nss[0])
    m,_ = strconv.Atoi(nss[1])
    favourite,_ = strconv.Atoi(nss[2])

    var a []int = make([]int, n)
    var tmp []byte
    for i := 0; i < n-1; i++ {
        tmp,_ = stin.ReadBytes(' ')
        a[i],_ = strconv.Atoi(string(bytes.Trim(tmp," ")))
    }
    tmp,_ = stin.ReadBytes('\n')
    a[n-1],_ = strconv.Atoi(string(bytes.Trim(tmp,"\n\r")))
    //fmt.Printf("%v %v %v\n", n, m, favourite)
    //fmt.Printf("%v\n", a)

    var pref []int = make([]int, n+1)
    pref[0] = 0
    for i := 1; i <= n; i++ {
        pref[i] = pref[i - 1] ^ a[i - 1]
    }

    var blocks queryArrayArray = make(queryArrayArray, n / BLOCK_SIZE + 2)

    for i := 0; i < m; i++ {
        ns,_ = stin.ReadBytes('\n')
        nss  = strings.Fields(string(bytes.Trim(ns,"\n\r ")))
        left,_ := strconv.Atoi(nss[0])
        right,_ := strconv.Atoi(nss[1])
        left -= 1
        right += 1
        blocks[left / BLOCK_SIZE] = append(blocks[left / BLOCK_SIZE], query{Left:left, Right:right, Number:i})
    }

    //fmt.Printf("%v\n", blocks)
    for i := 0; i < len(blocks); i++ {
        sort.Sort(blocks[i])
    }
    //fmt.Printf("%v\n", blocks)
    var answer []int64 = make([]int64, m)
    for i := 0; i < len(blocks); i++ {
        left := i * BLOCK_SIZE
        right := i * BLOCK_SIZE
        for q := 0; q < len(blocks[i]); q++ {
            for right < blocks[i][q].Right {
                vadd(pref[right])
                right += 1
            }
            for left < blocks[i][q].Left {
                vdel(pref[left])
                left += 1
            }
            for left > blocks[i][q].Left {
                left -= 1
                vadd(pref[left])
            }
            answer[blocks[i][q].Number] = result
        }
        for j := left; j < right; j++ {
            vdel(pref[j])
        }
    }

    for i := 0; i < len(answer); i++ {
        fmt.Printf("%v\n", answer[i])
    }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol617E(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, q, k := read(), read(), read()
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		sum[i+1] = sum[i] ^ read()
	}
	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		l, r := read(), read()
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		if qi.blockIdx != qj.blockIdx {
			return qi.blockIdx < qj.blockIdx
		}
		if qi.blockIdx&1 == 0 {
			return qi.r < qj.r
		}
		return qi.r > qj.r
	})

	l, r, _ans := 1, 1, int64(0)
	cnt := make([]int, 1<<20)
	cnt[0] = 1
	update := func(idx, delta int) {
		s := sum[idx]
		tar := k ^ s
		if delta == 1 {
			_ans += int64(cnt[tar])
			cnt[s]++
		} else {
			cnt[s]--
			_ans -= int64(cnt[tar])
		}
	}
	ans := make([]int64, q)
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q, k, v int
	Fscan(in, &n, &q, &k)
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		sum[i+1] = sum[i] ^ v
	}

	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		var l, r int
		Fscan(in, &l, &r)
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		if qi.blockIdx != qj.blockIdx {
			return qi.blockIdx < qj.blockIdx
		}
		if qi.blockIdx&1 == 0 {
			return qi.r < qj.r
		}
		return qi.r > qj.r
	})

	l, r, _ans := 1, 1, int64(0)
	cnt := make([]int64, 1<<20)
	cnt[0] = 1
	update := func(idx, delta int) {
		s := sum[idx]
		tar := k ^ s
		if delta == 1 {
			_ans += cnt[tar]
			cnt[s]++
		} else {
			cnt[s]--
			_ans -= cnt[tar]
		}
	}
	ans := make([]int64, q)
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol617E(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, q, k := read(), read(), read()
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		sum[i+1] = sum[i] ^ read()
	}
	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		l, r := read(), read()
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		return qi.blockIdx < qj.blockIdx || qi.blockIdx == qj.blockIdx && qi.r < qj.r
	})

	l, r, _ans := 1, 1, int64(0)
	cnt := make([]int64, 1<<20)
	cnt[0] = 1
	update := func(idx, delta int) {
		s := sum[idx]
		tar := k ^ s
		if delta == 1 {
			_ans += cnt[tar]
			cnt[s]++
		} else {
			cnt[s]--
			_ans -= cnt[tar]
		}
	}
	ans := make([]int64, q)
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol617E(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, q, k := read(), read(), read()
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		sum[i+1] = sum[i] ^ read()
	}
	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		l, r := read(), read()
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		return qi.blockIdx < qj.blockIdx || qi.blockIdx == qj.blockIdx && qi.r < qj.r
	})

	l, r, _ans := 1, 1, int64(0)
	cnt := make([]int64, 1<<20)
	cnt[0] = 1
	add := func(idx int) {
		s := sum[idx]
		_ans += cnt[k^s]
		cnt[s]++
	}
	del := func(idx int) {
		s := sum[idx]
		cnt[s]--
		_ans -= cnt[k^s]
	}
	ans := make([]int64, q)
	for _, q := range qs {
		for ; r < q.r; r++ {
			add(r)
		}
		for ; l < q.l; l++ {
			del(l - 1)
		}
		for l > q.l {
			l--
			add(l - 1)
		}
		for r > q.r {
			r--
			del(r)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q, k, v int
	Fscan(in, &n, &q, &k)
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		sum[i+1] = sum[i] ^ v
	}

	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		var l, r int
		Fscan(in, &l, &r)
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		if qi.blockIdx != qj.blockIdx {
			return qi.blockIdx < qj.blockIdx
		}
		if qi.blockIdx&1 == 0 {
			return qi.r < qj.r
		}
		return qi.r > qj.r
	})

	l, r, _ans := 1, 1, int64(0)
	cnt := make([]int, 1<<20)
	cnt[0] = 1
	update := func(idx, delta int) {
		s := sum[idx]
		tar := k ^ s
		if delta == 1 {
			_ans += int64(cnt[tar])
			cnt[s]++
		} else {
			cnt[s]--
			_ans -= int64(cnt[tar])
		}
	}
	ans := make([]int64, q)
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q, k, v int
	Fscan(in, &n, &q, &k)
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		sum[i+1] = sum[i] ^ v
	}

	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		var l, r int
		Fscan(in, &l, &r)
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		return qi.blockIdx < qj.blockIdx || qi.blockIdx == qj.blockIdx && qi.r < qj.r
	})
	ans := make([]int64, q)

	l, r, _ans := 1, 1, int64(0)
	cnt := make([]int64, 1<<20)
	cnt[0] = 1
	update := func(idx, delta int) {
		tar := k ^ sum[idx]
		if delta == 1 {
			_ans += cnt[tar]
			cnt[sum[idx]]++
		} else {
			cnt[sum[idx]]--
			_ans -= cnt[tar]
		}
	}
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q, k int
	Fscan(in, &n, &q, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sum := make([]int, n+1)
	for i, v := range a {
		sum[i+1] = sum[i] ^ v
	}

	ans := make([]int64, q)
	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		var l, r int
		Fscan(in, &l, &r)
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		return qi.blockIdx < qj.blockIdx || qi.blockIdx == qj.blockIdx && qi.r < qj.r
	})

	l, r, _ans := 1, 1, int64(0)
	cnt := make([]int64, 1<<20)
	if k != 0 {
		cnt[0] = 1
	}
	update := func(idx, delta int) {
		tar := k ^ sum[idx]
		if delta == 1 {
			cnt[sum[idx]]++
			_ans += cnt[tar]
		} else {
			_ans -= cnt[tar]
			cnt[sum[idx]]--
		}
	}
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q, k int
	Fscan(in, &n, &q, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sum := make([]int, n+1)
	for i, v := range a {
		sum[i+1] = sum[i] ^ v
	}

	ans := make([]int, q)
	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		var l, r int
		Fscan(in, &l, &r)
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		return qi.blockIdx < qj.blockIdx || qi.blockIdx == qj.blockIdx && qi.r < qj.r
	})

	l, r, _ans := 1, 1, 0
	cnt := make([]int, 1<<20)
	if k != 0 {
		cnt[0] = 1
	}
	update := func(idx, delta int) {
		tar := k ^ sum[idx]
		if delta == 1 {
			cnt[sum[idx]]++
			_ans += cnt[tar]
		} else {
			_ans -= cnt[tar]
			cnt[sum[idx]]--
		}
	}
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q, k int
	Fscan(in, &n, &q, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sum := make([]int, n+1)
	for i, v := range a {
		sum[i+1] = sum[i] ^ v
	}

	ans := make([]int, q)
	type query struct {
		blockIdx  int
		l, r, idx int
	}
	qs := make([]query, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		var l, r int
		Fscan(in, &l, &r)
		qs[i] = query{l / blockSize, l, r + 1, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		qi, qj := qs[i], qs[j]
		return qi.blockIdx < qj.blockIdx || qi.blockIdx == qj.blockIdx && qi.r < qj.r
	})

	l, r, _ans := 1, 1, 0
	cnt := make([]int, 1<<20)
	cnt[0] = 1
	update := func(idx, delta int) {
		tar := k ^ sum[idx]
		if delta == 1 {
			cnt[sum[idx]]++
			_ans += cnt[tar]
		} else {
			_ans -= cnt[tar]
			cnt[sum[idx]]--
		}
	}
	for _, q := range qs {
		for ; r < q.r; r++ {
			update(r, 1)
		}
		for ; l < q.l; l++ {
			update(l-1, -1)
		}
		for l > q.l {
			l--
			update(l-1, 1)
		}
		for r > q.r {
			r--
			update(r, -1)
		}
		ans[q.idx] = _ans
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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