There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monster being eaten, and they stand in the queue next to each other. Monsters eat each other instantly. There are no monsters which are being eaten at the same moment. After the monster A eats the monster B, the weight of the monster A increases by the weight of the eaten monster B. In result of such eating the length of the queue decreases by one, all monsters after the eaten one step forward so that there is no empty places in the queue again. A monster can eat several monsters one after another. Initially there were n monsters in the queue, the i-th of which had weight ai.For example, if weights are [1, 2, 2, 2, 1, 2] (in order of queue, monsters are numbered from 1 to 6 from left to right) then some of the options are:  the first monster can't eat the second monster because a1 = 1 is not greater than a2 = 2;  the second monster can't eat the third monster because a2 = 2 is not greater than a3 = 2;  the second monster can't eat the fifth monster because they are not neighbors;  the second monster can eat the first monster, the queue will be transformed to [3, 2, 2, 1, 2]. After some time, someone said a good joke and all monsters recovered. At that moment there were k (k ≤ n) monsters in the queue, the j-th of which had weight bj. Both sequences (a and b) contain the weights of the monsters in the order from the first to the last.You are required to provide one of the possible orders of eating monsters which led to the current queue, or to determine that this could not happen. Assume that the doctor didn't make any appointments while monsters were eating each other.

The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters. The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke.  The fourth line contains k integers b1, b2, ..., bk (1 ≤ bj ≤ 5·108) — the weights of the monsters after the joke.  Monsters are listed in the order from the beginning of the queue to the end.

In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line.  Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, separated by space, the symbol 'L' if the monster which stays the x-th in the queue eats the monster in front of him, or 'R' if the monster which stays the x-th in the queue eats the monster behind him. After each eating the queue is enumerated again.  When one monster eats another the queue decreases. If there are several answers, print any of them.

NoteIn the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue:  the second monster eats the monster to the left (i.e. the first monster), queue becomes [3, 2, 2, 1, 2];  the first monster (note, it was the second on the previous step) eats the monster to the right (i.e. the second monster), queue becomes [5, 2, 1, 2];  the fourth monster eats the mosnter to the left (i.e. the third monster), queue becomes [5, 2, 3];  the finally, the third monster eats the monster to the left (i.e. the second monster), queue becomes [5, 5]. Note that for each step the output contains numbers of the monsters in their current order in the queue.

package main

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

type step struct {
    i int
    d string
}

func doSolve(a, b []int, di int) ([]step, bool) {
    res := make([]step, 0)
    if len(b) == 0 {
        return res, len(a) == 0
    }
    bs, j, sum, mx := b[0], 0, 0, 0
    for j < len(a) && sum < bs {
        sum += a[j]
        mx = max(a[j], mx)
        j++
    }

    ok := sum == bs
    if ok {
        for i := 0; i < j - 1; i++ {
            l, r := a[i], a[i + 1]
            if l != r {
                indx, d := -1, ""
                if (l == mx) {
                    indx, d = i + 1, "R"
                    a[i] += r
                } else if (r == mx) {
                    indx, d = i, "L"
                    a[i + 1] += l
                }

                if indx != -1 {
                    res = append(res, step{i: 2 * i + 1 - indx + di, d: d})
                    a = append(a[:indx], a[indx + 1:]...)
                    break
                }
            }
        }

        if j == 1 || len(res) > 0 {
            if j == 1 {
                di++
                b = b[1:]
                a = a[1:]
            }
            nextStep, nextOk := doSolve(a, b, di)
            ok = ok && nextOk
            res = append(res, nextStep...)
        } else {
            ok = false
        }
    }

    return res, ok
}

func solve() {
	n := readInt()
    a := readIntArray(n)
	k := readInt()
    b := readIntArray(k)

    steps, ok := doSolve(a, b, 0)
    if ok {
        fmt.Println("YES")
        for _, st := range steps {
            fmt.Println(st.i + 1, " " + st.d)
        }
    } else {
        fmt.Println("NO")
    }
}

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

// IO

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

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

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

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

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

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

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

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

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

	var rpos []int
	var rdir []byte

	for ; (m > 0) && (n > 0); m-- {
		i := n
		s := 0
		for ; (i >= 1) && (s < b[m]); i-- {
			s += a[i]
		}
		if s != b[m] {
			fmt.Fprintf(bufout, "NO\n")
			return
		}
		for i++; i < n; n-- {
			p := -1
			ms := -1
			for j := i; j < n; j++ {
				if (a[j] != a[j+1]) && (ms < a[j]+a[j+1]) {
					p = j
					ms = a[j] + a[j+1]
				}
			}
			if p == -1 {
				fmt.Fprintf(bufout, "NO\n")
				return
			}
			if a[p] < a[p+1] {
				rpos = append(rpos, p+1)
				rdir = append(rdir, 'L')
			} else {
				rpos = append(rpos, p)
				rdir = append(rdir, 'R')
			}
			a[p] += a[p+1]
			for j := p + 1; j < n; j++ {
				a[j] = a[j+1]
			}
		}
		n--
	}

	if (m > 0) || (n > 0) {
		fmt.Fprintf(bufout, "NO\n")
		return
	}

	fmt.Fprintf(bufout, "YES\n")
	s := len(rpos)
	for i := 0; i < s; i++ {
		fmt.Fprintf(bufout, "%d %c\n", rpos[i], rdir[i])
	}
}

package main

import "fmt"

type Item struct {
	leftSonLength int16
	leftEatRight bool
	isActionExist bool
}

const N = 501
var Arr [N][N]Item
var a [N]int32
var suma [N]int32
var b [N]int32
var n, k int16
var isAnswerExist bool

func readData() {
	fmt.Scan(&n)
	for i := int16(1); i <= n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&k)
	for i := int16(1); i <= k; i++ {
		fmt.Scan(&b[i])
	}
}

func initData() {
	isAnswerExist = true
	for i := int16(1); i <= n; i++ {
		suma[i] = suma[i - 1] + a[i]
	}
}

func getSum(from int16, to int16) int32 {
	return suma[to] - suma[from - 1]
}
func actionExist(from int16, sum int32) int16 {
	for i := from; i <= n && getSum(from, i) <= sum; i++ {
		if getSum(from, i) == sum {
			return i + 1 - from
		}
	}
	return int16(-1)
}

func answerExist() bool {
	from := int16(1)
	for i := int16(1); i <= k; i++ {
		length := actionExist(from, b[i])
		if length == -1 || !Arr[from][length].isActionExist {
			return false
		}
		from += length
	}
	if from != n + 1 {
		return false
	} else {
		return true
	}
}

func dp() {
	for i := int16(1); i <= n; i++ {
		Arr[i][1].isActionExist = true
	}
	for l := int16(2); l <= n; l++ {
		for i := int16(1); i + l - 1 <= n; i++ {
			Arr[i][l].isActionExist = false
			for lson := int16(1); lson < l; lson++ {
				ri := i + lson
				rson := l - lson
				if Arr[i][lson].isActionExist && Arr[ri][rson].isActionExist {
					if getSum(i, i + lson - 1) > getSum(ri, ri + rson - 1) {
						Arr[i][l].leftEatRight = true
						Arr[i][l].leftSonLength = lson
						Arr[i][l].isActionExist = true
						break
					}
					if getSum(i, i + lson - 1) < getSum(ri, ri + rson - 1) {
						Arr[i][l].leftEatRight = false
						Arr[i][l].leftSonLength = lson
						Arr[i][l].isActionExist = true
						break
					}
				}
			}
		}
	}
	if !answerExist() {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		printAnswer()
	}
}

func printActions(preItems, from, length int16) {
	if length != 1 {
		printActions(preItems, from, Arr[from][length].leftSonLength)
		rightFrom := from + Arr[from][length].leftSonLength
		rightSonLength := length - Arr[from][length].leftSonLength
		printActions(preItems + 1, rightFrom, rightSonLength)
		if Arr[from][length].leftEatRight {
			fmt.Printf("%d R\n", preItems + 1)
		} else {
			fmt.Printf("%d L\n", preItems + 2)
		}
	}
}
func printAnswer() {
	from := int16(1)
	for i := int16(1); i <= k; i++ {
		length := actionExist(from, b[i])
		printActions(i - 1, from, length)
		from += length
	}
}

