In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.Your task is to determine the k-th identifier to be pronounced.

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ min(2·109, n·(n + 1) / 2). The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Print the k-th pronounced identifier (assume that the numeration starts from 1).

NoteIn the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4.

package main

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

func main() {
	cin := bufio.NewReader(os.Stdin)
	var n, k int32
	var id [100010]int32
	var sum [100010]int32
	var i int32
	fmt.Scanf("%d %d\n", &n, &k)
	sum[0] = 0

	for i = 1; i <= n; i++ {
		fmt.Fscanf(cin, "%d", &id[i])
	}
	for i = 1; i <= n; i++ {
		sum[i] += sum[i-1] + i
	}
	ret := 0
	for ret = 1; sum[ret] < k; {
		ret++
	}
	fmt.Printf("%d\n", id[k-sum[ret-1]])
}

package main

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

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

	id := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan() && i < n; i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			fmt.Println("Error!")
			return
		}
		id[i] = a
	}

	for i := 0; i <= n; i++ {
		if int64(i)*int64(i+1)/2 >= int64(k) {
			fmt.Println(id[int(int64(k)-int64(i)*int64(i-1)/2-1)])
			break
		}
	}
}

package main

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

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

	id := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan() && i < n; i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			fmt.Println("Error!")
			return
		}
		id[i] = a
	}

	i := 1
	for i <= n {
		if int64(i)*int64(i+1)/2 >= int64(k) {
			break
		}
		i++
	}
	fmt.Println(id[int(int64(k)-int64(i)*int64(i-1)/2-1)])
}

package main

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

func main() {
	fsc := NewFastScanner()

	N := fsc.NextInt()
	K := fsc.NextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = fsc.NextInt()
	}
	if K == 1 {
		fmt.Println(A[0])
		return
	}
	for i := 1; i <= N; i++ {
		var res1, res2 int64
		res1 = int64(i) * (int64(i) + 1) / 2
		res2 = int64(i+1) * (int64(i) + 2) / 2
		if res1 < int64(K) && int64(K) <= res2 {
			K -= int(res1)
			fmt.Println(A[K-1])
			break
		}
	}

}

//template

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

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	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) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}

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, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

var a [100005]int
var sum [100005]int

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

	var n, k int

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

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

	for i := 1; i <= n; i++ {
		sum[i] = sum[i - 1] + i
		if sum[i] >= k {
			fmt.Println(a[k - sum[i - 1] - 1])
			break
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	var id [100010]int
	fmt.Scanf("%d %d", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &id[i])
	}

	fmt.Println(id[n%k])
}

/*
10
10 4
10 4 18
10 4 18 3

5 / 4 = 1 ... 1
*/

package main

import (
	"fmt"
)

func main() {
	var n, k int
	var id [100010]int
	var sum [100010]int
	fmt.Scanf("%d %d", &n, &k)
	sum[0] = 0
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &id[i])
	}
	for i := 1; i <= n; i++ {
		sum[i] += sum[i-1] + i
	}
	ret := 0
	for ret = 1; sum[ret] < k; {
		ret++
	}
	fmt.Println(id[k-sum[ret-1]])
}

/*
1
3
6
10

10
10 4
10 4 18
10 4 18 3
*/

package main

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

func main() {
	cin := bufio.NewReader(os.Stdin)
	var n, k int32
	var id [100010]int32
	var sum [100010]int32
	var i int32
	fmt.Fscanf(cin, "%d %d\n", &n, &k)
	sum[0] = 0
	ret := 0
	for i = 1; i <= n; i++ {
		fmt.Fscanf(cin, "%d", &id[i])
		sum[i] += sum[i-1] + i
		if sum[ret] <= k {
			ret++
		}
	}
	fmt.Fprintf(os.Stdout, "%d\n", id[k-sum[ret-1]])
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var n, k int
	var id [100010]int
	var sum [100010]int
	fmt.Scanf("%d %d", &n, &k)
	sum[0] = 0
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &id[i])
	}
	for i := 1; i <= n; i++ {
		sum[i] += sum[i-1] + i
	}
	ret := 0
	for ret = 1; sum[ret] < k; {
		ret++
	}
	fmt.Fprintf(os.Stdout, "%d\n", id[k-sum[ret-1]])
}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	var id [100010]int
	fmt.Scanf("%d %d", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &id[i])
	}

	fmt.Println(id[k%n])
}

/*
10
10 4
10 4 18
10 4 18 3

9 :
5 / 4 = 1 ... 1
*/

package main

import (
	"fmt"
	"os"
)

func main() {
	var n, k int32
	var id [100010]int32
	var sum [100010]int32
	var i int32
	fmt.Scanf("%d %d\n", &n, &k)
	sum[0] = 0
	ret := 0

	for i = 1; i <= n; i++ {
		fmt.Scanf("%d", &id[i])
		sum[i] += sum[i-1] + i
		if sum[ret] <= k {
			ret++
		}
	}
	fmt.Fprintf(os.Stdout, "%d\n", id[k-sum[ret-1]])
}

package main

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

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

	id := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan() && i < n; i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error\n")
			return
		}
		id[i] = a
	}

	for i := 1; i <= n; i++ {
		if i*(i+1)/2 >= k {
			fmt.Println(id[k-i*(i-1)/2-1])
			break
		}
	}
}

package main

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

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

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

	for i := 1; i <= n; i++ {
		if i*(i+1)/2 > k {
			fmt.Println(id[k-i*(i-1)/2-1])
			break
		}
	}
}

package main

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

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

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

	for i := 1; i <= n; i++ {
		if i*(i+1)/2 >= k {
			fmt.Println(id[k-i*(i-1)/2-1])
			break
		}
	}
}

package main

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

func main() {
	fsc := NewFastScanner()

	N := fsc.NextInt()
	K := fsc.NextInt()

	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = fsc.NextInt()
	}

	for i := 1; i <= N; i++ {
		var res1, res2 int64
		res1 = int64(i) * (int64(i) + 1) / 2
		res2 = int64(i+1) * (int64(i) + 2) / 2
		if res1 < int64(K) && int64(K) <= res2 {
			K -= int(res1)
			fmt.Println(A[K-1])
			break
		}
	}

}

//template

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

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	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) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}

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, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

var a [100005]int
var sum [100005]int

func main() {
	cin := bufio.NewReader(os.Stdin)
	cout := bufio.NewWriter(os.Stderr)
	defer cout.Flush()

	var n, k int

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

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

	for i := 1; i <= n; i++ {
		sum[i] = sum[i - 1] + i
		if sum[i] >= k {
			fmt.Fprintln(cout, a[k - sum[i - 1] - 1])
			break
		}
	}
}

package main

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

var a [100005]int
var sum [100005]int

