You have a permutation: an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of distinct integers from $$$1$$$ to $$$n$$$. The length of the permutation $$$n$$$ is odd.Consider the following algorithm of sorting the permutation in increasing order.A helper procedure of the algorithm, $$$f(i)$$$, takes a single argument $$$i$$$ ($$$1 \le i \le n-1$$$) and does the following. If $$$a_i > a_{i+1}$$$, the values of $$$a_i$$$ and $$$a_{i+1}$$$ are exchanged. Otherwise, the permutation doesn't change.The algorithm consists of iterations, numbered with consecutive integers starting with $$$1$$$. On the $$$i$$$-th iteration, the algorithm does the following:   if $$$i$$$ is odd, call $$$f(1), f(3), \ldots, f(n - 2)$$$;  if $$$i$$$ is even, call $$$f(2), f(4), \ldots, f(n - 1)$$$. It can be proven that after a finite number of iterations the permutation will be sorted in increasing order.After how many iterations will this happen for the first time?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 999$$$; $$$n$$$ is odd) — the length of the permutation. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the permutation itself.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$999$$$.

For each test case print the number of iterations after which the permutation will become sorted in increasing order for the first time. If the given permutation is already sorted, print $$$0$$$.

NoteIn the first test case, the permutation will be changing as follows:   after the $$$1$$$-st iteration: $$$[2, 3, 1]$$$;  after the $$$2$$$-nd iteration: $$$[2, 1, 3]$$$;  after the $$$3$$$-rd iteration: $$$[1, 2, 3]$$$. In the second test case, the permutation will be changing as follows:   after the $$$1$$$-st iteration: $$$[4, 5, 1, 7, 2, 3, 6]$$$;  after the $$$2$$$-nd iteration: $$$[4, 1, 5, 2, 7, 3, 6]$$$;  after the $$$3$$$-rd iteration: $$$[1, 4, 2, 5, 3, 7, 6]$$$;  after the $$$4$$$-th iteration: $$$[1, 2, 4, 3, 5, 6, 7]$$$;  after the $$$5$$$-th iteration: $$$[1, 2, 3, 4, 5, 6, 7]$$$. In the third test case, the permutation is already sorted and the answer is $$$0$$$.

package main

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

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

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

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

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

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

/**
Run solve the problem CF1561A
Date: 11/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1561/A
Problem: CF1561A
**/
func (in *CF1561A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

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

		order := true
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i] != i+1 {
				order = false
			}
		}

		ite := 0

		for {
			ws := true
			for i:= 0;i<n;i++{
				if arr[i] != i+1{
					ws = false
				}
			}
			for i := ite; i < n-1; i += 2 {

				if arr[i] > arr[i+1] {
					arr[i], arr[i+1] = arr[i+1], arr[i]

				}
			}
			if ite == 0 {
				ite = 1
			} else {
				ite = 0
			}

			sol++
			if ws{
				break
			}

		}

		if order {
			fmt.Println(0)
		} else {
			fmt.Println(sol-1)
		}

	}
}

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

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

package main

import(
	"fmt"
)

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

	for t:=0; t<testcase; t++{
		var n int
		fmt.Scanf("%d\n", &n)

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

		cnt := 0
		for i:=0; i<n; i++{
			flg := false
			for index, val := range a{
				if index+1 != val{
					flg = true
					cnt++
					break
				}
			}

			if !flg{
				break
			}

			for j:=i%2; j<n-1; j+= 2{
				if a[j] > a[j+1]{
					a[j], a[j+1] = a[j+1], a[j]
				}
			}
		}
		fmt.Printf("%d\n", cnt)
	}
}

package main

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

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

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

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

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

		var t int
		k := 1
		for !sort.IntsAreSorted(arr) {
			var i int
			if k%2 != 0 {
				i = 1
			} else {
				i = 2
			}

			for ; i < n; i += 2 {
				if arr[i-1] > arr[i] {
					arr[i], arr[i-1] = arr[i-1], arr[i]
				}
			}

			t++
			k++
		}

		fmt.Fprintln(out, t)
	}
}

package main

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

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

	for i := 0; i < tc; i++ {
        n := readInt(in)
        a := readArrInt(in)
        i := 1
        for !isSorted(a) {
            if i % 2 == 1 {
                for j := 0; j < n-2; j += 2 {
                    if a[j] > a[j+1] {
                        a[j], a[j+1] = a[j+1], a[j]
                    }
                }
            } else {
                for j := 1; j < n-1; j += 2 {
                    if a[j] > a[j+1] {
                        a[j], a[j+1] = a[j+1], a[j]
                    }
                }
            }
            i++
        }
        fmt.Println(i-1)
	}
}

//Yeap this is faster
func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

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

func isSorted(a []int) bool {
    for i := 0; i < len(a)-1; i++ {
        if a[i] > a[i+1] {
            return false
        }
    }
    return true
}

package main

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

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

func main() {
	defer out.flush()

	tests()
	// solve()
}

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

	a := make([]int, n)
	for i := range a {
		a[i] = in.nextInt()
	}

	cnt := 0
	for i := 0; ; i++ {
		ok := false
		if i%2 == 0 {
			for j := 0; j < n-1; j += 2 {
				if a[j] > a[j+1] {
					a[j], a[j+1] = a[j+1], a[j]
					ok = true
				}
			}
		} else {
			for j := 1; j < n-1; j += 2 {
				if a[j] > a[j+1] {
					a[j], a[j+1] = a[j+1], a[j]
					ok = true
				}
			}
		}
		if !ok && cnt == 0 {
			cnt++
		} else if !ok && cnt == 1 {
			out.println(i - 1)
			return
		} else if ok && cnt == 1 {
			cnt--
		}
	}
}

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

/* --- I/O --- */
type In struct {
	scanner *bufio.Scanner
}

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

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

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

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

type Out struct {
	writer *bufio.Writer
}

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

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

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

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

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

package main

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

var (
	in = bufio.NewReader(os.Stdin)
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func solve() {
	var ans = 0
	var currentInteration = 1
	var n int
	fmt.Fscan(in, &n)
	var arr = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	for {
		if sort.IntsAreSorted(arr) {
			fmt.Println(ans)
			return
		}
		if currentInteration%2 != 0 {
			for j := 0; j < len(arr)-2; j += 2 {
				do(j, arr)
			}

		} else {
			for j := 1; j < len(arr)-1; j+=2 {
				do(j, arr)
			}
		}
		currentInteration++
		ans++
	}
}

func do(i int, arr []int) {
	if i+1 < len(arr) && arr[i] > arr[i+1] {
		arr[i], arr[i+1] = arr[i+1], arr[i]
	}
}

//x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-TEMPLATE_STARTING-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-

type pair struct {
	a int64
	b int64
}

func sortPair(pairs []pair) {
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].a < pairs[j].a
	})
}
func min(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 0; i < t; i++ {
		n := scanInt()
		a := make([]int, n)
		for i := range a {
			a[i] = scanInt()
		}
		fmt.Fprintln(wr, solve(a))
	}
}