func main() {
	readData()
	initData()
	dp()
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

type group struct {
	beg, end int
}

func output(A []int, beg, end, offset int) {
	var nums = make([]int, end-beg)
	for i := beg; i < end; i++ {
		nums[i-beg] = A[i]
	}

	for len(nums) != 1 {
		var maxeatelm = -1
		var maxeati = -1
		for i := 0; i < len(nums); i++ {
			var eat = false
			if i > 0 && nums[i-1] < nums[i] {
				eat = true
			}
			if i < len(nums)-1 && nums[i] > nums[i+1] {
				eat = true
			}
			if eat && maxeatelm < nums[i] {
				maxeatelm = nums[i]
				maxeati = i
			}
		}
		var newnums = make([]int, len(nums)-1)
		var j = 0
		for i := 0; i < len(nums); i++ {
			if i == maxeati {
				if i < len(nums)-1 && nums[i] > nums[i+1] {
					newnums[j] = nums[i] + nums[i+1]
					fmt.Fprintf(bufout, "%d R\n", i+1+offset)
					i += 1
					j += 1
				} else {
					newnums[j-1] += nums[i]
					fmt.Fprintf(bufout, "%d L\n", i+1+offset)
					i += 1
				}
			} else {
				newnums[j] = nums[i]
				j += 1
			}
		}
		nums = newnums
	}
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()
	var N, M int
	fmt.Fscanf(bufin, "%d\n", &N)
	var A = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Fscanf(bufin, "%d\n", &A[i])
	}
	fmt.Fscanf(bufin, "%d\n", &M)
	var B = make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Fscanf(bufin, "%d\n", &B[i])
	}
	var G []group
	{
		var j = 0
		for i := 0; i < M; i++ {
			var beg = j
			var maxa, maxcnt = 0, 0
			var b = 0
			for ; j < N && b < B[i]; j++ {
				b += A[j]
				if maxa < A[j] {
					maxa = A[j]
					maxcnt = 1
				} else if maxa == A[j] {
					maxcnt += 1
				}
			}
			var end = j
			if b != B[i] {
				fmt.Fprintf(bufout, "NO\n")
				return
			}
			if maxcnt != 1 && maxcnt == end-beg {
				fmt.Fprintf(bufout, "NO\n")
				return
			}
			G = append(G, group{beg, end})
		}
		if j != N {
			fmt.Fprintf(bufout, "NO\n")
			return
		}
	}
	//fmt.Println(G)
	fmt.Fprintf(bufout, "YES\n")
	for i := 0; i < len(G); i++ {
		output(A, G[i].beg, G[i].end, i)
	}
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

type Slice struct {
    start, end int
}

type Step struct {
    position int
    step string
}

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

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

func Build(startIndex int, items []int) ([]Step, bool) {
    maxIndex := 0
    cnt := len(items)
    var steps []Step

    if cnt == 1 {
        return steps, true
    }

    for i := 0; i < cnt; i++ {
        if items[i] > items[maxIndex] {
            maxIndex = i
        }
    }

    if maxIndex > 0 {
        for maxIndex > 0 {
            steps = append(steps, Step{startIndex + maxIndex, "L"})
            maxIndex--
            cnt--
        }

        for cnt > 1 {
            steps = append(steps, Step{startIndex, "R"})
            cnt--
        }

        return steps, true
    } else if items[maxIndex] > items[maxIndex+1] {
        for cnt > 1 {
            steps = append(steps, Step{startIndex, "R"})
            cnt--
        }
        return steps, true
    } else {
        for maxIndex + 1 < cnt && items[maxIndex] == items[maxIndex+1] {
            maxIndex++
        }

        if maxIndex+1 >= cnt || items[maxIndex] == items[maxIndex+1] {
            return steps, false
        } else {
            for maxIndex + 1 < cnt {
                steps = append(steps, Step{startIndex + maxIndex, "R"})
                cnt--
            }

            for maxIndex > 0 {
                steps = append(steps, Step{startIndex + maxIndex, "L"})
                maxIndex--
            }
        }
    }

    return steps, true
}

func main() {
    scanner.Split(bufio.ScanWords)

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

    for i := 0; i < n; i++ {
        a[i] = ReadInt()
    }

    k := ReadInt()
    b := make([]int, k)
    slices := make([]Slice, k)

    for i := 0; i < k; i++ {
        b[i] = ReadInt()
    }

    leftPointer := 0
    for i := 0; i < k; i++ {
        if leftPointer >= n {
            fmt.Println("NO")
            return
        }

        curSlice := Slice{leftPointer, leftPointer}
        curSum := a[leftPointer]
        leftPointer++

        for curSum < b[i] && leftPointer < n {
            curSum += a[leftPointer]
            leftPointer++
        }

        if curSum != b[i] {
            fmt.Println("NO")
            return
        } else {
            curSlice.end = leftPointer
            slices[i] = curSlice
        }
    }

    if leftPointer != n {
        fmt.Println("NO")
        return
    }

    var steps []Step

    for i := 0; i < k; i++ {
        newSteps, success := Build(i + 1, a[slices[i].start:slices[i].end])
        if !success {
            fmt.Println("NO")
            return
        } else {
            steps = append(steps, newSteps...)
        }
    }

    fmt.Println("YES")
    for i := 0; i < len(steps); i++ {
        fmt.Println(strconv.Itoa(steps[i].position) + " " + steps[i].step)
    }
}

package main

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

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

type AnsTuple struct {
	Index  int
	Direct string
}

var queue []AnsTuple