func main() {
	cin := bufio.NewReader(os.Stdin)
	cout := bufio.NewWriter(os.Stdout)

	var n, k int

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

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

	for i := 1; i <= n; i++ {
		sum[i] = sum[i - 1] + i
		if sum[i] >= k {
			fmt.Fprintln(cout, a[k - sum[i - 1] - 1])
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

var a [100005]int

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

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

	c := int(math.Sqrt(float64(k) * 2))
	r := k - (c-1) * (c) / 2

	fmt.Println(a[r - 1])
}

package main

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

var a [100005]int
var sum [100005]int

func main() {
	cin := bufio.NewReader(os.Stdin)
	cout := bufio.NewWriter(os.Stderr)

	var n, k int

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

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

	for i := 1; i <= n; i++ {
		sum[i] = sum[i - 1] + i
		if sum[i] >= k {
			fmt.Fprintln(cout, a[k - sum[i - 1] - 1])
			break
		}
	}
	cout.Flush()
}


In some social network, there are $$$n$$$ users communicating with each other in $$$m$$$ groups of friends. Let's analyze the process of distributing some news between users.Initially, some user $$$x$$$ receives the news from some source. Then he or she sends the news to his or her friends (two users are friends if there is at least one group such that both of them belong to this group). Friends continue sending the news to their friends, and so on. The process ends when there is no pair of friends such that one of them knows the news, and another one doesn't know.For each user $$$x$$$ you have to determine what is the number of users that will know the news if initially only user $$$x$$$ starts distributing it.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5 \cdot 10^5$$$) — the number of users and the number of groups of friends, respectively. Then $$$m$$$ lines follow, each describing a group of friends. The $$$i$$$-th line begins with integer $$$k_i$$$ ($$$0 \le k_i \le n$$$) — the number of users in the $$$i$$$-th group. Then $$$k_i$$$ distinct integers follow, denoting the users belonging to the $$$i$$$-th group. It is guaranteed that $$$\sum \limits_{i = 1}^{m} k_i \le 5 \cdot 10^5$$$.

Print $$$n$$$ integers. The $$$i$$$-th integer should be equal to the number of users that will know the news if user $$$i$$$ starts distributing it.

package main

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

func merge(groupgroup [][]int, groupnum []int, n0 int, n1 int) {
	for i := 0; i < len(groupgroup[n1]); i++ {
		k := groupgroup[n1][i]
		groupnum[k] = n0
		groupgroup[n0] = append(groupgroup[n0], k)
	}
	groupgroup[n1] = []int{}
}

func main() {
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)
	var n, m int
	fmt.Fscan(read, &n, &m)
	usergroup := make([][]int, n+1)

	for i := 0; i < m; i++ {
		var k int
		fmt.Fscan(read, &k)
		for j := 0; j < k; j++ {
			var u int
			fmt.Fscan(read, &u)
			usergroup[u] = append(usergroup[u], i)
		}
	}
	//fmt.Print(usergroup)

	groupnum := make([]int, m)
	groupgroup := make([][]int, m)
	for i := 0; i < m; i++ {
		groupnum[i] = i
		groupgroup[i] = append(groupgroup[i], i)
	}

	for i := 1; i < n+1; i++ {
		var gg0, gg1 int
		for j := 0; j < len(usergroup[i]); j++ {
			gg1 = usergroup[i][j]
			if j == 0 {
				gg0 = gg1
				continue
			} else {
				// merge
				n0 := groupnum[gg0]
				n1 := groupnum[gg1]
				if n0 != n1 {

					if len(groupgroup[n0]) < len(groupgroup[n1]) {
						gg0 = gg1
						merge(groupgroup, groupnum, n1, n0)
					} else {
						merge(groupgroup, groupnum, n0, n1)
					}
				}

			}

		}
	}

	grouplen := make([]int, m)
	for i := 1; i < n+1; i++ {
		if len(usergroup[i]) > 0 {
			k := usergroup[i][0]
			nl := groupnum[k]
			grouplen[nl] = grouplen[nl] + 1

		}
	}

	for i := 1; i < n+1; i++ {
		if len(usergroup[i]) == 0 {
			fmt.Fprint(write, 1, " ")
		} else {
			k := usergroup[i][0]
			nl := groupnum[k]
			fmt.Fprint(write, grouplen[nl], " ")
		}
	}

	write.Flush()

}

/*
7 5
3 2 5 4
0
2 1 2
1 1
2 6 7
*/

package main

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

func solve(j Jam) {
	n := uint32(j.Int())
	m := uint32(j.Int())
	uf := UnionFindNew(n)
	for i := uint32(0); i < m; i++ {
		k := uint32(j.Int())
		root := uint32(0)
		for ii := uint32(0); ii < k; ii++ {
			if ii == 0 {
				root = uint32(j.Int() - 1)
			} else {
				uf.Union(root, uint32(j.Int()-1))
			}
		}
	}
	for i := uint32(0); i < n; i++ {
		fmt.Printf("%d ", uf.Size(i))
	}
}

func main() {
	jam, closeFunc := JamNew()
	defer closeFunc()
	solve(jam)
}

type Jam interface {
	Scanner() *bufio.Scanner
	Writer() *bufio.Writer
	Close()

	Str() string
	Int() int64
	Float() float64

	P(format string, values ...interface{})
	PF(format string, values ...interface{})
}

func JamNew() (Jam, func()) {
	if len(os.Args) > 1 {
		panic("running with input file path is not supported")
	}

	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

	var writer = bufio.NewWriter(os.Stdout)
	jam := &jam{scanner, writer}
	return jam, jam.Close
}

type jam struct {
	sc *bufio.Scanner
	wr *bufio.Writer
}

func (j *jam) Close() {
	if err := j.wr.Flush(); err != nil {
		panic(err)
	}
}

func (j *jam) Scanner() *bufio.Scanner {
	return j.sc
}

func (j *jam) Writer() *bufio.Writer {
	return j.wr
}

func (j *jam) Str() string {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	return j.sc.Text()
}

func (j *jam) Int() int64 {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(j.sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}

	return res
}

func (j *jam) Float() float64 {
	j.sc.Scan()
	res, err := strconv.ParseFloat(j.sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (j *jam) P(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
}

func (j *jam) PF(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
	if err = j.wr.Flush(); err != nil {
		panic(err)
	}
}

type UnionFind struct {
	parent []uint32
	size   []uint32
	count  uint32
}

func UnionFindNew(count uint32) *UnionFind {
	parent := make([]uint32, count, count)
	size := make([]uint32, count, count)
	lim := count
	for i := uint32(0); i < lim; i++ {
		parent[i], size[i] = i, 1
	}
	return &UnionFind{parent, size, lim}
}

func (ufp *UnionFind) Reset() {
	lim := uint32(len(ufp.parent))
	for i := uint32(0); i < lim; i++ {
		ufp.parent[i], ufp.size[i] = i, 1
	}
	ufp.count = lim
}

func (ufp *UnionFind) validate(p uint32) {
	n := uint32(len(ufp.parent))
	if p >= n {
		panic(fmt.Sprintf("index %d is not between 0 and %d", p, n-1))
	}
}

func (ufp *UnionFind) Count() uint32 {
	return ufp.count
}

func (ufp *UnionFind) Find(p uint32) uint32 {
	// ufp.validate(p)

	root := p
	for root != ufp.parent[root] {
		root = ufp.parent[root]
	}
	for p != root {
		newp := ufp.parent[p]
		ufp.parent[p] = root
		p = newp
	}

	return root
}

func (ufp *UnionFind) Size(p uint32) uint32 {
	return ufp.size[ufp.Find(p)]
}

func (ufp *UnionFind) Connected(p, q uint32) bool {
	return ufp.Find(p) == ufp.Find(q)
}

func (ufp *UnionFind) Union(p, q uint32) {
	rootP := ufp.Find(p)
	rootQ := ufp.Find(q)

	if rootP == rootQ {
		return
	}

	if ufp.size[rootP] < ufp.size[rootQ] {
		ufp.parent[rootP] = rootQ
		ufp.size[rootQ] += ufp.size[rootP]
	} else {
		ufp.parent[rootQ] = rootP
		ufp.size[rootP] += ufp.size[rootQ]
	}

	ufp.count -= 1
}

package main

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

var reader = bufio.NewReader(os.Stdin);
var 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 ...); }

var (
	mm []int
	size []int
)

func main(){
	defer writer.Flush();

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

	mm = make([]int, n+1);
	size = make([]int, n+1);

	for i := 1; i <= n; i++ {
		mm[i] = i;
		size[i] = 1;
	}

	for ; m > 0; m-- {
		var k int;
		scanf("%d", &k);
		root := -1;
		for ; k > 0; k-- {
			var v int;
			scanf("%d", &v);
			if root == -1 {
				root = v;
			} else {
				merge(v, root);
			}
		}
		scanf("\n");
	}

	for i := 1; i <= n; i++ {
		printf("%d ", size[find(i)]);
	}
}

//	finds the root of the union
func find(x int) int {
	if mm[x] == x {
		return x;
	}
	mm[x] = find(mm[x]);
	return mm[x];
}

func merge(x, y int) {
	x, y = find(x), find(y);
	if x != y {
		mm[x] = y;
		size[y] += size[x];
	}
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	g := make([][]int, n+m)
	for i := 0; i < n+m; i++ {
		g[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		k := readInt()
		a := readIntArray(k)
		for _, u := range a {
			u--
			g[n+i] = append(g[n+i], u)
			g[u] = append(g[u], n+i)
		}
	}
	vis := make([]bool, len(g))
	colors := make([]int, len(g))
	colorsSize := make([]int, len(g))
	color := 0
	for i := 0; i < n; i++ {
		if !vis[i] {
			color++
			colorsSize[color] = dfs(g, vis, i, n, colors, color)
		}
	}
	a := make([]string, n)
	for i := 0; i < n; i++ {
		if !vis[i] {
			a[i] = "1"
		} else {
			a[i] = strconv.Itoa(colorsSize[colors[i]])
		}
	}

	fmt.Println(strings.Join(a, " "))
}

func dfs(g [][]int, vis []bool, u int, n int, colors []int, color int) int {
	vis[u] = true
	colors[u] = color
	ans := 0
	if u < n {
		ans++
	}
	for _, v := range g[u] {
		if !vis[v] {
			ans += dfs(g, vis, v, n, colors, color)
		}
	}
	return ans

}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

func max(a, b float64) float64 {
	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"
)

var reader = bufio.NewReader(os.Stdin)
var 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...) }