func solve(a []int) int {
	f := func(i int) {
		if a[i] > a[i+1] {
			a[i], a[i+1] = a[i+1], a[i]
		}
	}

	if sort.IntsAreSorted(a) {
		return 0
	}

	n := len(a)
	for i := 1; ; i++ {
		if i%2 == 1 {
			for j := 0; j <= n-3; j += 2 {
				f(j)
			}
		} else {
			for j := 1; j <= n-2; j += 2 {
				f(j)
			}
		}
		if sort.IntsAreSorted(a) {
			return i
		}
	}
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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

package main

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

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

func isSorted(a []int) bool {
	for i := range a {
		if a[i] != i+1 {
			return false
		}
	}
	return true
}

func solve(n int, a []int) int {
	var swap = 0
	for !isSorted(a) {
		for i := swap % 2; i+1 < n; i += 2 {
			if a[i] > a[i+1] {
				a[i], a[i+1] = a[i+1], a[i]
			}
		}
		swap++
	}
	return swap
}

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

package main

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

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

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

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

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

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

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

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

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		var OverAllDegrees int
		fmt.Fscan(input, &n)
		ARR := make([]int, n+1)
		Degree := make([]int, n+1)

		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARR[i])
			Degree[i] = MODULE(ARR[i], i)
			OverAllDegrees = OverAllDegrees + Degree[i]
		}

		var count int
		for j := 1; OverAllDegrees > 0; j++ {
			if j%2 == 1 {
				for m := 1; m <= n-2; {
					if ARR[m] > ARR[m+1] {
						OverAllDegrees = OverAllDegrees - Degree[m] - Degree[m+1]
						q := ARR[m]
						p := ARR[m+1]
						ARR[m] = p
						ARR[m+1] = q

						Degree[m] = MODULE(p, m)
						Degree[m+1] = MODULE(q, m+1)
						OverAllDegrees = OverAllDegrees + Degree[m] + Degree[m+1]

					}
					m = m + 2
				}
				count++

			}
			if j%2 == 0 {
				for m := 2; m <= n-1; {
					if ARR[m] > ARR[m+1] {
						OverAllDegrees = OverAllDegrees - Degree[m] - Degree[m+1]
						q := ARR[m]
						p := ARR[m+1]
						ARR[m] = p
						ARR[m+1] = q

						Degree[m] = MODULE(p, m)
						Degree[m+1] = MODULE(q, m+1)
						OverAllDegrees = OverAllDegrees + Degree[m] + Degree[m+1]

					}
					m = m + 2

				}
				count++

			}

			if OverAllDegrees == 0 {
				break
			}
		}
		fmt.Println(count)

	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		dd(a)
	}
}
func dd(a int) {
	arr := make([]int, a+1)
	for i := 1; i <= a; i++ {
		fmt.Scan(&arr[i])
	}
	if cc(arr) {
		fmt.Println("0")
		return
	}
	for i := 1; ; i++ {
		if i%2 != 0 {
			for j := 1; j <= a; j += 2 {
				if j+1 <= a && arr[j] > arr[j+1] {
					arr[j], arr[j+1] = arr[j+1], arr[j]
				}
			}
		} else {
			for j := 2; j <= a; j += 2 {
				if j+1 <= a && arr[j] > arr[j+1] {
					arr[j], arr[j+1] = arr[j+1], arr[j]
				}
			}
		}
		if cc(arr) {
			fmt.Println(i)
			return
		}
	}
}

//检验是否为排序好的
func cc(arr []int) bool {
	for i := 1; i < len(arr); i++ {
		if arr[i-1] > arr[i] {
			return false
		}
	}
	return true
}

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
	var n int
	var a = make([]int, 1e3+1)
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &n)
		for i := 1; i <= n; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, a)
		fmt.Fprintln(w, w1)
	}
}

func sorted(n int, a []int) bool {
	for i := 1; i <= n; i++ {
		if a[i] != i {
			return false
		}
	}
	return true
}

func do(n int, a []int) int {
	r := 0
	for !sorted(n, a) {
		r++
		k1, k2 := 1, 2
		if r%2 == 0 {
			k1, k2 = 2, 1
		}
		for i := k1; i <= n-k2; i += 2 {
			if a[i] > a[i+1] {
				a[i], a[i+1] = a[i+1], a[i]
			}
		}
	}
	return r
}

