Let $$$n$$$ be a positive integer. Let $$$a, b, c$$$ be nonnegative integers such that $$$a + b + c = n$$$.Alice and Bob are gonna play rock-paper-scissors $$$n$$$ times. Alice knows the sequences of hands that Bob will play. However, Alice has to play rock $$$a$$$ times, paper $$$b$$$ times, and scissors $$$c$$$ times.Alice wins if she beats Bob in at least $$$\lceil \frac{n}{2} \rceil$$$ ($$$\frac{n}{2}$$$ rounded up to the nearest integer) hands, otherwise Alice loses.Note that in rock-paper-scissors:  rock beats scissors;  paper beats rock;  scissors beat paper. The task is, given the sequence of hands that Bob will play, and the numbers $$$a, b, c$$$, determine whether or not Alice can win. And if so, find any possible sequence of hands that Alice can use to win.If there are multiple answers, print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then, $$$t$$$ testcases follow, each consisting of three lines:    The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).  The second line contains three integers, $$$a, b, c$$$ ($$$0 \le a, b, c \le n$$$). It is guaranteed that $$$a + b + c = n$$$.  The third line contains a string $$$s$$$ of length $$$n$$$. $$$s$$$ is made up of only 'R', 'P', and 'S'. The $$$i$$$-th character is 'R' if for his $$$i$$$-th Bob plays rock, 'P' if paper, and 'S' if scissors.

For each testcase:    If Alice cannot win, print "NO" (without the quotes).  Otherwise, print "YES" (without the quotes). Also, print a string $$$t$$$ of length $$$n$$$ made up of only 'R', 'P', and 'S' — a sequence of hands that Alice can use to win. $$$t$$$ must contain exactly $$$a$$$ 'R's, $$$b$$$ 'P's, and $$$c$$$ 'S's.  If there are multiple answers, print any of them.  The "YES" / "NO" part of the output is case-insensitive (i.e. "yEs", "no" or "YEs" are all valid answers). Note that 'R', 'P' and 'S' are case-sensitive.

NoteIn the first testcase, in the first hand, Alice plays paper and Bob plays rock, so Alice beats Bob. In the second hand, Alice plays scissors and Bob plays paper, so Alice beats Bob. In the third hand, Alice plays rock and Bob plays scissors, so Alice beats Bob. Alice beat Bob 3 times, and $$$3 \ge \lceil \frac{3}{2} \rceil = 2$$$, so Alice wins.In the second testcase, the only sequence of hands that Alice can play is "RRR". Alice beats Bob only in the last hand, so Alice can't win. $$$1 < \lceil \frac{3}{2} \rceil = 2$$$.

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	tt := 1
	fmt.Fscanf(in, "%d\n", &tt)
	for ii := 0; ii < tt; ii++ {
		n, a, b, c := 0, 0, 0, 0
		fmt.Fscanf(in, "%d\n", &n)
		fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
		s := ""
		a1, b1, c1 := 0, 0, 0
		fmt.Fscanf(in, "%s\n", &s)
		for i := 0; i < n; i++ {
			if s[i] == 'R' {
				a1++
			} else if s[i] == 'P' {
				b1++
			} else {
				c1++
			}
		}
		win := 0
		win = min(a, c1) + min(b, a1) + min(c, b1)
		if win*2 >= n {
			fmt.Fprintf(out, "YES\n")
			ans := []byte{}
			for i := 0; i < n; i++ {
				if s[i] == 'R' {
					if b > 0 {
						b--
						ans = append(ans, 'P')
					} else if c > b1 {
						c--
						ans = append(ans, 'S')
					} else {
						a--
						ans = append(ans, 'R')
					}
					a1--
				} else if s[i] == 'P' {
					if c > 0 {
						c--
						ans = append(ans, 'S')
					} else if b > a1 {
						b--
						ans = append(ans, 'P')
					} else {
						a--
						ans = append(ans, 'R')
					}
					b1--
				} else {
					if a > 0 {
						a--
						ans = append(ans, 'R')
					} else if b > a1 {
						b--
						ans = append(ans, 'P')
					} else {
						c--
						ans = append(ans, 'S')
					}
					c1--
				}
			}
			fmt.Fprintf(out, "%s\n", string(ans))
		} else {
			fmt.Fprintf(out, "NO\n")
		}
	}
	return
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {

	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a, b, c := ScanInt64(), ScanInt64(), ScanInt64()
		result := []rune{}
		aliceWinCount := int64(0)

		s := ScanWord()
		for i := 0; i < len(s); i++ {
			if s[i] == 'R' {
				if b > 0 {
					b--
					result = append(result, 'P')
					aliceWinCount++
				} else {
					result = append(result, '@')
				}

			} else if s[i] == 'P' {
				if c > 0 {
					c--
					result = append(result, 'S')
					aliceWinCount++
				} else {
					result = append(result, '@')
				}
			} else if s[i] == 'S' {
				if a > 0 {
					a--
					result = append(result, 'R')
					aliceWinCount++
				} else {
					result = append(result, '@')
				}
			}
		}

		if aliceWinCount >= int64(math.Ceil(float64(n)/float64(2))) {
			out <- "YES"
			for i := 0; i < len(s); i++ {
				if result[i] == '@' {
					if a > 0 {
						a--
						result[i] = 'R'
					} else if b > 0 {
						b--
						result[i] = 'P'
					} else if c > 0 {
						c--
						result[i] = 'S'
					}
				}
			}
			out <- string(result)
		} else {
			out <- "NO"
		}
	}

	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

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

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

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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 s(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, a, b, c int
		var s string
		fmt.Fscan(in, &n, &a, &b, &c, &s)
		ans := []byte(s)
		gap := make([]int, n)
		ngap := 0
		win := n
		for i := 0; i < n; i++ {
			hand := s[i]
			if hand == 'R' && b > 0 {
				ans[i] = 'P'
				b--
			} else if hand == 'P' && c > 0 {
				ans[i] = 'S'
				c--
			} else if hand == 'S' && a > 0 {
				ans[i] = 'R'
				a--
			} else {
				gap[ngap] = i
				ngap++
				win--
			}
		}
		if win*2 < n {
			fmt.Fprintln(out, "NO")
			continue
		}
		// fill the answer gaps
		for i := 0; i < ngap; i++ {
			ians := gap[i]
			if a > 0 {
				ans[ians] = 'R'
				a--
			} else if b > 0 {
				ans[ians] = 'P'
				b--
			} else {
				ans[ians] = 'S'
				c--
			}
		}
		fmt.Fprintln(out, "YES")
		fmt.Fprintln(out, string(ans))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, a, b, c int
		var s string
		fmt.Fscan(in, &n, &a, &b, &c, &s)
		ans := []byte(s)
		gap := make([]int, n)
		ngap := 0
		win := n
		for i := 0; i < n; i++ {
			hand := s[i]
			if hand == 'R' && b > 0 {
				ans[i] = 'P'
				b--
			} else if hand == 'P' && c > 0 {
				ans[i] = 'S'
				c--
			} else if hand == 'S' && a > 0 {
				ans[i] = 'R'
				a--
			} else {
				gap[ngap] = i
				ngap++
				win--
			}
		}
		if win*2 < n {
			fmt.Fprintln(out, "NO")
			continue
		}
		// fill the answer gaps with the remaining losing hands
		for i := 0; i < ngap; i++ {
			ians := gap[i]
			if a > 0 {
				ans[ians] = 'R'
				a--
			} else if b > 0 {
				ans[ians] = 'P'
				b--
			} else {
				ans[ians] = 'S'
				c--
			}
		}
		fmt.Fprintln(out, "YES")
		fmt.Fprintln(out, string(ans))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, a, b, c int
		var s string
		fmt.Fscan(in, &n, &a, &b, &c, &s)
		ans := []byte(s)
		gap := make([]int, n)
		ngap := 0
		win := n
		for i := 0; i < n; i++ {
			hand := s[i]
			if hand == 'R' && b > 0 {
				ans[i] = 'P'
				b--
			} else if hand == 'P' && c > 0 {
				ans[i] = 'S'
				c--
			} else if hand == 'S' && a > 0 {
				ans[i] = 'R'
				a--
			} else {
				gap[ngap] = i
				ngap++
				win--
			}
		}
		if win*2 < n {
			fmt.Fprintln(out, "NO")
			continue
		}
		// fill the answer gaps
		for i := 0; i < ngap; i++ {
			ians := gap[i]
			if a > 0 {
				ans[ians] = 'R'
				a--
			} else if b > 0 {
				ans[ians] = 'P'
				b--
			} else {
				ans[ians] = 'S'
				c--
			}
		}
		fmt.Fprintln(out, "YES")
		fmt.Fprintln(out, string(ans))
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		play, ok := solve()
		if ok {
			fmt.Printf("YES\n%s\n", play)
		} else {
			fmt.Println("NO")
		}
	}
}