var mm []int
var size []int

func main() {
	defer writer.Flush()

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

	mm = make([]int, n+1)
	size = make([]int, n+1)

	for i := 1; i <= n; i++ {
		mm[i] = i
		size[i] = 1
	}

	for ; m > 0; m-- {
		var k int
		scanf("%d", &k)

		root := -1
		for ; k > 0; k-- {
			var v int
			scanf("%d", &v)

			if root == -1 {
				root = v
			} else {
				merge(v, root)
			}

		}
		scanf("\n")
	}

	for i := 1; i <= n; i++ {
		printf("%d ", size[find(i)])
	}
}

func find(x int) int {
	if mm[x] == x {
		return x
	}
	mm[x] = find(mm[x])
	return mm[x]
}

func merge(x, y int) {
	x, y = find(x), find(y)
	if x != y {
		mm[x] = y
		size[y] += size[x]
	}
}

package main

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

func dsuGet(p []int, v int) int {
	if v == p[v] {
		return v
	}
	p[v] = dsuGet(p, p[v])
	return p[v]
}

func dsuUnite(p, s []int, a, b int) {
	a = dsuGet(p, a)
	b = dsuGet(p, b)
	if a != b {
		if s[a] < s[b] {
			a, b = b, a
		}
		p[b] = a
		s[a] += s[b]
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)

	p := make([]int, n)
	s := make([]int, n)

	for i := 0; i < n; i++ {
		p[i] = i
		s[i] = 1
	}

	for i := 0; i < m; i++ {
		var k int
		fmt.Fscanf(reader, "%d", &k)
		var f int
		for j := 0; j < k; j++ {
			var c int
			fmt.Fscanf(reader, "%d", &c)
			c--
			if j == 0 {
				f = c
			}
			dsuUnite(p, s, f, c)
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%d ", s[dsuGet(p, i)])
	}

	writer.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	//	"os"
	//	"syscall"
)

func initt(parent []int, count []int) {
	for i := 0; i < len(parent); i++ {
		parent[i] = i
	}
	for i := 0; i < len(count); i++ {
		count[i] = 1
	}
}

func find(parent []int, c int) int {
	if c == parent[c] {
		return c
	}
	parent[c] = find(parent, parent[c])
	return parent[c]
}

func merge(parent []int, count []int, x int, y int) {
	px := find(parent, x)
	py := find(parent, y)

	if px != py {
		parent[px] = py
		count[py] = count[py] + count[px]
	}
}

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

func main() {
	defer writer.Flush()

	n := 0
	m := 0

	// os.Stdin = os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")

	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	parent := make([]int, n+1)
	count := make([]int, n+1)

	initt(parent, count)

	for ; m != 0; m-- {
		k := 0
		first := 0
		fmt.Fscanf(reader, "%d", &k)

		for i := 0; i < k; i++ {
			ki := 0
			fmt.Fscanf(reader, "%d", &ki)
			if i == 0 {
				first = ki
			} else {
				merge(parent, count, first, ki)
			}
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 1; i <= n; i++ {
		str := ""
		if i == n {
			str = "%d\n"
		} else {
			str = "%d "
		}
		fmt.Fprintf(writer, str, count[find(parent, i)])
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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...) }

var mm []map[int]struct{}

func main() {
	defer writer.Flush()

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

	mm = make([]map[int]struct{}, 0)

	for ; m > 0; m-- {
		var k int
		scanf("%d", &k)

		x := make(map[int]struct{})
		for ; k > 0; k-- {
			var v int
			scanf("%d", &v)

			x[v] = struct{}{}
		}
		scanf("\n")

		found := false
		for k, em := range mm {
			for v := range x {
				if _, ok := em[v]; ok {
					for v := range x {
						mm[k][v] = struct{}{}
					}
					found = true
					break
				}
			}
		}

		if !found {
			mm = append(mm, x)
		}
	}

	for i := 1; i <= n; i++ {
		found := false
		for _, v := range mm {
			if _, ok := v[i]; ok {
				found = true
				printf("%d ", len(v))
				break
			}
		}

		if !found {
			printf("0 ")
		}
	}
	printf("\n")
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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...) }

var mm map[int]int

func main() {
	defer writer.Flush()

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

	mm = make(map[int]int)
	ans := make(map[int]map[int]struct{})

	for ; m > 0; m-- {
		var k int
		scanf("%d", &k)

		root := -1
		for ; k > 0; k-- {
			var v int
			scanf("%d", &v)

			if root == -1 {
				root = v
			}
			mm[v] = root
		}
		scanf("\n")
	}

	for k := range mm {
		if _, ok := ans[find(k)]; !ok {
			ans[find(k)] = map[int]struct{}{}
		}
		ans[find(k)][k] = struct{}{}
	}

	for i := 1; i <= n; i++ {
		if _, ok := ans[find(i)]; ok {
			printf("%d ", len(ans[find(i)]))
			continue
		}
		printf("1 ")
	}
	printf("\n")
}

func find(x int) int {
	if mm[x] == x {
		return x
	}
	mm[x] = find(mm[x])
	return mm[x]
}

package main

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

func dsuGet(p []int, v int) int {
	if v == p[v] {
		return v
	}
	p[v] = dsuGet(p, p[v])
	return p[v]
}

func dsuUnite(p, s []int, a, b int) {
	a = dsuGet(p, a)
	b = dsuGet(p, b)
	if a < b {
		if s[a] < s[b] {
			a, b = b, a
		}
		p[b] = a
		s[a] += s[b]
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)

	p := make([]int, n)
	s := make([]int, n)

	for i := 0; i < n; i++ {
		p[i] = i
		s[i] = 1
	}

	for i := 0; i < m; i++ {
		var k int
		fmt.Fscanf(reader, "%d", &k)
		var f int
		for j := 0; j < k; j++ {
			var c int
			fmt.Fscanf(reader, "%d", &c)
			c--
			if j == 0 {
				f = c
			}
			dsuUnite(p, s, f, c)
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%d ", s[dsuGet(p, i)])
	}

	writer.Flush()
}

package main

import (
	"fmt"
)

func initt(parent []int, count []int) {
	for i := 0; i < len(parent); i++ {
		parent[i] = i
	}
	for i := 0; i < len(count); i++ {
		count[i] = 1
	}
}

func find(parent []int, c int) int {
	cp := parent[c]
	if cp != c {
		ca := find(parent, cp)
		parent[cp] = ca
	}
	return parent[cp]
}

func merge(parent []int, count []int, x int, y int) {
	px := find(parent, x)
	py := find(parent, y)

	if px != py {
		parent[px] = py
		count[py] = count[py] + count[px]
	}
}

func main() {
	n := 0
	m := 0
	fmt.Scanf("%d %d\n", &n, &m)
	parent := make([]int, n+1)
	count := make([]int, n+1)

	initt(parent, count)

	for ; m != 0; m-- {
		k := 0
		first := 0
		fmt.Scanf("%d", &k)
		for i := 0; i < k; i++ {
			ki := 0
			fmt.Scanf("%d", &ki)
			if i == 0 {
				first = ki
			} else {
				merge(parent, count, first, ki)
			}
		}
	}

	for i := 1; i <= n; i++ {
		str := ""
		if i == n {
			str = "%d\n"
		} else {
			str = "%d "
		}
		fmt.Printf(str, count[find(parent, i)])
	}
}

package main

import (
	"fmt"
	"os"
	"syscall"
)

func initt(parent []int, count []int) {
	for i := 0; i < len(parent); i++ {
		parent[i] = i
	}
	for i := 0; i < len(count); i++ {
		count[i] = 1
	}
}

func find(parent []int, c int) int {
	cp := parent[c]
	if cp != c {
		ca := find(parent, cp)
		parent[cp] = ca
	}
	return parent[cp]
}

func merge(parent []int, count []int, x int, y int) {
	px := find(parent, x)
	py := find(parent, y)

	if px != py {
		parent[px] = py
		count[py] = count[py] + count[px]
	}
}

func main() {
	n := 0
	m := 0

	os.Stdin = os.NewFile(uintptr(syscall.Stdin), "/dev/stdin")

	fmt.Scanf("%d %d\n", &n, &m)
	parent := make([]int, n+1)
	count := make([]int, n+1)

	initt(parent, count)

	for ; m != 0; m-- {
		k := 0
		first := 0
		fmt.Scanf("%d", &k)
		for i := 0; i < k; i++ {
			ki := 0
			if i == k-1 {
				fmt.Scanf("%d\n", &ki)
			} else {
				fmt.Scanf("%d", &ki)
			}
			if i == 0 {
				first = ki
			} else {
				merge(parent, count, first, ki)
			}
		}
	}

	for i := 1; i <= n; i++ {
		str := ""
		if i == n {
			str = "%d\n"
		} else {
			str = "%d "
		}
		fmt.Printf(str, count[find(parent, i)])
	}
}


In order to celebrate Twice's 5th anniversary, Tzuyu and Sana decided to play a game.Tzuyu gave Sana two integers $$$a$$$ and $$$b$$$ and a really important quest.In order to complete the quest, Sana has to output the smallest possible value of ($$$a \oplus x$$$) + ($$$b \oplus x$$$) for any given $$$x$$$, where $$$\oplus$$$ denotes the bitwise XOR operation.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^{4}$$$). Description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^{9}$$$).

For each testcase, output the smallest possible value of the given expression.

NoteFor the first test case Sana can choose $$$x=4$$$ and the value will be ($$$6 \oplus 4$$$) + ($$$12 \oplus 4$$$) = $$$2 + 8$$$ = $$$10$$$. It can be shown that this is the smallest possible value.

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func solve(a, b int) int {
  res := 0.0
  for i := 0; i < 32; i++ {
    mask := 1 << i
    if a & mask != 0 && b & mask != 0 {
      res += math.Pow(2, float64(i))
    }
  }
  return a^int(res) + b^int(res)
}

func main() {
  defer writer.Flush()
  var test int
  scanf("%d\n", &test)
  for t := 0; t < test; t++ {
    var a, b int
    scanf("%d %d\n", &a, &b)
    printf("%d\n", solve(a, b))
  }
}

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--
		a, b := readTwoNums(reader)
		res := solve(a, b)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	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
}

func solve(a, b int) int {
	x := a & b
	return a ^ x + b ^ x
}

package main

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

func main() {
	var a, b, t int

	scanner := bufio.NewScanner(os.Stdin)

	if scanner.Scan() {
		line := scanner.Text()
		if len(line) > 0 {
			fmt.Sscanf(line, "%d", &t)
		}
	}

	for scanner.Scan() && t > 0 {
		line := scanner.Text()
		if len(line) >  0 {
			fmt.Sscanf(line, "%d %d", &a, &b)
			fmt.Println(a ^ b)
			t -= 1
		}
	}

}

package main

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

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

var T, a, b int

func check(x int, pos int) bool {
	return (x & (1 << pos)) > 0
}
func main() {
	for _, _ = fmt.Fscan(_r, &T); T > 0; T-- {
		_, _ = fmt.Fscan(_r, &a, &b)
		ans := 0
		for i := 0; i <= 30; i++ {
			if check(a, i) && check(b, i) {
				ans = ans | (1 << i)
			}
		}
		_, _ = fmt.Fprintln(_w, (ans^a)+(ans^b))
		_ = _w.Flush()
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b := ReadInt(), ReadInt()
		println(a ^ b)
	}
}

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

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, a, b int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b)
		Fprintln(out, (a^a&b)+(b^a&b))
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, a, b int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b)
		Fprintln(out, a^b)
	}
}