package main

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

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

	var T, n int

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

	for t := 0; t < T; t++ {
		fmt.Fscanf(r, "%d\n", &n)

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

		i := 0
		for {
			j := 1
			for ; j < n; j++ {
				if arr[j-1] > arr[j] {
					break
				}
			}

			if j == n {
				break
			}

			for j := i % 2; j < n-1; j += 2 {
				if arr[j] > arr[j+1] {
					arr[j], arr[j+1] = arr[j+1], arr[j]
				}
			}

			i++
		}

		fmt.Println(i)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1561A
Date: 11/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1561/A
Problem: CF1561A
**/
func (in *CF1561A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

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

		order := true
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i] != i+1 {
				order = false
			}
		}

		ite := 0

		for {
			ws := true
			for i := ite; i < n-1; i += 2 {
				if arr[i] > arr[i+1] {
					arr[i], arr[i+1] = arr[i+1], arr[i]
					ws = false

				}
			}
			if ite == 0 {
				ite = 1
			} else {
				ite = 0
			}

			sol++
			if ws {
				break
			}

		}

		if order {
			fmt.Println(0)
		} else {
			fmt.Println(sol-1)
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1561A
Date: 11/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1561/A
Problem: CF1561A
**/
func (in *CF1561A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		sol := 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}

		ite := 0
		order := false
		for {
			ws := true
			for i := ite; i < n-1; i += 2 {
				if arr[i] > arr[i+1] {
					arr[i], arr[i+1] = arr[i+1], arr[i]
					ws = false

				}
			}
			if ite == 0 {
				ite = 1
			} else {
				ite = 0
			}
			if ws && sol == 0 {
				order = true
			}
			sol++
			if ws {
				break
			}

		}

		if order {
			fmt.Println(0)
		} else {
			fmt.Println(sol-1)
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1561A
Date: 11/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1561/A
Problem: CF1561A
**/
func (in *CF1561A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		sol := 0
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}

		for {
			ws := true
			for i := 1; i < n; i++ {
				if arr[i-1] > arr[i] {
					arr[i-1], arr[i] = arr[i], arr[i-1]
					ws = false
				}
			}

			if ws {
				break
			}
			sol++
		}

		if sol > 0 {
			sol++
		}
		fmt.Println(sol)

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1561A
Date: 11/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1561/A
Problem: CF1561A
**/
func (in *CF1561A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		sol := 0
		for i := 0; i < n; i++ {
			val := in.NextInt()
			s := int(math.Abs(float64(i + 1 - val)))
			if s > sol {
				sol = s
			}
		}

		if sol ==0 {
			fmt.Println(sol)
		}else {
			fmt.Println(sol+1)
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1561A
Date: 11/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1561/A
Problem: CF1561A
**/
func (in *CF1561A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		index := 1
		max := 0
		for i := 0; i < n; i++ {
			val := in.NextInt()
			if max < val {
				max = val
				index = i + 1
			}
		}

		if index != n{
			fmt.Println(n - index+1)
		}else {
			fmt.Println(0)
		}

	}
}

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

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

package main

import(
	"fmt"
)

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

	for t:=0; t<testcase; t++{
		var n int
		fmt.Scanf("%d\n", &n)

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

		cnt := 0
		for i:=0; i<n; i++{
			flg := 0
			for j:=i%2; j<n-1; j+= 2{
				if a[j] > a[j+1]{
					a[j], a[j+1] = a[j+1], a[j]
					flg = 1
				}
			}
			if flg == 1{
				cnt++
			}
		}
		fmt.Printf("%d\n", cnt)
	}
}

package main

import(
	"fmt"
)

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

	for t:=0; t<testcase; t++{
		var n int
		fmt.Scanf("%d\n", &n)

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

		cnt := 0
		for i:=0; i<n; i++{
			flg := 0
			for j:=i%2; j<n-1; j+= 2{
				if a[j] > a[j+1]{
					a[j], a[j+1] = a[j+1], a[j]
					flg = 1
				}
			}
			if flg == 1{
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

package main

import(
	"fmt"
)

func main(){
	var testcase int
	fmt.Scanf("%d ", &testcase)

	for t:=0; t<testcase; t++{
		var n int
		fmt.Scanf("%d ", &n)

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

		cnt := 0
		for i:=0; i<n; i++{
			flg := 0
			for j:=i%2; j<n-1; j+= 2{
				if a[j] > a[j+1]{
					a[j], a[j+1] = a[j+1], a[j]
					flg = 1
				}
			}
			if flg == 1{
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

package main

import(
	"fmt"
)

func main(){
	var testcase int
	fmt.Scanf("%d", &testcase)

	for t:=0; t<testcase; t++{
		var n int
		fmt.Scanf("%d", &n)

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

		cnt := 0
		for i:=0; i<n; i++{
			flg := 0
			for j:=i%2; j<n-1; j+= 2{
				if a[j] > a[j+1]{
					a[j], a[j+1] = a[j+1], a[j]
					flg = 1
				}
			}
			if flg == 1{
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

package main

import(
	"fmt"
)

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

	for t:=0; t<testcase; t++{
		var n int
		fmt.Scanf("%v", &n)

		a := make([]int, n)
		for i:=0; i<n; i++{
			fmt.Scanf("%v", &a[i])
		}

		cnt := 0
		for i:=0; i<n; i++{
			flg := false
			for j:=i%2; j<n-1; j+= 2{
				if a[j] > a[j+1]{
					a[j], a[j+1] = a[j+1], a[j]
					flg = true;
				}
			}
			if flg{
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

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

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

		var t int
		k := 1
		swapped := true
		for swapped {
			swapped = false
			var i int
			if k%2 != 0 {
				i = 1
			} else {
				i = 2
			}

			for ; i < n; i += 2 {
				if arr[i-1] > arr[i] {
					arr[i], arr[i-1] = arr[i-1], arr[i]
					swapped = true
				}
			}

			if swapped {
				t++
				k++
			}
		}

		fmt.Fprintln(out, t)
	}
}

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

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

		var t int
		swapped := true
		for swapped {
			swapped = false
			for i := 1; i < n; i++ {
				if arr[i-1] > arr[i] {
					arr[i], arr[i-1] = arr[i-1], arr[i]
					swapped = true
					i++
				}
			}

			if swapped {
				t++
			}
		}

		fmt.Fprintln(out, t)
	}
}

package main

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

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

	for i := 0; i < tc; i++ {
        n := readInt(in)
        track := make([]int, n)
        arr := readArrInt(in)
        for j, a := range arr {
            track[j] = abs(a-j)
        }
        max := track[0]
        for _, t := range track {
            if t > max {
                max = t
            }
        }
        if max == 1 {
            fmt.Println(0)
        } else {
            fmt.Println(max)
        }
	}
}

//Yeap this is faster
func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

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

package main

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

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

	for i := 0; i < tc; i++ {
        n := readInt(in)
        track := make([]int, n)
        arr := readArrInt(in)
        for j, a := range arr {
            track[j] = a-j
        }
        max := track[0]
        for _, t := range track {
            if t > max {
                max = t
            }
        }
        if max == 1 {
            fmt.Println(0)
        } else {
            fmt.Println(max)
        }
	}
}

//Yeap this is faster
func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

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

func main() {
	defer out.flush()

	tests()
	// solve()
}

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

	a := make([]int, n)
	for i := range a {
		a[i] = in.nextInt()
	}

	for i := 0; ; i++ {
		ok := false
		if i%2 == 0 {
			for j := 0; j < n-1; j += 2 {
				if a[j] > a[j+1] {
					a[j], a[j+1] = a[j+1], a[j]
					ok = true
				}
			}
		} else {
			for j := 1; j < n-1; j += 2 {
				if a[j] > a[j+1] {
					a[j], a[j+1] = a[j+1], a[j]
					ok = true
				}
			}
		}
		if !ok {
			out.println(i)
			return
		}
	}
}

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

/* --- I/O --- */
type In struct {
	scanner *bufio.Scanner
}

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

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

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

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

type Out struct {
	writer *bufio.Writer
}

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

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

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

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

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

package main

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

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

func main() {
	defer out.flush()

	tests()
	// solve()
}

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

	a := make([]int, n)
	for i := range a {
		a[i] = in.nextInt()
	}

	answer := 0
	for i := 0; i < n; i++ {
		if a[i]-1 != i {
			abs := int(math.Abs(float64(a[i] - i)))
			if abs > answer {
				answer = abs
			}
		}
	}

	out.println(answer)
}

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

/* --- I/O --- */
type In struct {
	scanner *bufio.Scanner
}

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

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

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

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

type Out struct {
	writer *bufio.Writer
}

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

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

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

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

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

package main

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

var (
	out = bufio.NewWriter(os.Stdout)
	in  = bufio.NewReader(os.Stdin)
	arr []string
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	var arr = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	var isSorted = false
	var ans = 0
	for isSorted == false {
		tempIsSorted := true
		for i := 1; i < n; i++ {
			if arr[i] < arr[i-1] {
				arr[i-1], arr[i] = arr[i], arr[i-1]
				tempIsSorted = false
				i++
			}
		}
		//fmt.Println(arr)
		if tempIsSorted == false {
			ans++
		}
		isSorted = tempIsSorted
	}
	//fmt.Println(arr)
	fmt.Println(ans)
}

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

func lcsMethod(s1 string, s2 string, s1Index int, s2Index int, tempAns int) int {
	if s1Index >= len(s1) || s2Index >= len(s2) {
		return tempAns
	}
	if s1[s1Index] == s2[s2Index] {
		tempAns = lcsMethod(s1, s2, s2Index+1, s2Index+1, tempAns+1)
	} else {
		tempAns = int(math.Max(float64(tempAns), math.Max(float64(lcsMethod(s1, s2, s1Index+1, s2Index, tempAns)), float64(lcsMethod(s1, s2, s1Index, s2Index+1, tempAns)))))
	}
	return tempAns
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 1; i < t; i++ {
		n := scanInt()
		a := make([]int, n)
		for i := range a {
			a[i] = scanInt()
		}
		fmt.Fprintln(wr, solve(a))
	}
}

func solve(a []int) int {
	f := func(i int) {
		if a[i] > a[i+1] {
			a[i], a[i+1] = a[i+1], a[i]
		}
	}

	if sort.IntsAreSorted(a) {
		return 0
	}

	n := len(a)
	for i := 1; ; i++ {
		if i%2 == 1 {
			for j := 0; j <= n-3; j += 2 {
				f(j)
			}
		} else {
			for j := 1; j <= n-2; j += 2 {
				f(j)
			}
		}
		if sort.IntsAreSorted(a) {
			return i
		}
	}
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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


Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.Mike has $$$n$$$ sweets with sizes $$$a_1, a_2, \ldots, a_n$$$. All his sweets have different sizes. That is, there is no such pair $$$(i, j)$$$ ($$$1 \leq i, j \leq n$$$) such that $$$i \ne j$$$ and $$$a_i = a_j$$$.Since Mike has taught for many years, he knows that if he gives two sweets with sizes $$$a_i$$$ and $$$a_j$$$ to one child and $$$a_k$$$ and $$$a_p$$$ to another, where $$$(a_i + a_j) \neq (a_k + a_p)$$$, then a child who has a smaller sum of sizes will be upset. That is, if there are two children who have different sums of sweets, then one of them will be upset. Apparently, Mike does not want somebody to be upset. Mike wants to invite children giving each of them two sweets. Obviously, he can't give one sweet to two or more children. His goal is to invite as many children as he can. Since Mike is busy preparing to his first lecture in the elementary school, he is asking you to find the maximum number of children he can invite giving each of them two sweets in such way that nobody will be upset.

The first line contains one integer $$$n$$$ ($$$2 \leq n \leq 1\,000$$$) — the number of sweets Mike has. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^5$$$) — the sizes of the sweets. It is guaranteed that all integers are distinct.

Print one integer — the maximum number of children Mike can invite giving each of them two sweets in such way that nobody will be upset.

NoteIn the first example, Mike can give $$$9+2=11$$$ to one child, $$$8+3=11$$$ to another one, and $$$7+4=11$$$ to the third child. Therefore, Mike can invite three children. Note that it is not the only solution.In the second example, Mike can give $$$3+9=12$$$ to one child and $$$1+11$$$ to another one. Therefore, Mike can invite two children. Note that it is not the only solution.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	sum := make(map[int]int)
	ans := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if i != j {
				sum[a[i]+a[j]]++
				if sum[a[i]+a[j]] > ans {
					ans = sum[a[i]+a[j]]
				}
			}
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

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

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

// Author: sighduck
// URL: https://codeforces.com/contest/1121/problem/B

package main

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

func Solve(n int, a []int) int {
	sumCount := make(map[int]int)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sum := a[i] + a[j]
			sumCount[sum] += 1
		}
	}
	maxCount := 0
	for _, count := range sumCount {
		if count > maxCount {
			maxCount = count
		}
	}
	return maxCount
}

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

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

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


Mark has just purchased a rack of $$$n$$$ lightbulbs. The state of the lightbulbs can be described with binary string $$$s = s_1s_2\dots s_n$$$, where $$$s_i=\texttt{1}$$$ means that the $$$i$$$-th lightbulb is turned on, while $$$s_i=\texttt{0}$$$ means that the $$$i$$$-th lightbulb is turned off.Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following:  Select an index $$$i$$$ from $$$2,3,\dots,n-1$$$ such that $$$s_{i-1}\ne s_{i+1}$$$.  Toggle $$$s_i$$$. Namely, if $$$s_i$$$ is $$$\texttt{0}$$$, set $$$s_i$$$ to $$$\texttt{1}$$$ or vice versa. Mark wants the state of the lightbulbs to be another binary string $$$t$$$. Help Mark determine the minimum number of operations to do so.

The first line of the input contains a single integer $$$q$$$ ($$$1\leq q\leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$3\leq n\leq 2\cdot 10^5$$$) — the number of lightbulbs. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ — the initial state of the lightbulbs. The third line of each test case contains a binary string $$$t$$$ of length $$$n$$$ — the final state of the lightbulbs. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $$$s$$$ to $$$t$$$. If there is no such sequence of operations, print $$$-1$$$.

NoteIn the first test case, one sequence of operations that achieves the minimum number of operations is the following.   Select $$$i=3$$$, changing $$$\texttt{01}\color{red}{\texttt{0}}\texttt{0}$$$ to $$$\texttt{01}\color{red}{\texttt{1}}\texttt{0}$$$.  Select $$$i=2$$$, changing $$$\texttt{0}\color{red}{\texttt{1}}\texttt{10}$$$ to $$$\texttt{0}\color{red}{\texttt{0}}\texttt{10}$$$.  In the second test case, there is no sequence of operations because one cannot change the first digit or the last digit of $$$s$$$.In the third test case, even though the first digits of $$$s$$$ and $$$t$$$ are the same and the last digits of $$$s$$$ and $$$t$$$ are the same, it can be shown that there is no sequence of operations that satisfies the condition.In the fourth test case, one sequence that achieves the minimum number of operations is the following:   Select $$$i=3$$$, changing $$$\texttt{00}\color{red}{\texttt{0}}\texttt{101}$$$ to $$$\texttt{00}\color{red}{\texttt{1}}\texttt{101}$$$.  Select $$$i=2$$$, changing $$$\texttt{0}\color{red}{\texttt{0}}\texttt{1101}$$$ to $$$\texttt{0}\color{red}{\texttt{1}}\texttt{1101}$$$.  Select $$$i=4$$$, changing $$$\texttt{011}\color{red}{\texttt{1}}\texttt{01}$$$ to $$$\texttt{011}\color{red}{\texttt{0}}\texttt{01}$$$.  Select $$$i=5$$$, changing $$$\texttt{0110}\color{red}{\texttt{0}}\texttt{1}$$$ to $$$\texttt{0110}\color{red}{\texttt{1}}\texttt{1}$$$.  Select $$$i=3$$$, changing $$$\texttt{01}\color{red}{\texttt{1}}\texttt{011}$$$ to $$$\texttt{01}\color{red}{\texttt{0}}\texttt{011}$$$.

package main

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

func main() {
	CF1705D(os.Stdin, os.Stdout)
}
func CF1705D(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n int64
		fmt.Fscan(r, &n)
		a, b := make([]byte, n), make([]byte, n)
		fmt.Fscan(r, &a, &b)

		if a[0] != b[0] || a[n-1] != b[n-1] {
			fmt.Fprintln(w, "-1")
			continue
		}
		num, ans := int64(0), int64(0)
		for i := int64(1); i < n; i++ {
			if a[i] != a[i-1] {
				num++
			}
			if b[i] != b[i-1] {
				num--
			}
			ans += abs(num)
		}
		if num != 0 {
			fmt.Fprintln(w, "-1")
		} else {
			fmt.Fprintln(w, ans)
		}

	}
}

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

package main

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

func island(a []rune, i int) (int, int) {
	for i < len(a) && a[i] == '0' {
		i++
	}
	j := i
	for j < len(a) && a[j] == '1' {
		j++
	}
	return i, j
}

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

func solve() {
	n := get()
	s := []rune(gets())
	t := []rune(gets())

	defer line()

	if s[0] != t[0] || s[n-1] != t[n-1] {
		put(-1)
		return
	}

	var i, j, it, jt int
	var count int64
	for {
		i, j = island(s, j)
		it, jt = island(t, jt)
		if i == n || it == n {
			if i == n && it == n {
				put64(count)
				return
			}
			put(-1)
			return
		}

		count += int64(abs(i-it) + abs(j-jt))
	}
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

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

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func gets() string {
	in.Scan()
	return in.Text()
}

func putc(c rune) {
	out.WriteRune(c)
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func puts(s string) {
	out.WriteString(s)
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES")
	line()
}

func no() {
	puts("NO")
	line()
}

//func putf(x float64) {
//	out.WriteString(strconv.FormatFloat(x))
//}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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 int
		var s1, s2 string
		fmt.Fscan(in, &n, &s1, &s2)

		comp := func(s string) [][]int {
			res := [][]int{}
			r := []int{0, 0}
			for i := 1; i < len(s); i++ {
				if s[i] != s[i-1] {
					res = append(res, r)
					r = []int{i, i}
				}
				r[1] = i
			}
			res = append(res, r)
			return res
		}

		r1 := comp(s1)
		r2 := comp(s2)
		if s1[0] != s2[0] || len(r1) != len(r2) {
			fmt.Fprintln(out, -1)
			continue
		}

		var tot int
		for i := range r1 {
			tot += abs(r1[i][0]-r2[i][0]) + abs(r1[i][1]-r2[i][1])
		}
		fmt.Fprintln(out, tot/2)
	}
}

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--
		n := readNum(reader)
		s := readString(reader)
		x := readString(reader)
		res := solve(s[:n], x[:n])
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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
	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 readNInt64s(reader *bufio.Reader, n int) []int64 {
	res := make([]int64, n)
	s, _ := reader.ReadBytes('\n')

	var pos int

	for i := 0; i < n; i++ {
		pos = readInt64(s, pos, &res[i]) + 1
	}

	return res
}

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

func solve(s string, t string) int {
	// s[i-1] != s[i+1], then can toggle it s[i]
	// no way to change s[0] & s[n-1], otherwise seems always has a solution?
	n := len(s)

	if s == t {
		return 0
	}

	if s[0] != t[0] || s[n-1] != t[n-1] {
		return -1
	}

	if !can_change(s) {
		return -1
	}

	// 每次变化影响的是什么呢？
	// 在变化前 s[i] = s[i-1], 变化后肯定 s[i] = s[i+1]， 且 s[i] != s[i-1], 反之亦然
	// 也就是说无论怎么变化 s[i] != s[i-1] 的个数不会减少，
	// 似乎就是在移动 s[i] != s[i-1]的关系到正确的位置
	// 构造两个新的字符串 a[i] = 1, when s[i+1] != s[i]
	//             和  b[i] = 1, when t[i+1] != t[i]

	var a []int

	for i := 1; i < n; i++ {
		if s[i] != s[i-1] {
			a = append(a, i)
		}
	}

	var b []int

	for i := 1; i < n; i++ {
		if t[i] != t[i-1] {
			b = append(b, i)
		}
	}

	if len(a) != len(b) {
		return -1
	}

	var res int

	for i := 0; i < len(a); i++ {
		res += abs(a[i] - b[i])
	}
	return res
}

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

func can_change(s string) bool {
	for i := 1; i+1 < len(s); i++ {
		if s[i-1] != s[i+1] {
			return true
		}
	}
	return false
}

package main

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

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

	var T, n int
	var s, t string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s, &t)
		if s[0] != t[0] || s[n-1] != t[n-1] {
			Fprintln(out, -1)
			continue
		}
		ans := int64(0)
		i, j := 0, 0
		for i < n && j < n {
			i0 := i
			for i++; i < n && s[i] == s[i-1]; i++ {
			}
			j0 := j
			for j++; j < n && t[j] == t[j-1]; j++ {
			}
			if t[j-1] == '1' {
				ans += int64(abs(i0-j0) + abs(i-j))
			}
		}
		if i < n || j < n {
			ans = -1
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

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

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

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n int64
		fmt.Fscan(r, &n)
		a, b := make([]byte, n), make([]byte, n)
		fmt.Fscan(r, &a, &b)

		if a[0] != b[0] || a[n-1] != b[n-1] {
			fmt.Fprintln(w, "-1")
			continue
		}
		num, ans := int64(0), int64(0)
		for i := int64(1); i < n-2; i++ {
			if a[i] != a[i-1] {
				num++
			}
			if b[i] != b[i-1] {
				num--
			}
			ans += abs(num)
		}
		if num != 0 {
			fmt.Fprintln(w, "-1")
		} else {
			fmt.Fprintln(w, ans)
		}

	}
}

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

package main

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

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

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

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n int64
		fmt.Fscan(r, &n)
		a, b := make([]byte, n), make([]byte, n)
		fmt.Fscan(r, &a, &b)

		if a[0] != b[0] || a[n-1] != b[n-1] {
			fmt.Fprintln(w, "-1")
			continue
		}
		num, ans := int64(0), int64(0)
		for i := int64(1); i < n-1; i++ {
			if a[i] != a[i-1] {
				num++
			}
			if b[i] != b[i-1] {
				num--
			}
			ans += abs(num)

		}
		if num != 0 {
			fmt.Fprintln(w, "-1")
		} else {
			fmt.Fprintln(w, "ans")
		}

	}
}

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

package main

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

func island(a []rune, i int) (int, int) {
	for i < len(a) && a[i] == '0' {
		i++
	}
	j := i
	for j < len(a) && a[j] == '1' {
		j++
	}
	return i, j
}

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

func solve() {
	n := get()
	s := []rune(gets())
	t := []rune(gets())

	defer line()

	if s[0] != t[0] || s[n-1] != t[n-1] {
		put(-1)
		return
	}

	var i, j, it, jt, count int
	for {
		i, j = island(s, j)
		it, jt = island(t, jt)
		if i == n || it == n {
			if i == n && it == n {
				put(count)
				return
			}
			put(-1)
			return
		}

		count += abs(i-it) + abs(j-jt)
	}
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

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

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func gets() string {
	in.Scan()
	return in.Text()
}

func putc(c rune) {
	out.WriteRune(c)
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func puts(s string) {
	out.WriteString(s)
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES")
	line()
}

func no() {
	puts("NO")
	line()
}

//func putf(x float64) {
//	out.WriteString(strconv.FormatFloat(x))
//}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}


Kate has a set $$$S$$$ of $$$n$$$ integers $$$\{1, \dots, n\} $$$. She thinks that imperfection of a subset $$$M \subseteq S$$$ is equal to the maximum of $$$gcd(a, b)$$$ over all pairs $$$(a, b)$$$ such that both $$$a$$$ and $$$b$$$ are in $$$M$$$ and $$$a \neq b$$$. Kate is a very neat girl and for each $$$k \in \{2, \dots, n\}$$$ she wants to find a subset that has the smallest imperfection among all subsets in $$$S$$$ of size $$$k$$$. There can be more than one subset with the smallest imperfection and the same size, but you don't need to worry about it. Kate wants to find all the subsets herself, but she needs your help to find the smallest possible imperfection for each size $$$k$$$, will name it $$$I_k$$$. Please, help Kate to find $$$I_2$$$, $$$I_3$$$, ..., $$$I_n$$$.

The first and only line in the input consists of only one integer $$$n$$$ ($$$2\le n \le 5 \cdot 10^5$$$)  — the size of the given set $$$S$$$.

Output contains only one line that includes $$$n - 1$$$ integers: $$$I_2$$$, $$$I_3$$$, ..., $$$I_n$$$.

NoteFirst sample: answer is 1, because $$$gcd(1, 2) = 1$$$.Second sample: there are subsets of $$$S$$$ with sizes $$$2, 3$$$ with imperfection equal to 1. For example, $$$\{2,3\}$$$ and $$$\{1, 2, 3\}$$$.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

func main() {
	var n int
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewReader(bs)
	fmt.Fscanf(reader, "%d", &n)
	primes := make([]int, 0, n+1)
	sieve := make([]int, n+1)
	writer := bytes.NewBuffer(make([]byte, 0, 10000000))
	for i := 2; i <= n; i++ {
		if sieve[i] == 0 {
			sieve[i] = 1
			primes = append(primes, i)
		}
		for j := 0; j < len(primes); j++ {
			comp := i * primes[j]
			if comp > n {
				break
			}
			sieve[comp] = i
			if i%primes[j] == 0 {
				break
			}
		}
	}
	sort.Ints(sieve)
	for i := 2; i <= n; i++ {
		fmt.Fprintf(writer, "%d ", sieve[i])
	}
	writer.WriteTo(os.Stdout)
}

package main

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

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

	var n int
	Fscan(in, &n)
	vis := make([]bool, n+1)
	cnts := make([]int, n/2+1)
	for i := 2; i <= n; i++ {
		if !vis[i] {
			for j := i; j <= n; j += i {
				if !vis[j] {
					vis[j] = true
					cnts[j/i]++
				}
			}
		}
	}
	for i, c := range cnts {
		for ; c > 0; c-- {
			Fprint(out, i, " ")
		}
	}
}

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

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
	"sort"
)

func main() {
	var n int
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewReader(bs)
	fmt.Fscanf(reader, "%d", &n)
	primes := make([]int, 0, n+1)
	sieve := make([]int, n+1)
	writer := bytes.NewBuffer(make([]byte, 1000000))
	for i := 2; i <= n; i++ {
		if sieve[i] == 0 {
			sieve[i] = 1
			primes = append(primes, i)
		}
		for j := 0; j < len(primes); j++ {
			comp := i * primes[j]
			if comp > n {
				break
			}
			sieve[comp] = i
			if i%primes[j] == 0 {
				break
			}
		}
	}
	sort.Ints(sieve)
	for i := 2; i <= n; i++ {
		fmt.Fprintf(writer, "%d ", sieve[i])
	}
	writer.WriteTo(os.Stdout)
}


One day Kefa the parrot was walking down the street as he was on the way home from the restaurant when he saw something glittering by the road. As he came nearer he understood that it was a watch. He decided to take it to the pawnbroker to earn some money. The pawnbroker said that each watch contains a serial number represented by a string of digits from 0 to 9, and the more quality checks this number passes, the higher is the value of the watch. The check is defined by three positive integers l, r and d. The watches pass a check if a substring of the serial number from l to r has period d. Sometimes the pawnbroker gets distracted and Kefa changes in some substring of the serial number all digits to c in order to increase profit from the watch. The seller has a lot of things to do to begin with and with Kefa messing about, he gave you a task: to write a program that determines the value of the watch.Let us remind you that number x is called a period of string s (1 ≤ x ≤ |s|), if si  =  si + x for all i from 1 to |s|  -  x.

The first line of the input contains three positive integers n, m and k (1 ≤ n ≤ 105, 1 ≤ m + k ≤ 105) — the length of the serial number, the number of change made by Kefa and the number of quality checks. The second line contains a serial number consisting of n digits. Then m + k lines follow, containing either checks or changes.  The changes are given as 1 l r c (1 ≤ l ≤ r ≤ n, 0 ≤ c ≤ 9). That means that Kefa changed all the digits from the l-th to the r-th to be c.  The checks are given as 2 l r d (1 ≤ l ≤ r ≤ n, 1 ≤ d ≤ r - l + 1).

For each check on a single line print "YES" if the watch passed it, otherwise print "NO".

NoteIn the first sample test two checks will be made. In the first one substring "12" is checked on whether or not it has period 1, so the answer is "NO". In the second one substring "88", is checked on whether or not it has period 1, and it has this period, so the answer is "YES".In the second statement test three checks will be made. The first check processes substring "3493", which doesn't have period 2. Before the second check the string looks as "334334", so the answer to it is "YES". And finally, the third check processes substring "8334", which does not have period 1.

package main

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

var err = errors.New("internal error")

type hashutil_t struct {
	prime uint64
	radix uint8
	cache []uint64
}

func newHashUtil(r uint8, p uint64, size int) *hashutil_t {
	if r < 2 || p < 2 || float64(math.MaxUint64) < float64(r)*float64(p-1) {
		return nil
	}
	h := hashutil_t{radix: r, prime: p}
	h.cache = make([]uint64, size+1)
	h.cache[0] = 0
	for i := 1; i <= size; i++ {
		h.cache[i] = (h.cache[i-1]*uint64(r) + 1) % p
	}
	return &h
}

func (h *hashutil_t) neg(x uint64) uint64 { return (h.prime - x%h.prime) % h.prime }

func (h *hashutil_t) sum(x, y uint64) uint64 { return (x%h.prime + y%h.prime) % h.prime }

func (h *hashutil_t) val(l, r int, d uint8) (uint64, error) {
	if r-l < 1 || l < 0 || r > len(h.cache) {
		return 0, err
	}
	unit := h.sum(h.cache[r], h.neg(h.cache[l]))
	return (unit * uint64(d)) % h.prime, nil
}

type node_t struct {
	elem   uint64
	lazy   uint8
	flag   bool
	ln, rn *node_t
}

type segment_tree_t struct {
	root *node_t
	hash *hashutil_t
	size int
}

func newSegmentTree(digits []uint8, hash *hashutil_t) *segment_tree_t {
	var build_iter func(l, r int) *node_t
	build_iter = func(l, r int) *node_t {
		m, err := divide(l, r)
		if err != nil {
			val, _ := hash.val(l, r, digits[l])
			return &node_t{elem: val}
		}
		n := node_t{}
		n.ln = build_iter(l, m)
		n.rn = build_iter(m, r)
		n.elem = hash.sum(n.ln.elem, n.rn.elem)
		return &n
	}
	return &segment_tree_t{
		root: build_iter(0, len(digits)),
		hash: hash,
		size: len(digits),
	}
}

func (t *segment_tree_t) query(l, r int) (uint64, error) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return 0, err
	} else {
		l, r = newl, newr
	}

	var query_iter func(n *node_t, l, r, ql, qr int) uint64
	query_iter = func(n *node_t, l, r, ql, qr int) uint64 {
		m, _ := divide(l, r)
		t.pushdown(n, l, r)

		if l == ql && r == qr {
			return n.elem
		}
		if qr <= m {
			return query_iter(n.ln, l, m, ql, qr)
		}
		if m <= ql {
			return query_iter(n.rn, m, r, ql, qr)
		}
		vl := query_iter(n.ln, l, m, ql, m)
		vr := query_iter(n.rn, m, r, m, qr)
		return t.hash.sum(vl, vr)
	}
	return query_iter(t.root, 0, t.size, l, r), nil
}