func recv(v []int, count int) bool {
	if count == len(v) - 1 {
		return true
	}
	u := [2]int{}
	un := [2]int{}
	normalizeIndex := 0
	normalizeIndex2 := 0

	for i := 0; i < len(v); i++ {
		if v[i] == 0 {
			continue
		}

		u[0] = i
		un[0] = normalizeIndex
		normalizeIndex2 = normalizeIndex
		for j := i + 1; j < len(v); j++ {
			if v[j] == 0 {
				continue
			}
			normalizeIndex2++
			if v[i] == v[j] {
				break
			}

			u[1] = j
			un[1] = normalizeIndex2
			if v[u[0]] < v[u[1]] {
				//println(fmt.Errorf("%+v", v).Error())

				a := v[u[0]]
				b := v[u[1]]
				v[u[1]] += a
				v[u[0]] = 0
				queue = append(queue, AnsTuple{Index:un[1], Direct:"L"})
				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]
				v[u[0]] = a
				v[u[1]] = b
				//println("back", fmt.Errorf("%+v", v).Error())

			} else {
				//println(fmt.Errorf("%+v", v).Error())
				//println(u[0], u[1])

				a := v[u[0]]
				b := v[u[1]]

				v[u[0]] += b
				v[u[1]] = 0
				queue = append(queue, AnsTuple{Index:un[0], Direct:"R"})

				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]

				v[u[0]] = a
				v[u[1]] = b

			}

		}
		normalizeIndex++
	}
	return false
}
func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextIntArray()
	k := sc.NextInt()
	b := sc.NextIntArray()

	i := 0
	ans := make([]string, 0)
	for j := 0; j < k; j++ {
		sum := 0
		f := i
		for ; sum < b[j] && i < N; i++ {
			sum += a[i]
		}
		if sum != b[j] {
			fmt.Println("NO")
			return
		}
		if j == k - 1 && i != N {
			fmt.Println("NO")
			return
		}
		queue = make([]AnsTuple, 0)
		if !recv(a[f:i], 0) {
			fmt.Println("NO")
			return
		}
		for i := 0; i < len(queue); i++ {
			str := strconv.Itoa(queue[i].Index + j + 1)
			str += " "
			str += queue[i].Direct
			ans = append(ans, str)
		}

	}
	fmt.Println("YES")
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

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

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

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

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

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

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

	var rpos []int
	var rdir []byte

	for ; (m > 0) && (n > 0); m-- {
		i := n
		s := 0
		for ; (i >= 1) && (s < b[m]); i-- {
			s += a[i]
		}
		if s < b[m] {
			fmt.Fprintf(bufout, "NO\n")
			return
		}
		for i++; i < n; n-- {
			// for j := 1; j <= n; j++ {
			// 	fmt.Fprintf(bufout, "%d ", a[j])
			// }
			// fmt.Fprintf(bufout, "\n")
			p := -1
			ms := -1
			for j := i; j < n; j++ {
				if (a[j] != a[j+1]) && (ms < a[j]+a[j+1]) {
					p = j
					ms = a[j] + a[j+1]
				}
			}
			if p == -1 {
				fmt.Fprintf(bufout, "NO\n")
				return
			}
			if a[p] < a[p+1] {
				rpos = append(rpos, p+1)
				rdir = append(rdir, 'L')
			} else {
				rpos = append(rpos, p)
				rdir = append(rdir, 'R')
			}
			a[p] += a[p+1]
			for j := p + 1; j < n; j++ {
				a[j] = a[j+1]
			}
		}
		n--
	}

	if (m > 0) || (n > 0) {
		fmt.Fprintf(bufout, "NO\n")
		return
	}

	fmt.Fprintf(bufout, "YES\n")
	s := len(rpos)
	for i := 0; i < s; i++ {
		fmt.Fprintf(bufout, "%d %c\n", rpos[i], rdir[i])
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

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

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

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

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

	var rpos []int
	var rdir []byte

	for k := m; k >= 1; k-- {
		found := true
		for (n > k) && (a[n] != b[k]) && found {
			found = false
			for i := n; i >= 2; i-- {
				if a[i] != a[i-1] {
					if a[i-1] < a[i] {
						rpos = append(rpos, i)
						rdir = append(rdir, 'L')
					} else {
						rpos = append(rpos, i-1)
						rdir = append(rdir, 'R')
					}
					a[i-1] += a[i]
					for j := i; j < n; j++ {
						a[j] = a[j+1]
					}
					n--
					found = true
					break
				}
			}
		}
		if (n < k) || (a[n] != b[k]) {
			fmt.Fprintf(bufout, "NO\n")
			return
		}
		n--
	}

	fmt.Fprintf(bufout, "YES\n")
	s := len(rpos)
	for i := 0; i < s; i++ {
		fmt.Fprintf(bufout, "%d %c\n", rpos[i], rdir[i])
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

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

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

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

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

	var rpos []int
	var rdir []byte

	for k := m; k >= 1; k-- {
		found := true
		for (n > k) && (a[n] != b[k]) && found {
			found = false
			p := -1
			s := -1
			for i := n; i >= k+1; i-- {
				if a[i] != a[i-1] {
					if s < a[i]+a[i-1] {
						p = i
						s = a[i] + a[i-1]
						found = true
					}
				}
			}
			if found {
				i := p
				if a[i-1] < a[i] {
					rpos = append(rpos, i)
					rdir = append(rdir, 'L')
				} else {
					rpos = append(rpos, i-1)
					rdir = append(rdir, 'R')
				}
				a[i-1] += a[i]
				for j := i; j < n; j++ {
					a[j] = a[j+1]
				}
				n--
			}
		}
		if (n < k) || (a[n] != b[k]) {
			fmt.Fprintf(bufout, "NO\n")
			return
		}
		n--
	}

	if n > 0 {
		fmt.Fprintf(bufout, "NO\n")
		return
	}

	fmt.Fprintf(bufout, "YES\n")
	s := len(rpos)
	for i := 0; i < s; i++ {
		fmt.Fprintf(bufout, "%d %c\n", rpos[i], rdir[i])
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

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

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

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

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

	var rpos []int
	var rdir []byte

	for k := m; k >= 1; k-- {
		found := true
		for (n > k) && (a[n] != b[k]) && found {
			found = false
			for i := n; i >= 2; i-- {
				if a[i] != a[i-1] {
					if a[i-1] < a[i] {
						rpos = append(rpos, i)
						rdir = append(rdir, 'L')
					} else {
						rpos = append(rpos, i-1)
						rdir = append(rdir, 'R')
					}
					a[i-1] += a[i]
					for j := i; j < n; j++ {
						a[j] = a[j+1]
					}
					n--
					found = true
					break
				}
			}
		}
		if (n < k) || (a[n] != b[k]) {
			fmt.Fprintf(bufout, "NO\n")
			return
		}
		n--
	}

	if n > 0 {
		fmt.Fprintf(bufout, "NO\n")
		return
	}

	fmt.Fprintf(bufout, "YES\n")
	s := len(rpos)
	for i := 0; i < s; i++ {
		fmt.Fprintf(bufout, "%d %c\n", rpos[i], rdir[i])
	}
}

package main

import "fmt"

type Item struct {
	leftSonLength int16
	leftEatRight bool
	isActionExist bool
}

const N = 501
var Arr [N][N]Item
var a [N]int32
var suma [N]int32
var b [N]int32
var n, k int16
var isAnswerExist bool

func readData() {
	fmt.Scan(&n)
	for i := int16(1); i <= n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&k)
	for i := int16(1); i <= k; i++ {
		fmt.Scan(&b[i])
	}
}

func initData() {
	isAnswerExist = true
	for i := int16(1); i <= n; i++ {
		suma[i] = suma[i - 1] + a[i]
	}
}

func getSum(from int16, to int16) int32 {
	return suma[to] - suma[from - 1]
}
func actionExist(from int16, sum int32) int16 {
	for i := from; i <= n && getSum(from, i) <= sum; i++ {
		if getSum(from, i) == sum {
			return i + 1 - from
		}
	}
	return int16(-1)
}

func answerExist() bool {
	from := int16(1)
	for i := int16(1); i <= k; i++ {
		length := actionExist(from, b[i])
		if length == -1 || !Arr[from][length].isActionExist {
			return false
		}
		from += length
	}
	return true
}

func dp() {
	for i := int16(1); i <= n; i++ {
		Arr[i][1].isActionExist = true
	}
	for l := int16(2); l <= n; l++ {
		for i := int16(1); i + l - 1 <= n; i++ {
			Arr[i][l].isActionExist = false
			for lson := int16(1); lson < l; lson++ {
				ri := i + lson
				rson := l - lson
				if Arr[i][lson].isActionExist && Arr[ri][rson].isActionExist {
					if getSum(i, i + lson - 1) > getSum(ri, ri + rson - 1) {
						Arr[i][l].leftEatRight = true
						Arr[i][l].leftSonLength = lson
						Arr[i][l].isActionExist = true
						break
					}
					if getSum(i, i + lson - 1) < getSum(ri, ri + rson - 1) {
						Arr[i][l].leftEatRight = false
						Arr[i][l].leftSonLength = lson
						Arr[i][l].isActionExist = true
						break
					}
				}
			}
		}
	}
	if !answerExist() {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		printAnswer()
	}
}

func printActions(preItems, from, length int16) {
	if length != 1 {
		printActions(preItems, from, Arr[from][length].leftSonLength)
		rightFrom := from + Arr[from][length].leftSonLength
		rightSonLength := length - Arr[from][length].leftSonLength
		printActions(preItems + 1, rightFrom, rightSonLength)
		if Arr[from][length].leftEatRight {
			fmt.Printf("%d R\n", preItems + 1)
		} else {
			fmt.Printf("%d L\n", preItems + 2)
		}
	}
}
func printAnswer() {
	from := int16(1)
	for i := int16(1); i <= k; i++ {
		length := actionExist(from, b[i])
		printActions(i - 1, from, length)
		from += length
	}
}

func main() {
	readData()
	initData()
	dp()
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

type group struct {
	beg, end int
}

func output(A []int, beg, end, offset int) {
	var nums = make([]int, end-beg)
	for i := beg; i < end; i++ {
		nums[i-beg] = A[i]
	}

	for len(nums) != 1 {
		var maxeatelm = -1
		var maxeati = -1
		for i := 0; i < len(nums); i++ {
			var eat = false
			if i > 0 && nums[i-1] < nums[i] {
				eat = true
			}
			if i < len(nums)-1 && nums[i] > nums[i+1] {
				eat = true
			}
			if eat && maxeatelm < nums[i] {
				maxeatelm = nums[i]
				maxeati = i
			}
		}
		var newnums = make([]int, len(nums)-1)
		var j = 0
		for i := 0; i < len(nums); i++ {
			if i == maxeati {
				if i < len(nums)-1 && nums[i] > nums[i+1] {
					newnums[j] = nums[i] + nums[i+1]
					fmt.Fprintf(bufout, "%d R\n", i+1+offset)
					i += 1
					j += 1
				} else {
					newnums[j-1] += nums[i]
					fmt.Fprintf(bufout, "%d L\n", i+1+offset)
					i += 1
				}
			} else {
				newnums[j] = nums[i]
				j += 1
			}
		}
		nums = newnums
	}
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()
	var N, M int
	fmt.Fscanf(bufin, "%d\n", &N)
	var A = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Fscanf(bufin, "%d\n", &A[i])
	}
	fmt.Fscanf(bufin, "%d\n", &M)
	var B = make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Fscanf(bufin, "%d\n", &B[i])
	}
	var G []group
	{
		var j = 0
		for i := 0; i < M; i++ {
			var beg = j
			var maxa, maxcnt = 0, 0
			var b = 0
			for ; j < N && b < B[i]; j++ {
				b += A[j]
				if maxa < A[j] {
					maxa = A[j]
					maxcnt = 1
				} else if maxa == A[j] {
					maxcnt += 1
				}
			}
			var end = j
			if b != B[i] {
				fmt.Fprintf(bufout, "NO\n")
				return
			}
			if maxcnt != 1 && maxcnt == end-beg {
				fmt.Fprintf(bufout, "NO\n")
				return
			}
			G = append(G, group{beg, end})
		}
	}
	//fmt.Println(G)
	fmt.Fprintf(bufout, "YES\n")
	for i := 0; i < len(G); i++ {
		output(A, G[i].beg, G[i].end, i)
	}
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

type Slice struct {
    start, end int
}

type Step struct {
    position int
    step string
}

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

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

func Build(startIndex int, items []int) ([]Step, bool) {
    maxIndex := 0
    cnt := len(items)
    var steps []Step

    if cnt == 1 {
        return steps, true
    }

    for i := 0; i < cnt; i++ {
        if items[i] > items[maxIndex] {
            maxIndex = i
        }
    }

    if maxIndex > 0 {
        for maxIndex > 0 {
            steps = append(steps, Step{startIndex + maxIndex, "L"})
            maxIndex--
            cnt--
        }

        for cnt > 1 {
            steps = append(steps, Step{startIndex, "R"})
            cnt--
        }

        return steps, true
    } else if items[maxIndex] > items[maxIndex+1] {
        for cnt > 1 {
            steps = append(steps, Step{startIndex, "R"})
            cnt--
        }
        return steps, true
    } else {
        for maxIndex + 1 < cnt && items[maxIndex] == items[maxIndex+1] {
            maxIndex++
        }

        if maxIndex+1 >= cnt || items[maxIndex] == items[maxIndex+1] {
            return steps, false
        } else {
            for maxIndex + 1 < cnt {
                steps = append(steps, Step{startIndex + maxIndex, "R"})
                cnt--
            }

            for maxIndex > 0 {
                steps = append(steps, Step{startIndex + maxIndex, "L"})
                maxIndex--
            }
        }
    }

    return steps, true
}

func main() {
    scanner.Split(bufio.ScanWords)

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

    for i := 0; i < n; i++ {
        a[i] = ReadInt()
    }

    k := ReadInt()
    b := make([]int, k)
    slices := make([]Slice, k)

    for i := 0; i < k; i++ {
        b[i] = ReadInt()
    }

    leftPointer := 0
    for i := 0; i < k; i++ {
        curSlice := Slice{leftPointer, leftPointer}
        curSum := a[leftPointer]
        leftPointer++

        for curSum < b[i] && leftPointer < n {
            curSum += a[leftPointer]
            leftPointer++
        }

        if curSum != b[i] {
            fmt.Println("NO")
            return
        } else {
            curSlice.end = leftPointer
            slices[i] = curSlice
        }
    }

    var steps []Step

    for i := 0; i < k; i++ {
        newSteps, success := Build(i + 1, a[slices[i].start:slices[i].end])
        if !success {
            fmt.Println("NO")
            return
        } else {
            steps = append(steps, newSteps...)
        }
    }

    fmt.Println("YES")
    for i := 0; i < len(steps); i++ {
        fmt.Println(strconv.Itoa(steps[i].position) + " " + steps[i].step)
    }
}

package main

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

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

type AnsTuple struct {
	Index  int
	Direct string
}

var queue []AnsTuple

func recv(v []int, count int) bool {
	if count == len(v) - 1 {
		return true
	}
	u := [2]int{}
	un := [2]int{}
	normalizeIndex := 0
	normalizeIndex2 := 0

	for i := 0; i < len(v); i++ {
		if v[i] == 0 {
			continue
		}

		u[0] = i
		un[0] = normalizeIndex
		normalizeIndex2 = normalizeIndex
		for j := i + 1; j < len(v); j++ {
			if v[j] == 0 {
				continue
			}
			normalizeIndex2++
			if v[i] == v[j] {
				continue
			}

			u[1] = j
			un[1] = normalizeIndex2
			if v[u[0]] < v[u[1]] {

				a := v[u[0]]
				b := v[u[1]]
				v[u[1]] += a
				v[u[0]] = 0
				queue = append(queue, AnsTuple{Index:un[1], Direct:"L"})
				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]
				v[u[0]] = a
				v[u[1]] = b
				println("back", fmt.Errorf("%+v", v).Error())

			} else {
				a := v[u[0]]
				b := v[u[1]]

				v[u[0]] += b
				v[u[1]] = 0
				queue = append(queue, AnsTuple{Index:un[0], Direct:"R"})

				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]

				v[u[0]] = a
				v[u[1]] = b

			}

		}
		normalizeIndex++
	}
	return false
}
func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextIntArray()
	k := sc.NextInt()
	b := sc.NextIntArray()

	i := 0
	ans := make([]string, 0)
	for j := 0; j < k; j++ {
		sum := 0
		f := i
		for ; sum < b[j] && i < N; i++ {
			sum += a[i]
		}
		if sum != b[j] {
			fmt.Println("NO")
			return
		}
		if j == k - 1 && i != N {
			fmt.Println("NO")
			return
		}
		queue = make([]AnsTuple, 0)
		if !recv(a[f:i], 0) {
			fmt.Println("NO")
			return
		}
		for i := 0; i < len(queue); i++ {
			str := strconv.Itoa(queue[i].Index + j + 1)
			str += " "
			str += queue[i].Direct
			ans = append(ans, str)
		}

	}
	fmt.Println("YES")
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

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