package main

import "fmt"

func main() {
	var a, b, t, ret int
	ret, err := fmt.Scanf("%d", &t)

	if err != nil || ret != 1 {
		fmt.Println("Error:", err)
	}

	for i := 0; i < t; i++ {
		ret, err = fmt.Scanf("%d %d", &a, &b)
		if err == nil && ret == 2 {
			fmt.Println(a ^ b)
		} else {
			fmt.Println("Error:", err)
		}
	}
}


You have a garland consisting of $$$n$$$ lamps. Each lamp is colored red, green or blue. The color of the $$$i$$$-th lamp is $$$s_i$$$ ('R', 'G' and 'B' — colors of lamps in the garland).You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is $$$1$$$) have distinct colors.In other words, if the obtained garland is $$$t$$$ then for each $$$i$$$ from $$$1$$$ to $$$n-1$$$ the condition $$$t_i \ne t_{i + 1}$$$ should be satisfied.Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of lamps. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ characters 'R', 'G' and 'B' — colors of lamps in the garland.

In the first line of the output print one integer $$$r$$$ — the minimum number of recolors needed to obtain a diverse garland from the given one. In the second line of the output print one string $$$t$$$ of length $$$n$$$ — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

package main

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

var (

)

func to(t byte) int {
	if t == 'R' {
		return 0
	} else if t == 'B' {
		return 1
	} else {
		return 2
	}
}
func next(v int) {

}
func solveD(s []byte, n int,dp,from [][]int) {
	dp[0][0] = 1
	dp[0][1] = 1
	dp[0][2] = 1
	dp[0][to(s[0])] = 0;
	for i := 1; i < n; i++ {
		for j := 0; j < 3; j++ {
			add := 0
			if j != to(s[i]) {
				add++
			}
			pre1 := (j + 1) % 3
			pre2 := (pre1 + 1) % 3
			if dp[i-1][pre1] < dp[i-1][pre2] {
				dp[i][j] = dp[i-1][pre1] + add
				from[i][j] = pre1
			} else {
				dp[i][j] = dp[i-1][pre2] + add
				from[i][j] = pre2
			}
		}
	}
}
func toC(v int)byte  {
	if v == 0{
		return 'R'
	}else if v==1{
		return 'B'
	}else {
		return 'G'
	}
}
func anstr(pre,n int,from [][]int) []byte {
	res := make([]byte,n)
	for i:= n-1;i >= 0;i--{
		res[i] = toC(pre)
		pre = from[i][pre]
	}
	return res
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	str := make([]byte, n+1)
	fmt.Fscanf(buf, "%s\n", &str)

	dp :=make([][]int,n)
	from := make([][]int,n)
	for i:= 0;i < n;i++{
		dp[i] = make([]int,3)
		from[i] = make([]int,3)
	}

	solveD(str,n,dp,from)
	end := 0
	for i:= 1;i < 3;i++{
		if dp[n-1][end] > dp[n-1][i]{
			end = i
		}
	}
	fmt.Printf("%d\n", dp[n-1][end])
	fmt.Printf("%s\n", anstr(end,n,from))
}

package main

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

var (
	idToC = []rune{rune('S'), rune('R'), rune('G'), rune('B')}
	cToId = map[rune]int{rune('R'): 1, rune('G'): 2, rune('B'): 3}
)

func gotXor(a rune, b rune) rune {
	aid := cToId[a]
	bid := cToId[b]
	return idToC[aid^bid]
}

func gotNext(a rune) rune {
	aid := cToId[a]
	naid := aid + 1
	if naid > 3 {
		naid = 1
	}
	return idToC[naid]
}

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

	var n int
	fmt.Fscanln(reader, &n)
	rs, _ := reader.ReadString('\n')
	s := []rune(rs)

	m := 0
	i := 0
	for i < n-1 {
		if s[i] == s[i+1] {
			m++
			if i < n-2 {
				if s[i] != s[i+2] {
					s[i+1] = gotXor(s[i], s[i+2])
				} else {
					s[i+1] = gotNext(s[i])
				}
				i += 2
			} else {
				s[i+1] = gotNext(s[i])
				break
			}
		} else {
			i++
		}
	}
	fmt.Println(m)
	fmt.Println(string(s))
}

package main

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

var in = bufio.NewReaderSize(os.Stdin, 2<<16)
var st = [3]byte{'R', 'G', 'B'}

func main() {
	var n int
	fmt.Fscan(in, &n)
	var ans = make([]byte, n, n)
	fmt.Fscan(in, &ans)
	cnt := 0
	for i := 0; i < len(ans)-1; i++ {
		if ans[i] == ans[i+1] {
			for _, ch := range st {
				if ch != ans[i] && ((i != len(ans)-2 && ch != ans[i+2]) || i == len(ans)-2) {
					ans[i+1] = ch
					cnt++
					break
				}
			}
		}
	}
	fmt.Printf("%d\n%s\n", cnt, ans)
}