func (t *segment_tree_t) update(l, r int, d uint8) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return
	} else {
		l, r = newl, newr
	}

	var update_iter func(n *node_t, l, r, ul, ur int)
	update_iter = func(n *node_t, l, r, ul, ur int) {
		m, _ := divide(l, r)

		if l == ul && r == ur {
			n.flag, n.lazy = true, d
			t.pushdown(n, l, r)
			return
		} else {
			t.pushdown(n, l, r)
		}
		if ur <= m {
			update_iter(n.ln, l, m, ul, ur)
			t.pushdown(n.rn, m, r)
		}
		if m <= ul {
			update_iter(n.rn, m, r, ul, ur)
			t.pushdown(n.ln, l, m)
		}
		if ul < m && m < ur {
			update_iter(n.ln, l, m, ul, m)
			update_iter(n.rn, m, r, m, ur)
		}
		n.elem, n.flag = t.hash.sum(n.ln.elem, n.rn.elem), false
	}
	update_iter(t.root, 0, t.size, l, r)
}

func (t *segment_tree_t) pushdown(n *node_t, l, r int) {
	if n.flag {
		n.elem, _ = t.hash.val(l, r, n.lazy)
		if _, err := divide(l, r); err == nil {
			n.ln.lazy, n.rn.lazy = n.lazy, n.lazy
			n.ln.flag, n.rn.flag = n.flag, n.flag
		}
		n.flag = false
	}
}

