The flag of Berland is such rectangular field n × m that satisfies following conditions:  Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.  Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.  Each color should be used in exactly one stripe. You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).

The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field. Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.

Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).

6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB

NoteThe field in the third example doesn't have three parralel stripes.Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()

	A := make([]string, N)
	for i := 0; i < N; i++ {
		A[i] = io.NextLine()
	}

	if h, w := N / 3, M / 3;
		(N % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, h, M),
			MakeRectangle(h, 0, h << 1, M),
			MakeRectangle(h << 1, 0, N, M))) ||
		(M % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, N, w),
			MakeRectangle(0, w, N, w << 1),
			MakeRectangle(0, w << 1, N, M))) {
		io.Println("YES")
	} else {
		io.Println("NO")
	}
}

type Rectangle struct {
	R0 int
	C0 int
	Rf int
	Cf int
}

func MakeRectangle(r0, c0, rf, cf int) *Rectangle {
	return &Rectangle {
		R0: r0,
		C0: c0,
		Rf: rf,
		Cf: cf,
	}
}

func Valid(A []string, r1, r2, r3 *Rectangle) bool {
	charSet := make(map[byte]bool)
	rects := [...]*Rectangle{r1, r2, r3}
	for _, rect := range rects {
		if !SameRectangle(A, rect.R0, rect.C0, rect.Rf, rect.Cf) {
			return false
		}
		charSet[A[rect.R0][rect.C0]] = true
	}
	return len(charSet) == 3
}

func SameRectangle(A []string, r0, c0, rf, cf int) bool {
	for r := r0; r < rf; r++ {
		for c := c0; c < cf; c++ {
			if A[r][c] != A[r0][c0] {
				return false
			}
		}
	}
	return true
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()

	A := make([]string, N)
	for i := 0; i < N; i++ {
		A[i] = io.NextLine()
	}

	if h, w := N / 3, M / 3;
		(N % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, h, M),
			MakeRectangle(h, 0, h << 1, M),
			MakeRectangle(h << 1, 0, N, M))) ||
		(M % 3 == 0 && Valid(A,
			MakeRectangle(0, 0, N, w),
			MakeRectangle(0, w, N, w << 1),
			MakeRectangle(0, w << 1, N, M))) {
		io.Println("YES")
	} else {
		io.Println("NO")
	}
}

type Rectangle struct {
	R0 int
	C0 int
	Rf int
	Cf int
}

func MakeRectangle(r0, c0, rf, cf int) *Rectangle {
	return &Rectangle {
		R0: r0,
		C0: c0,
		Rf: rf,
		Cf: cf,
	}
}

func Valid(A []string, r1, r2, r3 *Rectangle) bool {
	charSet := make(map[byte]bool)
	rects := []*Rectangle{r1, r2, r3}
	for _, rect := range rects {
		if !SameRectangle(A, rect.R0, rect.C0, rect.Rf, rect.Cf) {
			return false
		}
		charSet[A[rect.R0][rect.C0]] = true
	}
	return len(charSet) == 3
}

func SameRectangle(A []string, r0, c0, rf, cf int) bool {
	for r := r0; r < rf; r++ {
		for c := c0; c < cf; c++ {
			if A[r][c] != A[r0][c0] {
				return false
			}
		}
	}
	return true
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


n soldiers stand in a circle. For each soldier his height ai is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |ai - aj| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.

The first line contains integer n (2 ≤ n ≤ 100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 1000). The soldier heights are given in clockwise or counterclockwise direction.

Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.

package main
import (
	"fmt"
	//"sort"
	//"unicode/utf8"
)
func main() {
	var n,vt1,vt2,aa,b int
	fmt.Scan(&n)
	a:=make([]int,101)
	for i:=1;i<=n;i++ {
		fmt.Scan(&a[i])
	}
	vt1=1
	vt2=n
	for i:=1;i<=n-1;i++ {
		aa=a[vt1]-a[vt2]
		if aa<0 {
			aa*=(-1)
		}
		b=a[i]-a[i+1]
		if b<0 {
			b*=(-1)
		}
		if aa>b {
			vt1=i
			vt2=i+1
		}
	}
	fmt.Println(vt1,vt2)

}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    min, ansi, ansj := 1000, 0, 0
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    for i := 0; i < n; i++ {
        u := int(math.Abs(float64(a[i])-float64(a[(i+1)%n])))
        if min > u {
            min = u
            ansi = i+1
            ansj = ((i+1)%n)+1
        }
    }
    fmt.Println(ansi,ansj)
}

// 34A-mic
package main

import (
    "fmt"
    "math"
)

func main() {
    a := make([]int, 105)
    var n, j, k int
    b := 10000
    c := 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    a[n] = a[0]
    for i := 0; i < n; i++ {
        c = int(math.Abs(float64(a[i]) - float64(a[i+1])))
        if c < b {
            b = c
            j = i + 1
            k = j + 1
            if n+1 == k {
                k = 1
            }
        }
    }
    fmt.Print(j)
    fmt.Print(" ")
    fmt.Print(k)
    fmt.Println()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i])
	}
	t := abs(a[0] - a[1])
	x := 0
	for i := 1; i < n; i++ {
		if abs(a[i-1] - a[i]) < t {
			t = abs(a[i-1] - a[i])
			x = i - 1
		}
	}
	if abs(a[0] - a[n-1]) < t {
		fmt.Fprintln(w, 1, n)
	} else {
		fmt.Fprintln(w, x+1, x+2)
	}
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    min, ansi, ansj := 1000, 0, 0
    for i := 0; i < n; i++ { fmt.Scan(&a[i]) }
    for i := 0; i < n; i++ {
        u := int(math.Abs(float64(a[i])-float64(a[(i+1)%n])))
        if min > u {
            min = u
            ansi = i+1
            ansj = (i+2)%n
        }
    }
    fmt.Println(ansi,ansj)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