func solve() (string, bool) {
	var n int
	fmt.Scanf("%d\n", &n)
	var r, p, s int
	fmt.Scanf("%d %d %d\n", &r, &p, &s)
	var bob string
	fmt.Scanf("%s\n", &bob)
	var bobR, bobP, bobS int
	for _, c := range bob {
		if c == rune('R') {
			bobR++
		}
		if c == rune('P') {
			bobP++
		}
		if c == rune('S') {
			bobS++
		}
	}
	var score int
	score += min(r, bobS)
	score += min(p, bobR)
	score += min(s, bobP)
	if score*2 < n {
		return "", false
	}
	play := make([]byte, len(bob))
	for i, c := range bob {
		if c == rune('R') {
			if p > 0 {
				play[i] = byte('P')
				p--
			} else {
				play[i] = byte('-')
			}
		}
		if c == rune('P') {
			if s > 0 {
				play[i] = byte('S')
				s--
			} else {
				play[i] = byte('-')
			}
		}
		if c == rune('S') {
			if r > 0 {
				play[i] = byte('R')
				r--
			} else {
				play[i] = byte('-')
			}
		}
	}
	for i := range play {
		if play[i] == byte('-') {
			if p > 0 {
				play[i] = byte('P')
				p--
			} else if s > 0 {
				play[i] = byte('S')
				s--
			} else if r > 0 {
				play[i] = byte('R')
				r--
			}
		}
	}
	return string(play), true
}

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

package main

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

/* solution */

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		solveOne()
	}
}