package main

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

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

type AnsTuple struct {
	Index  int
	Direct string
}

var queue []AnsTuple

func recv(v []int, count int) bool {
	if count == len(v) - 1 {
		return true
	}
	u := [2]int{}
	un := [2]int{}
	normalizeIndex := 0
	normalizeIndex2 := 0

	for i := 0; i < len(v); i++ {
		if v[i] == 0 {
			continue
		}
		u[0] = i
		un[0] = normalizeIndex
		normalizeIndex2 = normalizeIndex
		for j := i + 1; j < len(v); j++ {
			if v[i] == v[j] {
				continue
			}
			normalizeIndex2++

			u[1] = j
			un[1] = normalizeIndex2
			if v[u[0]] < v[u[1]] {
				a := v[u[0]]
				b := v[u[1]]
				v[u[1]] += a
				v[u[0]] = 0
				queue = append(queue, AnsTuple{Index:un[1], Direct:"L"})
				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]
				v[u[0]] = a
				v[u[1]] = b

			} else {
				a := v[u[0]]
				b := v[u[1]]

				v[u[0]] += b
				v[u[1]] = 0
				queue = append(queue, AnsTuple{Index:un[0], Direct:"R"})

				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]

				v[u[0]] = a
				v[u[1]] = b

			}

		}
		normalizeIndex++
	}
	return false
}
func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextIntArray()
	k := sc.NextInt()
	b := sc.NextIntArray()

	i := 0
	ans := make([]string, 0)
	for j := 0; j < k; j++ {
		sum := 0
		f := i
		for ; sum < b[j] && i < N; i++ {
			sum += a[i]
		}
		if sum != b[j] {
			fmt.Println("NO")
			return
		}
		queue = make([]AnsTuple, 0)
		if !recv(a[f:i], 0) {
			fmt.Println("NO")
			return
		}
		for i := 0; i < len(queue); i++ {
			str := strconv.Itoa(queue[i].Index + j + 1)
			str += " "
			str += queue[i].Direct
			ans = append(ans, str)
		}

	}
	fmt.Println("YES")
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

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