type Rost struct {
	Index int
	Rost int
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)
	a := make([]Rost, n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(r, &x)
		a[i] = Rost{i+1, x}
	}
	sort.Slice(a, func(i, j int) bool { return a[i].Rost < a[j].Rost})
	x := 0
	y := 1
	h := a[y].Rost - a[x].Rost
	for i := 2; i < n; i++ {
		if a[i].Rost - a[i-1].Rost < h {
			h = a[i].Rost - a[i-1].Rost
			x = i-1
			y = i
		}
	}
	fmt.Fprintln(w, a[x].Index, a[y].Index)

}


Multiset —is a set of numbers in which there can be equal elements, and the order of the numbers does not matter. Two multisets are equal when each value occurs the same number of times. For example, the multisets $$$\{2,2,4\}$$$ and $$$\{2,4,2\}$$$ are equal, but the multisets $$$\{1,2,2\}$$$ and $$$\{1,1,2\}$$$ — are not.You are given two multisets $$$a$$$ and $$$b$$$, each consisting of $$$n$$$ integers.In a single operation, any element of the $$$b$$$ multiset can be doubled or halved (rounded down). In other words, you have one of the following operations available for an element $$$x$$$ of the $$$b$$$ multiset:   replace $$$x$$$ with $$$x \cdot 2$$$,  or replace $$$x$$$ with $$$\lfloor \frac{x}{2} \rfloor$$$ (round down).  Note that you cannot change the elements of the $$$a$$$ multiset.See if you can make the multiset $$$b$$$ become equal to the multiset $$$a$$$ in an arbitrary number of operations (maybe $$$0$$$).For example, if $$$n = 4$$$, $$$a = \{4, 24, 5, 2\}$$$, $$$b = \{4, 1, 6, 11\}$$$, then the answer is yes. We can proceed as follows:   Replace $$$1$$$ with $$$1 \cdot 2 = 2$$$. We get $$$b = \{4, 2, 6, 11\}$$$.  Replace $$$11$$$ with $$$\lfloor \frac{11}{2} \rfloor = 5$$$. We get $$$b = \{4, 2, 6, 5\}$$$.  Replace $$$6$$$ with $$$6 \cdot 2 = 12$$$. We get $$$b = \{4, 2, 12, 5\}$$$.  Replace $$$12$$$ with $$$12 \cdot 2 = 24$$$. We get $$$b = \{4, 2, 24, 5\}$$$.  Got equal multisets $$$a = \{4, 24, 5, 2\}$$$ and $$$b = \{4, 2, 24, 5\}$$$.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases. Each test case consists of three lines. The first line of the test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) —the number of elements in the multisets $$$a$$$ and $$$b$$$. The second line gives $$$n$$$ integers: $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_1 \le a_2 \le \dots \le a_n \le 10^9$$$) —the elements of the multiset $$$a$$$. Note that the elements may be equal. The third line contains $$$n$$$ integers: $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_1 \le b_2 \le \dots \le b_n \le 10^9$$$) — elements of the multiset $$$b$$$. Note that the elements may be equal. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print on a separate line:   YES if you can make the multiset $$$b$$$ become equal to $$$a$$$,  NO otherwise.  You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as positive answer).

NoteThe first example is explained in the statement.In the second example, it is impossible to get the value $$$31$$$ from the numbers of the multiset $$$b$$$ by available operations.In the third example, we can proceed as follows:   Replace $$$2$$$ with $$$2 \cdot 2 = 4$$$. We get $$$b = \{4, 14, 14, 26, 42\}$$$.  Replace $$$14$$$ with $$$\lfloor \frac{14}{2} \rfloor = 7$$$. We get $$$b = \{4, 7, 14, 26, 42\}$$$.  Replace $$$26$$$ with $$$\lfloor \frac{26}{2} \rfloor = 13$$$. We get $$$b = \{4, 7, 14, 13, 42\}$$$.  Replace $$$42$$$ with $$$\lfloor \frac{42}{2} \rfloor = 21$$$. We get $$$b = \{4, 7, 14, 13, 21\}$$$.  Replace $$$21$$$ with $$$\lfloor \frac{21}{2} \rfloor = 10$$$. We get $$$b = \{4, 7, 14, 13, 10\}$$$.  Got equal multisets $$$a = \{4, 7, 10, 13, 14\}$$$ and $$$b = \{4, 7, 14, 13, 10\}$$$.

package main