func solveOne() {

	n := readInt()
	r, p, s := readInt(), readInt(), readInt()
	bob := read()

	win := 0
	out := make([]byte, n)
	for i := 0; i < len(bob); i++ {
		c := bob[i]
		if c == 'R' && p > 0 {
			p--
			out[i] = 'P'
			win++
		}
		if c == 'P' && s > 0 {
			s--
			out[i] = 'S'
			win++
		}
		if c == 'S' && r > 0 {
			out[i] = 'R'
			r--
			win++
		}
	}

	for i := 0; i < n; i++ {
		if out[i] != 'P' && out[i] != 'R' && out[i] != 'S' {
			if r > 0 {
				out[i] = 'R'
				r--
			} else if p > 0 {
				out[i] = 'P'
				p--
			} else {
				out[i] = 'S'
				s--
			}
		}
	}

	if win >= n/2+n%2 {
		print("YES")
		print(string(out))
	} else {
		print("NO")
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

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

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {
	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a, b, c := ScanInt64(), ScanInt64(), ScanInt64()
		result := []rune{}
		s := ScanWord()

		for i := int64(0); i < n; i++  {
			if s[i] == 'R' && b > 0{
				result = append(result, 'P')
				b--
			}else if s[i] == 'P' && c > 0{
				result = append(result, 'S')
				c--
			}else if s[i] == 'S' && a > 0{
				result = append(result, 'R')
				a--
			}else{
				result = append(result, '@')
			}
		}

		if (n-a-b-c)<(n+1)/2{
			fmt.Println("NO")
		}else{
			for i := int64(0); i < n; i++  {
				if result[i] == '@'{
					if a > 0{
						a--
						result[i] = 'R'

					}else if b > 0{
						b--
						result[i] = 'P'
					}else{
						c--
						result[i] = 'S'
					}
				}
			}

			fmt.Println("YES")
			fmt.Println(string(result))
		}

	}

}

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

var in *bufio.Scanner

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

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

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

func s(val interface{}) string {
	return fmt.Sprintf("%v", val)
}

func GCDVAlue(a, b int64) int64{
	if b == 0{
		return a
	}
	return GCDVAlue(b, a%b)
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n, a, b, c int
		var s string
		fmt.Scanln(&n)
		fmt.Scanln(&a, &b, &c)
		fmt.Scanln(&s)
		idx := make(map[rune][]int)
		idx['R'] = make([]int, 0)
		idx['S'] = make([]int, 0)
		idx['P'] = make([]int, 0)
		win := 0
		res := make([]byte, len(s))
		for k, v := range s {
			idx[v] = append(idx[v], k)
		}
		for i := 0; i < len(idx['P']) && c > 0; i++ {
			res[idx['P'][i]] = 'S'
			c--
			win++
		}
		for i := 0; i < len(idx['R']) && b > 0; i++ {
			res[idx['R'][i]] = 'P'
			b--
			win++
		}
		for i := 0; i < len(idx['S']) && a > 0; i++ {
			res[idx['S'][i]] = 'R'
			a--
			win++
		}
		for k, v := range s {
			if res[k] == 0 {
				if v == 'P' && b > 0 {
					b--
					res[k] = 'P'
				} else if v == 'S' && c > 0 {
					c--
					res[k] = 'S'
				} else if v == 'R' && a > 0 {
					a--
					res[k] = 'R'
				}
			}
		}
		for k := range res {
			if res[k] == 0 {
				if a > 0 {
					a--
					res[k] = 'R'
				} else if b > 0 {
					b--
					res[k] = 'P'
				} else {
					c--
					res[k] = 'S'
				}
			}
		}
		nw := n / 2
		if n%2 == 1 {
			nw++
		}
		if win >= nw {
			fmt.Println("YES")
			fmt.Println(string(res))
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var a, b, c int
var S []rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		a, b, c = ReadInt3()
		S = ReadRuneSlice()

		need := (n + (2 - 1)) / 2

		r, p, s := 0, 0, 0
		for i := 0; i < len(S); i++ {
			if S[i] == 'R' {
				r++
			} else if S[i] == 'P' {
				p++
			} else {
				s++
			}
		}

		wins := 0
		wins += Min(a, s)
		wins += Min(b, r)
		wins += Min(c, p)

		if wins >= need {
			fmt.Println("YES")

			answers := make([]rune, n)
			for i := 0; i < n; i++ {
				answers[i] = 'x'
			}

			// 勝てるやつを割り振る
			for i := 0; i < len(S); i++ {
				if S[i] == 'R' && b > 0 {
					answers[i] = 'P'
					b--
				} else if S[i] == 'P' && c > 0 {
					answers[i] = 'S'
					c--
				} else if S[i] == 'S' && a > 0 {
					answers[i] = 'R'
					a--
				}
			}

			// あまりを割り振る
			for i := 0; i < n; i++ {
				if answers[i] == 'x' {
					if a > 0 {
						answers[i] = 'R'
						a--
					} else if b > 0 {
						answers[i] = 'P'
						b--
					} else if c > 0 {
						answers[i] = 'S'
						c--
					}
				}
			}

			fmt.Println(string(answers))
		} else {
			fmt.Println("NO")
		}
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	mp := map[byte]byte{
		'R': 0,
		'P': 1,
		'S': 2,
	}
	for Fscan(in, &t); t > 0; t-- {
		pos := make([][]int, 3)
		var n, a, b, c int
		var s []byte
		Fscan(in, &n, &a, &b, &c, &s)
		for i, c := range s {
			s[i] = mp[c]
			pos[s[i]] = append(pos[s[i]], i)
		}
		min2, min0, min1 := min(a, len(pos[2])), min(b, len(pos[0])), min(c, len(pos[1]))
		ans := min0 + min1 + min2
		limit := n / 2
		if n&1 == 1 {
			limit++
		}
		if ans >= limit {
			Fprintln(out, "YES")

			for i := 0; i < min0; i++ {
				s[pos[0][i]] = 'P'
				b--
			}
			for i := 0; i < min1; i++ {
				s[pos[1][i]] = 'S'
				c--
			}
			for i := 0; i < min2; i++ {
				s[pos[2][i]] = 'R'
				a--
			}
			for i, ch := range s {
				if ch > 2 {
					continue
				}
				var left byte
				if a > 0 {
					left = 'R'
					a--
				} else if b > 0 {
					left = 'P'
					b--
				} else {
					left = 'S'
				}
				s[i] = left
			}
			Fprintln(out, string(s))
		} else {
			Fprintln(out, "NO")
		}
	}

}

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

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	tt := 1
	fmt.Fscanf(in, "%d\n", &tt)
	for ii := 0; ii < tt; ii++ {
		n, a, b, c := 0, 0, 0, 0
		fmt.Fscanf(in, "%d\n", &n)
		fmt.Fscanf(in, "%d %d %d\n", &a, &b, &c)
		s := ""
		a1, b1, c1 := 0, 0, 0
		fmt.Fscanf(in, "%s\n", &s)
		for i := 0; i < n; i++ {
			if s[i] == 'R' {
				a1++
			} else if s[i] == 'P' {
				b1++
			} else {
				c1++
			}
		}
		win := 0
		win = min(a, c1) + min(b, a1) + min(c, b1)
		if win*2 > n {
			fmt.Fprintf(out, "YES\n")
			ans := []byte{}
			for i := 0; i < n; i++ {
				if s[i] == 'R' {
					if b > 0 {
						b--
						ans = append(ans, 'P')
					} else if c > b1 {
						c--
						ans = append(ans, 'S')
					} else {
						a--
						ans = append(ans, 'R')
					}
					a1--
				} else if s[i] == 'P' {
					if c > 0 {
						c--
						ans = append(ans, 'S')
					} else if b > a1 {
						b--
						ans = append(ans, 'P')
					} else {
						a--
						ans = append(ans, 'R')
					}
					b1--
				} else {
					if a > 0 {
						a--
						ans = append(ans, 'R')
					} else if b > a1 {
						b--
						ans = append(ans, 'P')
					} else {
						c--
						ans = append(ans, 'S')
					}
					c1--
				}
			}
			fmt.Fprintf(out, "%s\n", string(ans))
		} else {
			fmt.Fprintf(out, "NO\n")
		}
	}
	return
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {

	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a, b, c := ScanInt64(), ScanInt64(), ScanInt64()
		result := []rune{}
		aliceWinCount := int64(0)

		s := ScanWord()
		for i := 0; i < len(s); i++ {
			if s[i] == 'R' {
				if b > 0 {
					b--
					result = append(result, 'P')
					aliceWinCount++
				} else {
					result = append(result, '@')
				}

			} else if s[i] == 'P' {
				if c > 0 {
					c--
					result = append(result, 'S')
					aliceWinCount++
				} else {
					result = append(result, '@')
				}
			} else if s[i] == 'S' {
				if a > 0 {
					a--
					result = append(result, 'R')
					aliceWinCount++
				} else {
					result = append(result, '@')
				}
			}
		}

		if aliceWinCount >= int64(math.Ceil(float64(n)/float64(2))) {
			out <- "YES"
			for i := 0; i < len(s); i++ {
				if result[i] == '@' {
					if a > 0 {
						result[i] = 'R'
					} else if b > 0 {
						result[i] = 'P'
					} else if c > 0 {
						result[i] = 'S'
					}
				}
			}
			out <- string(result)
		} else {
			out <- "NO"
		}
	}

	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

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

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

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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 s(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

const (
	MAX_INT int64 = math.MaxInt64
	MIN_INT int64 = math.MinInt64
)

func main() {

	for t := ScanInt64(); t > 0; t-- {
		n := ScanInt64()
		a, b, c := ScanInt64(), ScanInt64(), ScanInt64()
		result := []rune{}
		winCount := int64(0)

		s := ScanWord()
		for i := 0; i < len(s); i++ {
			if s[i] == 'R' {
				if b > 0 {
					b--
					result = append(result, 'P')
					winCount++
				}
			} else if s[i] == 'P' {
				if c > 0 {
					c--
					result = append(result, 'S')
					winCount++
				}
			} else if s[i] == 'S' {
				if a > 0 {
					a--
					result = append(result, 'R')
					winCount++
				}
			}
		}

		if winCount >= int64(math.Ceil(float64(n)/float64(2))) {
			out <- "YES"
			out <- string(result)
		} else {
			out <- "NO"
		}
	}

	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

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

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

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

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

func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}

func ScanInt64() int64 {
	intStr := ScanWord()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

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

func Max(args ...int64) int64 {
	maxVal := MIN_INT
	for _, v := range args {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func Min(args ...int64) int64 {
	minVal := MAX_INT
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
	}
	return minVal
}

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 s(v interface{}) string {
	return fmt.Sprintf("%v", v)
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, a, b, c, win int
		var s, ans string
		fmt.Fscan(in, &n, &a, &b, &c, &s)
		for _, hand := range s {
			switch hand {
			case 'R':
				ans += "P"
				if b <= 0 {
					continue
				}
				b--
				win++
			case 'P':
				ans += "S"
				if c <= 0 {
					continue
				}
				c--
				win++
			case 'S':
				ans += "R"
				if a <= 0 {
					continue
				}
				a--
				win++
			}
		}
		if win >= int(math.Ceil(float64(n)/2)) {
			fmt.Fprintln(out, "YES")
			fmt.Fprintln(out, ans)
			continue
		}
		fmt.Fprintln(out, "NO")
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, a, b, c, win int
		var s, ans string
		fmt.Fscan(in, &n, &a, &b, &c, &s)
		for _, hand := range s {
			switch hand {
			case 'R':
				if a <= 0 {
					continue
				}
				a--
				win++
				ans += "P"
			case 'P':
				if b <= 0 {
					continue
				}
				b--
				win++
				ans += "S"
			case 'S':
				if c <= 0 {
					continue
				}
				c--
				win++
				ans += "R"
			}
		}
		if win >= int(math.Ceil(float64(n)/2)) {
			fmt.Fprintln(out, "YES")
			fmt.Fprintln(out, ans)
			continue
		}
		fmt.Fprintln(out, "NO")
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		play, ok := solve()
		if ok {
			fmt.Printf("YES\n%s", play)
		} else {
			fmt.Println("NO")
		}
	}
}

func solve() (string, bool) {
	var n int
	fmt.Scanf("%d\n", &n)
	var r, p, s int
	fmt.Scanf("%d %d %d\n", &r, &p, &s)
	var bob string
	fmt.Scanf("%s\n", &bob)
	var bobR, bobP, bobS int
	for _, c := range bob {
		if c == rune('R') {
			bobR++
		}
		if c == rune('P') {
			bobP++
		}
		if c == rune('S') {
			bobS++
		}
	}
	var score int
	score += min(r, bobS)
	score += min(p, bobR)
	score += min(s, bobP)
	if score*2 < n {
		return "", false
	}
	play := make([]byte, len(bob))
	for i, c := range bob {
		if c == rune('R') {
			if p > 0 {
				play[i] = byte('P')
				p--
			} else {
				play[i] = byte('-')
			}
		}
		if c == rune('P') {
			if s > 0 {
				play[i] = byte('S')
				s--
			} else {
				play[i] = byte('-')
			}
		}
		if c == rune('S') {
			if r > 0 {
				play[i] = byte('R')
				r--
			} else {
				play[i] = byte('-')
			}
		}
	}
	for i := range play {
		if play[i] == byte('-') {
			if p > 0 {
				play[i] = byte('P')
				p--
			}
			if s > 0 {
				play[i] = byte('S')
				s--
			}
			if r > 0 {
				play[i] = byte('R')
				r--
			}
		}
	}
	return string(play), true
}

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		play, ok := solve()
		if ok {
			fmt.Printf("YES\n%s\n", play)
		} else {
			fmt.Println("NO")
		}
	}
}

func solve() (string, bool) {
	var n int
	fmt.Scanf("%d\n", &n)
	var r, p, s int
	fmt.Scanf("%d %d %d\n", &r, &p, &s)
	var bob string
	fmt.Scanf("%s\n", &bob)
	var bobR, bobP, bobS int
	for _, c := range bob {
		if c == rune('R') {
			bobR++
		}
		if c == rune('P') {
			bobP++
		}
		if c == rune('S') {
			bobS++
		}
	}
	var score int
	score += min(r, bobS)
	score += min(p, bobR)
	score += min(s, bobP)
	if score*2 < n {
		return "", false
	}
	play := make([]byte, len(bob))
	for i, c := range bob {
		if c == rune('R') {
			if p > 0 {
				play[i] = byte('P')
				p--
			} else {
				play[i] = byte('-')
			}
		}
		if c == rune('P') {
			if s > 0 {
				play[i] = byte('S')
				s--
			} else {
				play[i] = byte('-')
			}
		}
		if c == rune('S') {
			if r > 0 {
				play[i] = byte('R')
				r--
			} else {
				play[i] = byte('-')
			}
		}
	}
	for i := range play {
		if play[i] == byte('-') {
			if p > 0 {
				play[i] = byte('P')
				p--
			}
			if s > 0 {
				play[i] = byte('S')
				s--
			}
			if r > 0 {
				play[i] = byte('R')
				r--
			}
		}
	}
	return string(play), true
}

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n, a, b, c int
		var s string
		fmt.Scanln(&n)
		fmt.Scanln(&a, &b, &c)
		fmt.Scanln(&s)
		res := make([]byte, 0)
		win := 0
		for _, v := range s {
			switch v {
			case 'R':
				if b > 0 {
					b--
					win++
					res = append(res, 'P')
				} else if a > 0 {
					a--
					res = append(res, 'R')
				} else {
					c--
					res = append(res, 'S')
				}
			case 'P':
				if c > 0 {
					c--
					win++
					res = append(res, 'S')
				} else if b > 0 {
					b--
					res = append(res, 'P')
				} else {
					a--
					res = append(res, 'R')
				}
			case 'S':
				if a > 0 {
					a--
					win++
					res = append(res, 'R')
				} else if c > 0 {
					c--
					res = append(res, 'S')
				} else {
					b--
					res = append(res, 'P')
				}
			}
		}
		nw := n / 2
		if n%2 > 0 {
			nw++
		}
		if win >= nw {
			fmt.Println("YES")
			fmt.Println(string(res))
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	var n, a, b, c int
	var s string
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&n)
		fmt.Scanln(&a, &b, &c)
		fmt.Scanln(&s)
		var res []byte
		win := 0
		for _, v := range s {
			switch v {
			case 'R':
				if b > 0 {
					b--
					win++
					res = append(res, 'P')
				} else if a > 0 {
					a--
					res = append(res, 'R')
				} else {
					c--
					res = append(res, 'S')
				}
			case 'P':
				if c > 0 {
					c--
					win++
					res = append(res, 'S')
				} else if b > 0 {
					b--
					res = append(res, 'P')
				} else {
					a--
					res = append(res, 'R')
				}
			case 'S':
				if a > 0 {
					a--
					win++
					res = append(res, 'R')
				} else if c > 0 {
					c--
					res = append(res, 'S')
				} else {
					b--
					res = append(res, 'P')
				}
			}
		}
		nw := n / 2
		if n%2 > 0 {
			nw++
		}
		if win >= nw {
			fmt.Println("YES")
			fmt.Println(string(res))
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var n int
var a, b, c int
var S []rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		a, b, c = ReadInt3()
		S = ReadRuneSlice()

		need := (n + (2 - 1)) / 2

		r, p, s := 0, 0, 0
		for i := 0; i < len(S); i++ {
			if S[i] == 'R' {
				r++
			} else if S[i] == 'P' {
				p++
			} else {
				s++
			}
		}

		wins := 0
		wins += Min(a, s)
		wins += Min(b, r)
		wins += Min(c, p)

		if wins >= need {
			fmt.Println("YES")
			answers := make([]rune, n)
			for i := 0; i < n; i++ {
				answers[i] = 'x'
			}

			// 勝てるやつを割り振る
			for i := 0; i < len(S); i++ {
				if S[i] == 'R' && b > 0 {
					answers[i] = 'P'
					b--
				} else if S[i] == 'P' && c > 0 {
					answers[i] = 'S'
					c--
				} else if a > 0 {
					answers[i] = 'R'
					a--
				}
			}

			// あまりを割り振る
			for i := 0; i < n; i++ {
				if answers[i] == 'x' {
					if a > 0 {
						answers[i] = 'R'
						a--
					} else if b > 0 {
						answers[i] = 'P'
						b--
					} else if c > 0 {
						answers[i] = 'S'
						c--
					}
				}
			}

			fmt.Println(string(answers))
		} else {
			fmt.Println("NO")
		}
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	mp := map[byte]byte{
		'R': 0,
		'P': 1,
		'S': 2,
	}
	for Fscan(in, &t); t > 0; t-- {
		pos := make([][]int, 3)

		ans := 0

		var n, a, b, c int
		var s []byte
		Fscan(in, &n, &a, &b, &c, &s)
		for i, c := range s {
			s[i] = mp[c]
			pos[s[i]] = append(pos[s[i]], i)
		}
		min2, min0, min1 := min(a, len(pos[2])), min(b, len(pos[0])), min(c, len(pos[1]))
		ans += min0 + min1 + min2

		limit := n / 2
		if n&1 == 1 {
			limit++
		}
		if ans >= limit {
			Fprintln(out, "YES")

			for i := 0; i < min0; i++ {
				s[pos[0][i]] = 'P'
			}
			for i := 0; i < min1; i++ {
				s[pos[1][i]] = 'S'
			}
			for i := 0; i < min2; i++ {
				s[pos[2][i]] = 'R'
			}
			for i,c := range s {
				var left byte
				if a > 0 {
					left = 'R'
					a--
				} else if b > 0 {
					left = 'P'
					b--
				} else {
					left = 'S'
					c--
				}
				if c <=2 {
					s[i] = left
				}
			}
			Fprintln(out, string(s))
		} else {
			Fprintln(out, "NO")
		}
	}

}

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

package main

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

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	mp := map[byte]byte{
		'R': 0,
		'P': 1,
		'S': 2,
	}
	for Fscan(in, &t); t > 0; t-- {
		pos := make([][]int, 3)

		ans := 0

		var n, a, b, c int
		var s []byte
		Fscan(in, &n, &a, &b, &c, &s)
		for i, c := range s {
			s[i] = mp[c]
			pos[s[i]] = append(pos[s[i]], i)
		}
		min2, min0, min1 := min(a, len(pos[2])), min(b, len(pos[0])), min(c, len(pos[1]))
		ans += min0 + min1 + min2

		limit := n / 2
		if n&1 == 1 {
			limit++
		}
		if ans >= limit {
			Fprintln(out, "YES")

			for i := 0; i < min0; i++ {
				s[pos[0][i]] = 'P'
			}
			for i := 0; i < min1; i++ {
				s[pos[1][i]] = 'S'
			}
			for i := 0; i < min2; i++ {
				s[pos[2][i]] = 'R'
			}
			for i,c := range s {
				if c <=2 {
					var left byte
					if a > 0 {
						left = 'R'
						a--
					} else if b > 0 {
						left = 'P'
						b--
					} else {
						left = 'S'
						c--
					}
					s[i] = left
				}
			}
			Fprintln(out, string(s))
		} else {
			Fprintln(out, "NO")
		}
	}

}

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


The only difference between this problem and D1 is the bound on the size of the tree.You are given an unrooted tree with $$$n$$$ vertices. There is some hidden vertex $$$x$$$ in that tree that you are trying to find.To do this, you may ask $$$k$$$ queries $$$v_1, v_2, \ldots, v_k$$$ where the $$$v_i$$$ are vertices in the tree. After you are finished asking all of the queries, you are given $$$k$$$ numbers $$$d_1, d_2, \ldots, d_k$$$, where $$$d_i$$$ is the number of edges on the shortest path between $$$v_i$$$ and $$$x$$$. Note that you know which distance corresponds to which query.What is the minimum $$$k$$$ such that there exists some queries $$$v_1, v_2, \ldots, v_k$$$ that let you always uniquely identify $$$x$$$ (no matter what $$$x$$$ is).Note that you don't actually need to output these queries.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$)  — the number of vertices in the tree. Each of the next $$$n-1$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$), meaning there is an edges between vertices $$$x$$$ and $$$y$$$ in the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case print a single nonnegative integer, the minimum number of queries you need, on its own line.

NoteIn the first test case, there is only one vertex, so you don't need any queries.In the second test case, you can ask a single query about the node $$$1$$$. Then, if $$$x = 1$$$, you will get $$$0$$$, otherwise you will get $$$1$$$.

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(); X,Y := fill2(N-1); for i:=0;i<N-1;i++ { X[i]--; Y[i]-- }
		gr := make([][]int,N)
		for i:=0;i<N-1;i++ { x,y := X[i],Y[i]; gr[x] = append(gr[x],y); gr[y] = append(gr[y],x) }
		best := N+10
		sumc := ia(N)
		numz := ia(N)
		ansarr := ia(N)
		var dfs func(n,p int)
		var dfs2 func(n,p int)
		dfs = func(n,p int) {
			sumc[n] = 0; numz[n] = 0; ansarr[n] = 0
			for _,c := range gr[n] {
				if c == p { continue }
				dfs(c,n);
				sumc[n] += ansarr[c]; if ansarr[c] == 0 { numz[n]++ }
			}
			ansarr[n] = sumc[n]
			if numz[n] > 1 { ansarr[n] += numz[n]-1 }
		}
		reroot := func(oldp,oldc int) {
			// Take away oldc from oldp
			sumc[oldp] -= ansarr[oldc]
			if ansarr[oldc] == 0 { numz[oldp]-- }
			ansarr[oldp] = sumc[oldp]
			if numz[oldp] > 1 { ansarr[oldp] += numz[oldp]-1 }

			// add oldp to oldc
			sumc[oldc] += ansarr[oldp]
			if ansarr[oldp] == 0 { numz[oldc]++ }
			ansarr[oldc] = sumc[oldc]
			if numz[oldc] > 1 { ansarr[oldc] += numz[oldc]-1 }
		}
		dfs2 = func(n,p int) {
			best = min(best,ansarr[n])
			for _,c := range gr[n] {
				if c == p { continue }
				reroot(n,c); dfs2(c,n);	reroot(c,n)
			}
		}
		dfs(0,-1)
		dfs2(0,-1)
		if N > 1 { best++ }
		fmt.Fprintln(wrtr,best)
	}
}


