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


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"
	"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], " ")
			}
			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
	}
}


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

// 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 (
    "fmt"
)

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

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 := 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 (
  "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)
	}
}

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


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"
	"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"
	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"
	"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++
			}
		}
		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()
}


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

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

// 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]))
	}
}


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 (
         "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 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)
}


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--
		in := readNNums(reader, 7)
		res := solve(in[0], in[1], in[2], in[3], in[4], in[5], in[6])
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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
	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 MOD = 1000000007

func pow(a, b int) int {
	A := int64(a)
	R := int64(1)
	for b > 0 {
		if b&1 == 1 {
			R = (R * A) % MOD
		}
		A = (A * A) % MOD
		b >>= 1
	}
	return int(R)
}

func inverse(x int) int {
	return pow(x, MOD-2)
}

func add(a, b int) int {
	a += b
	if a >= MOD {
		a -= MOD
	}
	return a
}

func sub(a, b int) int {
	return add(a, MOD-b)
}

func mul(a, b int) int {
	A := int64(a) * int64(b)
	A %= MOD
	return int(A)
}

func solve(n int, m int, rb int, cb int, rd int, cd int, p int) int {
	p = sub(1, mul(p, inverse(100)))

	dr, dc := -1, -1
	var u int
	v := 1
	for i := 0; i < 4*(n-1)*(m-1); i++ {
		if !(rb+dr >= 1 && rb+dr <= n) {
			dr *= -1
		}
		if !(cb+dc >= 1 && cb+dc <= m) {
			dc *= -1
		}
		rb += dr
		cb += dc
		u++
		if rb == rd || cb == cd {
			u = mul(u, p)
			v = mul(v, p)
		}
	}
	ans := mul(u, inverse(sub(1, v)))
	return ans
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 7
	pow := func(x, n int64) int64 {
		x %= mod
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int64) int64 { return pow(a, mod-2) }
	div := func(a, b int64) int64 { return a % mod * inv(b%mod) % mod }

	solve := func(Case int) {
		var n, m, x, y, tx, ty int
		var P int64
		Fscan(in, &n, &m, &x, &y, &tx, &ty, &P)
		T := 2 * (n - 1) * (m - 1) / gcd(n-1, m-1)

		p := div(P, 100)
		np := div(100-P, 100)

		dx, dy := 1, 1
		//x0, y0 := x, y

		if x+dx < 1 || x+dx > n {
			dx = -dx
		}
		if y+dy < 1 || y+dy > m {
			dy = -dy
		}
		//dx0, dy0 := dx, dy

		part1 := int64(0)
		part2 := int64(0)
		powNp := int64(1)
		k := int64(0)
		t := int64(0)
		for {
			if x == tx || y == ty {
				part1 = (part1 + t*powNp) % mod
				part2 = (part2 + powNp) % mod
				powNp = powNp * np % mod
				k++
			}
			t++
			x += dx
			y += dy
			if x+dx < 1 || x+dx > n {
				dx = -dx
			}
			if y+dy < 1 || y+dy > m {
				dy = -dy
			}
			if int(t)==T  {
				break
			}
			//Println(t, x,y,dx,dy,"#", x0,y0,dx0,dy0)
		}
		//Println()
		part2 = part2 * t % mod

		sq := div(1, 1+mod-powNp)
		part1 = part1 * sq % mod

		sq2 := div(powNp, (1+mod-powNp)*(1+mod-powNp)%mod)
		part2 = part2 * sq2 % mod

		ans := (part1 + part2) % mod
		ans = ans * p % mod
		Fprintln(out, ans)
	}

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

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

}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 7
	pow := func(x, n int64) int64 {
		x %= mod
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int64) int64 { return pow(a, mod-2) }
	div := func(a, b int64) int64 { return a % mod * inv(b) % mod }

	solve := func(Case int) {
		var n, m, x, y, tx, ty int
		var P int64
		Fscan(in, &n, &m, &x, &y, &tx, &ty, &P)
		p := div(P, 100)
		np := div(100-P, 100)

		dx, dy := 1, 1
		x0, y0 := x, y

		part1 := int64(0)
		part2 := int64(0)
		powNp := int64(1)
		k := int64(0)
		t := int64(0)
		for ; ; t++ {
			if x == tx || y == ty {
				part1 = (part1 + t*powNp) % mod
				part2 = (part2 + powNp) % mod
				powNp = powNp * np % mod
				k++
			}

			if x+dx < 1 || x+dx > n {
				dx = -dx
			}
			if y+dy < 1 || y+dy > m {
				dy = -dy
			}
			x += dx
			y += dy
			if x == x0 && y == y0 {
				t++
				break
			}
		}
		part2 = part2 * t % mod

		sq := div(1, 1+mod-powNp)
		part1 = part1 * sq % mod

		sq2 := div(powNp, (1+mod-powNp)*(1+mod-powNp)%mod)
		part2 = part2 * sq2 % mod

		ans := (part1 + part2) % mod
		ans = ans * p % mod
		Fprintln(out, ans)
	}

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

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

}

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


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, _ := in.ReadBytes('\n')
	r := uint64(0)
	if n[0]%4 == 0 {
		r++
	}
	for i := 1; i < len(n) && n[i] != '\r'; i++ {
		if n[i]%4 == 0 {
			r++
		}
		s := (n[i-1]-'0')*10 + (n[i] - '0')
		if s%4 == 0 {
			r += uint64(i)
		}
	}
	out.WriteString(strconv.FormatUint(r, 10) + "\n")
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	reader := bufio.NewReader(os.Stdin)

	s, _ := reader.ReadString('\n')
	s = strings.TrimSpace(s)
	var ret int64

	if s[0] == '0' || s[0] == '4' || s[0] == '8' {
		ret++
	}

	for i := 1; i < len(s); i++ {
		// println(s[i-1 : i+1])
		m, _ := strconv.Atoi(s[i-1 : i+1])
		if m%4 == 0 {
			ret += int64(i)
		}

		if (s[i]-'0')%4 == 0 {
			ret++
		}
	}

	println(ret)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