func (t *segment_tree_t) limit(l, r int) (int, int, error) {
	if r-l < 1 {
		return 0, 0, err
	}
	if l < 0 {
		l = 0
	}
	if r > t.size {
		r = t.size
	}
	return l, r, nil
}

func divide(l, r int) (int, error) {
	m := (l + r) / 2
	if l < m && m < r {
		return m, nil
	} else {
		return 0, err
	}
}

func printTree(t *segment_tree_t) {
	var print_iter func(node *node_t, l, r int)
	print_iter = func(node *node_t, l, r int) {
		if m, err := divide(l, r); err != nil {
			printn("    leaf", l, r, node.flag, node.elem)
		} else {
			if node.flag {
				return
			}
			printn("internel", l, r, node.flag, node.elem)
			print_iter(node.ln, l, m)
			print_iter(node.rn, m, r)
		}
	}
	print_iter(t.root, 0, t.size)
}

func readBase() (int, []uint8) {
	n, _, k := nextInt(), nextInt(), nextInt()
	a := make([]uint8, n)
	scanner.Split(bufio.ScanBytes)
	for i := 0; i < n; i++ {
		a[i] = uint8(next()[0] - '0')
	}
	scanner.Split(bufio.ScanWords)
	return k, a
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	k, a := readBase()
	h := newHashUtil(10, 11518723, len(a))
	st := newSegmentTree(a, h)

	for i := 0; i < k; {
		op, l, r := nextInt(), nextInt(), nextInt()
		if op == 1 {
			c := uint8(nextInt())
			st.update(l-1, r, c)
			// printn("#U0", l-1, r, c)
			// printTree(st)
		} else {
			d := nextInt()
			if d == r-l+1 {
				printn("YES")
			} else {
				s0, s1, w := l-1, l-1+d, r-l+1-d
				h0, _ := st.query(s0, s0+w)
				// printn("#Q1", s0, s0+w, h0)
				// printTree(st)
				h1, _ := st.query(s1, s1+w)
				// printn("#Q2", s1, s1+w, h1)
				// printTree(st)
				sw, _ := h.val(s1-s0, s1-s0+1, 1)
				if (h0*sw)%h.prime == h1 {
					printn("YES")
				} else {
					printn("NO")
				}

			}
			i++
		}
	}
}