Alice and Bob are playing a game on an array $$$a$$$ of $$$n$$$ positive integers. Alice and Bob make alternating moves with Alice going first.In his/her turn, the player makes the following move: If $$$a_1 = 0$$$, the player loses the game, otherwise: Player chooses some $$$i$$$ with $$$2\le i \le n$$$. Then player decreases the value of $$$a_1$$$ by $$$1$$$ and swaps $$$a_1$$$ with $$$a_i$$$. Determine the winner of the game if both players play optimally.

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

For each test case, if Alice will win the game, output "Alice". Otherwise, output "Bob". You can output each letter in any case. For example, "alIcE", "Alice", "alice" will all be considered identical.

NoteIn the first testcase, in her turn, Alice can only choose $$$i = 2$$$, making the array equal $$$[1, 0]$$$. Then Bob, in his turn, will also choose $$$i = 2$$$ and make the array equal $$$[0, 0]$$$. As $$$a_1 = 0$$$, Alice loses.In the second testcase, once again, players can only choose $$$i = 2$$$. Then the array will change as follows: $$$[2, 1] \to [1, 1] \to [1, 0] \to [0, 0]$$$, and Bob loses.In the third testcase, we can show that Alice has a winning strategy.

package main

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

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func solve() {
	_, a := _readArr()
	x := a[0]
	a = a[1:]
	if _min(a...) < x {
		_print("Alice")
	} else {
		_print("Bob")
	}
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr(x ...int) (int, []int) {
	var n int
	if len(x) == 0 {
		fmt.Fscan(in, &n)
	} else {
		n = x[0]
	}
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] > x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _min(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] < x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _sum(x ...int) int {
	res := 0
	for _, i := range x {
		res += i
	}
	return res
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}
func _makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

var in *bufio.Reader = bufio.NewReader(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

func ans() {
	var n int
	Fscan(in, &n)
	var a []int = make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &a[i])
	}
	var min int = a[1]
	for i := 2; i < n; i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	if a[0] <= min {
		Fprintln(out, "Bob")
		return
	}
	Fprintln(out, "Alice")
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	a := readArrayInt(reader)

	for i := 1; i < n; i++ {
		if a[i] < a[0] {
			fmt.Fprintln(writer, "Alice")
			return
		}
	}
	fmt.Fprintln(writer, "Bob")
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func solve() {
	_, a := _readArr()
	x := a[0]
	a = a[1:]
	if _sum(a...)%2 != x%2 {
		_print("Alice")
	} else {
		_print("Bob")
	}
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr(x ...int) (int, []int) {
	var n int
	if len(x) == 0 {
		fmt.Fscan(in, &n)
	} else {
		n = x[0]
	}
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] > x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _min(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] < x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _sum(x ...int) int {
	res := 0
	for _, i := range x {
		res += i
	}
	return res
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}
func _makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func solve() {
	_, a := _readArr()
	if _sum(a...)%2 == 0 {
		_print("Bob")
	} else {
		_print("Alice")
	}
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr(x ...int) (int, []int) {
	var n int
	if len(x) == 0 {
		fmt.Fscan(in, &n)
	} else {
		n = x[0]
	}
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] > x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _min(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] < x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _sum(x ...int) int {
	res := 0
	for _, i := range x {
		res += i
	}
	return res
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}
func _makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

var in *bufio.Reader = bufio.NewReader(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

func ans() {
	var n int
	Fscan(in, &n)
	var a []int = make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &a[i])
	}
	for i := 1; i < n; i++ {
		if a[0] <= a[i] {
			Fprintln(out, "Bob")
			return
		}
	}
	Fprintln(out, "Alice")
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	a := readArrayInt64(reader)

	var sum int64
	for i := 0; i < n; i++ {
		sum += a[i]
	}

	if sum%2 == 0 {
		fmt.Fprintln(writer, "Bob")
	} else {
		fmt.Fprintln(writer, "Alice")
	}

}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func max(a int, b int) int {
	return int(maxInt64(int64(a), int64(b)))
}

func maxInt64(a int64, b int64) int64 {
	if a > b {
		return a
	}

	return b
}

func min(a int, b int) int {
	return int(minInt64(int64(a), int64(b)))
}

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

	return b
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}


You are given a connected undirected weighted graph consisting of $$$n$$$ vertices and $$$m$$$ edges.You need to print the $$$k$$$-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from $$$i$$$ to $$$j$$$ and from $$$j$$$ to $$$i$$$ are counted as one).More formally, if $$$d$$$ is the matrix of shortest paths, where $$$d_{i, j}$$$ is the length of the shortest path between vertices $$$i$$$ and $$$j$$$ ($$$1 \le i < j \le n$$$), then you need to print the $$$k$$$-th element in the sorted array consisting of all $$$d_{i, j}$$$, where $$$1 \le i < j \le n$$$.