import (
	"bufio"
	"bytes"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	// A[i] 不能通过 *2 得到，只能通过 /2得到

	sort.Ints(A)

	pq := make(IntHeap, n)

	copy(pq, B)

	heap.Init(&pq)

	for i := n - 1; i >= 0; i-- {
		a := A[i]
		for pq[0] > a {
			b := heap.Pop(&pq).(int)
			for b > a {
				b >>= 1
			}
			heap.Push(&pq, b)
		}
		if pq[0] < a {
			return false
		}
		heap.Pop(&pq)
	}
	return true
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

package main

import (
	"bufio"
	"bytes"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	// A[i] 不能通过 *2 得到，只能通过 /2得到

	sort.Ints(A)

	pq := make(IntHeap, n)

	copy(pq, B)

	heap.Init(&pq)

	for i := n - 1; i >= 0; i-- {
		a := A[i]
		for pq[0] > a {
			b := heap.Pop(&pq).(int)
			b /= 2
			heap.Push(&pq, b)
		}
		if pq[0] < a {
			return false
		}
		heap.Pop(&pq)
	}
	return true
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

package main

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

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

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

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

func do(a, b []int) string {
	m := make(map[int]int)
	for _, v := range a {
		for v&1 == 0 {
			v >>= 1
		}
		m[v]++
	}
	// log.Print(m)
	for _, v := range b {
		for v > 0 && m[v] <= 0 {
			v >>= 1
		}
		if v == 0 {
			return "NO"
		}
		m[v]--
	}
	return "YES"
}

package main

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

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

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

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

package main

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

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  n := get(sc)
  a := map[int]int{}
  for i := 0; i < n; i++ {
    x := get(sc)
    for x > 0 && x % 2 == 0 {
      x /= 2
    }
    if _, in := a[x]; in {
      a[x]++
    } else {
      a[x] = 1
    }
  }
  for i := 0; i < n; i++ {
    x := get(sc)
    ok := false
    for {
      if v, in := a[x]; in && v > 0 {
        a[x]--
        ok = true
        break
      }
      if x == 0 {
        break
      }
      x /= 2
    }
    if !ok {
      wr.WriteString("NO\n")
      i++
      for i < n {
        sc.Scan()
        i++
      }
      return
    }
  }
  wr.WriteString("YES\n")
}

const (
  once = false
  maxBufSize = 10000000
)

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

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

  if once {
    solve(sc, wr)
  } else {
    times := get(sc)
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

func get(sc *bufio.Scanner) int {
  x, _ := strconv.Atoi(str(sc))
  return x
}

func str(sc *bufio.Scanner) string {
  sc.Scan()
  return sc.Text()
}

func put(wr *bufio.Writer, i int) {
  wr.WriteString(strconv.Itoa(i))
}

func line(wr *bufio.Writer) {
  wr.WriteRune('\n')
}

func space(wr *bufio.Writer) {
  wr.WriteRune(' ')
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	sort.Ints(A)
	// process from big to small
	root := NewNode()

	for _, num := range B {
		AddNum(root, num)
	}

	for i := n - 1; i >= 0; i-- {
		num := A[i]
		if !FindNum(root, num) {
			return false
		}
	}
	return true
}

type Trie struct {
	children []*Trie
	cnt      int
}

func NewNode() *Trie {
	node := new(Trie)
	node.children = make([]*Trie, 2)
	node.cnt = 0
	return node
}

func (node *Trie) AddNum(num int, p int) {
	if p < 0 {
		return
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		node.children[x] = NewNode()
	}
	node.children[x].AddNum(num, p-1)
	node.cnt++
}

func (node *Trie) FindNum(num int, p int) bool {
	if node.cnt == 0 {
		return false
	}
	if p < 0 {
		return true
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		return false
	}
	if !node.children[x].FindNum(num, p-1) {
		return false
	}
	node.cnt--
	return true
}

func AddNum(root *Trie, num int) {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			root.AddNum(num, i)
			break
		}
	}
}

func FindNum(root *Trie, num int) bool {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			return root.FindNum(num, i)
		}
	}
	return false
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const H = 31

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	sort.Ints(A)
	// process from big to small
	root := NewNode()

	for _, num := range B {
		AddNum(root, num)
	}

	for i := n - 1; i >= 0; i-- {
		num := A[i]
		if !FindNum(root, num) {
			return false
		}
	}
	return true
}

type Trie struct {
	children []*Trie
	cnt      int
}

func NewNode() *Trie {
	node := new(Trie)
	node.children = make([]*Trie, 2)
	node.cnt = 0
	return node
}

func (node *Trie) AddNum(num int, p int) {
	if p < 0 {
		return
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		node.children[x] = NewNode()
	}
	node.children[x].AddNum(num, p-1)
	node.cnt++
}

func (node *Trie) FindNum(num int, p int) bool {
	if p < 0 {
		return true
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		return false
	}
	if !node.children[x].FindNum(num, p-1) {
		return false
	}
	node.cnt--
	return node.cnt >= 0
}

func AddNum(root *Trie, num int) {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			root.AddNum(num, i)
			break
		}
	}
}

func FindNum(root *Trie, num int) bool {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			return root.FindNum(num, i)
		}
	}
	return false
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(A, B)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const H = 30

func solve(A, B []int) bool {
	n := len(A)
	// 如果按照bit 来看的话，相当于对于a, 110100, 只需要看 1101 部分，
	// 是否是b的前缀
	for i := 0; i < n; i++ {
		tmp := A[i]
		for tmp&1 == 0 {
			tmp >>= 1
		}
		// right 0 part irrlevant
		A[i] = tmp
	}

	sort.Ints(A)
	// process from big to small
	root := NewNode()

	for _, num := range B {
		AddNum(root, num)
	}

	for i := n - 1; i >= 0; i-- {
		num := A[i]
		if !FindNum(root, num) {
			return false
		}
	}
	return true
}

type Trie struct {
	children []*Trie
	cnt      int
}

func NewNode() *Trie {
	node := new(Trie)
	node.children = make([]*Trie, 2)
	node.cnt = 0
	return node
}

func (node *Trie) AddNum(num int, p int) {
	if p < 0 {
		return
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		node.children[x] = NewNode()
	}
	node.children[x].AddNum(num, p-1)
	node.cnt++
}

func (node *Trie) FindNum(num int, p int) bool {
	if p < 0 {
		return true
	}
	x := (num >> p) & 1
	if node.children[x] == nil {
		return false
	}
	if !node.children[x].FindNum(num, p-1) {
		return false
	}
	node.cnt--
	return node.cnt >= 0
}

func AddNum(root *Trie, num int) {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			root.AddNum(num, i)
			break
		}
	}
}

func FindNum(root *Trie, num int) bool {
	for i := H - 1; i >= 0; i-- {
		if (num>>i)&1 == 1 {
			return root.FindNum(num, i)
		}
	}
	return false
}