package main

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

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	var s [2e5 + 10]int
	var ss string
	//t := time.Now()
	//fmt.Println(t)
	//fmt.Scanf("%s", &ss)
	ss, _ = ReadLine()

	for i := 0; i < T; i++ {
		//var c int
		//fmt.Scanf("%c", &c)
		c := ss[i]
		if c == 'R' {
			s[i] = 0
		} else if c == 'G' {
			s[i] = 1
		} else if c == 'B' {
			s[i] = 2
		}
	}
	//t = time.Now()
	//fmt.Println(t)
	ans := 0
	for e := range ss {
		if e == 0 {
			continue
		}

		if s[e] == s[e-1] {
			ans ++
			s[e] = change(&s, e, T)
		}
	}

	fmt.Printf("%d\n", ans)
	for i := 0; i < T; i++ {
		if s[i] == 0 {
			fmt.Printf("R")
		}
		if s[i] == 1 {
			fmt.Printf("G")
		}
		if s[i] == 2 {
			fmt.Printf("B")
		}
	}
	fmt.Printf("\n")
	//t = time.Now()
	//fmt.Println(t)
}

func ReadLine() (string, error) {
	line, err := bufio.NewReader(os.Stdin).ReadString('\n')
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(string(line)), nil
}

func change(s *[2e5 + 10]int, e int, leng int) int {
	cc := []int{0, 0, 0}
	cc[s[e-1]] = 1
	if e+1 < leng {
		cc[s[e+1]]=1
	}
	for e := range cc {
		if cc[e] == 0{
			return e
		}
	}
	return 0
}


Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.Vova's character has h1 health points and an attack power of a1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c1 > a2.The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1) or drink a healing potion (it increases Vova's health by c1; Vova's health can exceed h1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack.Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.

The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion. The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1) — the Modcrab's health and his attack power.

In the first line print one integer n denoting the minimum number of phases required to win the battle. Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab. The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action. If there are multiple optimal solutions, print any of them.

NoteIn the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win.In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.

package main
import "fmt"

func main(){
	var h1,a1,c1,h2,a2 int
	fmt.Scan(&h1, &a1, &c1, &h2, &a2)
	save:= make([]string,10000)
	var c int

	for h2>0 {
		if h1>a2 {
			save[c]="STRIKE"
			c++
			h2-=a1
			h1-=a2
		} else {
			if a1>=h2 {
				save[c]="STRIKE"
				c++
				h2-=a1
				h1-=a2
				break
			} else {
				save[c]="HEAL"
				c++
				h1+=c1
				h1-=a2
			}
		}
	}
	fmt.Println(c)
	for i:=0;i<c;i++ {
		fmt.Println(save[i])
	}
}

package main

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

func solve() {
	h1 := readInt()
	a1 := readInt()
	c1 := readInt()
	h2 := readInt()
	a2 := readInt()

	for i := 0; ; i++ {
		a, v := runGame(h1, a1, c1, h2, a2, i)
		if !v {
			continue
		}
		fmt.Println(len(a))
		for _, isattack := range a {
			if isattack {
				fmt.Println("STRIKE")
			} else {
				fmt.Println("HEAL")
			}
		}
		break
	}
}

func runGame(h1, a1, c1, h2, a2, nheals int) (attacks []bool, success bool) {
	attacks = make([]bool, 0, 1000)
	for {
		if nheals > 0 {
			// Heal
			h1 += c1
			attacks = append(attacks, false)
			nheals--
		} else {
			// Attack
			h2 -= a1
			attacks = append(attacks, true)
		}

		// monster dies
		if h2 <= 0 {
			return attacks, true
		}

		// monster attacks
		h1 -= a2
		if h1 <= 0 {
			return attacks, false
		}
	}
}

var scanner *bufio.Scanner

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	var h1, a1, c1, h2, a2 int
	fmt.Scan(&h1, &a1, &c1)
	fmt.Scan(&h2, &a2)
	var ans []string
	for h2 > 0 {
		if h1 <= a2 && h2 > a1 {
			h1 += c1
			h1 -= a2
			ans = append(ans, "HEAL")
		} else {
			h2 -= a1
			h1 -= a2
			ans = append(ans, "STRIKE")
		}
	}
	fmt.Println(len(ans))
	for _, val := range ans {
		fmt.Println(val)
	}
}

package main

import "fmt"

var ans []string
var h1, a1, c1, h2, a2, ret int

func main() {
  fmt.Scan(&h1)
  fmt.Scan(&a1)
  fmt.Scan(&c1)
  fmt.Scan(&h2)
  fmt.Scan(&a2)
  for true {
    ret++
    if a1 >= h2 {
      ans = append(ans, "STRIKE")
      break
    }
    if a2 >= h1 {
      ans = append(ans, "HEAL")
      h1 += c1 - a2
    } else {
      ans = append(ans, "STRIKE")
      h1 -= a2
      h2 -= a1
    }
  }
  fmt.Println(ret)
  for i := 0; i < ret; i++ {
    fmt.Println(ans[i])
  }
}

package main
import (
    "fmt"
)

func printResult(vec []string) {
    fmt.Println(len(vec))
    for _, a := range(vec) {
        fmt.Println(a)
    }
}

func main() {
    var H1, a1, c1 int
    fmt.Scan(&H1, &a1, &c1);
    var H2, a2 int;
    fmt.Scan(&H2, &a2);

    h1 := H1
    h2 := H2
    vec := make([]string, 0)
    for {
        switch {
            case a1 >= h2: // last attack
                vec = append(vec, "STRIKE")
                printResult(vec)
                return;
            case a2 >= h1: // heal
                vec = append(vec, "HEAL")
                h1 += c1
                h1 -= a2; // be attacked
            default: // normal attack
                vec = append(vec, "STRIKE");
                h2 -= a1;
                h1 -= a2;
        }
    }

}

package main
import (
    "fmt"
)

func getResult(vec []string, c chan string) {
    str := fmt.Sprintln(len(vec))
    for _, a := range(vec) {
        str += fmt.Sprintln(a)
    }
    c <- str
}

func main() {
    var H1, a1, c1 int
    fmt.Scan(&H1, &a1, &c1);
    var H2, a2 int;
    fmt.Scan(&H2, &a2);

    h1 := H1
    h2 := H2
    vec := make([]string, 0)
    for {
        switch {
            case a1 >= h2: // last attack
                vec = append(vec, "STRIKE")
                c := make(chan string)
                go getResult(vec, c)
                fmt.Println(<-c)
                return;
            case a2 >= h1: // heal
                vec = append(vec, "HEAL")
                h1 += c1
                h1 -= a2; // be attacked
            default: // normal attack
                vec = append(vec, "STRIKE");
                h2 -= a1;
                h1 -= a2;
        }
    }

}

package main
import (
    "fmt"
    "bytes"
)

func getResult(vec []string, c chan string) {
    var buf bytes.Buffer
    buf.WriteString(fmt.Sprintln(len(vec)))
    for _, a := range(vec) {
        buf.WriteString(fmt.Sprintln(a))
    }
    //c <- string(buf.Bytes())
    c <- buf.String()
}

func main() {
    var H1, a1, c1 int
    fmt.Scan(&H1, &a1, &c1);
    var H2, a2 int;
    fmt.Scan(&H2, &a2);

    h1 := H1
    h2 := H2
    vec := make([]string, 0)
    for {
        switch {
            case a1 >= h2: // last attack
                vec = append(vec, "STRIKE")
                c := make(chan string)
                go getResult(vec, c)
                fmt.Println(<-c)
                return;
            case a2 >= h1: // heal
                vec = append(vec, "HEAL")
                h1 += c1
                h1 -= a2; // be attacked
            default: // normal attack
                vec = append(vec, "STRIKE");
                h2 -= a1;
                h1 -= a2;
        }
    }

}

//  URL: http://codeforces.com/contest/903/problem/B
//  ~ Greedy Implementation Problem

package main

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

func solve(h1 int, a1 int, c1 int, h2 int, a2 int) []string {
	var actions = []string{}
	for h2 > 0 {
		if h1 <= a2 && h2 > a1 {
			actions = append(actions, "HEAL")
			h1 += c1
		} else {
			actions = append(actions, "STRIKE")
			h2 -= a1
		}
		h1 -= a2
	}
	return actions
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var h1, a1, c1 int
	fmt.Fscanf(reader, "%d %d %d\n", &h1, &a1, &c1)
	var h2, a2 int
	fmt.Fscanf(reader, "%d %d\n", &h2, &a2)
	actions := solve(h1, a1, c1, h2, a2)
	fmt.Fprintf(writer, "%d\n", len(actions))
	for i := 0; i < len(actions); i++ {
		fmt.Fprintf(writer, "%s\n", actions[i])
	}
}