The first line of the input contains three integers $$$n, m$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le \min\Big(\frac{n(n-1)}{2}, 2 \cdot 10^5\Big)$$$, $$$1 \le k \le \min\Big(\frac{n(n-1)}{2}, 400\Big)$$$ — the number of vertices in the graph, the number of edges in the graph and the value of $$$k$$$, correspondingly. Then $$$m$$$ lines follow, each containing three integers $$$x$$$, $$$y$$$ and $$$w$$$ ($$$1 \le x, y \le n$$$, $$$1 \le w \le 10^9$$$, $$$x \ne y$$$) denoting an edge between vertices $$$x$$$ and $$$y$$$ of weight $$$w$$$. It is guaranteed that the given graph is connected (there is a path between any pair of vertices), there are no self-loops (edges connecting the vertex with itself) and multiple edges (for each pair of vertices $$$x$$$ and $$$y$$$, there is at most one edge between this pair of vertices in the graph).

Print one integer — the length of the $$$k$$$-th smallest shortest path in the given graph (paths from the vertex to itself are not counted, paths from $$$i$$$ to $$$j$$$ and from $$$j$$$ to $$$i$$$ are counted as one).

package main

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

type Path struct {
	v int
	s int
	w int64
}

type Int64s []int64

func (this Int64s) Len() int { return len(this) }