package main

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

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

type AnsTuple struct {
	Index  int
	Direct string
}

var queue []AnsTuple

func recv(v []int, count int) bool {
	if count == len(v) - 1 {
		return true
	}
	u := [2]int{}
	un := [2]int{}
	normalizeIndex := 0
	normalizeIndex2 := 0

	for i := 0; i < len(v); i++ {
		if v[i] == 0 {
			continue
		}
		u[0] = i
		un[0] = normalizeIndex
		normalizeIndex2 = normalizeIndex
		for j := i + 1; j < len(v); j++ {
			if v[i] == v[j] {
				continue
			}
			if v[j] == 0 {
				continue
			}
			normalizeIndex2++

			u[1] = j
			un[1] = normalizeIndex2
			if v[u[0]] < v[u[1]] {
				a := v[u[0]]
				b := v[u[1]]
				v[u[1]] += a
				v[u[0]] = 0
				queue = append(queue, AnsTuple{Index:un[1], Direct:"L"})
				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]
				v[u[0]] = a
				v[u[1]] = b

			} else {
				a := v[u[0]]
				b := v[u[1]]

				v[u[0]] += b
				v[u[1]] = 0
				queue = append(queue, AnsTuple{Index:un[0], Direct:"R"})

				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]

				v[u[0]] = a
				v[u[1]] = b

			}

		}
		normalizeIndex++
	}
	return false
}
func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextIntArray()
	k := sc.NextInt()
	b := sc.NextIntArray()

	i := 0
	ans := make([]string, 0)
	for j := 0; j < k; j++ {
		sum := 0
		f := i
		for ; sum < b[j] && i < N; i++ {
			sum += a[i]
		}
		if sum != b[j] {
			fmt.Println("NO")
			return
		}
		if j == k - 1 && i != N - 1 {
			fmt.Println("NO")
			return
		}
		queue = make([]AnsTuple, 0)
		if !recv(a[f:i], 0) {
			fmt.Println("NO")
			return
		}
		for i := 0; i < len(queue); i++ {
			str := strconv.Itoa(queue[i].Index + j + 1)
			str += " "
			str += queue[i].Direct
			ans = append(ans, str)
		}

	}
	fmt.Println("YES")
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

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

package main

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

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

type AnsTuple struct {
	Index  int
	Direct string
}

var queue []AnsTuple

func recv(v []int, count int) bool {
	if count == len(v) - 1 {
		return true
	}
	u := [2]int{}
	un := [2]int{}
	normalizeIndex := 0
	normalizeIndex2 := 0

	for i := 0; i < len(v); i++ {
		if v[i] == 0 {
			continue
		}
		u[0] = i
		un[0] = normalizeIndex
		normalizeIndex2 = normalizeIndex
		for j := i + 1; j < len(v); j++ {
			if v[i] == v[j] {
				continue
			}
			if v[j] == 0 {
				continue
			}
			normalizeIndex2++

			u[1] = j
			un[1] = normalizeIndex2
			if v[u[0]] < v[u[1]] {
				a := v[u[0]]
				b := v[u[1]]
				v[u[1]] += a
				v[u[0]] = 0
				queue = append(queue, AnsTuple{Index:un[1], Direct:"L"})
				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]
				v[u[0]] = a
				v[u[1]] = b

			} else {
				a := v[u[0]]
				b := v[u[1]]

				v[u[0]] += b
				v[u[1]] = 0
				queue = append(queue, AnsTuple{Index:un[0], Direct:"R"})

				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]

				v[u[0]] = a
				v[u[1]] = b

			}

		}
		normalizeIndex++
	}
	return false
}
func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextIntArray()
	k := sc.NextInt()
	b := sc.NextIntArray()

	i := 0
	ans := make([]string, 0)
	for j := 0; j < k; j++ {
		sum := 0
		f := i
		for ; sum < b[j] && i < N; i++ {
			sum += a[i]
		}
		if sum != b[j] {
			fmt.Println("NO")
			return
		}
		queue = make([]AnsTuple, 0)
		if !recv(a[f:i], 0) {
			fmt.Println("NO")
			return
		}
		for i := 0; i < len(queue); i++ {
			str := strconv.Itoa(queue[i].Index + j + 1)
			str += " "
			str += queue[i].Direct
			ans = append(ans, str)
		}

	}
	fmt.Println("YES")
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

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

package main

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

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

type AnsTuple struct {
	Index  int
	Direct string
}

var queue []AnsTuple

func recv(v []int, count int) bool {
	if count == len(v) - 1 {
		return true
	}
	u := [2]int{}
	un := [2]int{}
	normalizeIndex := 0
	normalizeIndex2 := 0

	for i := 0; i < len(v); i++ {
		if v[i] == 0 {
			continue
		}
		u[0] = i
		un[0] = normalizeIndex
		normalizeIndex2 = normalizeIndex
		for j := i + 1; j < len(v); j++ {
			if v[i] == v[j] {
				continue
			}
			if v[j] == 0 {
				continue
			}
			normalizeIndex2++

			u[1] = j
			un[1] = normalizeIndex2
			if v[u[0]] < v[u[1]] {
				a := v[u[0]]
				b := v[u[1]]
				v[u[1]] += a
				v[u[0]] = 0
				queue = append(queue, AnsTuple{Index:un[1], Direct:"L"})
				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]
				v[u[0]] = a
				v[u[1]] = b

			} else {
				a := v[u[0]]
				b := v[u[1]]

				v[u[0]] += b
				v[u[1]] = 0
				queue = append(queue, AnsTuple{Index:un[0], Direct:"R"})

				if recv(v, count + 1) {
					return true
				}
				queue = queue[:len(queue) - 1]

				v[u[0]] = a
				v[u[1]] = b

			}

		}
		normalizeIndex++
	}
	return false
}
func main() {
	sc := NewScanner()
	N := sc.NextInt()
	a := sc.NextIntArray()
	k := sc.NextInt()
	b := sc.NextIntArray()

	i := 0
	ans := make([]string, 0)
	for j := 0; j < k; j++ {
		sum := 0
		f := i
		for ; sum < b[j] && i < N; i++ {
			sum += a[i]
		}
		if sum != b[j] {
			fmt.Println("NO")
			return
		}
		if j == k - 1 && i != N {
			fmt.Println("NO")
			return
		}
		queue = make([]AnsTuple, 0)
		if !recv(a[f:i], 0) {
			fmt.Println("NO")
			return
		}
		for i := 0; i < len(queue); i++ {
			str := strconv.Itoa(queue[i].Index + j + 1)
			str += " "
			str += queue[i].Direct
			ans = append(ans, str)
		}

	}
	fmt.Println("YES")
	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[i])
	}
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

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


Vasiliy finally got to work, where there is a huge amount of tasks waiting for him. Vasiliy is given a matrix consisting of n rows and m columns and q tasks. Each task is to swap two submatrices of the given matrix.For each task Vasiliy knows six integers ai, bi, ci, di, hi, wi, where ai is the index of the row where the top-left corner of the first rectangle is located, bi is the index of its column, ci is the index of the row of the top-left corner of the second rectangle, di is the index of its column, hi is the height of the rectangle and wi is its width.It's guaranteed that two rectangles in one query do not overlap and do not touch, that is, no cell belongs to both rectangles, and no two cells belonging to different rectangles share a side. However, rectangles are allowed to share an angle.Vasiliy wants to know how the matrix will look like after all tasks are performed.

The first line of the input contains three integers n, m and q (2 ≤ n, m ≤ 1000, 1 ≤ q ≤ 10 000) — the number of rows and columns in matrix, and the number of tasks Vasiliy has to perform. Then follow n lines containing m integers vi, j (1 ≤ vi, j ≤ 109) each — initial values of the cells of the matrix. Each of the following q lines contains six integers ai, bi, ci, di, hi, wi (1 ≤ ai, ci, hi ≤ n, 1 ≤ bi, di, wi ≤ m).