func init() { scanner.Split(bufio.ScanWords) }

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	txt, p := scanner.Text(), 0
	for p < len(txt) && (txt[p] == '\n' || txt[p] == '\r') {
		p++
	}
	if p < len(txt) {
		return txt[p:]
	} else {
		return next()
	}
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) { return fmt.Fprint(stdout, a...) }

func printn(a ...interface{}) (int, error) { return fmt.Fprintln(stdout, a...) }

func printf(format string, a ...interface{}) (int, error) { return fmt.Fprintf(stdout, format, a...) }

func flush() error { return stdout.Flush() }

package main

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

var err = errors.New("internal error")

type hashutil_t struct {
	prime uint64
	radix uint8
	cache []uint64
}

func newHashUtil(r uint8, p uint64, size int) *hashutil_t {
	if r < 2 || p < 2 || float64(math.MaxUint64) < float64(r)*float64(p-1) {
		return nil
	}
	h := hashutil_t{radix: r, prime: p}
	h.cache = make([]uint64, size+1)
	h.cache[0] = 0
	for i := 1; i <= size; i++ {
		h.cache[i] = (h.cache[i-1]*uint64(r) + 1) % p
	}
	return &h
}

func (h *hashutil_t) neg(x uint64) uint64 { return (h.prime - x%h.prime) % h.prime }

func (h *hashutil_t) sum(x, y uint64) uint64 { return (x%h.prime + y%h.prime) % h.prime }

func (h *hashutil_t) val(l, r int, d uint8) (uint64, error) {
	if r-l < 1 || l < 0 || r > len(h.cache) {
		return 0, err
	}
	unit := h.sum(h.cache[r], h.neg(h.cache[l]))
	return (unit * uint64(d)) % h.prime, nil
}

type node_t struct {
	elem   uint64
	lazy   uint8
	flag   bool
	ln, rn *node_t
}

type segment_tree_t struct {
	root *node_t
	hash *hashutil_t
	size int
}

func newSegmentTree(digits []uint8, hash *hashutil_t) *segment_tree_t {
	var build_iter func(l, r int) *node_t
	build_iter = func(l, r int) *node_t {
		m, err := divide(l, r)
		if err != nil {
			val, _ := hash.val(l, r, digits[l])
			return &node_t{elem: val}
		}
		n := node_t{}
		n.ln = build_iter(l, m)
		n.rn = build_iter(m, r)
		n.elem = hash.sum(n.ln.elem, n.rn.elem)
		return &n
	}
	return &segment_tree_t{
		root: build_iter(0, len(digits)),
		hash: hash,
		size: len(digits),
	}
}

func (t *segment_tree_t) query(l, r int) (uint64, error) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return 0, err
	} else {
		l, r = newl, newr
	}

	var query_iter func(n *node_t, l, r, ql, qr int) uint64
	query_iter = func(n *node_t, l, r, ql, qr int) uint64 {
		m, _ := divide(l, r)

		t.pushdown(n, l, r)

		if l == ql && r == qr {
			return n.elem
		}
		if qr <= m {
			return query_iter(n.ln, l, m, ql, qr)
		}
		if m <= ql {
			return query_iter(n.rn, m, r, ql, qr)
		}
		vl := query_iter(n.ln, l, m, ql, m)
		vr := query_iter(n.rn, m, r, m, qr)
		return t.hash.sum(vl, vr)
	}
	return query_iter(t.root, 0, t.size, l, r), nil
}

func (t *segment_tree_t) update(l, r int, d uint8) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return
	} else {
		l, r = newl, newr
	}

	var update_iter func(n *node_t, l, r, ul, ur int)
	update_iter = func(n *node_t, l, r, ul, ur int) {
		m, _ := divide(l, r)

		if l == ul && r == ur {
			n.flag, n.lazy = true, d
			t.pushdown(n, l, r)
			return
		}
		if ur <= m {
			update_iter(n.ln, l, m, ul, ur)
			t.pushdown(n.rn, m, r)
		}
		if m <= ul {
			update_iter(n.rn, m, r, ul, ur)
			t.pushdown(n.ln, l, m)
		}
		if ul < m && m < ur {
			update_iter(n.ln, l, m, ul, m)
			update_iter(n.rn, m, r, m, ur)
		}
		n.elem, n.flag = t.hash.sum(n.ln.elem, n.rn.elem), false
	}
	update_iter(t.root, 0, t.size, l, r)
}

func (t *segment_tree_t) pushdown(n *node_t, l, r int) {
	if n.flag {
		n.elem, _ = t.hash.val(l, r, n.lazy)
		if _, err := divide(l, r); err == nil {
			n.ln.lazy, n.rn.lazy = n.lazy, n.lazy
			n.ln.flag, n.rn.flag = n.flag, n.flag
		}
		n.flag = false
	}
}

func (t *segment_tree_t) limit(l, r int) (int, int, error) {
	if r-l < 1 {
		return 0, 0, err
	}
	if l < 0 {
		l = 0
	}
	if r > t.size {
		r = t.size
	}
	return l, r, nil
}