You are given an array $$$a$$$ of length $$$n$$$.You are also given a set of distinct positions $$$p_1, p_2, \dots, p_m$$$, where $$$1 \le p_i < n$$$. The position $$$p_i$$$ means that you can swap elements $$$a[p_i]$$$ and $$$a[p_i + 1]$$$. You can apply this operation any number of times for each of the given positions.Your task is to determine if it is possible to sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps.For example, if $$$a = [3, 2, 1]$$$ and $$$p = [1, 2]$$$, then we can first swap elements $$$a[2]$$$ and $$$a[3]$$$ (because position $$$2$$$ is contained in the given set $$$p$$$). We get the array $$$a = [3, 1, 2]$$$. Then we swap $$$a[1]$$$ and $$$a[2]$$$ (position $$$1$$$ is also contained in $$$p$$$). We get the array $$$a = [1, 3, 2]$$$. Finally, we swap $$$a[2]$$$ and $$$a[3]$$$ again and get the array $$$a = [1, 2, 3]$$$, sorted in non-decreasing order.You can see that if $$$a = [4, 1, 2, 3]$$$ and $$$p = [3, 2]$$$ then you cannot sort the array.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m < n \le 100$$$) — the number of elements in $$$a$$$ and the number of elements in $$$p$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$). The third line of the test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i < n$$$, all $$$p_i$$$ are distinct) — the set of positions described in the problem statement.

For each test case, print the answer — "YES" (without quotes) if you can sort the initial array in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$) using only allowed swaps. Otherwise, print "NO".

package main

import (
	"fmt"
)

const MAXN = 110

var n, m int
var a, f [MAXN]int

func check() bool {
	for {
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] > a[i+1] {
				sorted = false
				if f[i] == 0 {
					return false
				}
				a[i], a[i+1] = a[i+1], a[i]
				break
			}
		}
		if sorted {
			break
		}
	}
	return true
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for test := 1; test <= t; test++ {
		fmt.Scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
			f[i] = 0
		}
		fmt.Scanf("\n")
		for i := 1; i <= m; i++ {
			var x int
			fmt.Scanf("%d", &x)
			f[x] = 1
		}
		fmt.Scanf("\n")

		if check() {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}

	}
}

/**
 * Copyright shopee
 * @Author : Yuxiang.Lei
 * @MailBox: Yuxiang.Lei@shopee.com
 * @Date : 2020-02-24
 * @Version: v2.4
 **/

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		s := readLine(reader)
		ss := strings.Split(string(s), " ")
		n, _ := strconv.Atoi(ss[0])
		m, _ := strconv.Atoi(ss[1])
		s = readLine(reader)
		ss = strings.Split(string(s), " ")
		an := make([]int, n)
		for i := 0; i < len(ss); i++ {
			an[i], _ = strconv.Atoi(ss[i])
		}
		s = readLine(reader)
		ss = strings.Split(string(s), " ")
		pn := make([]int, m)
		pmap := make(map[int]struct{})
		for i := 0; i < len(ss); i++ {
			pn[i], _ = strconv.Atoi(ss[i])
			pmap[pn[i]-1] = struct{}{}
		}
		// fmt.Println(n,m,an,pn)
		max, i, flag := 0, 0, true
		for i = 0; i < len(an); {
			j := getRange(pmap, i)
			tmin, tmax := getRangeOfAn(i, j, an)
			// fmt.Println(tmin, tmax, max)
			if max > tmin {
				flag = false
				break
			}
			max = tmax
			i = j + 1
		}
		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func getRangeOfAn(start, end int, list []int) (int, int) {
	min, max := list[start], list[start]
	if end >= len(list) {
		end = len(list) -1
	}
	for i := start + 1; i <= end; i++ {
		if min > list[i] {
			min = list[i]
		}
		if max < list[i] {
			max = list[i]
		}
	}
	return min, max
}

func getRange(m map[int]struct{}, start int) int {
	for {
		_, ok := m[start]
		if ok {
			start++
		} else {
			break
		}
	}
	return start
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

package main

import "fmt"

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

func merge(f []int, x int, y int) {
	f[find(f, x)] = find(f, y)
}

func solve(a []int, p []int) bool {
	n := len(a)
	f := make([]int, n)
	for i := range f {
		f[i] = i
	}
	for _, v := range p {
		merge(f, v, v+1)
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i] > a[j] {
				if find(f, i) != find(f, j) {
					return false
				}
			}
		}
	}

	return true
}