Print n lines containing m integers each — the resulting matrix.

package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}

func getI() int {
  return int(getI64())
}

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

type Node struct {
	value int
	right *Node
	down *Node
}

func newNode(v int) *Node{
	return &Node{value: v}
}

func readMatrix (n, m int) *Node {
	//var root, currentNode, rowFirstNode *Node
	var matrix [][]*Node

	matrix = make([][]*Node, n+2, n+2)

	for colNo := 0; colNo < m + 2; colNo++ {
		matrix[0] = append(matrix[0], newNode(-1))

	}

	for rowNo := 1; rowNo < n+1; rowNo++ {
		matrix[rowNo] = append(matrix[rowNo], newNode(-1))
		for colNo := 1; colNo < m + 1; colNo++ {
			matrix[rowNo] = append(matrix[rowNo], newNode(getI()))
		}
		matrix[rowNo] = append(matrix[rowNo], newNode(-1))
	}

	for colNo := 0; colNo < m + 2; colNo++ {
		matrix[n+1] = append(matrix[n+1], newNode(-1))

	}

	for rowNo := 0; rowNo < n + 2; rowNo++ {
		for colNo := 0; colNo < m + 2; colNo++ {
			if colNo < m + 1 {
				matrix[rowNo][colNo].right = matrix[rowNo][colNo + 1]
			}
			if rowNo < n + 1 {
				matrix[rowNo][colNo].down = matrix[rowNo + 1][colNo]
			}
		}
	}

	return matrix[0][0]

}

func printMatrix(root *Node, n, m int) {
	var currentNode, rowFirst *Node
	rowFirst = root.right.down
	currentNode = rowFirst
	for rowFirst.value != -1 {
		for currentNode.value != -1 {
			writer.WriteString(strconv.Itoa(currentNode.value))
			currentNode = currentNode.right
			if currentNode.value != -1 {
				writer.WriteByte(' ')
			}
		}
		writer.WriteByte('\n')
		rowFirst = rowFirst.down
		currentNode = rowFirst
	}
}

func getXY(root *Node, x, y int) *Node{
	var node *Node
	node = root
	for i:=0; i < x; i++ {
		node = node.down
	}
	for i:=0; i < y; i++ {
		node = node.right
	}
	return node
}

func swap(a, b, c, d, h, w int, root *Node) {
	abNode := getXY(root, a - 1, b - 1)
	cdNode := getXY(root, c - 1, d - 1)

	abNodeVer := abNode
	cdNodeVer := cdNode

	for i:=0; i < h; i++ {
		abNodeVer = abNodeVer.down
		cdNodeVer = cdNodeVer.down
		abNodeVer.right, cdNodeVer.right = cdNodeVer.right, abNodeVer.right
	}

	abNodeHor := abNode
	cdNodeHor := cdNode

	for i:=0; i < w; i++ {
		abNodeHor = abNodeHor.right
		cdNodeHor = cdNodeHor.right
		abNodeHor.down, cdNodeHor.down = cdNodeHor.down, abNodeHor.down
	}

	abNodeVer, cdNodeVer = cdNodeVer.right, abNodeVer.right

	for i:=0; i < w; i++ {
		abNodeVer.down, cdNodeVer.down = cdNodeVer.down, abNodeVer.down
		cdNodeVer = cdNodeVer.right
		abNodeVer = abNodeVer.right
	}

	abNodeHor, cdNodeHor = cdNodeHor.down, abNodeHor.down

	for i:=0; i < h; i++ {
		abNodeHor.right, cdNodeHor.right = cdNodeHor.right, abNodeHor.right
		cdNodeHor = cdNodeHor.down
		abNodeHor = abNodeHor.down
	}

}

func main()  {
	var (
		m, n, q int
		root *Node
	)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

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

	n = getI()
	m = getI()
	q = getI()

	root = readMatrix(n, m)

	for i := 0; i < q; i++ {
		a, b, c, d, h, w := getI(), getI(), getI(), getI(), getI(), getI()
		swap(a, b, c, d, h, w, root)
	}

	printMatrix(root, n, m)
}

package main

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

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

type Node struct {
	val   int
	down  *Node
	right *Node
}

func create(v int) *Node {
	return &Node{
		val:   v,
		down:  nil,
		right: nil,
	}
}

const maxn = 1005

var n, m, q int
var a [maxn][maxn]*Node

func swap(i1 int, j1 int, i2 int, j2 int, h int, w int) {
	node1 := a[0][0]
	node2 := a[0][0]

	for ; i1 > 1; i1-- {
		node1 = node1.down
	}

	for ; j1 > 1; j1-- {
		node1 = node1.right
	}

	for ; i2 > 1; i2-- {
		node2 = node2.down
	}

	for ; j2 > 1; j2-- {
		node2 = node2.right
	}

	save1, save2 := node1, node2

	for k := 1; k <= w; k++ {
		node1, node2 = node1.right, node2.right
		node1.down, node2.down = node2.down, node1.down
	}

	node1, node2 = node2.down, node1.down
	for k := 1; k <= h; k++ {
		node1.right, node2.right = node2.right, node1.right
		node1, node2 = node1.down, node2.down
	}

	for k := 1; k <= h; k++ {
		save1, save2 = save1.down, save2.down
		save1.right, save2.right = save2.right, save1.right
	}

	save1, save2 = save2.right, save1.right
	for k := 1; k <= w; k++ {
		save1.down, save2.down = save2.down, save1.down
		save1, save2 = save1.right, save2.right
	}
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	in.Scan()
	n, _ = strconv.Atoi(in.Text())

	in.Scan()
	m, _ = strconv.Atoi(in.Text())

	in.Scan()
	q, _ = strconv.Atoi(in.Text())

	for i := 0; i <= n+1; i++ {
		for j := 0; j <= m+1; j++ {
			a[i][j] = create(-1)
		}
	}

	for i := 0; i <= n; i++ {
		for j := 0; j <= m; j++ {
			a[i][j].down = a[i+1][j]
			a[i][j].right = a[i][j+1]
		}
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			in.Scan()
			a[i][j].val, _ = strconv.Atoi(in.Text())
		}
	}

	for k := 1; k <= q; k++ {
		in.Scan()
		i1, _ := strconv.Atoi(in.Text())
		in.Scan()
		j1, _ := strconv.Atoi(in.Text())
		in.Scan()
		i2, _ := strconv.Atoi(in.Text())
		in.Scan()
		j2, _ := strconv.Atoi(in.Text())
		in.Scan()
		h, _ := strconv.Atoi(in.Text())
		in.Scan()
		w, _ := strconv.Atoi(in.Text())
		swap(i1, j1, i2, j2, h, w)
	}

	row := a[0][1].down
	for i := 1; i <= n; i++ {
		col := row
		for j := 1; j <= m; j++ {
			out.WriteString(strconv.Itoa(col.val))
			if j < m {
				out.WriteByte(' ')
			}
			col = col.right
		}
		out.WriteByte('\n')
		row = row.down
	}

}


This is an interactive problem.Initially, there is an array $$$a = [1, 2, \ldots, n]$$$, where $$$n$$$ is an odd positive integer. The jury has selected $$$\frac{n-1}{2}$$$ disjoint pairs of elements, and then the elements in those pairs are swapped. For example, if $$$a=[1,2,3,4,5]$$$, and the pairs $$$1 \leftrightarrow 4$$$ and $$$3 \leftrightarrow 5$$$ are swapped, then the resulting array is $$$[4, 2, 5, 1, 3]$$$. As a result of these swaps, exactly one element will not change position. You need to find this element.To do this, you can ask several queries. In each query, you can pick two integers $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq n$$$). In return, you will be given the elements of the subarray $$$[a_l, a_{l + 1}, \dots, a_r]$$$ sorted in increasing order. Find the element which did not change position. You can make at most $$$\mathbf{15}$$$ queries.The array $$$a$$$ is fixed before the interaction and does not change after your queries.Recall that an array $$$b$$$ is a subarray of the array $$$a$$$ if $$$b$$$ can be obtained from $$$a$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n < 10^4$$$; $$$n$$$ is odd) — the length of the array $$$a$$$. After reading the first line of each test case, you should begin the interaction. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.