func printTree(t *segment_tree_t, leafOnly bool) {
	var print_iter func(node *node_t, l, r int)
	print_iter = func(node *node_t, l, r int) {
		if m, err := divide(l, r); err != nil {
			printn("    leaf", l, r, node.flag, node.elem)
		} else {
			if !leafOnly {
				printn("internel", l, r, node.flag, node.elem)
			}
			print_iter(node.ln, l, m)
			print_iter(node.rn, m, r)
		}
	}
	print_iter(t.root, 0, t.size)
}

func divide(l, r int) (int, error) {
	m := (l + r) / 2
	if l < m && m < r {
		return m, nil
	} else {
		return 0, err
	}
}

func readBase() (int, []uint8) {
	n, _, k := nextInt(), nextInt(), nextInt()
	a := make([]uint8, n)
	scanner.Split(bufio.ScanBytes)
	for i := 0; i < n; i++ {
		a[i] = uint8(next()[0] - '0')
	}
	scanner.Split(bufio.ScanWords)
	return k, a
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	k, a := readBase()
	h := newHashUtil(10, 11518723, len(a))
	st := newSegmentTree(a, h)

	for i := 0; i < k; {
		op, l, r := nextInt(), nextInt(), nextInt()
		if op == 1 {
			c := uint8(nextInt())
			st.update(l-1, r, c)
		} else {
			d := nextInt()
			if d == r-l+1 {
				printn("YES")
			} else {
				s0, s1, w := l-1, l-1+d, r-l+1-d
				h0, _ := st.query(s0, s0+w)
				h1, _ := st.query(s1, s1+w)
				sw, _ := h.val(s1-s0, s1-s0+1, 1)
				if (h0*sw)%h.prime == h1 {
					printn("YES")
				} else {
					printn("NO")
				}

			}
			i++
		}
	}
}

func init() { scanner.Split(bufio.ScanWords) }

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	txt, p := scanner.Text(), 0
	for p < len(txt) && (txt[p] == '\n' || txt[p] == '\r') {
		p++
	}
	if p < len(txt) {
		return txt[p:]
	} else {
		return next()
	}
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) { return fmt.Fprint(stdout, a...) }

func printn(a ...interface{}) (int, error) { return fmt.Fprintln(stdout, a...) }

func printf(format string, a ...interface{}) (int, error) { return fmt.Fprintf(stdout, format, a...) }

func flush() error { return stdout.Flush() }

package main

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

var err = errors.New("internal error")

type hashutil_t struct {
	prime uint64
	radix uint8
	cache []uint64
}

func newHashUtil(r uint8, p uint64, size int) *hashutil_t {
	if r < 2 || p < 2 || float64(math.MaxUint64) < float64(r)*float64(p-1) {
		return nil
	}
	h := hashutil_t{radix: r, prime: p}
	h.cache = make([]uint64, size+1)
	h.cache[0] = 0
	for i := 1; i <= size; i++ {
		h.cache[i] = (h.cache[i-1]*uint64(r) + 1) % p
	}
	return &h
}

func (h *hashutil_t) neg(x uint64) uint64 { return (h.prime - x%h.prime) % h.prime }

func (h *hashutil_t) sum(x, y uint64) uint64 { return (x%h.prime + y%h.prime) % h.prime }

func (h *hashutil_t) val(l, r int, d uint8) (uint64, error) {
	if r-l < 1 || l < 0 || r > len(h.cache) {
		return 0, err
	}
	unit := h.sum(h.cache[r], h.neg(h.cache[l]))
	return (unit * uint64(d)) % h.prime, nil
}

type node_t struct {
	elem   uint64
	lazy   uint8
	flag   bool
	ln, rn *node_t
}

type segment_tree_t struct {
	root *node_t
	hash *hashutil_t
	size int
}

func newSegmentTree(digits []uint8, hash *hashutil_t) *segment_tree_t {
	var build_iter func(l, r int) *node_t
	build_iter = func(l, r int) *node_t {
		m, err := divide(l, r)
		if err != nil {
			val, _ := hash.val(l, r, digits[l])
			return &node_t{elem: val}
		}
		n := node_t{}
		n.ln = build_iter(l, m)
		n.rn = build_iter(m, r)
		n.elem = hash.sum(n.ln.elem, n.rn.elem)
		return &n
	}
	return &segment_tree_t{
		root: build_iter(0, len(digits)),
		hash: hash,
		size: len(digits),
	}
}

func (t *segment_tree_t) query(l, r int) (uint64, error) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return 0, err
	} else {
		l, r = newl, newr
	}

	var query_iter func(n *node_t, l, r, ql, qr int) uint64
	query_iter = func(n *node_t, l, r, ql, qr int) uint64 {
		m, _ := divide(l, r)

		if n.flag {
			t.pushdown(n, l, r)
		}

		if l == ql && r == qr {
			return n.elem
		}
		if qr <= m {
			return query_iter(n.ln, l, m, ql, qr)
		}
		if m <= ql {
			return query_iter(n.rn, m, r, ql, qr)
		}
		vl := query_iter(n.ln, l, m, ql, m)
		vr := query_iter(n.rn, m, r, m, qr)
		return t.hash.sum(vl, vr)
	}
	return query_iter(t.root, 0, t.size, l, r), nil
}

func (t *segment_tree_t) update(l, r int, d uint8) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return
	} else {
		l, r = newl, newr
	}

	var update_iter func(n *node_t, l, r, ul, ur int)
	update_iter = func(n *node_t, l, r, ul, ur int) {
		m, _ := divide(l, r)

		if l == ul && r == ur {
			n.flag, n.lazy = true, d
			t.pushdown(n, l, r)
			return
		}
		if ur <= m {
			update_iter(n.ln, l, m, ul, ur)
			t.pushdown(n.rn, m, r)
		}
		if m <= ul {
			t.pushdown(n.ln, l, m)
			update_iter(n.rn, m, r, ul, ur)
		}
		if ul < m && m < ur {
			update_iter(n.ln, l, m, ul, m)
			update_iter(n.rn, m, r, m, ur)
		}
		n.elem, n.flag = t.hash.sum(n.ln.elem, n.rn.elem), false
	}
	update_iter(t.root, 0, t.size, l, r)
}

func (t *segment_tree_t) pushdown(n *node_t, l, r int) {
	n.elem, _ = t.hash.val(l, r, n.lazy)
	n.flag = false
	if _, err := divide(l, r); err == nil {
		n.ln.lazy, n.rn.lazy = n.lazy, n.lazy
		n.ln.flag, n.rn.flag = true, true
	}
}

func (t *segment_tree_t) limit(l, r int) (int, int, error) {
	if r-l < 1 {
		return 0, 0, err
	}
	if l < 0 {
		l = 0
	}
	if r > t.size {
		r = t.size
	}
	return l, r, nil
}

func printTree(t *segment_tree_t, leafOnly bool) {
	var print_iter func(node *node_t, l, r int)
	print_iter = func(node *node_t, l, r int) {
		if m, err := divide(l, r); err != nil {
			printn("    leaf", l, r, node.flag, node.elem)
		} else {
			if !leafOnly {
				printn("internel", l, r, node.flag, node.elem)
			}
			print_iter(node.ln, l, m)
			print_iter(node.rn, m, r)
		}
	}
	print_iter(t.root, 0, t.size)
}

func divide(l, r int) (int, error) {
	m := (l + r) / 2
	if l < m && m < r {
		return m, nil
	} else {
		return 0, err
	}
}

func readBase() (int, []uint8) {
	n, _, k := nextInt(), nextInt(), nextInt()
	a := make([]uint8, n)
	scanner.Split(bufio.ScanBytes)
	for i := 0; i < n; i++ {
		a[i] = uint8(next()[0] - '0')
	}
	scanner.Split(bufio.ScanWords)
	return k, a
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	k, a := readBase()
	h := newHashUtil(10, 11518723, len(a))
	st := newSegmentTree(a, h)

	//printTree(st, false)
	for i := 0; i < k; {
		op, l, r := nextInt(), nextInt(), nextInt()
		if op == 1 {
			c := uint8(nextInt())
			st.update(l-1, r, c)
			//printTree(st, false)
		} else {
			d := nextInt()
			s0, s1, w := l-1, l-1+d, r-l+1-d
			h0, _ := st.query(s0, s0+w)
			h1, _ := st.query(s1, s1+w)
			sw, _ := h.val(s1-s0, s1-s0+1, 1)
			if (h0*sw)%h.prime == h1 {
				printn("YES")
			} else {
				printn("NO")
			}
			i++
		}
	}
}

func init() { scanner.Split(bufio.ScanWords) }

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	txt, p := scanner.Text(), 0
	for p < len(txt) && (txt[p] == '\n' || txt[p] == '\r') {
		p++
	}
	if p < len(txt) {
		return txt[p:]
	} else {
		return next()
	}
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) { return fmt.Fprint(stdout, a...) }