func (this Int64s) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return this[i] < this[j]
}

func (this Int64s) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

type Paths []*Path

func (this Paths) Len() int { return len(this) }

func (this Paths) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return this[i].w < this[j].w
}

func (this Paths) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

var edges [200000][]*Path
var n, m, k int

var union [200000]int

func find(i int) int {
	if union[i] == i {
		return i
	} else {
		union[i] = find(union[i])
		return union[i]
	}
}

func merge(i, j int) {
	union[find(j)] = find(i)
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &k)
	for i := 0;i < n;i ++ {
		union[i] = i;
		edges[i] = []*Path{}
	}
	paths := &Paths{}
	for i := 0;i < m;i ++ {
		var x, y int
		var w int64
		fmt.Fscanf(reader, "%d %d %d\n", &x, &y, &w)
		*paths = append(*paths, &Path{x - 1, y - 1, w})
	}
	sort.Sort(paths)
	for i := 0;i < k && i < len(*paths);i ++ {
		p := (*paths)[i]
		edges[p.s] = append(edges[p.s], p)
		merge(p.s, p.v)
	}

	visited := map[int]bool{}
	m := map[int][]int{}

	res := Int64s{}
	for i := 0;i < len(*paths) && i < k;i ++ {
		p := (*paths)[i]
		u := find(p.s)
		if _, ok := m[u]; !ok {
			m[u] = make([]int, 0, 401)
		}
		if _, ok := visited[p.s]; !ok {
			m[u] = append(m[u], p.s)
			visited[p.s] = true
		}
		if _, ok := visited[p.v]; !ok {
			m[u] = append(m[u], p.v)
			visited[p.v] = true
		}
	}
	for _, vset := range m {
		//fmt.Printf("vset: %+v\n",vset)
		vmap := map[int]int{}
		d := make([][]int64, len(vset))
		for i := 0;i < len(vset);i ++ {
			vmap[vset[i]] = i
			d[i] = make([]int64, len(vset))
		}
		for i := 0;i < len(vset);i ++ {
			edgelist := edges[vset[i]]
			for j := 0;j < len(edgelist);j ++ {
				e := edgelist[j]
				d[i][vmap[e.v]] = e.w
				d[vmap[e.v]][i] = e.w
			}
		}
		for k := 0;k < len(vset);k ++ {
			for i := 0;i < len(vset);i ++ {
				for j := 0;j < len(vset);j ++ {
					if i != j && d[i][k] != 0 && d[k][j] != 0 && (d[i][j] == 0 || d[i][k] + d[k][j] < d[i][j]) {
						d[i][j] = d[i][k] + d[k][j]
					}
				}
			}
		}
		for i := 0;i < len(vset);i ++ {
			for j := i + 1;j < len(vset);j ++ {
				res = append(res, d[i][j])
			}
		}
	}
	sort.Sort(res)
	fmt.Printf("%d", res[k - 1])
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
type edge struct {
	v, w int
	d    int64
}
type hp []edge