func main() {
	var T int
	fmt.Scan(&T)

	for cas := 1; cas <= T; cas++ {
		var n, m int
		fmt.Scan(&n, &m)
		var a []int = make([]int, n)
		for i := range a {
			fmt.Scan(&a[i])
		}
		var p []int = make([]int, m)
		for i := range p {
			var v int
			fmt.Scan(&v)
			p[i] = v - 1
		}

		if solve(a, p) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1311/B
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t    int
	n, m int
	A    []int
	P    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		A = ReadIntSlice(n)
		P = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	for i := 0; i < m; i++ {
		P[i]--
	}

	for i := 0; i < n-1; i++ {
		for j := 1; j < n-i; j++ {
			if A[j-1] > A[j] {
				if sub(j-1, P) {
					A[j-1], A[j] = A[j], A[j-1]
				} else {
					fmt.Println("NO")
					return
				}
			}
		}
	}

	fmt.Println("YES")
}

func sub(a int, P []int) bool {
	for i := 0; i < len(P); i++ {
		if P[i] == a {
			return true
		}
	}
	return false
}

// AOJ
func bubbleSortAOJ(A []int, n int) int {
	flag := true
	res := 0
	for flag {
		flag = false
		for j := n - 1; j >= 1; j-- {
			if A[j-1] > A[j] {
				A[j-1], A[j] = A[j], A[j-1]
				res++
				flag = true
			}
		}
	}

	return res
}

// wikipedia
// ※最後尾の最大値から確定していく
func bubbleSortWikipedia(A []int, n int) int {
	res := 0
	for i := 0; i < n-1; i++ {
		for j := 1; j < n-i; j++ {
			if A[j-1] > A[j] {
				A[j-1], A[j] = A[j], A[j-1]
				res++
			}
		}
	}

	return res
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var T, n, m, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		p := make([]bool, n)
		for ; m > 0; m-- {
			Fscan(in, &v)
			p[v-1] = true
		}
		for i := 0; i < n; i++ {
			st := i
			for ; p[i]; i++ {
			}
			sort.Ints(a[st : i+1])
		}
		if sort.IntsAreSorted(a) {
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var t, n, m int

func main() {
	fmt.Fscan(reader, &t)
	for ; t != 0; t-- {
		fmt.Fscan(reader, &n, &m)
		a := make([]int, n)
		p := make(map[int]bool)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := 0; i < m; i++ {
			var pi int
			fmt.Fscan(reader, &pi)
			p[pi-1] = true
		}
		ans := "YES"
		for i := 0; i < n; i++ {
			for j := 0; j < n-i-1; j++ {
				if a[j] > a[j+1] {
					if p[j] {
						a[j], a[j+1] = a[j+1], a[j]
					} else {
						ans = "NO"
						break
					}
				}
			}
			if ans == "NO" {
				break
			}
		}
		fmt.Println(ans)
	}
}

package main

import(
	"fmt"
)

func main(){
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Scan(&a,&b)
		var ar[101] int
		var arr[101] int
		for i:=0;i<a;i++{
			fmt.Scan(&ar[i])
		}
		var check=make(map[int]bool)
		for i:=0;i<b;i++{
			fmt.Scan(&arr[i])
			check[arr[i]-1]=true
		}
		for i:=0;;i++{
			var lock bool=false
			for j:=1;j<a;j++{
				if ar[j-1]>ar[j]{
					if check[j-1]{
						ar[j-1]=ar[j-1]+ar[j]
						//fmt.Println(ar[j-1])
						ar[j]=ar[j-1]-ar[j]
						//fmt.Println(ar[j])
						ar[j-1]=ar[j-1]-ar[j]
						//fmt.Println(ar[])
						//fmt.Print(ar[j-1]," ",ar[j],"\n")
						lock=true
					}
				}
			}
			if !lock{
				break
			}
		}
		i:=1
		for i<a && ar[i-1]<=ar[i]{
			i++
		}
		if i==a{
			fmt.Println("YES")
		}else{
			fmt.Println("NO")
		}

	}
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		a := ScanIntSlice(n)
		p := ScanIntSlice(m)
		for i := 0; i < m; i++{
			p[i]--
		}
		sort.Ints(p)

		r := true
		for i :=0;i<n;i++ {
			for j:=0;j<m;j++ {
				if a[p[j]]>a[p[j]+1]{
					a[p[j]],a[p[j]+1] = a[p[j]+1], a[p[j]]
				}
			}
		}
		//P(a)
		//
		for i:=0; i<n-1; i++{
			if a[i]>a[i+1] {
				r = false
				break
			}
		}

		if r {
			P("YES")
		} else {
			P("NO")
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		a := ScanIntSlice(n)
		p := ScanIntSlice(m)
		for i := 0; i < m; i++{
			p[i]--
		}
		sort.Ints(p)

		r := true
		for i :=0;i<n;i++ {
			for j:=0;j<m;j++ {
				if a[p[j]]>a[p[j]+1]{
					a[p[j]],a[p[j]+1] = a[p[j]+1], a[p[j]]
				}

			}

		}
		for i:=0; i<n-1; i++{
			if a[i]>a[i+1] {
				r = false
				break
			}
		}

		if r {
			P("YES")
		} else {
			P("NO")
		}
	}

	close(O)
	oWg.Wait()
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan( &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a)

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

		for i := 0; i < b; i++ {
			var x int
			fmt.Scan( &x)
			positions[x-1] = true
		}

		valid := true
		for i := 0; i <a-1; i++ {
			for j := 0; j < a-i-1; j++ {
				if ar1[j] > ar1[j+1] && valid {
					if positions[j] {
						temp := ar1[j]
						ar1[j] = ar1[j+1]
						ar1[j+1] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

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

type pair struct {
	val int
	index int
}

func Max(x, y int) int {
    if x < y {
        return y
    }
    return x
}

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

func main () {
	in := bufio.NewReader(os.Stdin);
	out := bufio.NewWriter(os.Stdout);
	t := 0;
	fmt.Fscan(in, &t);
	for i := 0; i < t; i++ {
		n, m := 0, 0;
		fmt.Fscan(in, &n, &m);
		a := make([]pair, n);
		x := 0;
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &x);
			a[j] = pair{x, j};
		}

		sort.SliceStable(a, func (i, j int) bool {
			return a[i].val < a[j].val
		});

		p := make([]bool, n);
		for j := 0; j < m; j++ {
			var x int;
			fmt.Fscan(in, &x);
			p[x] = true;
		}
		ans := true;
		for key, item := range a {
			for j := Min(key + 1, item.index + 1); j < Max(key + 1, item.index + 1); j++ {
				if !p[j] {
					ans = false;
				}
			}
		}

		if (ans) {
			fmt.Fprintln(out, "YES");
		} else {
			fmt.Fprintln(out, "NO");
		}
	}
	out.Flush();
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
out:
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)
		arr := make([]int, a)
		pos := make(map[int]bool, b)
		for i := 0; i < a; i++ {
			fmt.Scan(&arr[i])
		}
		for i := 0; i < b; i++ {
			var temp int
			fmt.Scan(&temp)
			pos[temp] = true
		}
		for i := 0; i < a-1; i++ {
			for j := 0; j < a-1; j++ {
				if arr[j] > arr[j+1] {
					if _, exists := pos[j+1]; exists {
						arr[j], arr[j+1] = arr[j+1], arr[j]
					} else {
						fmt.Println("NO")
						continue out
					}
				}
			}
		}
		fmt.Println("YES")

	}
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
	r.out.Flush()
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

func (r *Scan) readInt() int {
	x, err := strconv.Atoi(r.readString())
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Fprintf(r.out, "%s", s)
}

func main() {
	scan := setup()

	var t, n, m int

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.ints(&n, &m)

		a := make([]int, n)
		p := make([]bool, n)
		for i := 0; i<n; i++ {
			scan.ints(&a[i])
		}
		for i := 0; i<m; i++ {
			var x int
			scan.ints(&x)
			x--
			p[x] = true
		}

		pos := true
		for i := 0; i<n; i++ {
			swap := true
			for j := i+1; j<n; j++ {
				swap = swap && p[j-1]
				if a[j] < a[i]  && !swap {
					pos = false
				}
			}
		}

		if pos {
			scan.print("YES\n")
		} else {
			scan.print("NO\n")
		}
	}

	scan.close()
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

func (r *Scan) readInt() int {
	x, err := strconv.Atoi(r.readString())
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Printf("%s", s)
}

func main() {
	scan := setup()

	var t, n, m int

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.ints(&n, &m)

		a := make([]int, n)
		p := make([]bool, n)
		for i := 0; i<n; i++ {
			scan.ints(&a[i])
		}
		for i := 0; i<m; i++ {
			var x int
			scan.ints(&x)
			x--
			p[x] = true
		}

		pos := true
		for i := 0; i<n; i++ {
			swap := true
			for j := i+1; j<n; j++ {
				swap = swap && p[j-1]
				if a[j] < a[i]  && !swap {
					pos = false
				}
			}
		}

		if pos {
			scan.print("YES\n")
		} else {
			scan.print("NO\n")
		}
	}

	scan.close()
}

package main

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

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

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

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

		a := make([]int, n)
		b := make([]int, n)
		p := make([]int, m)

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

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

		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})

		sort.Slice(p, func(i, j int) bool {
			return p[i] < p[j]
		})

		ok := true

		for i := range b {
			j := 0

			found := false
			for j = i; j < n; j++ {
				if a[j] == b[i] {
					found = true
					break
				}
			}

			if found {
				a[j] = 101

				d := j - i

				for k := range p {
					if p[k] > i && p[k] <= j {
						d--
					}
				}

				if d != 0 {
					ok = false
				}

				if !ok {
					break
				}
			}
		}

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

	}

}