package main
import "fmt"

func main(){
	var h1,a1,c1,h2,a2 int
	fmt.Scan(&h1, &a1, &c1, &h2, &a2)
	save:= make([]string,100)
	var c int
	h:=h1

	for h2>0 {
		if h1>a2 {
			save[c]="STRIKE"
			c++
			h2-=a1
			h1-=a2
		} else if h1<=a2 {
			if a1>=h2 {
				save[c]="STRIKE"
				c++
				break
			} else {
				save[c]="HEAL"
				c++
				if h1+c1>=h {
					h1=h
				} else {h1+=c1}
			}
		}
	}
	fmt.Println(c)
	for i:=0;i<c;i++ {
		fmt.Println(save[i])
	}
}

package main

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

func solve() {
	h1 := readInt()
	a1 := readInt()
	c1 := readInt()
	h2 := readInt()
	a2 := readInt()

	for i := 0; ; i++ {
		a, v := runGame(h1, a1, c1, h2, a2, i)
		if !v {
			continue
		}
		for _, isattack := range a {
			if isattack {
				fmt.Println("STRIKE")
			} else {
				fmt.Println("HEAL")
			}
		}
		break
	}
}

func runGame(h1, a1, c1, h2, a2, nheals int) (attacks []bool, success bool) {
	attacks = make([]bool, 0, 1000)
	for {
		if nheals > 0 {
			// Heal
			h1 += c1
			attacks = append(attacks, false)
			nheals--
		} else {
			// Attack
			h2 -= a1
			attacks = append(attacks, true)
		}

		// monster dies
		if h2 <= 0 {
			return attacks, true
		}

		// monster attacks
		h1 -= a2
		if h1 <= 0 {
			return attacks, false
		}
	}
}

var scanner *bufio.Scanner

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	var h1, a1, c1, h2, a2 int
	fmt.Scan(&h1, &a1, &c1)
	fmt.Scan(&h2, &a2)
	var ans []string
	for h2 >= 0 {
		if h1 <= a2 {
			h1 += c1
			h1 -= a2
			ans = append(ans, "HEAL")
		} else {
			h2 -= a1
			h1 -= a2
			ans = append(ans, "STRIKE")
		}
	}
	fmt.Println(len(ans))
	for _, val := range ans {
		fmt.Println(val)
	}
}

package main

import (
	"fmt"
)

func main() {
	var h1, a1, c1, h2, a2 int
	fmt.Scan(&h1, &a1, &c1)
	fmt.Scan(&h2, &a2)
	var ans []string
	for h2 > 0 {
		if h1 <= a2 {
			h1 += c1
			h1 -= a2
			ans = append(ans, "HEAL")
		} else {
			h2 -= a1
			h1 -= a2
			ans = append(ans, "STRIKE")
		}
	}
	fmt.Println(len(ans))
	for _, val := range ans {
		fmt.Println(val)
	}
}


You are given an array $$$a_1, a_2, \dots, a_n$$$. You can perform operations on the array. In each operation you can choose an integer $$$i$$$ ($$$1 \le i < n$$$), and swap elements $$$a_i$$$ and $$$a_{i+1}$$$ of the array, if $$$a_i + a_{i+1}$$$ is odd.Determine whether it can be sorted in non-decreasing order using this operation any number of times.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print "Yes" or "No" depending on whether you can or can not sort the given array. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

NoteIn the first test case, we can simply swap $$$31$$$ and $$$14$$$ ($$$31 + 14 = 45$$$ which is odd) and obtain the non-decreasing array $$$[1,6,14,31]$$$.In the second test case, the only way we could sort the array is by swapping $$$4$$$ and $$$2$$$, but this is impossible, since their sum $$$4 + 2 = 6$$$ is even.In the third test case, there is no way to make the array non-decreasing.In the fourth test case, the array is already non-decreasing.

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var odd, even []int

		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				odd = append(odd, x)
			} else {
				even = append(even, x)
			}
		}

		if ok(odd) && ok(even) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var odd, even []int

		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				odd = append(odd, x)
			} else {
				even = append(even, x)
			}
		}

		if ok(odd) && ok(even) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		flag := true
		odd := 0
		even := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if !flag {
				continue
			}

			if x&1 == 1 {
				if odd > x {
					flag = false
				} else {
					odd = x
				}
			} else {
				if even > x {
					flag = false
				} else {
					even = x
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} 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, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		flag := true
		odd := 0
		even := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				if odd > x {
					flag = false
				} else {
					odd = x
				}
			} else {
				if even > x {
					flag = false
				} else {
					even = x
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a, b := make([]int, n), make([]int, n)
		for i := 0; i < n; i++{
			var x int
			Fscan(r, &x)
			if x%2 != 0 {
				a = append(a, x)
			} else {
				b = append(b, x)
			}
		}
		if sort.IntsAreSorted(a) && sort.IntsAreSorted(b) {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

//B.

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-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		var curMaxOdd, curMaxEven int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		var isNo bool
		for i := 0; i < n; i++ {
			if numsA[i]&1 == 1 {
				if numsA[i] < curMaxOdd {
					fmt.Fprintln(out, "No")
					isNo = true
					break
				}
				curMaxOdd = max(curMaxOdd, numsA[i])
			} else {
				if numsA[i] < curMaxEven {
					fmt.Fprintln(out, "No")
					isNo = true
					break
				}
				curMaxEven = max(curMaxEven, numsA[i])
			}
		}
		if isNo == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

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

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 f bool
		var maxE, maxO int
		for i := 0; i < n; i++ {
			if arr[i]%2 == 0 {
				if arr[i] < maxE {
					f = false
					break
				}

				maxE = arr[i]
			}

			if arr[i]%2 != 0 {
				if arr[i] < maxO {
					f = false
					break
				}

				maxO = arr[i]
			}
			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

package main

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

var a [1e5 + 5]int

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	var t, n int
	var flag bool
	var Odd, Even int
	for t = read(); t > 0; t-- {
		n = read()
		flag = false
		Odd, Even = 0, 0
		for i := 1; i <= n; i++ {
			a[i] = read()
		}
		for i := 1; i <= n; i++ {
			if a[i]&1 == 1 {
				if a[i] < Odd {
					flag = true
					break
				}
				Odd = a[i]
			} else {
				if a[i] < Even {
					flag = true
					break
				}
				Even = a[i]
			}
		}
		if flag {
			Fprintln(out, "No")
		} else {
			Fprintln(out, "Yes")
		}
	}
}

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

//nolint
package main

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

func Main() {
	var t, n, tp int
	scan(&t)
	for ; t > 0; t-- {
		maxOdd, maxEven := 0, 0
		scan(&n)
		possible := true
		for ; n > 0; n-- {
			scan(&tp)
			if tp%2 == 1 {
				if tp >= maxOdd {
					maxOdd = tp
				} else {
					possible = false
				}
				continue
			}
			if tp >= maxEven {
				maxEven = tp
			} else {
				possible = false
			}
		}
		if possible {
			println("yes")
		} else {
			println("no")
		}
	}
}

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

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

func main() {
	defer writer.Flush()

	Main()
}

package main

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

/*
5
1
1
2
1 2
2
2 1
3
1 2 3
3
3 2 1
---
YES
YES
YES
YES
NO
=======
6
4
3 5 1 4
4
4 3 2 1
4
2 4 6 4
5
5 2 5 4 1
4
1 2 2 1
4
1 3 3 1
---
NO
NO
NO
?
YES
NO

1 2 4 5 5

5
5
1 4 2 4 1
5
1 4 1 4 1
5
1 1 3 3 1
5
1 1 3 8 1
5
1 1 2 3 1
---
NO - 1 1 2 4 4
YES - 1 1 1 4 4
NO
NO
NO - 1 1 1 2 3
*/

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

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		ans := "YES"

		prevOdd := -1
		prevEven := -1

		for _, num := range a {
			if (num%2 != 0 && num < prevOdd) || (num%2 == 0 && num < prevEven) {
				ans = "NO"
				break
			}

			if num%2 != 0 {
				prevOdd = num
			}

			if num%2 == 0 {
				prevEven = num
			}
		}

		fmt.Fprintln(writer, ans)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

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

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

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

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

func main(){
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)

	defer write.Flush()

    var tc int
    Fscanf(read, "%d\n", &tc)

    for tt := 0; tt < tc; tt++ {
        var n int
        Fscanf(read, "%d\n", &n)

        ok := true
        last_odd, last_even := 0, 0
        for i := 0; i < n; i++ {
            var val int
            Fscanf (read, "%d", &val)
            if val % 2 == 1 {
                if val < last_odd {
                    ok = false
                } else {
                    last_odd = val
                }
            } else{
                if val < last_even {
                    ok = false
                } else {
                    last_even = val
                }
            }
        }
        Fscanf(read, "\n")
        if ok {
            Fprintln(write, "Yes")
        } else{
            Fprintln(write, "No")
        }
    }

}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt(in)
	for ; t != 0; t-- {
		solve()
	}
}

func solve() {
	n := readInt(in)
	a := readArrInt(in)
	last := 0
	flag := true
	for i := 0; i < n; i++ {
		if a[i]%2 == 0 {
			if a[i] >= last {
				last = a[i]
			} else {
				flag = false
			}
		}
	}
	last = 0
	for i := 0; i < n; i++ {
		if a[i]%2 == 1 {
			if a[i] >= last {
				last = a[i]
			} else {
				flag = false
			}
		}
	}
	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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"
	"io"
	"os"
)

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

	var n, t int
	arr := make([]int, int(1e5))
Outer:
	for Fscan(in, &t); t > 0; t-- {
		odd, even := -1, -1
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		for i := 0; i < n; i++ {
			if arr[i]&1 == 1 {
				if arr[i] < odd {
					Fprintln(out, "No")
					continue Outer
				}
				odd = arr[i]
			} else {
				if arr[i] < even {
					Fprintln(out, "No")
					continue Outer
				}
				even = arr[i]
			}
		}
		Fprintln(out, "Yes")
	}
}

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