func (h hp) Len() int            { return len(h) }
func (h hp) Less(i, j int) bool  { return h[i].d < h[j].d }
func (h hp) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *hp) Push(v interface{}) { *h = append(*h, v.(edge)) }
func (h *hp) Pop() interface{}   { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v }
func (h *hp) push(v edge)        { heap.Push(h, v) }
func (h *hp) pop() edge          { return heap.Pop(h).(edge) }

func CF1196F(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, k, v, w, wt int
	Fscan(in, &n, &m, &k)
	q := hp{}
	for ; m > 0; m-- {
		Fscan(in, &v, &w, &wt)
		q = append(q, edge{v, w, int64(wt)})
	}
	heap.Init(&q)

	ans := int64(0)
	dis := make([]map[int]int64, n+1)
	for i := 1; i <= n; i++ {
		dis[i] = map[int]int64{}
	}
	for k > 0 && len(q) > 0 {
		e := q.pop()
		v, w := e.v, e.w
		if dis[v][w] > 0 {
			continue
		}
		for v, d := range dis[v] {
			q.push(edge{w, v, d + e.d})
		}
		for w, d := range dis[w] {
			q.push(edge{v, w, d + e.d})
		}
		dis[v][w] = e.d
		dis[w][v] = e.d
		ans = e.d
		k--
	}
	Fprint(out, ans)
}

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


Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to n computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to n. So the i-th hacked computer is located at the point xi. Moreover the coordinates of all computers are distinct. Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.Leha should calculate a sum of F(a) for all a, where a is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote A the set of all integers from 1 to n. Noora asks the hacker to find value of the expression . Here F(a) is calculated as the maximum among the distances between all pairs of computers from the set a. Formally, . Since the required sum can be quite large Noora asks to find it modulo 109 + 7.Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.