func printn(a ...interface{}) (int, error) { return fmt.Fprintln(stdout, a...) }

func printf(format string, a ...interface{}) (int, error) { return fmt.Fprintf(stdout, format, a...) }

func flush() error { return stdout.Flush() }

package main

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

func check(arr []byte, d int) bool {
	if len(arr)%d != 0 {
		return false
	}
	if len(arr) == 0 {
		return true
	}
	n := len(arr) / d
	for i := 0; i < d; i++ {
		c := arr[i]
		for j := 1; j < n; j++ {
			if c != arr[i+j*d] {
				return false
			}
		}
	}
	return true
}

func solve(check func([]byte, int) bool) {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)

	scanner.Scan()
	parsedLine := strings.Split(scanner.Text(), " ")
	k, _ := strconv.Atoi(parsedLine[2])

	scanner.Scan()
	seq := []byte(scanner.Text())

	for scanner.Scan() && k > 0 {
		parsedLine = strings.Split(scanner.Text(), " ")
		l, _ := strconv.Atoi(parsedLine[1])
		r, _ := strconv.Atoi(parsedLine[2])
		if parsedLine[0] == "1" {
			c := byte(parsedLine[3][0])
			for i := l; i <= r; i++ {
				seq[i-1] = c
			}
		} else {
			d, _ := strconv.Atoi(parsedLine[3])
			result := check(seq[l-1:r], d)
			if result {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
			k--
		}
	}
}

func main() {
	solve(check)
}

package main

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

var err = errors.New("internal error")

type hashutil_t struct {
	prime uint64
	radix uint8
	cache []uint64
}

func newHashUtil(r uint8, p uint64, size int) *hashutil_t {
	if r < 2 || p < 2 || float64(math.MaxUint64) < float64(r)*float64(p-1) {
		return nil
	}
	h := hashutil_t{radix: r, prime: p}
	h.cache = make([]uint64, size+1)
	h.cache[0] = 0
	for i := 1; i <= size; i++ {
		h.cache[i] = (h.cache[i-1]*uint64(r) + 1) % p
	}
	return &h
}

func (h *hashutil_t) neg(x uint64) uint64 { return (h.prime - x%h.prime) % h.prime }

func (h *hashutil_t) sum(x, y uint64) uint64 { return (x%h.prime + y%h.prime) % h.prime }

func (h *hashutil_t) val(l, r int, d uint8) (uint64, error) {
	if r-l < 1 || l < 0 || r > len(h.cache) {
		return 0, err
	}
	unit := h.sum(h.cache[r], h.neg(h.cache[l]))
	return (unit * uint64(d)) % h.prime, nil
}

type node_t struct {
	elem   uint64
	lazy   uint8
	flag   bool
	ln, rn *node_t
}

type segment_tree_t struct {
	root *node_t
	hash *hashutil_t
	size int
}

func newSegmentTree(digits []uint8, hash *hashutil_t) *segment_tree_t {
	var build_iter func(l, r int) *node_t
	build_iter = func(l, r int) *node_t {
		m, err := divide(l, r)
		if err != nil {
			val, _ := hash.val(l, r, digits[l])
			return &node_t{elem: val}
		}
		n := node_t{}
		n.ln = build_iter(l, m)
		n.rn = build_iter(m, r)
		n.elem = hash.sum(n.ln.elem, n.rn.elem)
		return &n
	}
	return &segment_tree_t{
		root: build_iter(0, len(digits)),
		hash: hash,
		size: len(digits),
	}
}

func (t *segment_tree_t) query(l, r int) (uint64, error) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return 0, err
	} else {
		l, r = newl, newr
	}

	var query_iter func(n *node_t, l, r, ql, qr int) uint64
	query_iter = func(n *node_t, l, r, ql, qr int) uint64 {
		m, _ := divide(l, r)

		t.pushdown(n, l, r)

		if l == ql && r == qr {
			return n.elem
		}
		if qr <= m {
			return query_iter(n.ln, l, m, ql, qr)
		}
		if m <= ql {
			return query_iter(n.rn, m, r, ql, qr)
		}
		vl := query_iter(n.ln, l, m, ql, m)
		vr := query_iter(n.rn, m, r, m, qr)
		return t.hash.sum(vl, vr)
	}
	return query_iter(t.root, 0, t.size, l, r), nil
}

func (t *segment_tree_t) update(l, r int, d uint8) {
	if newl, newr, err := t.limit(l, r); err != nil {
		return
	} else {
		l, r = newl, newr
	}

	var update_iter func(n *node_t, l, r, ul, ur int)
	update_iter = func(n *node_t, l, r, ul, ur int) {
		m, _ := divide(l, r)

		if l == ul && r == ur {
			n.flag, n.lazy = true, d
			t.pushdown(n, l, r)
			return
		}
		if ur <= m {
			update_iter(n.ln, l, m, ul, ur)
			t.pushdown(n.rn, m, r)
		}
		if m <= ul {
			update_iter(n.rn, m, r, ul, ur)
			t.pushdown(n.ln, l, m)
		}
		if ul < m && m < ur {
			update_iter(n.ln, l, m, ul, m)
			update_iter(n.rn, m, r, m, ur)
		}
		n.elem, n.flag = t.hash.sum(n.ln.elem, n.rn.elem), false
	}
	update_iter(t.root, 0, t.size, l, r)
}

func (t *segment_tree_t) pushdown(n *node_t, l, r int) {
	if n.flag {
		n.elem, _ = t.hash.val(l, r, n.lazy)
		if _, err := divide(l, r); err == nil {
			n.ln.lazy, n.rn.lazy = n.lazy, n.lazy
			n.ln.flag, n.rn.flag = n.flag, n.flag
		}
		n.flag = false
	}
}

func (t *segment_tree_t) limit(l, r int) (int, int, error) {
	if r-l < 1 {
		return 0, 0, err
	}
	if l < 0 {
		l = 0
	}
	if r > t.size {
		r = t.size
	}
	return l, r, nil
}

func printTree(t *segment_tree_t, leafOnly bool) {
	var print_iter func(node *node_t, l, r int)
	print_iter = func(node *node_t, l, r int) {
		if m, err := divide(l, r); err != nil {
			printn("    leaf", l, r, node.flag, node.elem)
		} else {
			if !leafOnly {
				printn("internel", l, r, node.flag, node.elem)
			}
			print_iter(node.ln, l, m)
			print_iter(node.rn, m, r)
		}
	}
	print_iter(t.root, 0, t.size)
}

func divide(l, r int) (int, error) {
	m := (l + r) / 2
	if l < m && m < r {
		return m, nil
	} else {
		return 0, err
	}
}

func readBase() (int, []uint8) {
	n, _, k := nextInt(), nextInt(), nextInt()
	a := make([]uint8, n)
	scanner.Split(bufio.ScanBytes)
	for i := 0; i < n; i++ {
		a[i] = uint8(next()[0] - '0')
	}
	scanner.Split(bufio.ScanWords)
	return k, a
}

func main() {
	//defer profile.Start(profile.ProfilePath(".")).Stop()
	defer flush()

	k, a := readBase()
	h := newHashUtil(10, 11518723, len(a))
	st := newSegmentTree(a, h)

	for i := 0; i < k; {
		op, l, r := nextInt(), nextInt(), nextInt()
		if op == 1 {
			c := uint8(nextInt())
			st.update(l-1, r, c)
		} else {
			d := nextInt()
			if d == r-l+1 {
				printn("YES")
			} else {
				s0, s1, w := l-1, l-1+d, r-l+1-d
				h0, _ := st.query(s0, s0+w)
				h1, _ := st.query(s1, s1+w)
				printn(s0, s0+w, s1, s1+w)
				sw, _ := h.val(s1-s0, s1-s0+1, 1)
				if (h0*sw)%h.prime == h1 {
					printn("YES")
				} else {
					printn("NO")
				}

			}
			i++
		}
	}
}

func init() { scanner.Split(bufio.ScanWords) }

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	txt, p := scanner.Text(), 0
	for p < len(txt) && (txt[p] == '\n' || txt[p] == '\r') {
		p++
	}
	if p < len(txt) {
		return txt[p:]
	} else {
		return next()
	}
}

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

var stdout = bufio.NewWriter(os.Stdout)

func printa(a ...interface{}) (int, error) { return fmt.Fprint(stdout, a...) }

func printn(a ...interface{}) (int, error) { return fmt.Fprintln(stdout, a...) }

func printf(format string, a ...interface{}) (int, error) { return fmt.Fprintf(stdout, format, a...) }

func flush() error { return stdout.Flush() }