package main

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

var rdr *bufio.Reader = bufio.NewReader(os.Stdin)
var wr *bufio.Writer = bufio.NewWriter(os.Stdout)

func Printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func Scanf(f string, a ...interface{}) {
	fmt.Fscanf(rdr, f, a...)
}

func Flush() {
	wr.Flush()
}

func main() {
	defer Flush()

	var t, n, ib, pb, x int;
	var able bool;
	Scanf("%d\n", &t);

	for ab := 0; ab < t; ab++{
		Scanf("%d\n", &n);
		ib, pb = -1, -1;
		able = true;

		for i := 0; i < n - 1; i++{
			Scanf("%d ", &x);
			if((x & 1) == 1){
				if(ib > x){
					able = false;
				}
				ib = x;
			}else{
				if(pb > x){
					able = false;
				}
				pb = x;
			}
		}

		Scanf("%d\n", &x);
		if((x & 1) == 1){
			if(ib > x){
				able = false;
			}
			ib = x;
		}else{
			if(pb > x){
				able = false;
			}
			pb = x;
		}

		if(able){
			Printf("yes\n");
		} else{
			Printf("no\n");
		}
	}
}

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var odd, even []int

		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				odd = append(odd, x)
			} else {
				even = append(even, x)
			}
		}

		if ok(odd) && ok(even) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

package main

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

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

	var t, n, x int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		flag := true
		odd := 0
		even := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x)
			if x&1 == 1 {
				if odd > x {
					flag = false
				} else {
					odd = x
				}
			} else {
				if even > x {
					flag = false
				} else {
					even = x
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var q, n int
	fmt.Scanf("%d", &q)
	for i := 0; i < q; i++ {
		fmt.Scanf("%d", &n)
		var x int
		var odd []int
		var even []int
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &x)
			if x%2 == 0 {
				even = append(even, x)
			} else {
				odd = append(odd, x)
			}
		}

		if check(odd) && check(even) {
			fmt.Println("YES")
		} else {
			fmt.Println("No")
		}
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var q, n int
	var a [100001]int

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

		flag := true
		odd := -1
		even := -2
		for j := 0; j < n && flag; j++ {
			if a[j]&1 == 1 {
				if even > a[j] {
					flag = false
				} else {
					odd = a[j]
				}
			} else {
				if odd > a[j] {
					flag = false
				} else {
					even = a[j]
				}
			}
		}

		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {
						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					if i >= 2 && a[i-2] > a[i-1] {
						f = false
						break
					}
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		//if n == 2 {
		//	if  a[0] > a[1] {
		//		if (a[0]+a[1])%2 == 0{
		//			Fprintln(w, "No")
		//		} else {
		//			Fprintln(w, "Yes")
		//		}
		//		continue
		//	}
		//	if a[0] <= a[1] {
		//		Fprintln(w, "Yes")
		//		continue
		//	}
		//}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {
						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		if n == 2 {
			if (a[0]+a[1])%2 == 0 && a[0] > a[1] {
				Fprintln(w, "No")
				continue
			}
			if a[0] <= a[1] {
				Fprintln(w, "Yes")
				continue
			}
		}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {
						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		if n == 1 {
			Fprintln(w, "Yes")
			continue
		}
		if n == 2 {
			if (a[0]+a[1])%2 == 0 && a[0] > a[1] {
				Fprintln(w, "No")
				continue
			}
			if a[0] <= a[1] {
				Fprintln(w, "Yes")
				continue
			}
		}
		f := true
		s := make([]bool, n)
		for i := 1; i < n; i++ {
			if a[i-1] > a[i] {
				if (a[i-1]+a[i])%2 == 0 {
					f = false
					break
				} else {
					if s[i-1] {

						f = false
						break
					}
					a[i-1], a[i] = a[i], a[i-1]
					s[i] = true
				}
			}
		}
		if f {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(r, &a[i])
		}
		if n == 1 {
			Fprintln(w, "Yes")
			continue
		}
		if n == 2 {
			if (a[0]+a[1])%2 == 0 && a[0] > a[1] {
				Fprintln(w, "No")
				continue
			}
			if a[0] <= a[1] {
				Fprintln(w, "Yes")
				continue
			}
		}
		f1 := true
		//f2 := true
		//for i := 0; i < n; i+=2 {
		//	if i + 1 < n {
		//		if a[i] > a[i+1] && (a[i] + a[i+1]) %2 == 0 {
		//			f1 = false
		//			break
		//		}
		//	}
		//}
		//
		//for i := 1; i < n; i+=2 {
		//	if i + 1 < n {
		//		if a[i] > a[i+1] && (a[i] + a[i+1]) %2 == 0 {
		//			f2 = false
		//			break
		//		}
		//	}
		//}
		for i := 1; i <= n-2; i++ {
			if a[i] < a[i-1] && a[i] < a[i + 1] && a[i-1] > a[i+1] {
				f1 = false
				break
			}
			if a[i] < a[i-1] && (a[i] + a[i-1])%2==0{

				f1 = false
			}
			if a[i] > a[i+1] && (a[i] + a[i+1])%2==0{
				f1 = false
			}
		}
		if f1  {
			Fprintln(w, "Yes")
		} else {
			Fprintln(w, "No")
		}
	}

}

//B.

//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//	"sort"
//)
//
//func main() {
//	in := bufio.NewReader(os.Stdin)
//	out := bufio.NewWriter(os.Stdout)
//	defer out.Flush()
//
//	var t int
//	fmt.Fscan(in, &t)
//	for ; t > 0; t-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		evenCnt := make([]int, n+1)
//		oddCnt := make([]int, n+1)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		for i := 0; i < n; i++ {
//			evenCnt[i+1] = evenCnt[i]
//			oddCnt[i+1] = oddCnt[i]
//			if numsB[i]&1 == 0 {
//				evenCnt[i+1]++
//			} else {
//				oddCnt[i+1]++
//			}
//		}
//		var flag bool
//		for i:=0;i<n;i++{
//			if numsA[i] == numsB[i] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "Yes")
//		}
//	}
//}

//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//	"sort"
//)
//
//func main() {
//	in := bufio.NewReader(os.Stdin)
//	out := bufio.NewWriter(os.Stdout)
//	defer out.Flush()
//
//	var t int
//	fmt.Fscan(in, &t)
//	for ; t > 0; t-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		var a, b int
//		var flag bool
//		for ; a < n && flag == false; a++ {
//			if numsA[a] == numsB[b] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "Yes")
//		}
//	}
//}

//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//	"sort"
//)
//
//func main() {
//	in := bufio.NewReader(os.Stdin)
//	out := bufio.NewWriter(os.Stdout)
//	defer out.Flush()
//
//	var t int
//	fmt.Fscan(in, &t)
//	for ; t > 0; t-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		copy(numsB, numsA)
//		visB := make([]bool, n)
//		sort.Ints(numsB)
//		var a, b int
//		var flag bool
//		for ; a < n && flag == false; a++ {
//			if numsA[a] == numsB[b] {
//				visB[b] = true
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					visB[p] = true
//					break
//				}
//				if visB[p] == false && numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "Yes")
//		}
//	}
//}

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		numsB := make([]int, n)
		copy(numsB, numsA)
		visB := make([]bool, n)
		sort.Ints(numsB)
		var a, b int
		var flag bool
		for ; a < n && flag == false; a++ {
			if numsA[a] == numsB[b] {
				visB[b] = true
				for b < n && visB[b] == true {
					b++
				}
				continue
			}
			p := sort.SearchInts(numsB, numsA[a]) - 1
			visB[p+1] = true
			for ; p >= b; p-- {
				if visB[p] == true {
					continue
				}
				if (numsB[p]+numsA[a])&1 == 0 {
					fmt.Fprintln(out, "No")
					flag = true
					break
				}
			}
		}
		if flag == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

//B.

//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//	"sort"
//)
//
//func main() {
//	in := bufio.NewReader(os.Stdin)
//	out := bufio.NewWriter(os.Stdout)
//	defer out.Flush()
//
//	var t int
//	fmt.Fscan(in, &t)
//	for ; t > 0; t-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		evenCnt := make([]int, n+1)
//		oddCnt := make([]int, n+1)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		for i := 0; i < n; i++ {
//			evenCnt[i+1] = evenCnt[i]
//			oddCnt[i+1] = oddCnt[i]
//			if numsB[i]&1 == 0 {
//				evenCnt[i+1]++
//			} else {
//				oddCnt[i+1]++
//			}
//		}
//		var flag bool
//		for i:=0;i<n;i++{
//			if numsA[i] == numsB[i] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "Yes")
//		}
//	}
//}

//package main
//
//import (
//	"bufio"
//	"fmt"
//	"os"
//	"sort"
//)
//
//func main() {
//	in := bufio.NewReader(os.Stdin)
//	out := bufio.NewWriter(os.Stdout)
//	defer out.Flush()
//
//	var t int
//	fmt.Fscan(in, &t)
//	for ; t > 0; t-- {
//		var n int
//		fmt.Fscan(in, &n)
//		numsA := make([]int, n)
//		for i := 0; i < n; i++ {
//			fmt.Fscan(in, &numsA[i])
//		}
//		numsB := make([]int, n)
//		copy(numsB, numsA)
//		sort.Ints(numsB)
//		var a, b int
//		var flag bool
//		for ; a < n && flag == false; a++ {
//			if numsA[a] == numsB[b] {
//				b++
//				continue
//			}
//			for p := b; p < n; p++ {
//				if numsB[p] == numsA[a] {
//					break
//				}
//				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
//					fmt.Fprintln(out, "No")
//					flag = true
//					break
//				}
//			}
//		}
//		if flag == false {
//			fmt.Fprintln(out, "Yes")
//		}
//	}
//}

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		numsB := make([]int, n)
		copy(numsB, numsA)
		visB := make([]bool, n)
		sort.Ints(numsB)
		var a, b int
		var flag bool
		for ; a < n && flag == false; a++ {
			if numsA[a] == numsB[b] {
				visB[b] = true
				b++
				continue
			}
			for p := b; p < n; p++ {
				if numsB[p] == numsA[a] {
					visB[p] = true
					break
				}
				if visB[p] == false && numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
					fmt.Fprintln(out, "No")
					flag = true
					break
				}
			}
		}
		if flag == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