The first line contains one integer n (1 ≤ n ≤ 3·105) denoting the number of hacked computers. The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 109) denoting the coordinates of hacked computers. It is guaranteed that all xi are distinct.

Print a single integer — the required sum modulo 109 + 7.

NoteThere are three non-empty subsets in the first sample test:,  and . The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: , , , . In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

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

	n := readInt()
	x := make([]int, n)
	for i := range x {
		x[i] = readInt()
	}
	sort.Ints(x)

	const mod int64 = 1e9 + 7
	pow := make([]int64, n+1)
	pow[0] = 1
	for i := range pow[1:] {
		pow[i+1] = pow[i] * 2 % mod
	}
	var res int64
	for i := range x {
		xi := int64(x[i])
		res = ((res+xi*pow[i])%mod + mod - (xi*pow[n-1-i])%mod) % mod
	}
	fmt.Println(res)
}

package main

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

var (
	MOD = int64(1000000007)
	POW2 [300001]int64
)

func Init() {
	POW2[0] = 1
	for i := 1; i < len(POW2); i++ {
		POW2[i] = (POW2[i - 1] << 1) % MOD
	}
}

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

	sort.Sort(Int64Slice(X))

	sum := int64(0)
	for i, v := range X {
		sum += v * (POW2[i] - POW2[N - i - 1])
		sum %= MOD
	}
	io.Println(sum)
}

type Int64Slice []int64

func (a Int64Slice) Len() int {
	return len(a)
}

func (a Int64Slice) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a Int64Slice) Less(i, j int) bool {
	return a[i] < a[j]
}

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