package main

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

func readInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	return t
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	t := readInt(scanner)
	for i := 0; i < t; i++ {
		n := readInt(scanner)
		m := readInt(scanner)

		// array elements
		a := make([]int, n)
		// swap positions
		p := make([]int, m)
		for j := 0; j < n; j++ {
			a[j] = readInt(scanner)
		}
		for j := 0; j < m; j++ {
			p[j] = readInt(scanner)
		}
		sort.Ints(p)

		// sort each contiguous segment independently
		l := 0
		for l < len(p) {
			r := l
			for r+1 < len(p) && p[r+1] == p[r] + 1 {
				r += 1
			}

			sort.Ints(a[p[l]-1:p[r]+1])
			l = r+1
		}
		if sort.IntsAreSorted(a) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan( &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a+1)

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

		for i := 0; i < b; i++ {
			var x int
			fmt.Scan( &x)
			positions[x] = true
		}

		valid := true
		for i := 1; i <= a-1; i++ {
			for j := i; j < a; j++ {
				if ar1[j-1] > ar1[j] && valid {
					if positions[j] {
						temp := ar1[j-1]
						ar1[j-1] = ar1[j]
						ar1[j] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a+1)

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

		for i := 0; i < b; i++ {
			var x int
			fmt.Scanf("%d", &x)
			positions[x] = true
		}

		valid := true
		for i := 1; i <= a-1; i++ {
			for j := i; j < a; j++ {
				if ar1[j-1] > ar1[j] && valid {
					if positions[j] {
						temp := ar1[j-1]
						ar1[j-1] = ar1[j]
						ar1[j] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan( &t)
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)

		ar1 := make([]int, a)
		positions := make([]bool, a)

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

		for i := 0; i < b; i++ {
			var x int
			fmt.Scan( &x)
			positions[x-1] = true
		}

		valid := true
		for i := 0; i <a-1; i++ {
			for j := i; j < a-1; j++ {
				if ar1[j] > ar1[j+1] && valid {
					if positions[j] {
						temp := ar1[j]
						ar1[j] = ar1[j+1]
						ar1[j+1] = temp
					} else {
						valid = false
					}
				} else if !valid {
					break
				}
			}
		}
		if valid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
out:
	for ; t > 0; t-- {
		var a, b int
		fmt.Scan(&a, &b)
		arr := make([]int, a)
		pos := make(map[int]bool, b)
		for i := 0; i < a; i++ {
			fmt.Scan(&arr[i])
		}
		for i := 0; i < b; i++ {
			var temp int
			fmt.Scan(&temp)
			pos[temp] = true
		}
		for i := 0; i < a-1; i++ {
			for j := 0; j < a-2; j++ {
				if arr[j] > arr[j+1] {
					if _, exists := pos[j+1]; exists {
						arr[j], arr[j+1] = arr[j+1], arr[j]
					} else {
						fmt.Println("NO")
						continue out
					}
				}
			}
		}
		fmt.Println("YES")

	}
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

func (r *Scan) readInt() int {
	x, err := strconv.Atoi(r.readString())
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Printf("%s", s)
}

func main() {
	scan := setup()

	var t, a, b int

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.ints(&a, &b)
		diff := b-a
		mves := 0
		if diff > 0 {
			if (diff%2) == 1 {
				mves = 1
			} else {
				mves = 2
			}
		} else if diff < 0 {
			if (-diff)%2 == 1 {
				mves = 2
			} else {
				mves = 1
			}
		}
		fmt.Printf("%d\n", mves)
	}

	scan.close()
}

package main

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

func readInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	return t
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	t := readInt(scanner)
	for i := 0; i < t; i++ {
		n := readInt(scanner)
		m := readInt(scanner)

		// array elements
		a := make([]int, n)
		// swap positions
		p := make([]int, m)
		for j := 0; j < n; j++ {
			a[j] = readInt(scanner)
		}
		for j := 0; j < m; j++ {
			p[j] = readInt(scanner)
		}

		// sort each contiguous segment independently
		l := 0
		for l < len(p) {
			r := l
			for r+1 < len(p) && p[r+1] == p[r] + 1 {
				r += 1
			}

			sort.Ints(a[p[l]-1:p[r]+1])
			l = r+1
		}
		if sort.IntsAreSorted(a) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

const MAXN = 110

var n, m int
var a, b, f [MAXN]int

func check() bool {
	for {
		sorted := true
		for i := 1; i < n; i++ {
			if a[i] > a[i+1] {
				sorted = false
				if f[i] == 0 {
					return false
				}
				a[i], a[i+1] = a[i+1], a[i]
				break
			}
		}
		if sorted {
			break
		}
	}
	return true
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 1; i <= t; i++ {
		fmt.Scanf("%d %d", &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
			f[i] = 0
		}
		for i := 1; i <= m; i++ {
			fmt.Scanf("%d", &b[i])
			f[b[i]] = 1
		}

		if check() {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}

	}
}


There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure:  The crow sets ai initially 0.  The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi + 2 - bi + 3.... Memory gives you the values a1, a2, ..., an, and he now wants you to find the initial numbers b1, b2, ..., bn written in the row? Can you do it?

The first line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of integers written in the row. The next line contains n, the i'th of which is ai ( - 109 ≤ ai ≤ 109) — the value of the i'th number.

Print n integers corresponding to the sequence b1, b2, ..., bn. It's guaranteed that the answer is unique and fits in 32-bit integer type.

NoteIn the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and  - 4 = 4 - 6 + 1 - 3.In the second sample test, the sequence 1,  - 3, 4, 11, 6 satisfies the reports. For example, 5 = 11 - 6 and 6 = 6.

package main

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

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

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

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

	for i := 1; i < n; i++ {
		b := a[i] + a[i+1]
		fmt.Printf("%d ", b)
	}
	fmt.Printf("%d\n", a[n])
}

// http://codeforces.com/contest/712/problem/A
package main

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

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

func main () {
	var n int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)
	mass := make([]int, n)
	ans := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(input, &mass[i])
	}

	ans[n - 1] = mass[n - 1]
	for i := n - 2; i >= 0; i-- {
		ans[i] = mass[i] + mass[i + 1]
	}

	for i := 0; i < n; i++ {
		fmt.Print(ans[i], " ")
	}
}

// http://codeforces.com/contest/712/problem/A
package main

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

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

func main () {
	var n int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)
	mass := make([]int, n)
	ans := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(input, &mass[i])
	}

	ans[n - 1] = mass[n - 1]
	for i := n - 2; i >= 0; i-- {
		ans[i] = mass[i] + mass[i + 1]
	}

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

package main

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

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

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

	var tail_value int = 0
	for i := n - 1; i >= 0; i-- {
		if i%2 == 0 {
			array[i] -= tail_value
			tail_value += array[i]
		} else {
			array[i] += tail_value
			tail_value -= array[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Printf("%d ", array[i])
	}
	fmt.Println()
}

package main

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

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

    nums := make([]int, n)
    results := make([]int, n)
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)

    for i:=0; scanner.Scan(); i++ {
        nums[i], _ = strconv.Atoi(scanner.Text())
    }

    results[n-1] = nums[n-1]
    for i:=n-2; i >= 0; i-- {
        results[i] = nums[i] + nums[i+1]
    }

    var buf bytes.Buffer

    for i:=0; i < n; i++ {
        buf.WriteString(strconv.Itoa(results[i]) + " ")
    }
    fmt.Print(buf.String())

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s := strings.Split(text, " ")

	c, _ := strconv.Atoi(s[0])
	//x, _ := strconv.ParseInt(s[1], 10, 64)
	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s = strings.Split(text, " ")
	ans := make([]int64, c)
	v1 := int64(0)
	v2 := int64(0)
	for i := c - 1; i >= 0; i-- {
		v, _ := strconv.ParseInt(s[i], 10, 64)

		if i%2 == 0 {
			ans[i] = v - v1
			v1 += ans[i]
			v2 -= ans[i]

		} else {
			ans[i] = v - v2
			v1 -= ans[i]
			v2 += ans[i]

		}
	}
	for _, v := range ans {
		fmt.Printf("%d ", v)
	}
	fmt.Println()

}

// cf712a project main.go
package main

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

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

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func PrintInts(ints []int) {
	for _, value := range ints {
		writer.WriteString(strconv.Itoa(value))
		writer.WriteByte(' ')
	}
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n int
	var m []int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		m = append(m, ReadInt32())
	}
	b := make([]int, n)
	for i := n - 1; i >= 0; i-- {
		if i == n-1 {
			b[i] = m[i]
		} else {
			b[i] = m[i] + m[i+1]
		}

	}
	PrintInts(b)

}

// http://codeforces.com/contest/712/problem/A
package main

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

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

func main () {
	var n int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)

	mass := make([]int, n)
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		mass[i] = tmp
	}

	ans[n - 1] = mass[n - 1]
	for i := n - 2; i >= 0; i-- {
		ans[i] = mass[i] + mass[i + 1]
	}

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