//B.

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		numsA := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &numsA[i])
		}
		numsB := make([]int, n)
		copy(numsB, numsA)
		sort.Ints(numsB)
		var a, b int
		var flag bool
		for ; a < n && flag == false; a++ {
			if numsA[a] == numsB[b] {
				b++
				continue
			}
			for p := b; p < n; p++ {
				if numsB[p] == numsA[a] {
					break
				}
				if numsB[p] < numsA[a] && (numsB[p]+numsA[a])&1 == 0 {
					fmt.Fprintln(out, "No")
					flag = true
					break
				}
			}
		}
		if flag == false {
			fmt.Fprintln(out, "Yes")
		}
	}
}

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 f bool
		for i := 0; i < n-1; i++ {
			if arr[i]%2 == 0 && arr[i+1]%2 == 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if arr[i]%2 != 0 && arr[i+1]%2 != 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if arr[i] > arr[i+1] && (arr[i]+arr[i+1])%2 != 0 {
				arr[i], arr[i+1] = arr[i+1], arr[i]

				if i > 0 && arr[i] < arr[i-1] {
					f = false
					break
				}
			}

			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

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 f bool
		for i := 0; i < n-1; i++ {
			if arr[i]%2 == 0 && arr[i+1]%2 == 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if arr[i]%2 != 0 && arr[i+1]%2 != 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if arr[i] > arr[i+1] && (arr[i]+arr[i+1])%2 != 0 {
				arr[i], arr[i+1] = arr[i+1], arr[i]
			}

			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

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 f bool
		for i := 0; i < n-1; i++ {
			if arr[i]%2 == 0 && arr[i+1]%2 == 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if arr[i]%2 != 0 && arr[i+1]%2 != 0 && arr[i] > arr[i+1] {
				f = false
				break
			}

			if i < n-2 && arr[i] > arr[i+2] {
				f = false
				break
			}

			f = true
		}

		if !f {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
}

package main

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

var a [1e5 + 5]int

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	var t, n int
	var flag bool
	Odd, Even := 0, 0
	for t = read(); t > 0; t-- {
		n = read()
		flag = false
		for i := 1; i <= n; i++ {
			a[i] = read()
		}
		for i := 1; i <= n; i++ {
			if a[i]&1 == 1 {
				if a[i] < Odd {
					flag = true
					break
				}
				Odd = a[i]
			} else {
				if a[i] < Even {
					flag = true
					break
				}
				Even = a[i]
			}
		}
		if flag {
			Fprintln(out, "No")
		} else {
			Fprintln(out, "Yes")
		}
	}
}

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

package main

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

var a [1e5 + 5]int

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	var t, n int
	flag := false
	Odd, Even := 0, 0
	for t = read(); t > 0; t-- {
		n = read()
		for i := 1; i <= n; i++ {
			a[i] = read()
		}
		for i := 1; i <= n; i++ {
			if a[i]&1 == 1 {
				if a[i] < Odd {
					flag = true
					break
				}
				Odd = a[i]
			} else {
				if a[i] < Even {
					flag = true
					break
				}
				Even = a[i]
			}
		}
		if flag {
			Fprintln(out, "No")
		} else {
			Fprintln(out, "Yes")
		}
	}
}

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

//nolint
package main

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

// main execution here...
func do() {
	var t, n, tp int
	scan(&t)
	for ; t > 0; t-- {
		maxOdd, maxEven := 0, 0
		scan(&n)
		for i := 0; i < n; i++ {
			scan(&tp)
			if tp%2 == 0 {
				if tp >= maxOdd {
					maxOdd = tp
				} else {
					println("no")
					break
				}
				continue
			}
			if tp >= maxEven {
				maxEven = tp
			} else {
				println("no")
				break
			}
		}
		println("yes")
	}
}

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

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

func main() {
	defer writer.Flush()

	do()
}

package main

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

/*
5
1
1
2
1 2
2
2 1
3
1 2 3
3
3 2 1
---
YES
YES
YES
YES
NO
=======
6
4
3 5 1 4
4
4 3 2 1
4
2 4 6 4
5
5 2 5 4 1
4
1 2 2 1
4
1 3 3 1
---
NO
NO
NO
?
YES
NO

1 2 4 5 5

2
5
1 4 2 4 1
5
1 4 1 4 1
5
1 1 3 3 1
5
1 1 3 8 1
5
1 1 2 3 1
---
YES - 1 1 2 4 4
YES - 1 1 1 4 4
NO
NO
NO - 1 1 1 2 3
*/

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

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)
		sa := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
			sa[i] = a[i]
		}
		scanf("\n")

		sort.Ints(sa)

		ans := "YES"

		l := 0
		for ; l < n; l++ {
			if a[l] != sa[l] {
				break
			}
		}

		r := n - 1
		for ; r >= 0; r-- {
			if a[r] != sa[r] {
				break
			}
		}

		for i := l + 1; i <= r; i++ {
			if (a[l]+a[i])%2 == 0 {
				ans = "NO"
			}
		}

		fmt.Fprintln(writer, ans)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

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

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

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}