NoteIn the first test, the interaction proceeds as follows. SolutionJuryExplanation$$$\texttt{2}$$$There are 2 test cases.$$$\texttt{5}$$$In the first test case, the hidden array is $$$[4,2,5,1,3]$$$, with length $$$5$$$.$$$\texttt{? 1 4}$$$$$$\texttt{1 2 4 5}$$$The solution requests the subarray $$$[4,2,5,1]$$$ in increasing order, and the jury responds with $$$[1,2,4,5]$$$.$$$\texttt{? 3 5}$$$$$$\texttt{1 3 5}$$$The solution requests the subarray $$$[5,1,3]$$$ in increasing order, and the jury responds with $$$[1,3,5]$$$.$$$\texttt{! 2}$$$The solution has somehow determined that $$$a_2=2$$$, and outputs it. Since the output is correct, the jury continues to the next test case.$$$\texttt{3}$$$In the second test case, the hidden array is $$$[1,3,2]$$$, with length $$$3$$$.$$$\texttt{? 1 1}$$$$$$\texttt{1}$$$The solution requests the number $$$[1]$$$ only, and the jury responds with $$$[1]$$$.$$$\texttt{! 1}$$$The solution has determined that $$$a_1=1$$$, and outputs it. Since the output is correct and there are no more test cases, the jury and the solution exit. Note that the line breaks in the example input and output are for the sake of clarity, and do not occur in the real interaction.

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)

		l, r := 1, n
		for l < r {
			mid := (r + l) / 2
			fmt.Fprintf(out, "? %d %d\n", l, mid)
			out.Flush()

			var c int
			for i := l; i <= mid; i++ {
				var v int
				fmt.Fscan(in, &v)
				if v >= l && v <= mid {
					c++
				}
			}

			if c%2 != 0 {
				r = mid
			} else {
				l = mid + 1
			}
		}

		fmt.Fprintf(out, "! %d\n", l)
		out.Flush()
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	left, right := 1, n
	for left < right{
		m := left + right
		m /= 2
		fmt.Fprintf(w, "? %d %d\n", left, m)
		w.Flush()
		cnt := 0
		for i:=left;i<=m;i++ {
			var a int
			fmt.Fscan(r, &a)
			if a <= m && a >= left {
				cnt++
			}
		}
		if cnt % 2 == 0 {
			left = m + 1
		} else {
			right = m
		}
	}
	fmt.Fprintf(w, "! %d\n", left)
	w.Flush()
}

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

package main

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

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

func main() {
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		playGame(n)
	}
}

func playGame(n int) {
	father_l := 1
	father_r := n
	l := father_l
	r := (father_r-father_l)/2 + 1
	length := r - l + 1
	for {
		guess(l, r)
		reply := readArrInt(input)
		correct_in_here := length
		for _, v := range reply {
			if v > r || v < l {
				correct_in_here--
			}
		}
		if correct_in_here%2 == 1 {
			father_l = l
			father_r = r
			l = father_l
			r = (father_r + father_l) / 2
		} else {
			father_l = r + 1
			l = father_l
			r = (father_r + father_l) / 2
		}
		if l == r {
			guess(l, r)
			asdfg := readInt(input)
			if asdfg == l {
				answer(asdfg)
			} else {
				answer(l + 1)
			}
			return
		}
		length = r - l + 1
	}
}

func guess(l int, r int) {
	writer.WriteString("?")
	writer.WriteString(" ")
	writer.Write([]byte(strconv.Itoa(l)))
	writer.WriteString(" ")
	writer.Write([]byte(strconv.Itoa(r)))
	writer.WriteString(" ")
	writer.WriteString("\n")
	writer.Flush()
}

func answer(l int) {
	writer.WriteString("!")
	writer.WriteString(" ")
	writer.Write([]byte(strconv.Itoa(l)))
	writer.WriteString("\n")
	writer.Flush()
}

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

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

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func gi64() int64     { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis64(n int) []int64  { res := make([]int64,n); for i:=0;i<n;i++ { res[i] = gi64() }; return res }

func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}

func ia64(m int) []int64 { return make([]int64,m) }
func iai64(m int,v int64) []int64 { a := make([]int64,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi64(n int,m int,v int64) [][]int64 {
	r := make([][]int64,n); for i:=0;i<n;i++ { x := make([]int64,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill264(m int) ([]int64,[]int64) { a,b := ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i] = gi64(),gi64()}; return a,b }
func fill364(m int) ([]int64,[]int64,[]int64) { a,b,c := ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi64(),gi64(),gi64()}; return a,b,c }
func fill464(m int) ([]int64,[]int64,[]int64,[]int64) { a,b,c,d := ia64(m),ia64(m),ia64(m),ia64(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi64(),gi64(),gi64(),gi64()}; return a,b,c,d }
func abs64(a int64) int64 { if a < 0 { return -a }; return a }
func rev64(a []int64) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max64(a,b int64) int64 { if a > b { return a }; return b }
func min64(a,b int64) int64 { if a > b { return b }; return a }
func maxarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr64(a []int64) int64 { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr64(a []int64) int64 { ans := int64(0); for _,aa := range(a) { ans += aa }; return ans }
func zeroarr64(a []int64) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod64(a,e,mod int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint64(a,e int64) int64 { res, m := int64(1), a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd64(a,b int64) int64 { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended64(a,b int64) (int64,int64,int64) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended64(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv64(a,m int64) (int64,bool) { g,x,_ := gcdExtended64(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func vecint64string(a []int64) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.FormatInt(a,10) }; return strings.Join(astr," ") }
func makefact64(n int,mod int64) ([]int64,[]int64) {
	fact,factinv := make([]int64,n+1),make([]int64,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * int64(i) % mod }
	factinv[n] = powmod64(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * int64(i+1) % mod }
	return fact,factinv
}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); if N == -1 { panic("SHOULD NOT GET HERE1") }
		l,r := 1,N
		for l != r {
			m := (l+r)>>1
			fmt.Fprintf(wrtr,"? %v %v\n",l,m); wrtr.Flush()
			cnt := 0
			for i:=0;i<m-l+1;i++ {
				a := gi()
				//fmt.Fprintf(os.Stderr,"i:%v a:%v m-l+1:%v\n",i,a,m-l+1)
				if a == -1 { panic("SHOULD NOT GET HERE2") }
				if l <= a && a <= m { cnt++ }
			}
			if cnt % 2 == 1 { r = m } else { l = m+1 }
		}
		fmt.Fprintf(wrtr,"! %v\n",l); wrtr.Flush()
	}
}

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)

		l, r := 1, n
		for r-l > 1 {
			mid := (r + l) / 2
			fmt.Fprintf(out, "? %d %d\n", l, mid)
			out.Flush()

			var c int
			for i := 0; i < mid; i++ {
				var v int
				fmt.Fscan(in, &v)
				if v >= l && v <= mid {
					c++
				}
			}

			if c%2 != 0 {
				r = mid
			} else {
				l = mid + 1
			}
		}

		fmt.Fprintf(out, "! %d\n", l)
		out.Flush()
	}
}

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)

		l, r := 1, n
		d := 1
		for r-l > 1 {
			mid := (r + l) / 2
			fmt.Fprintf(out, "? %d %d\n", l, mid)
			out.Flush()

			var c int
			for i := 0; i < mid; i++ {
				var v int
				fmt.Fscan(in, &v)
				if v >= l && v <= mid {
					d = v
					c++
				}
			}

			if c == 1 {
				break
			}

			if c%2 != 0 {
				r = mid
			} else {
				l = mid
			}
		}

		fmt.Fprintf(out, "! %d\n", d)
		out.Flush()
	}
}

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)

		l, r := 1, n
		for r-l > 1 {
			mid := (r - l) / 2
			fmt.Fprintf(out, "? %d %d\n", l, mid)
			out.Flush()

			var c int
			for i := 0; i < mid; i++ {
				var v int
				fmt.Fscan(in, &v)
				if v >= l && v <= mid {
					c++
				}
			}

			if c%2 != 0 {
				r = mid
			} else {
				l = mid
			}
		}

		fmt.Fprintf(out, "? %d %d\n", l, l)
		out.Flush()
		var v int
		fmt.Fscan(in, &v)
		if v != l {
			v++
		}
		fmt.Fprintf(out, "! %d\n", v)
		out.Flush()
	}
}