//N _
const (
	N = 1e6 + 5
)

func inputter(inputReader *bufio.Reader,strs chan *string){
	for {
		input , _ := inputReader.ReadString('\n')
		input = strings.TrimSpace(input)
		if len(input) > 0 {
			inputs := strings.Split(input, " ")
			for i := range inputs{
				strs <- &inputs[i]
			}
		}
	}
}

func main(){
	rs := bufio.NewReader(os.Stdin)
	ws := bufio.NewWriter(os.Stdout)

	strs := make(chan *string, 100)

	go inputter(rs, strs)

	str := <-strs
	i := len(*str)-1
	last := (*str)[i]

	tot := int64(0)

	if (last - '0') % 4 == 0 {
		tot++
	}

	ctr := int64(0)

	for i := len(*str)-2; i >= 0; i-- {
		ths := (*str)[i] - '0'
		x := ths * 10 + last
		if x % 4 == 0{
			ctr++
		}
		tot += ctr
		last = ths
		if last % 4 == 0 {
			tot++
		}
	}

	ws.WriteString(fmt.Sprint(tot))

	ws.Flush()
}

package main

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

func main() {
	fsc := NewFastScanner()
	S := fsc.Next()
	N := len(S)
	var result int64
	result = 0
	for i := 0; i < N; i++ {
		var res int
		res, _ = strconv.Atoi(S[i : i+1])
		if res%4 == 0 {
			result++
		}
		if i+1 < N {
			res, _ = strconv.Atoi(S[i : i+2])
			if res%4 == 0 {
				result += int64(i + 1)
			}
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	s := reader.NextString()
	res := int64(0)
	for i := range s {
		if (s[i] - '0') % 4 == 0 {
			res++
		}
		if i > 0 {
			if (((s[i-1] - '0') * 10) + (s[i] - '0')) % 4 == 0 {
				res += int64(i)
			}
		}
	}
	writer.Printf("%d\n", res)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, _ := in.ReadBytes('\n')
	r := uint64(0)
	if n[0]%4 == 0 {
		r++
	}
	for i := 1; i < len(n); i++ {
		if n[i]%4 == 0 {
			r++
		}
		s := (n[i-1]-'0')*10 + (n[i] - '0')
		if s%4 == 0 {
			r += uint64(i)
		}
	}
	out.WriteString(strconv.FormatUint(r, 10) + "\n")
}