// http://codeforces.com/contest/712/problem/A
package main

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

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

func main () {
	var n int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)

	mass := make([]int, n)
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&mass[i])
	}

	ans[n - 1] = mass[n - 1]
	for i := n - 2; i >= 0; i-- {
		ans[i] = mass[i] + mass[i + 1]
	}

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

// http://codeforces.com/contest/712/problem/A
package main

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

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

func main () {
	var n int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)

	mass := make([]int, n)
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&mass[i])
	}

	ans[n - 1] = mass[n - 1]
	for i := n - 2; i >= 0; i-- {
		ans[i] = mass[i] + mass[i + 1]
	}

	for i := 0; i < n; i++ {
		fmt.Print(ans[i], " ")
	}
}

package main

import "fmt"

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

	array := make([]int, n)
	for i := 0; i < n; i++ {
		if _, err := fmt.Scanf("%d", &array[i]); err != nil {
			return
		}
	}

	var tail_value int = 0
	for i := n - 1; i >= 0; i-- {
		if i%2 == 0 {
			array[i] -= tail_value
			tail_value += array[i]
		} else {
			array[i] += tail_value
			tail_value -= array[i]
		}
	}

	for i := 0; i < n; i++ {
		fmt.Printf("%d ", array[i])
	}
	fmt.Println()
}