Polycarp has $$$n$$$ coins, the value of the $$$i$$$-th coin is $$$a_i$$$. It is guaranteed that all the values are integer powers of $$$2$$$ (i.e. $$$a_i = 2^d$$$ for some non-negative integer number $$$d$$$).Polycarp wants to know answers on $$$q$$$ queries. The $$$j$$$-th query is described as integer number $$$b_j$$$. The answer to the query is the minimum number of coins that is necessary to obtain the value $$$b_j$$$ using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value $$$b_j$$$, the answer to the $$$j$$$-th query is -1.The queries are independent (the answer on the query doesn't affect Polycarp's coins).

The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the number of coins and the number of queries. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ — values of coins ($$$1 \le a_i \le 2 \cdot 10^9$$$). It is guaranteed that all $$$a_i$$$ are integer powers of $$$2$$$ (i.e. $$$a_i = 2^d$$$ for some non-negative integer number $$$d$$$). The next $$$q$$$ lines contain one integer each. The $$$j$$$-th line contains one integer $$$b_j$$$ — the value of the $$$j$$$-th query ($$$1 \le b_j \le 10^9$$$).

Print $$$q$$$ integers $$$ans_j$$$. The $$$j$$$-th integer must be equal to the answer on the $$$j$$$-th query. If Polycarp can't obtain the value $$$b_j$$$ the answer to the $$$j$$$-th query is -1.

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

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

	coins := [31]int{}
	var n, q int
	var v uint
	for Fscan(in, &n, &q); n > 0; n-- {
		Fscan(in, &v)
		coins[bits.TrailingZeros(v)]++
	}
o:
	for ; q > 0; q-- {
		s, c := 0, coins
		for Fscan(in, &v); v > 0; v &= v - 1 {
			p := bits.TrailingZeros(v)
			for cost := 1; ; cost <<= 1 {
				if cost <= c[p] {
					c[p] -= cost
					s += cost
					break
				}
				if p == 0 {
					Fprintln(out, -1)
					continue o
				}
				cost -= c[p]
				s += c[p]
				c[p] = 0
				p--
			}
		}
		Fprintln(out, s)
	}
}

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


Alice and Borys are playing tennis.A tennis match consists of games. In each game, one of the players is serving and the other one is receiving.Players serve in turns: after a game where Alice is serving follows a game where Borys is serving, and vice versa.Each game ends with a victory of one of the players. If a game is won by the serving player, it's said that this player holds serve. If a game is won by the receiving player, it's said that this player breaks serve.It is known that Alice won $$$a$$$ games and Borys won $$$b$$$ games during the match. It is unknown who served first and who won which games.Find all values of $$$k$$$ such that exactly $$$k$$$ breaks could happen during the match between Alice and Borys in total.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). Description of the test cases follows. Each of the next $$$t$$$ lines describes one test case and contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^5$$$; $$$a + b > 0$$$) — the number of games won by Alice and Borys, respectively. It is guaranteed that the sum of $$$a + b$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print two lines. In the first line, print a single integer $$$m$$$ ($$$1 \le m \le a + b + 1$$$) — the number of values of $$$k$$$ such that exactly $$$k$$$ breaks could happen during the match. In the second line, print $$$m$$$ distinct integers $$$k_1, k_2, \ldots, k_m$$$ ($$$0 \le k_1 < k_2 < \ldots < k_m \le a + b$$$) — the sought values of $$$k$$$ in increasing order.

NoteIn the first test case, any number of breaks between $$$0$$$ and $$$3$$$ could happen during the match:   Alice holds serve, Borys holds serve, Alice holds serve: $$$0$$$ breaks;  Borys holds serve, Alice holds serve, Alice breaks serve: $$$1$$$ break;  Borys breaks serve, Alice breaks serve, Alice holds serve: $$$2$$$ breaks;  Alice breaks serve, Borys breaks serve, Alice breaks serve: $$$3$$$ breaks. In the second test case, the players could either both hold serves ($$$0$$$ breaks) or both break serves ($$$2$$$ breaks).In the third test case, either $$$2$$$ or $$$3$$$ breaks could happen:   Borys holds serve, Borys breaks serve, Borys holds serve, Borys breaks serve, Borys holds serve: $$$2$$$ breaks;  Borys breaks serve, Borys holds serve, Borys breaks serve, Borys holds serve, Borys breaks serve: $$$3$$$ breaks.

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

var t int

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

	for o := 0; o < t; o++ {
		var a, b int
		fmt.Fscan(input, &a, &b)

		if (a+b)%2 == 0 {
			m := (a + b) / 2

			p := MAXX(a, b)

			minim := p - m

			maxim := (a + b) - minim
			oo := (maxim - minim + 2) / 2
			fmt.Println(oo)
			for i := minim; i <= maxim; {
				fmt.Println(i)
				i = i + 2
			}

		} else {
			m := (a + b) / 2

			p := MAXX(a, b)

			min1 := p - m - 1

			maxim := (a + b) - min1
			oo := maxim - min1 + 1

			fmt.Println(oo)
			for j := min1; j <= maxim; j++ {
				fmt.Println(j)
			}

		}

	}
}

package main

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

func main() {
	defer wr.Flush()

	t := scanInt()
	for i := 0; i < t; i++ {
		a, b := scanInt(), scanInt()
		n, s := solve(a, b)
		fmt.Fprintln(wr, n)
		for i := range s {
			if i > 0 {
				fmt.Fprint(wr, " ")
			}
			fmt.Fprint(wr, s[i])
		}
		fmt.Fprint(wr, "\n")
	}
}

func solve(a, b int) (int, []int) {
	if a > b {
		a, b = b, a
	}
	n := a + b

	// a<=b
	var m int
	var s []int
	if n%2 == 1 {
		m = (a + 1) * 2
		s = make([]int, m)
		q := n/2 - a
		for i := range s {
			s[i] = q + i
		}
	} else {
		m = a + 1
		s = make([]int, m)

		q := n/2 - a
		for i := range s {
			s[i] = q
			q += 2
		}
	}
	return m, s
}

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

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

	wr = bufio.NewWriter(os.Stdout)
}

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

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	var a, b int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &a, &b)
		w1 := do(a, b)
		fmt.Fprintln(w, len(w1))
		for i, v := range w1 {
			if i > 0 {
				fmt.Fprint(w, " ")
			}
			fmt.Fprint(w, v)
			if i == len(w1)-1 {
				fmt.Fprintln(w)
			}
		}
	}
}

func do(a, b int) []int {
	m := map[int]struct{}{}
	m = g(a, b, m)
	m = g(b, a, m)
	keys := make([]int, 0, len(m))
	for k := range m {
		keys = append(keys, k)
	}
	sort.Ints(keys)
	return keys
}

func g(a, b int, m map[int]struct{}) map[int]struct{} {
	n1 := (a + b + 1) / 2
	n2 := a + b - n1
	for b1 := 0; b1 <= n2 && b1 <= a; b1++ {
		s1 := a - b1
		b2 := n1 - s1
		s2 := b - b2
		if s1 >= 0 && b2 >= 0 && s2 >= 0 {
			m[b1+b2] = struct{}{}
		}
	}
	return m
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

var t int

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

	for o := 0; o < t; o++ {
		var a, b int
		fmt.Fscan(input, &a, &b)

		if (a+b)%2 == 0 {
			m := (a + b) / 2

			p := MAXX(a, b)

			minim := p - m

			maxim := (a + b) - minim

			for i := minim; i <= maxim; {
				fmt.Println(i)
				i = i + 2
			}

		} else {
			m := (a + b) / 2

			p := MAXX(a, b)

			min1 := p - m - 1

			maxim := (a + b) - min1

			for j := min1; j <= maxim; j++ {
				fmt.Println(j)
			}

		}

	}
}