package main

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

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

    nums := make([]int, n)
    results := make([]int, n)
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)

    for i:=0; scanner.Scan(); i++ {
        nums[i], _ = strconv.Atoi(scanner.Text())
    }

    results[n-1] = nums[n-1]
    for i:=n-2; i >= 0; i-- {
        results[i] = nums[i] + results[i+1]
    }

    resStr := ""
    for i:=0; i < n; i++ {
        resStr += strconv.Itoa(results[i]) + " "
    }
    fmt.Print(resStr)

}

// cf712a project main.go
package main

import (
	"fmt"
)

type A []int

func main() {
	var n int
	var m A
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		m = append(m, a)
	}
	m = reverse(m)
	fmt.Println(m)
	var b A

	for i, a := range m {
		if i == 0 {
			b = append(b, a)
		} else {
			l := a
			flag := i%2 != 0
			for j := 0; j < i; j++ {
				if flag {
					l += b[j]
				} else {
					l -= b[j]
				}
				flag = !flag
			}
			b = append(b, l)
		}
	}
	b = reverse(b)
	o := fmt.Sprint(b)
	fmt.Println(o[1 : len(o)-1])
}
func reverse(a []int) []int {
	for i, j := 0, len(a)-1; i < len(a)/2; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}


Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index v fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.

The first input line contains 3 space-separated integer numbers n, m, v (3 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ v ≤ n), n — amount of servers, m — amount of direct connections, v — index of the server that fails and leads to the failure of the whole system.

If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

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

	if m > (n - 2) * (n - 1) / 2  + 1 || m < n - 1 {
		fmt.Printf("-1")
		return
	}
	var isolate int

	if v == 1 {
		isolate = 2
	} else {
		isolate = 1
	}
	fmt.Printf("%d %d\n", v, isolate)
	m --
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		} else {
			fmt.Printf("%d %d\n", v, i)
			m --
		}
	}
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		}
		for j := i + 1;j <= n;j ++ {
			if j == isolate || j == v {
				continue
			}
			if m == 0 {
				return
			} else {
				fmt.Printf("%d %d\n", i, j)
				m --
			}
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

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

	if m > (n - 2) * (n - 1) / 2 || n <= m - 1 {
		fmt.Printf("-1")
		return
	}
	var isolate int

	if v == 1 {
		isolate = 2
	} else {
		isolate = 1
	}
	fmt.Printf("%d %d\n", v, isolate)
	m --
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		} else {
			fmt.Printf("%d %d\n", v, i)
			m --
		}
	}
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		}
		for j := i + 1;j <= n;j ++ {
			if j == isolate || j == v {
				continue
			}
			if m == 0 {
				return
			} else {
				fmt.Printf("%d %d\n", i, j)
				m --
			}
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

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

	if m > (n - 2) * (n - 1) / 2 {
		fmt.Printf("-1")
		return
	}
	if m == 0 {
		return
	}
	var isolate int

	if v == 1 {
		isolate = 2
	} else {
		isolate = 1
	}
	fmt.Printf("%d %d\n", v, isolate)
	m --
	for i := 1;i <= n;i ++ {
		if m == 0 {
			return
		}
		if i == isolate || i == v {
			continue
		} else {
			fmt.Printf("%d %d\n", v, i)
			m --
		}
	}
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		}
		for j := i + 1;j <= n;j ++ {
			if j == isolate || j == v {
				continue
			}
			if m == 0 {
				return
			} else {
				fmt.Printf("%d %d\n", i, j)
				m --
			}
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

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

	if m > (n - 2) * (n - 1) / 2 || m <= n{
		fmt.Printf("-1")
		return
	}
	var isolate int

	if v == 1 {
		isolate = 2
	} else {
		isolate = 1
	}
	fmt.Printf("%d %d\n", v, isolate)
	m --
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		} else {
			fmt.Printf("%d %d\n", v, i)
			m --
		}
	}
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		}
		for j := i + 1;j <= n;j ++ {
			if j == isolate || j == v {
				continue
			}
			if m == 0 {
				return
			} else {
				fmt.Printf("%d %d\n", i, j)
				m --
			}
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

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

	if m > (n - 2) * (n - 1) / 2 || m < n - 1 {
		fmt.Printf("-1")
		return
	}
	var isolate int

	if v == 1 {
		isolate = 2
	} else {
		isolate = 1
	}
	fmt.Printf("%d %d\n", v, isolate)
	m --
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		} else {
			fmt.Printf("%d %d\n", v, i)
			m --
		}
	}
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		}
		for j := i + 1;j <= n;j ++ {
			if j == isolate || j == v {
				continue
			}
			if m == 0 {
				return
			} else {
				fmt.Printf("%d %d\n", i, j)
				m --
			}
		}
	}
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

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

	if m > (n - 2) * (n - 1) / 2 || m <= n{
		fmt.Printf("-1")
		return
	}
	var isolate int

	if v == 1 {
		isolate = 2
	} else {
		isolate = 1
	}
	fmt.Printf("%d %d\n", v, isolate)
	m --
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		} else {
			fmt.Printf("%d %d\n", v, i)
			m --
		}
	}
	for i := 1;i <= n;i ++ {
		if i == isolate || i == v {
			continue
		}
		for j := 1;j <= n;j ++ {
			if j == isolate || j == v || i == j{
				continue
			}
			if m == 0 {
				return
			} else {
				fmt.Printf("%d %d\n", i, j)
				m --
			}
		}
	}
}