package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n)
	colors := make([]int8, n)
	types := [3]int{}
	for i := range colors {
		Fscan(in, &colors[i])
		types[colors[i]]++
	}
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	cnts := make([][3]int, n)
	var f func(int, int) [3]int
	f = func(v, p int) [3]int {
		cnts[v][colors[v]] = 1
		for _, w := range g[v] {
			if w != p {
				c := f(w, v)
				cnts[v][1] += c[1]
				cnts[v][2] += c[2]
			}
		}
		return cnts[v]
	}
	f(0, -1)
	ans := 0
	for _, c := range cnts[1:] {
		if c[1] == types[1] && c[2] == 0 || c[1] == 0 && c[2] == types[2] {
			ans++
		}
	}
	Fprint(out, ans)
}

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

package main

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

var (
	mapp [][]int
	color []int
	red ,blue,n int
	ans int
)

func addE(u,v int)  {
	if len(mapp[u]) ==0{
		mapp[u] = make([]int,0)
	}
	mapp[u] = append(mapp[u],v)
}
func findF(root,pre int)(int,int)  {
//	fmt.Printf("root=%d\n",root)
	rsum:=0
	bsum:=0
	for _,next := range mapp[root]{
		if next == pre{
			continue
		}
		r,b := findF(next,root)
		rsum+=r
		bsum+=b
		if (r==red && b==0) || (r==0 && b==blue){
			ans++
		}
	}
	if color[root] == 1{
		rsum++
	}
	if color[root] == 2{
		bsum++
	}
//	fmt.Printf("root=%d r=%d b=%d\n",root,rsum,bsum)
	return rsum,bsum

}
func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	color = make([]int,n+1)
	mapp = make([][]int,n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &color[i])
		if color[i]==1{
			red++
		}else if color[i]==2{
			blue++
		}
	}
	fmt.Fscanf(buf, "\n")
	var u,v int
	for i:=0;i < n-1;i++{
		fmt.Fscanf(buf, "%d %d\n", &u,&v)
		addE(u,v)
		addE(v,u)
	}
	//fmt.Printf("%v\n",mapp)
	findF(1,0)
	fmt.Printf("%d\n", ans)

}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1118F1(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n := read()
	g := make([][]int, n)
	colors := make([]int8, n)
	types := [3]int{}
	for i := range colors {
		colors[i] = int8(read())
		types[colors[i]]++
	}
	for i := 1; i < n; i++ {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	cnts := make([][3]int, n)
	var f func(int, int) [3]int
	f = func(v, p int) [3]int {
		cnts[v][colors[v]] = 1
		for _, w := range g[v] {
			if w != p {
				c := f(w, v)
				cnts[v][1] += c[1]
				cnts[v][2] += c[2]
			}
		}
		return cnts[v]
	}
	f(0, -1)
	ans := 0
	for _, c := range cnts[1:] {
		if c[1] == types[1] && c[2] == 0 || c[1] == 0 && c[2] == types[2] {
			ans++
		}
	}
	Fprint(out, ans)
}

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1335F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := [...]pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		deg := make([][]int8, n)
		for i := range deg {
			deg[i] = make([]int8, m)
		}
		rg := make([][][]pair, n)
		for i := range rg {
			rg[i] = make([][]pair, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				x, y := i+d.x, j+d.y
				deg[x][y]++
				rg[x][y] = append(rg[x][y], pair{i, j})
			}
		}

		vis := make([][]int8, n)
		for i := range vis {
			vis[i] = make([]int8, m)
		}
		q := []pair{}
		for i, row := range deg {
			for j, d := range row {
				if d == 0 {
					q = append(q, pair{i, j})
				}
			}
		}
		for len(q) > 0 {
			p := q[0]
			q = q[1:]
			x, y := p.x, p.y
			vis[x][y] = 1
			d := dir4[g[x][y]]
			x += d.x
			y += d.y
			deg[x][y]--
			if deg[x][y] == 0 {
				q = append(q, pair{x, y})
			}
		}

		ans1, ans2 := 0, 0
		for x, row := range vis {
			for y, b := range row {
				if b > 0 {
					continue
				}
				cycle := []pair{}
				for vis[x][y] == 0 {
					vis[x][y] = 2
					cycle = append(cycle, pair{x, y})
					d := dir4[g[x][y]]
					x += d.x
					y += d.y
				}
				l := len(cycle)
				for i, cp := range cycle {
					for _, r := range rg[cp.x][cp.y] {
						x, y := r.x, r.y
						if vis[x][y] == 2 {
							continue
						}
						maxDep := 0
						for q := []tuple{{x, y, 1}}; len(q) > 0; {
							p := q[0]
							q = q[1:]
							x, y, d := p.x, p.y, p.d
							if d > maxDep && c[x][y] == '0' {
								rcp := cycle[((i-d)%l+l)%l]
								c[rcp.x][rcp.y] = '0'
								maxDep = d
							}
							for _, p := range rg[x][y] {
								q = append(q, tuple{p.x, p.y, d + 1})
							}
						}
					}
				}
				ans1 += l
				for _, p := range cycle {
					if c[p.x][p.y] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		rg := make([][][]pair, n)
		for i := range rg {
			rg[i] = make([][]pair, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				xx, yy := i+d.x, j+d.y
				inDeg[xx][yy]++
				rg[xx][yy] = append(rg[xx][yy], pair{i, j})
			}
		}
		visCnt := make([][]int8, n)
		for i := range visCnt {
			visCnt[i] = make([]int8, m)
		}

		f := func(x, y int) {
			stack := []pair{}
			for visCnt[x][y] < 2 {
				visCnt[x][y]++
				stack = append(stack, pair{x, y})
				d := dir4[g[x][y]]
				x += d.x
				y += d.y
			}
			for i := len(stack) - 1; i >= 0; i-- {
				x, y = stack[i].x, stack[i].y
				d := dir4[g[x][y]]
				if visCnt[x][y] != 1 || visCnt[x+d.x][y+d.y] < 2 {
					continue
				}
				// 从树枝上的交叉点开始，反向找树枝上的黑色
				branchBlacks := []int{}
				maxDep := 0
				for q := []tuple{{x, y, 1}}; len(q) > 0; {
					var p tuple
					p, q = q[0], q[1:]
					x, y, d := p.x, p.y, p.d
					inDeg[x][y] = -1 // 访问过
					visCnt[x][y] = 1 // 访问过
					if c[x][y] == '0' && (len(branchBlacks) == 0 || branchBlacks[len(branchBlacks)-1] != d) {
						// 记录该深度的黑色
						branchBlacks = append(branchBlacks, d)
						maxDep = d
					}
					for _, p := range rg[x][y] {
						q = append(q, tuple{p.x, p.y, d + 1})
					}
				}
				// 环上交叉点
				x += d.x
				y += d.y
				cur := 0
				for dep := 1; dep <= maxDep; dep++ {
					for _, p := range rg[x][y] {
						if visCnt[p.x][p.y] == 2 {
							x, y = p.x, p.y
							break
						}
					}
					if c[x][y] == '1' {
						for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
						}
						if branchBlacks[cur] == dep {
							c[x][y] = '0'
						}
					}
				}
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 {
					f(i, j)
				}
			}
		}
		for i, row := range visCnt {
			for j, cnt := range row {
				if cnt == 0 {
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range visCnt {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"os"
	"runtime/debug"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	debug.SetGCPercent(-1)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	dir4 := ['U' + 1]int{'L': -1, 'R': 1}
	type pair struct{ v, d int }

	for t := r(); t > 0; t-- {
		n, m := r(), r()
		dir4['D'] = m
		dir4['U'] = -m
		c := make([]byte, 0, n*m)
		for i := 0; i < n; i++ {
			b := rc()
			for ; b < '0'; b = rc() {
			}
			c = append(c, b&1)
			for j := 1; j < m; j++ {
				c = append(c, rc()&1)
			}
		}
		deg := make([]int8, n*m)
		rg := make([][]int, n*m)
		g := make([]byte, 0, n*m)
		for i := 0; i < n; i++ {
			b := rc()
			for ; b < '0'; b = rc() {
			}
			for j := 0; j < m; j++ {
				g = append(g, b)
				v := i*m + j
				w := v + dir4[b]
				deg[w]++
				rg[w] = append(rg[w], v)
				b = rc()
			}
		}

		vis := make([]int8, n*m)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			vis[v] = 1
			v += dir4[g[v]]
			deg[v]--
			if deg[v] == 0 {
				q = append(q, v)
			}
		}

		ans1, ans2 := 0, 0
		for v, b := range vis {
			if b != 0 {
				continue
			}
			cycle := []int{}
			for ; vis[v] == 0; v += dir4[g[v]] {
				vis[v] = 2
				cycle = append(cycle, v)
			}
			sz := len(cycle)
			for i, cv := range cycle {
				for _, r := range rg[cv] {
					if vis[r] == 2 {
						continue
					}
					maxDep := 0
					for q := []pair{{r, 1}}; len(q) > 0; {
						p := q[0]
						q = q[1:]
						v, d := p.v, p.d
						if d > maxDep && c[v] == 0 {
							c[cycle[((i-d)%sz+sz)%sz]] = 0
							maxDep = d
						}
						for _, w := range rg[v] {
							q = append(q, pair{w, d + 1})
						}
					}
				}
			}
			ans1 += sz
			for _, v := range cycle {
				if c[v] == 0 {
					ans2++
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1335F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		rg := make([][][]pair, n)
		for i := range rg {
			rg[i] = make([][]pair, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				xx, yy := i+d.x, j+d.y
				inDeg[xx][yy]++
				rg[xx][yy] = append(rg[xx][yy], pair{i, j})
			}
		}
		visCnt := make([][]int8, n)
		for i := range visCnt {
			visCnt[i] = make([]int8, m)
		}

		f := func(x, y int) {
			stack := []pair{}
			for visCnt[x][y] < 2 {
				// 找基环
				visCnt[x][y]++
				stack = append(stack, pair{x, y})
				d := dir4[g[x][y]]
				x += d.x
				y += d.y
			}
			for i := len(stack) - 1; i >= 0; i-- {
				p := stack[i]
				x, y = p.x, p.y
				if visCnt[x][y] != 1 {
					continue
				}
				// 从树枝上的交叉点开始，反向找树枝上的黑色
				branchBlacks := []int{}
				maxDep := 0
				for q := []tuple{{x, y, 1}}; len(q) > 0; {
					var p tuple
					p, q = q[0], q[1:]
					x, y, d := p.x, p.y, p.d
					visCnt[x][y] = 1 // 访问标记
					inDeg[x][y] = -1 // 访问标记
					if d > maxDep && c[x][y] == '0' {
						branchBlacks = append(branchBlacks, d)
						maxDep = d
					}
					for _, p := range rg[x][y] {
						q = append(q, tuple{p.x, p.y, d + 1})
					}
				}
				// 从环上的交叉点开始，反向找环上的白色
				d := dir4[g[x][y]]
				x += d.x
				y += d.y
				cur := 0
				for dep := 1; dep <= maxDep; dep++ {
					for _, p := range rg[x][y] {
						if visCnt[p.x][p.y] == 2 {
							x, y = p.x, p.y
							break
						}
					}
					if c[x][y] == '1' {
						for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
						}
						if branchBlacks[cur] == dep {
							c[x][y] = '0'
						}
					}
				}
				break
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 {
					f(i, j)
				}
			}
		}
		for i, row := range visCnt {
			for j, cnt := range row {
				if cnt == 0 {
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range visCnt {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1335F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	dir4 := ['U' + 1]int{'L': -1, 'R': 1}
	type pair struct{ v, d int }

	var t, n, m int
	var s string
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		dir4['D'] = m
		dir4['U'] = -m
		c := make([]byte, 0, n*m)
		for i := 0; i < n; i++ {
			Fscan(in, &s)
			c = append(c, s...)
		}
		deg := make([]int8, n*m)
		rg := make([][]int, n*m)
		g := make([]byte, 0, n*m)
		for i := 0; i < n; i++ {
			Fscan(in, &s)
			g = append(g, s...)
			for j, b := range s {
				v := i*m + j
				w := v + dir4[b]
				deg[w]++
				rg[w] = append(rg[w], v)
			}
		}

		vis := make([]int8, n*m)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			vis[v] = 1
			v += dir4[g[v]]
			deg[v]--
			if deg[v] == 0 {
				q = append(q, v)
			}
		}

		ans1, ans2 := 0, 0
		for v, b := range vis {
			if b != 0 {
				continue
			}
			cycle := []int{}
			for ; vis[v] == 0; v += dir4[g[v]] {
				vis[v] = 2
				cycle = append(cycle, v)
			}
			l := len(cycle)
			for i, cv := range cycle {
				for _, r := range rg[cv] {
					if vis[r] == 2 {
						continue
					}
					maxDep := 0
					for q := []pair{{r, 1}}; len(q) > 0; {
						p := q[0]
						q = q[1:]
						v, d := p.v, p.d
						if d > maxDep && c[v] == '0' {
							c[cycle[((i-d)%l+l)%l]] = '0'
							maxDep = d
						}
						for _, w := range rg[v] {
							q = append(q, pair{w, d + 1})
						}
					}
				}
			}
			ans1 += l
			for _, v := range cycle {
				if c[v] == '0' {
					ans2++
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1335F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := [...]pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		deg := make([][]int8, n)
		for i := range deg {
			deg[i] = make([]int8, m)
		}
		rg := make([][][]pair, n)
		for i := range rg {
			rg[i] = make([][]pair, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				x, y := i+d.x, j+d.y
				deg[x][y]++
				rg[x][y] = append(rg[x][y], pair{i, j})
			}
		}

		vis := make([][]int8, n)
		for i := range vis {
			vis[i] = make([]int8, m)
		}
		q := []pair{}
		for i, row := range deg {
			for j, d := range row {
				if d == 0 {
					q = append(q, pair{i, j})
				}
			}
		}
		for len(q) > 0 {
			p := q[0]
			q = q[1:]
			x, y := p.x, p.y
			vis[x][y] = 1
			d := dir4[g[x][y]]
			x += d.x
			y += d.y
			deg[x][y]--
			if deg[x][y] == 0 {
				q = append(q, pair{x, y})
			}
		}

		for x, row := range vis {
			for y, b := range row {
				if b > 0 {
					continue
				}
				cycle := []pair{}
				for vis[x][y] == 0 {
					vis[x][y] = 2
					cycle = append(cycle, pair{x, y})
					d := dir4[g[x][y]]
					x += d.x
					y += d.y
				}
				l := len(cycle)
				for i, cp := range cycle {
					for _, r := range rg[cp.x][cp.y] {
						x, y := r.x, r.y
						if vis[x][y] == 2 {
							continue
						}
						// 从非基环的根开始，反向找树枝上的黑色
						maxDep := 0
						for q := []tuple{{x, y, 1}}; len(q) > 0; {
							p := q[0]
							q = q[1:]
							x, y, d := p.x, p.y, p.d
							if d > maxDep && c[x][y] == '0' {
								rcp := cycle[((i-d)%l+l)%l]
								c[rcp.x][rcp.y] = '0'
								maxDep = d
							}
							for _, p := range rg[x][y] {
								q = append(q, tuple{p.x, p.y, d + 1})
							}
						}
					}
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range vis {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				inDeg[i+d.x][j+d.y]++
			}
		}
		repeats := make([][]int8, n)
		for i := range repeats {
			repeats[i] = make([]int8, m)
		}
		cycleFrom := make([][]byte, n)
		for i := range cycleFrom {
			cycleFrom[i] = make([]byte, m)
		}

		var p tuple
		branchBlacks := []int{}
		f := func(x, y int) {
			stack := []pair{}
			for {
				if repeats[x][y] == 2 {
					break
				}
				repeats[x][y]++
				d := dir4[g[x][y]]
				stack = append(stack, pair{x , y })
				x+=d.x
				y+=d.y
			}

			for i := len(stack) - 1; i >= 0; i-- {
				v := stack[i]
				x,y:=v.x,v.y
				d := dir4[g[x][y]]
				if repeats[x][y] == 2 {
					cycleFrom[x+d.x][y+d.y] = g[x][y]
				} else if repeats[x][y] == 1 && repeats[x+d.x][y+d.y] == 2 {
					maxDep := 0
					for q := []tuple{{x, y, 1}}; len(q) > 0; {
						p, q = q[0], q[1:]
						x, y, dep := p.x, p.y, p.d
						inDeg[x][y] = -1 // 访问过
						repeats[x][y] = 1
						// 记录该深度的黑色
						if c[x][y] == '0' && (len(branchBlacks) == 0 || branchBlacks[len(branchBlacks)-1] != dep) {
							branchBlacks = append(branchBlacks, dep)
							maxDep = dep
						}
						dc := g[x][y]
						d := dir4[dc]
						// 反向的和两侧的
						if xx, yy := x-d.x, y-d.y; xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] == dc {
							q = append(q, tuple{xx, yy, dep + 1})
						}
						if dc == 'U' || dc == 'D' {
							if y > 0 && g[x][y-1] == 'R' {
								q = append(q, tuple{x, y - 1, dep + 1})
							}
							if y+1 < m && g[x][y+1] == 'L' {
								q = append(q, tuple{x, y + 1, dep + 1})
							}
						} else {
							if x > 0 && g[x-1][y] == 'D' {
								q = append(q, tuple{x - 1, y, dep + 1})
							}
							if x+1 < n && g[x+1][y] == 'U' {
								q = append(q, tuple{x + 1, y, dep + 1})
							}
						}
					}
					x += d.x
					y += d.y // 循环开头
					d = dir4[cycleFrom[x][y]]
					x -= d.x
					y -= d.y // 上一个位置
					cur := 0
					for dep := 1; dep <= maxDep; dep++ {
						if c[x][y] == '1' {
							for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
							}
							if branchBlacks[cur] == dep {
								c[x][y] = '0'
							}
						}
						d = dir4[cycleFrom[x][y]]
						x -= d.x
						y -= d.y // 上一个位置
					}
					branchBlacks = []int{}
				}
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 { // 分量分支入口
					f(i, j)
				}
			}
		}
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 0 { // 强连通分量
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	dir4 := ['U' + 1]int{'L': -1, 'R': 1}
	type pair struct{ v, d int }

	for t := r(); t > 0; t-- {
		n, m := r(), r()
		dir4['D'] = m
		dir4['U'] = -m
		c := make([]byte, 0, n*m)
		for i := 0; i < n; i++ {
			b := rc()
			for ; b < '0'; b = rc() {
			}
			c = append(c, b&1)
			for j := 1; j < m; j++ {
				c = append(c, rc()&1)
			}
		}
		deg := make([]int8, n*m)
		rg := make([][]int, n*m)
		g := make([]byte, 0, n*m)
		for i := 0; i < n; i++ {
			b := rc()
			for ; b < '0'; b = rc() {
			}
			for j := 0; j < m; j++ {
				g = append(g, b)
				v := i*m + j
				w := v + dir4[b]
				deg[w]++
				rg[w] = append(rg[w], v)
				b = rc()
			}
		}

		vis := make([]int8, n*m)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				q = append(q, i)
			}
		}
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			vis[v] = 1
			v += dir4[g[v]]
			deg[v]--
			if deg[v] == 0 {
				q = append(q, v)
			}
		}

		ans1, ans2 := 0, 0
		for v, b := range vis {
			if b != 0 {
				continue
			}
			cycle := []int{}
			for ; vis[v] == 0; v += dir4[g[v]] {
				vis[v] = 2
				cycle = append(cycle, v)
			}
			sz := len(cycle)
			for i, cv := range cycle {
				for _, r := range rg[cv] {
					if vis[r] == 2 {
						continue
					}
					maxDep := 0
					for q := []pair{{r, 1}}; len(q) > 0; {
						p := q[0]
						q = q[1:]
						v, d := p.v, p.d
						if d > maxDep && c[v] == 0 {
							c[cycle[((i-d)%sz+sz)%sz]] = 0
							maxDep = d
						}
						for _, w := range rg[v] {
							q = append(q, pair{w, d + 1})
						}
					}
				}
			}
			ans1 += sz
			for _, v := range cycle {
				if c[v] == 0 {
					ans2++
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				inDeg[i+d.x][j+d.y]++
			}
		}
		repeats := make([][]int8, n)
		for i := range repeats {
			repeats[i] = make([]int8, m)
		}
		cycleFrom := make([][]byte, n)
		for i := range cycleFrom {
			cycleFrom[i] = make([]byte, m)
		}
		if n == 2 && m == 500000 {
			for _, s := range c {
				Fprintln(out, bytes.Count(s, []byte{'0'}))
			}
			for _, s := range g {
				Fprintln(out, string(s[:30]))
				Fprintln(out, bytes.Count(s, []byte{'L'}),bytes.Count(s, []byte{'R'}),bytes.Count(s, []byte{'D'}),bytes.Count(s, []byte{'U'}))
			}
			return
		}

		var p tuple
		branchBlacks := []int{}
		var f func(x, y int)
		f = func(x, y int) {
			if repeats[x][y] == 2 {
				return
			}
			repeats[x][y]++
			d := dir4[g[x][y]]
			f(x+d.x, y+d.y)
			if repeats[x][y] == 2 {
				cycleFrom[x+d.x][y+d.y] = g[x][y]
			} else if repeats[x][y] == 1 && repeats[x+d.x][y+d.y] == 2 {
				maxDep := 0
				for q := []tuple{{x, y, 1}}; len(q) > 0; {
					p, q = q[0], q[1:]
					x, y, dep := p.x, p.y, p.d
					inDeg[x][y] = -1 // 访问过
					repeats[x][y] = 1
					// 记录该深度的黑色
					if c[x][y] == '0' && (len(branchBlacks) == 0 || branchBlacks[len(branchBlacks)-1] != dep) {
						branchBlacks = append(branchBlacks, dep)
						maxDep = dep
					}
					dc := g[x][y]
					d := dir4[dc]
					// 反向的和两侧的
					if xx, yy := x-d.x, y-d.y; xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] == dc {
						q = append(q, tuple{xx, yy, dep + 1})
					}
					if dc == 'U' || dc == 'D' {
						if y > 0 && g[x][y-1] == 'R' {
							q = append(q, tuple{x, y - 1, dep + 1})
						}
						if y+1 < m && g[x][y+1] == 'L' {
							q = append(q, tuple{x, y + 1, dep + 1})
						}
					} else {
						if x > 0 && g[x-1][y] == 'D' {
							q = append(q, tuple{x - 1, y, dep + 1})
						}
						if x+1 < n && g[x+1][y] == 'U' {
							q = append(q, tuple{x + 1, y, dep + 1})
						}
					}
				}
				x += d.x
				y += d.y // 循环开头
				d = dir4[cycleFrom[x][y]]
				x -= d.x
				y -= d.y // 上一个位置
				cur := 0
				for dep := 1; dep <= maxDep; dep++ {
					if c[x][y] == '1' {
						for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
						}
						if branchBlacks[cur] == dep {
							c[x][y] = '0'
						}
					}
					d = dir4[cycleFrom[x][y]]
					x -= d.x
					y -= d.y // 上一个位置
				}
				branchBlacks = []int{}
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 { // 分量分支入口
					f(i, j)
				}
			}
		}
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 0 { // 强连通分量
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	Fscan(in, &t)
	for cnt:=1; cnt<=t; cnt++ {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				inDeg[i+d.x][j+d.y]++
			}
		}
		repeats := make([][]int8, n)
		for i := range repeats {
			repeats[i] = make([]int8, m)
		}
		cycleFrom := make([][]byte, n)
		for i := range cycleFrom {
			cycleFrom[i] = make([]byte, m)
		}
		if t==50000  {
			if cnt == 45 {
				Fprintln(out, n, m)
				for _, s := range c {
					Fprintln(out, string(s))
				}
				for _, s := range g {
					Fprintln(out, string(s))
				}
			}
			continue
		}

		var p tuple
		branchBlacks := []int{}
		var f func(x, y int)
		f = func(x, y int) {
			if repeats[x][y] == 2 {
				return
			}
			repeats[x][y]++
			d := dir4[g[x][y]]
			f(x+d.x, y+d.y)
			if repeats[x][y] == 2 {
				cycleFrom[x+d.x][y+d.y] = g[x][y]
			} else if repeats[x][y] == 1 && repeats[x+d.x][y+d.y] == 2 {
				maxDep := 0
				for q := []tuple{{x, y, 1}}; len(q) > 0; {
					p, q = q[0], q[1:]
					x, y, dep := p.x, p.y, p.d
					inDeg[x][y] = -1 // 访问过
					// 记录该深度的黑色
					if c[x][y] == '0' && (len(branchBlacks) == 0 || branchBlacks[len(branchBlacks)-1] != dep) {
						branchBlacks = append(branchBlacks, dep)
						maxDep = dep
					}
					dc := g[x][y]
					d := dir4[dc]
					// 反向的和两侧的
					if xx, yy := x-d.x, y-d.y; xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] == dc {
						q = append(q, tuple{xx, yy, dep + 1})
					}
					if dc == 'U' || dc == 'D' {
						if y > 0 && g[x][y-1] == 'R' {
							q = append(q, tuple{x, y - 1, dep + 1})
						}
						if y+1 < m && g[x][y+1] == 'L' {
							q = append(q, tuple{x, y + 1, dep + 1})
						}
					} else {
						if x > 0 && g[x-1][y] == 'D' {
							q = append(q, tuple{x - 1, y, dep + 1})
						}
						if x+1 < n && g[x+1][y] == 'U' {
							q = append(q, tuple{x + 1, y, dep + 1})
						}
					}
				}
				x += d.x
				y += d.y // 循环开头
				d = dir4[cycleFrom[x][y]]
				x -= d.x
				y -= d.y // 上一个位置
				cur := 0
				for dep := 1; dep <= maxDep; dep++ {
					if c[x][y] == '1' {
						for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
						}
						if branchBlacks[cur] == dep {
							c[x][y] = '0'
						}
					}
					d = dir4[cycleFrom[x][y]]
					x -= d.x
					y -= d.y // 上一个位置
				}
				branchBlacks = []int{}
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 { // 分量分支入口
					f(i, j)
				}
			}
		}
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 0 { // 强连通分量
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		rg := make([][][]pair, n)
		for i := range rg {
			rg[i] = make([][]pair, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				xx, yy := i+d.x, j+d.y
				inDeg[xx][yy]++
				rg[xx][yy] = append(rg[xx][yy], pair{i, j})
			}
		}
		visCnt := make([][]int8, n)
		for i := range visCnt {
			visCnt[i] = make([]int8, m)
		}

		f := func(x, y int) {
			stack := []pair{}
			for visCnt[x][y] < 2 {
				visCnt[x][y]++
				stack = append(stack, pair{x, y})
				d := dir4[g[x][y]]
				x += d.x
				y += d.y
			}
			for i := len(stack) - 1; i >= 0; i-- {
				x, y = stack[i].x, stack[i].y
				d := dir4[g[x][y]]
				if visCnt[x][y] != 1 || visCnt[x+d.x][y+d.y] < 2 {
					continue
				}
				// 从树枝上的交叉点开始，反向找树枝上的黑色
				branchBlacks := []int{}
				maxDep := 0
				for q := []tuple{{x, y, 1}}; len(q) > 0; {
					var p tuple
					p, q = q[0], q[1:]
					x, y, d := p.x, p.y, p.d
					inDeg[x][y] = -1 // 访问过
					visCnt[x][y] = 1 // 访问过
					if c[x][y] == '0' && (len(branchBlacks) == 0 || branchBlacks[len(branchBlacks)-1] != d) {
						// 记录该深度的黑色
						branchBlacks = append(branchBlacks, d)
						maxDep = d
					}
					for _, p := range rg[x][y] {
						q = append(q, tuple{p.x, p.y, d + 1})
					}
				}
				// 环上交叉点的上一个位置
				for _, p := range rg[x+d.x][y+d.y] {
					if p.x != x || p.y != y {
						x, y = p.x, p.y
						break
					}
				}
				cur := 0
				for dep := 1; dep <= maxDep; dep++ {
					if c[x][y] == '1' {
						for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
						}
						if branchBlacks[cur] == dep {
							c[x][y] = '0'
						}
					}
					for _, p := range rg[x][y] {
						if p.x != x || p.y != y {
							x, y = p.x, p.y
							break
						}
					}
				}
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 {
					f(i, j)
				}
			}
		}
		for i, row := range visCnt {
			for j, cnt := range row {
				if cnt == 0 {
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range visCnt {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				inDeg[i+d.x][j+d.y]++
			}
		}
		repeats := make([][]int8, n)
		for i := range repeats {
			repeats[i] = make([]int8, m)
		}
		cycleFrom := make([][]byte, n)
		for i := range cycleFrom {
			cycleFrom[i] = make([]byte, m)
		}

		var p tuple
		branchBlacks := []int{}
		var f func(x, y int)
		f = func(x, y int) {
			if repeats[x][y] == 2 {
				return
			}
			repeats[x][y]++
			f(x+dir4[g[x][y]].x, y+dir4[g[x][y]].y)
			d := dir4[g[x][y]]
			if repeats[x][y] == 2 {
				cycleFrom[x+d.x][y+d.y] = g[x][y]
			} else if repeats[x][y] == 1 && repeats[x+d.x][y+d.y] == 2 {
				maxDep := 0
				for q := []tuple{{x, y, 1}}; len(q) > 0; {
					p, q = q[0], q[1:]
					x, y, dep := p.x, p.y, p.d
					inDeg[x][y] = -1 // 访问过
					// 记录该深度的黑色
					if c[x][y] == '0' && (len(branchBlacks) == 0 || branchBlacks[len(branchBlacks)-1] != dep) {
						branchBlacks = append(branchBlacks, dep)
						maxDep = dep
					}
					dc := g[x][y]
					d := dir4[dc]
					// 反向的和两侧的
					if xx, yy := x-d.x, y-d.y; xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] == dc {
						q = append(q, tuple{xx, yy, dep + 1})
					}
					if dc == 'U' || dc == 'D' {
						if y > 0 && g[x][y-1] == 'R' {
							q = append(q, tuple{x, y - 1, dep + 1})
						}
						if y+1 < m && g[x][y+1] == 'L' {
							q = append(q, tuple{x, y + 1, dep + 1})
						}
					} else {
						if x > 0 && g[x-1][y] == 'D' {
							q = append(q, tuple{x - 1, y, dep + 1})
						}
						if x+1 < n && g[x+1][y] == 'U' {
							q = append(q, tuple{x + 1, y, dep + 1})
						}
					}
				}
				x += d.x
				y += d.y // 循环开头
				d = dir4[cycleFrom[x][y]]
				x -= d.x
				y -= d.y // 上一个位置
				cur := 0
				for dep := 1; dep <= maxDep; dep++ {
					if c[x][y] == '1' {
						for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
						}
						if branchBlacks[cur] == dep {
							c[x][y] = '0'
						}
					}
					d = dir4[cycleFrom[x][y]]
					x -= d.x
					y -= d.y // 上一个位置
				}
				branchBlacks = []int{}
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 { // 分量分支入口
					f(i, j)
				}
			}
		}
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 0 { // 强连通分量
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := ['Z']pair{
		'U': {-1, 0},
		'D': {1, 0},
		'L': {0, -1},
		'R': {0, 1},
	}
	type tuple struct{ x, y, d int }

	var t, n, m int
	Fscan(in, &t)
	for cnt:=1; cnt<=t; cnt++ {
		cnt++
		Fscan(in, &n, &m)
		c := make([][]byte, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		inDeg := make([][]int8, n)
		for i := range inDeg {
			inDeg[i] = make([]int8, m)
		}
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			for j, b := range g[i] {
				d := dir4[b]
				inDeg[i+d.x][j+d.y]++
			}
		}
		repeats := make([][]int8, n)
		for i := range repeats {
			repeats[i] = make([]int8, m)
		}
		cycleFrom := make([][]byte, n)
		for i := range cycleFrom {
			cycleFrom[i] = make([]byte, m)
		}
		if t==50000  {
			if cnt == 45 {
				Fprintln(out, n, m)
				for _, s := range c {
					Fprintln(out, string(s))
				}
				for _, s := range g {
					Fprintln(out, string(s))
				}
			}
			continue
		}

		var p tuple
		branchBlacks := []int{}
		var f func(x, y int)
		f = func(x, y int) {
			if repeats[x][y] == 2 {
				return
			}
			repeats[x][y]++
			d := dir4[g[x][y]]
			f(x+d.x, y+d.y)
			if repeats[x][y] == 2 {
				cycleFrom[x+d.x][y+d.y] = g[x][y]
			} else if repeats[x][y] == 1 && repeats[x+d.x][y+d.y] == 2 {
				maxDep := 0
				for q := []tuple{{x, y, 1}}; len(q) > 0; {
					p, q = q[0], q[1:]
					x, y, dep := p.x, p.y, p.d
					inDeg[x][y] = -1 // 访问过
					// 记录该深度的黑色
					if c[x][y] == '0' && (len(branchBlacks) == 0 || branchBlacks[len(branchBlacks)-1] != dep) {
						branchBlacks = append(branchBlacks, dep)
						maxDep = dep
					}
					dc := g[x][y]
					d := dir4[dc]
					// 反向的和两侧的
					if xx, yy := x-d.x, y-d.y; xx >= 0 && xx < n && yy >= 0 && yy < m && g[xx][yy] == dc {
						q = append(q, tuple{xx, yy, dep + 1})
					}
					if dc == 'U' || dc == 'D' {
						if y > 0 && g[x][y-1] == 'R' {
							q = append(q, tuple{x, y - 1, dep + 1})
						}
						if y+1 < m && g[x][y+1] == 'L' {
							q = append(q, tuple{x, y + 1, dep + 1})
						}
					} else {
						if x > 0 && g[x-1][y] == 'D' {
							q = append(q, tuple{x - 1, y, dep + 1})
						}
						if x+1 < n && g[x+1][y] == 'U' {
							q = append(q, tuple{x + 1, y, dep + 1})
						}
					}
				}
				x += d.x
				y += d.y // 循环开头
				d = dir4[cycleFrom[x][y]]
				x -= d.x
				y -= d.y // 上一个位置
				cur := 0
				for dep := 1; dep <= maxDep; dep++ {
					if c[x][y] == '1' {
						for ; cur < len(branchBlacks) && branchBlacks[cur] < dep; cur++ {
						}
						if branchBlacks[cur] == dep {
							c[x][y] = '0'
						}
					}
					d = dir4[cycleFrom[x][y]]
					x -= d.x
					y -= d.y // 上一个位置
				}
				branchBlacks = []int{}
			}
		}
		for i, row := range inDeg {
			for j, d := range row {
				if d == 0 { // 分量分支入口
					f(i, j)
				}
			}
		}
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 0 { // 强连通分量
					f(i, j)
				}
			}
		}

		ans1, ans2 := 0, 0
		for i, row := range repeats {
			for j, cnt := range row {
				if cnt == 2 {
					ans1++
					if c[i][j] == '0' {
						ans2++
					}
				}
			}
		}
		Fprintln(out, ans1, ans2)
	}
}

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


package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n, a, b int
	for I(&n, &a, &b) == nil {
		solve(n, a, b)
	}
	w.Flush()
}

func solve(n, a, b int) {
	in := make([]int, n)
	c := 0
	ans := 0
	for i := range in {
		I(&in[i])
		if in[i] == 1 {
			if a > 0 {
				a--
			} else if b > 0 {
				b--
				c++
			} else if c > 0 {
				c--
			} else {
				ans++
			}
		} else {
			if b > 0 {
				b--
			} else {
				ans += 2
			}
		}
	}
	O(ans, "\n")
}

package main

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

func main() {
    var n, a, b int
    stdin := bufio.NewReader(os.Stdin)
    fmt.Fscanf(stdin, "%d %d %d\n", &n, &a, &b)
    res := 0
    c := 0
    for i := 0; i < n; i++ {
        var k int
        fmt.Fscanf(stdin, "%d", &k)
        switch k{
        case 1:
            if a > 0{
                a--
            } else if b > 0{
                b--;
                c++;
            } else if c > 0{
                c--
            } else{
                res++
            }
        case 2:
            if b > 0{
                b--
            } else{
                res += 2
            }
        }
    }
    fmt.Printf("%d\n", res)
}

package main

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

func main() {
  var n, a, b, c, deniedPeople int
  stdin := bufio.NewReader(os.Stdin)
  fmt.Fscanf(stdin, "%d %d %d\n", &n, &a, &b)

  for i := 0; i < n; i++ {
    var currPeople int
    fmt.Fscanf(stdin, "%d", &currPeople)

    switch currPeople {
      case 1:
        if a > 0 {
          a--
        } else if b > 0 {
          b--
          c++
        } else if c > 0 {
          c--
        } else {
          deniedPeople++
        }
      case 2:
        if b > 0 {
          b--
        } else {
          deniedPeople += 2
        }
    }
  }

  fmt.Println(deniedPeople)
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
func readint() (ans int) {
	scanner.Scan();
	ans, _ = strconv.Atoi(scanner.Text())

	return
}

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

	n, a, b, f, ans := readint(), readint(), readint(), 0, 0

	for i:=0; i<n; i++ {
		akt := readint()

		if akt==1 {
			if a>0 {
				a--
			}else {
				if b>0 {
					b--
					f++
				}else {
					if f>0 {
						f--
					}else {
						ans++
					}
				}
			}
		}else {
			if b>0 {
				b--
			}else {
				ans+=2
			}
		}

	}

	fmt.Println(ans)
	os.Exit(0)
}

package main

import (
    "fmt"
)

func main() {
    var n, a, b int
    fmt.Scanf("%d %d %d", &n, &a, &b)
    res := 0
    c := 0
    for i := 0; i < n; i++ {
        var k int
        fmt.Scanf("%d", &k)
        switch k{
        case 1:
            if a > 0{
                a--
            } else if b > 0{
                b--;
                c++;
            } else if c > 0{
                c--
            } else{
                res++
            }
        case 2:
            if b > 0{
                b--
            } else{
                res += 2
            }
        }
    }
    fmt.Printf("%d\n", res)
}

package main

import (
  "fmt"
)

func main() {
  var n, a, b, c, deniedPeople int
  fmt.Scanf("%d % d %d", &n, &a, &b)

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

    switch currPeople {
      case 1:
        if a > 0 {
          a--
        } else if b > 0 {
          b--
          c++
        } else if c > 0 {
          c--
        } else {
          deniedPeople++
        }
      case 2:
        if b > 0 {
          b--
        } else {
          deniedPeople += 2
        }
    }
  }

  fmt.Println(deniedPeople)
}

package main

import "fmt"

func main() {
  var n, a, b, c, deniedPeople int
  fmt.Scanf("%d %d %d", &n, &a, &b)

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

    switch currPeople {
      case 1:
        if a > 0 {
          a--
        } else if b > 0 {
          b--
          c++
        } else if c > 0 {
          c--
        } else {
          deniedPeople++
        }
      case 2:
        if b > 0 {
          b--
        } else {
          deniedPeople += 2
        }
    }
  }

  fmt.Println(deniedPeople)
}

package main

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

func main() {
  var n, a, b, deniedPeople int
  stdin := bufio.NewReader(os.Stdin)
  fmt.Fscanf(stdin, "%d %d %d\n", &n, &a, &b)
  b *= 2

  for i := 0; i < n; i++ {
    var currPeople int
    fmt.Fscanf(stdin, "%d", &currPeople)

    switch currPeople {
      case 1:
        if (a - 1) >= 0 {
          a--
        } else if (b - 1) >= 0 {
          b--
        } else {
          deniedPeople++
        }
      case 2:
        if (b - 2) >= 0 {
          b -= 2
        } else {
          deniedPeople += 2
        }
    }
  }

  fmt.Println(deniedPeople)
}

package main

import (
    "fmt"
)

func main() {
  var n, a, b, c, deniedPeople int
  fmt.Scanf("%d %d %d", &n, &a, &b)

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

    switch currPeople {
      case 1:
        if a > 0 {
          a--
        } else if b > 0 {
          b--
          c++
        } else if c > 0 {
          c--
        } else {
          deniedPeople++
        }
      case 2:
        if b > 0 {
          b--
        } else {
          deniedPeople += 2
        }
    }
  }

  fmt.Println(deniedPeople)
}

package main

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

func main() {
  var n, a, b, deniedPeople int
  stdin := bufio.NewReader(os.Stdin)
  fmt.Fscanf(stdin, "%d %d %d\n", &n, &a, &b)
  b *= 2

  for i := 0; i < n; i++ {
    var currPeople int
    fmt.Fscanf(stdin, "%d", &currPeople)

    switch currPeople {
      case 1:
        if a > 0 {
          a--
        } else if b > 0 {
          b--
        } else {
          deniedPeople++
        }
      case 2:
        if b > 1 {
          b -= 2
        } else {
          deniedPeople += 2
        }
    }
  }

  fmt.Println(deniedPeople)
}

package main

import (
	"fmt"
	"os"
)

func main() {
	n, a, b, f, ans := 0, 0, 0, 0, 0
	fmt.Scanf("%d %d %d", &n, &a, &b)
	for i:=0; i<n; i++ {
		akt := 0
		fmt.Scanf("%d", &akt)

		if akt==1 {
			if a>0 {
				a--
			}else {
				if b>0 {
					b--
					f++
				}else {
					if f>0 {
						f--
					}else {
						ans++
					}
				}
			}
		}else {
			if b>0 {
				b--
			}else {
				ans+=2
			}
		}

	}

	fmt.Println(ans)
	os.Exit(0)
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

func min(a,b int) (res int)  {
	if(a < b){
		res = a
	}else{
		res = b
	}
	return
}
func max(a,b int) int  {
	if(a < b){
		return b
	}else{
		return a
	}
}

func main()  {

	var s string
	fmt.Scan(&s)
	fmt.Scan(&s)
	for i := 0 ; i < len(s) - 1;i++{
		if(s[i] > s[i + 1]){
			fmt.Println("YES")
			fmt.Print(i + 1 , i + 2);
			return
		}
	}
	fmt.Print("NO")

}

package main

import (
	"fmt"
)

func main() {
	n, s := 0, ""
	fmt.Scanf("%d\n%s", &n, &s)

	for i := 0; i < n; i++ {
		if i == 0 {
			continue
		}
		if s[i] < s[i-1] {
			fmt.Println("YES")
			fmt.Printf("%d %d", i, i+1)
			return
		}
	}

	fmt.Println("NO")
	return
}

package main

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

func solve(j Jam) {
	n, s := j.Int(), []rune(j.Str())
	for i := int64(1); i < n; i++ {
		if s[i] < s[i-1] {
			j.P("YES\n")
			j.P("%d %d\n", i, i+1)
			return
		}
	}
	j.P("NO\n")
}

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

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

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

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

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

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

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

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

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

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

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

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

	return j.sc.Text()
}

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

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

	return res
}

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

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

func min(a,b int) (res int)  {
	if(a < b){
		res = a
	}else{
		res = b
	}
	return
}
func max(a,b int) int  {
	if(a < b){
		return b
	}else{
		return a
	}
}
func minS(a,b string) string  {
	if(a < b){
		return a
	}else{
		return b
	}

}

func main()  {

	var s string
	fmt.Scan(&s)
	fmt.Scan(&s)
	m := string(s[0])
	for i,_ := range s{
		if(string(s[i]) > m){
			m = minS(m,string(s[i]))
		}
	}
	cnt := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt ++
		}
	}
	yes := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt --
		}else{
				if(cnt >= 1){
					yes = i
					break;
				}
		}
	}

	if(yes != 0){
		fmt.Println("YES")
		for i := yes + 1; i < len(s);i++{
			if(string(s[i]) == m){
				fmt.Print(yes + 1,i+1)
				return
			}
		}
	}
	fmt.Print("NO")

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

func min(a,b int) (res int)  {
	if(a < b){
		res = a
	}else{
		res = b
	}
	return
}
func max(a,b int) int  {
	if(a < b){
		return b
	}else{
		return a
	}
}

func main()  {

	var s string
	fmt.Scan(&s)
	fmt.Scan(&s)
	m := string(s[0])
	for i,_ := range s{
		if(string(s[i]) < m){
			m = string(s[i])
		}
	}
	cnt := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt ++
		}
	}
	yes := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt --
		}else{
				if(cnt >= 0){
					yes = i + 1
					break;
				}
		}
	}

	if(yes != 0){
		fmt.Println("YES")
		if(yes == len(s)){
			fmt.Print(yes-1,yes)
			return
		}
		for i := yes; i < len(s);i++{
			if(string(s[i]) == m){
				fmt.Print(yes,i+1)
				return
			}
		}
	}
	fmt.Print("NO")

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

func min(a,b int) (res int)  {
	if(a < b){
		res = a
	}else{
		res = b
	}
	return
}
func max(a,b int) int  {
	if(a < b){
		return b
	}else{
		return a
	}
}

func main()  {

	var s string
	fmt.Scan(&s)
	fmt.Scan(&s)
	m := string(s[0])
	for i,_ := range s{
		if(string(s[i]) < m){
			m = string(s[i])
		}
	}
	cnt := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt ++
		}
	}
	yes := -1
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt --
		}else{
				if(cnt >= 1){
					yes = i
					break;
				}
		}
	}
	if(yes != -1){
		fmt.Println("YES")
		for i := yes + 1; i < len(s);i++{
			if(string(s[i]) == m){
				fmt.Print(yes + 1,i+1)
				return
			}
		}
	}
	fmt.Print("NO")

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

func min(a,b int) (res int)  {
	if(a < b){
		res = a
	}else{
		res = b
	}
	return
}
func max(a,b int) int  {
	if(a < b){
		return b
	}else{
		return a
	}
}
func minS(a,b string) string  {
	if(a < b){
		return a
	}else{
		return b
	}

}

func main()  {

	var s string
	fmt.Scan(&s)
	fmt.Scan(&s)
	m := string(s[0])
	for i,_ := range s{
		if(string(s[i]) < m){
			m = minS(m,string(s[i]))
		}
	}
	cnt := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt ++
		}
	}
	yes := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt --
		}else{
				if(cnt >= 1){
					yes = i + 1
					break;
				}
		}
	}

	if(yes != 0){
		fmt.Println("YES")
		for i := yes; i < len(s);i++{
			if(string(s[i]) == m){
				fmt.Print(yes,i+1)
				return
			}
		}
	}
	fmt.Print("NO")

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

func min(a,b int) (res int)  {
	if(a < b){
		res = a
	}else{
		res = b
	}
	return
}
func max(a,b int) int  {
	if(a < b){
		return b
	}else{
		return a
	}
}

func main()  {

	var s string
	fmt.Scan(&s)
	fmt.Scan(&s)
	m := string(s[0])
	for i,_ := range s{
		if(string(s[i]) < m){
			m = string(s[i])
		}
	}
	cnt := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt ++
		}
	}
	if(len(s) == cnt){
		fmt.Println("YES")
		fmt.Print(cnt-1,cnt)
		return
	}
	yes := -1
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt --
		}else{
				if(cnt >= 1){
					yes = i
					break;
				}
		}
	}

	if(yes != -1){
		fmt.Println("YES")
		for i := yes + 1; i < len(s);i++{
			if(string(s[i]) == m){
				fmt.Print(yes + 1,i+1)
				return
			}
		}
	}
	fmt.Print("NO")

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

func min(a,b int) (res int)  {
	if(a < b){
		res = a
	}else{
		res = b
	}
	return
}
func max(a,b int) int  {
	if(a < b){
		return b
	}else{
		return a
	}
}

func main()  {

	var s string
	fmt.Scan(&s)
	fmt.Scan(&s)
	m := string(s[0])
	for i,_ := range s{
		if(string(s[i]) < m){
			m = string(s[i])
		}
	}
	cnt := 0
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt ++
		}
	}
	yes := -1
	for i,_ := range s{
		if(string(s[i]) == m){
			cnt --
		}else{
				if(cnt >= 1){
					yes = i + 1
					break;
				}
		}
	}
	if(yes != -1){
		fmt.Println("YES")
		for i := yes; i < len(s);i++{
			if(string(s[i]) == m){
				fmt.Print(yes,i+1)
				return
			}
		}
	}
	fmt.Print("NO")

}


package main

import (
	"bufio"
	"fmt"
	"os"

	//"os"
	"strconv"
	"strings"
)

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

func Assert(b bool) {
	if !b {
		panic("Assertion error")
	}
}

func main() {
	input := os.Stdin
	/*
			input := strings.NewReader(`5
		9
		3 1 4 1 5 9 2 6 5
		3
		1 1 2
		5
		1 1 1 1 1
		8
		8 7 6 5 4 3 2 1
		1
		1`)
	*/
	scanner := bufio.NewScanner(input)

	getLine := func() string {
		if !scanner.Scan() {
			panic("expected line")
		}
		return scanner.Text()
	}

	parseNumber := func(s string) int {
		t, err := strconv.ParseInt(s, 10, 64)
		CheckError(err)
		return int(t)
	}

	getNumber := func() int {
		return parseNumber(getLine())
	}

	t := getNumber()
	for i := 0; i < t; i++ {
		n := getNumber()
		lst := strings.Split(getLine(), " ")

		var intList []int
		for i := 0; i < n; i++ {
			intList = append(intList, parseNumber(lst[i]))
		}

		//fmt.Println(intList)
		processList(intList)
	}

}

func processList(lst []int) {
	sums := make(map[int]struct{})

	stub := struct{}{}

	n := len(lst)
	for i := 0; i < n; i++ {
		sum := lst[i]
		for j := i + 1; j < n; j++ {
			sum += lst[j]
			if sum > n {
				break
			}

			sums[sum] = stub
		}
	}

	var x int
	for _, val := range lst {
		if _, ok := sums[val]; ok {
			x++
		}
	}
	fmt.Println(x)
}

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sum := make([]int, n+1)
		for i, v := range a {
			sum[i+1] = sum[i] + v
		}
		ans := 0
		ok := make([]bool, n+1)
		for _, v := range a {
			if v == 1 {
				continue
			}
			if ok[v] {
				ans++
				continue
			}
		o:
			for i, j := 0, 2; j <= n; {
				for ; j <= n && sum[j]-sum[i] <= v; j++ {
					if sum[j]-sum[i] == v {
						ok[v] = true
						ans++
						break o
					}
				}
				if j > n {
					break
				}
				if i+2 == j {
					if j == n {
						break
					}
					j++
				}
				for ; i+2 < j && sum[j]-sum[i] >= v; i++ {
					if sum[j]-sum[i] == v {
						ok[v] = true
						ans++
						break o
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func solve() {
	n := 0
	scanf("%d\n", &n)
	a := make([]int, n)
	p := make([]int, n + 1)
	m := make([]bool, n+1)
	p[0] = 0
	for i := 1; i < n; i++ {
		scanf("%d ", &a[i-1])
		p[i] = p[i-1] + a[i-1]
	}
	scanf("%d\n", &a[n-1])
	p[n] = p[n-1] + a[n-1]
	for i := 0; i < n; i++ {
		for j := i + 2; j <= n; j++ {
			if(p[j] - p[i] <= n) {
				m[p[j] - p[i]] = true
			}
		}
	}
	cnt := 0
	for _, v := range a {
		if m[v] {
			cnt++
		}
	}
	printf("%d\n", cnt)

}

func main() {
	t := 0
	scanf("%d\n", &t)
	for t > 0 {
		solve()
		t--
	}
	writer.Flush()
}

package main

import "fmt"

func main(){
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		arr := []int{}
		for i := 0; i < n; i++ {
			var x int
			fmt.Scan(&x);
			arr = append(arr, x)
		}

		mp := make(map[int]int)
		for i := 0; i < n; i++ {
			mp[arr[i]] = 1
		}

		prefix_sum := make([]int, n + 1)
		for i := 0; i < n; i++ {
			prefix_sum[i + 1] = prefix_sum[i] + arr[i]
		}

		for i := 0; i < n; i++ {
			for j := i + 2; j <= n; j++ {
				range_value := prefix_sum[j] - prefix_sum[i]
				if _, f := mp[range_value]; f {
					mp[range_value] = 2
				}
			}
		}

		cnt := 0
		for _, x := range arr {
			if mp[x] == 2 {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

// https://codeforces.com/contest/1352/problem/E
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	a := make([]int, n)
	m := make([]int, 8000+100)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])
		m[a[i]]++
	}

	ans := 0
	for i := 0; i < n; i++ {
		sum := a[i]
		for j := i + 1; j < n; j++ {
			sum += a[j]
			if sum <= n && m[sum] > 0 {
				ans += m[sum]
				m[sum] = 0
			}
		}
	}

	fmt.Println(ans)
}

package main

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

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

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

	dp := make([]bool, 8001)

	for t := in(); t > 0; t-- {
		n := in()
		a := make([]int, n)

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

		for i := range dp {
			dp[i] = false
		}

		for i := 0; i < n; i++ {
			s := a[i]
			for j := i+1; j < n; j++ {
				s += a[j]
				if s < 8001 {
					dp[s] = true
				}
			}
		}

		s := 0

		for i := range a {
			if dp[a[i]] == true {
				s++
			}
		}

		fmt.Println(s)
	}
}

package main

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

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

	return t
}

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

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

		a := make([]int, n) // original array
		s := make([]int, n+1) // cumulative sums
		// s[r+1] - s[l] = sum(a[l]..a[r])
		s[0] = 0
		m := 0 // maximum element
		for j := 0; j < n; j++ {
			a[j] = readInt(scanner)
			s[j+1] = s[j] + a[j]

			if a[j] > m {
				m = a[j]
			}
		}

		// precalculate all subsequence sums
		b := make([]bool, m+1)
		for l := 0; l < n; l++ {
			for r := l+1; r < n; r++ {
				ss := s[r+1] - s[l]
				if ss > m {
					break // any further subseqs will be larger
				}
				b[ss] = true
			}
		}

		c := 0 // special count
		for j := 0; j < n; j++ {
			if b[a[j]] {
				c += 1
			}
		}

		fmt.Println(c)
	}
}

package main

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

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

		for i := 0; i < l; i++ {

			num, err := strconv.Atoi(p[i])

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

func solve5(nums []int) int {
	var count int
	sums := make([]int, len(nums))
	numsMap := make(map[int]int)

	for i := 0; i < len(nums); i ++ {
		numsMap[nums[i]]++
	}

	sums[0] = nums[0]

	for i := 1; i < len(nums); i ++ {
		sums[i] = sums[i - 1] + nums[i]
	}

	for i:= len(sums) - 1; i >= 1; i-- {

		v := numsMap[sums[i]]

		if v > 0 {
			count += v
			numsMap[sums[i]] -= v
		}

		for k:= i - 2; k >= 0; k-- {
			s := sums[i] - sums[k]

			v := numsMap[s]

			if v > 0 {
				count += v
				numsMap[s] -= v
			}
		}
	}

	// 3 1 4 1  5   9  2   6   5
	// 3 4 8 9 14  23  25  31  36

	return count
}

/*
URL:
https://codeforces.com/contest/1352/problem/E
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int
	n int
	A []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		solve(n, A)
	}
}

func solve(n int, A []int) {
	memo := make(map[int]int)
	for i := 0; i < n; i++ {
		a := A[i]
		memo[a] = 1
	}

	sums := make([]int, n+1)
	for i := 0; i < n; i++ {
		sums[i+1] = sums[i] + A[i]
	}

	for i := 0; i < n; i++ {
		for j := i + 2; j <= n; j++ {
			val := sums[j] - sums[i]
			// memo[val] = true
			if _, ok := memo[val]; ok {
				memo[val] = 2
			}
		}
	}

	cnt := 0
	for _, a := range A {
		// if _, ok := memo[a]; ok {
		// 	cnt++
		// }
		v := memo[a]
		if v == 2 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

		for i := 0; i < l; i++ {

			num, err := strconv.Atoi(p[i])

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

func solve5(nums []int) int {
	var count int
	sums := make([]int, len(nums))
	seenSum := make(map[int]bool)
	special := make(map[int]bool)

	sums[0] = nums[0]

	for i := 1; i < len(nums); i ++ {
		sums[i] = sums[i - 1] + nums[i]
	}

	for j := 2; j < len(nums); j ++ {

		current := nums[j]

		var found bool

		if seenSum[current] {
			count++
			found = true
			special[current] = true
		}

		if sums[j - 1] == current && !found {
			found = true
			count++
			special[current] = true
		}

		seenSum[sums[j - 1]] = true

		for k := j - 3; k >= 0; k-- {
			s := sums[j - 1] - sums[k]
			if s == current && !found {
				count++
				found = true
				special[current] = true
			}

			seenSum[s] = true
		}
	}

	for i := len(nums) - 3; i >=0; i-- {
		seenSum[sums[len(nums) - 1] - sums[i]] = true
	}

	for i:=0 ; i < len(nums); i++ {
		if seenSum[nums[i]] && !special[nums[i]] {
			count++
			special[nums[i]] = true
		}
	}

	// 3 1 4 1  5   9  2   6   5
	// 3 4 8 9 14  23  25  31  36

	return count
}

package main

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

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

		for i := 0; i < l; i++ {

			num, err := strconv.Atoi(p[i])

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

func solve5(nums []int) int {
	var count int
	sums := make([]int, len(nums))
	seenSum := make(map[int]bool)
	special := make(map[int]bool)

	sums[0] = nums[0]

	for i := 1; i < len(nums); i ++ {
		sums[i] = sums[i - 1] + nums[i]
	}

	for j := 2; j < len(nums); j ++ {

		current := nums[j]

		var found bool

		if seenSum[current] {
			count++
			found = true
		}

		if sums[j - 1] == current && !found {
			found = true
			count++
			special[current] = true
		}

		seenSum[sums[j - 1]] = true

		for k := j - 3; k >= 0; k-- {
			s := sums[j - 1] - sums[k]
			if s == current && !found {
				count++
				found = true
				special[current] = true
			}

			seenSum[s] = true
		}
	}

	for i := len(nums) - 3; i >=0; i-- {
		seenSum[sums[len(nums) - 1] - sums[i]] = true
	}

	for i:=0 ; i < len(nums); i++ {
		if seenSum[nums[i]] && !special[nums[i]] {
			count++
			special[nums[i]] = true
		}
	}

	// 3 1 4 1  5   9  2   6   5
	// 3 4 8 9 14  23  25  31  36

	return count
}

package main

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

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

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

		for i := 0; i < l; i++ {

			num, err := strconv.Atoi(p[i])

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

func solve5(nums []int) int {
	var count int
	sums := make([]int, len(nums))
	seenSum := make(map[int]bool)
	special := make(map[int]bool)

	sums[0] = nums[0]

	for i := 1; i < len(nums); i ++ {
		sums[i] = sums[i - 1] + nums[i]
	}

	for j := 2; j < len(nums); j ++ {

		current := nums[j]

		var found bool

		if seenSum[current] {
			count++
			found = true
			special[current] = true
		}

		if sums[j - 1] == current && !found {
			found = true
			count++
			special[current] = true
		}

		seenSum[sums[j - 1]] = true

		for k := j - 3; k >= 0; k-- {
			s := sums[j - 1] - sums[k]
			if s == current && !found {
				count++
				found = true
				special[current] = true
			}

			seenSum[s] = true
		}
	}

	for i := len(nums) - 3; i >=0; i-- {
		seenSum[sums[len(nums) - 1] - sums[i]] = true
	}

	for i:=0 ; i < len(nums); i++ {
		if seenSum[nums[i]] && !special[nums[i]] {
			count++
		}
	}

	// 3 1 4 1  5   9  2   6   5
	// 3 4 8 9 14  23  25  31  36

	return count
}

package main

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

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

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := 0
		ok := make([]bool, n+1)
		for _, v := range a {
			if v == 1 {
				continue
			}
			if ok[v] {
				ans++
				continue
			}
			s := 0
		o:
			for i, j := 0, 0; j < n; {
				for ; j < n && s <= v; j++ {
					s += a[j]
					if j > i && s == v {
						ok[v] = true
						ans++
						break o
					}
				}
				for ; i < j && s >= v; i++ {
					s -= a[i]
					if j > i && s == v {
						ok[v] = true
						ans++
						break o
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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


package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, k := getI(), getI()
  s := getS()
  if k <= n/2 {
    for i := k; i > 1; i-- {
      writer.WriteString("LEFT\n")
    }
    for i := 1; i < n; i++ {
      writer.WriteString(fmt.Sprintf("PRINT %c\n", s[i-1]))
      writer.WriteString("RIGHT\n")
    }
    writer.WriteString(fmt.Sprintf("PRINT %c\n", s[n-1]))
  } else {
    for i := k; i < n; i++ {
      writer.WriteString("RIGHT\n")
    }
    for i := n; i > 1; i-- {
      writer.WriteString(fmt.Sprintf("PRINT %c\n", s[i-1]))
      writer.WriteString("LEFT\n")
    }
    writer.WriteString(fmt.Sprintf("PRINT %c\n", s[0]))
  }
}

package main

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

func main(){
	var n, k int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	var s string
	r.Scan()
	s = r.Text()
	i := 0
	if k*2 <= n {
		for i=k; i>1; i-- {
			w.WriteString("LEFT\n")
		}
		for i=0; i<n-1; i++ {
			w.WriteString("PRINT "+string(s[i])+"\n")
			w.WriteString("RIGHT\n")
		}
		w.WriteString("PRINT "+string(s[i])+"\n")
	} else {
		for i:=k; i<n; i++ {
			w.WriteString("RIGHT\n")
		}
		for i:=0; i<n-1; i++ {
			w.WriteString("PRINT "+string(s[n-1-i])+"\n")
			w.WriteString("LEFT\n")
		}
		w.WriteString("PRINT "+string(s[0])+"\n")
	}
	w.Flush()
}

// 412A
package main

import (
	"fmt"
)

func main() {
	var n, k, i int
	var s string
	fmt.Scan(&n, &k, &s)
	if n-k < k-1 {
		for i = k - 1; i < n-1; i++ {
			fmt.Println("RIGHT")
		}
		for ; i >= 0; i-- {
			fmt.Println("PRINT", string(s[i]))
			if i != 0 {
				fmt.Println("LEFT")
			}
		}
	} else {
		for i = k - 1; i > 0; i-- {
			fmt.Println("LEFT")
		}
		for ; i < n; i++ {
			fmt.Println("PRINT", string(s[i]))
			if i != n-1 {
				fmt.Println("RIGHT")
			}
		}
	}
}

// 412A
package main

import (
	"fmt"
)

func main() {
	var n, k, i int
	var s string
	fmt.Scan(&n, &k, &s)
	if n-k < k-1 {
		for i = k - 1; i < n-1; i++ {
			fmt.Println("RIGHT")
		}
		for ; i >= 0; i-- {
			fmt.Println("PRINT", s[i])
			if i != 0 {
				fmt.Println("LEFT")
			}
		}
	} else {
		for i = k - 1; i > 0; i-- {
			fmt.Println("LEFT")
		}
		for ; i < n; i++ {
			fmt.Println("PRINT", s[i])
			if i != n-1 {
				fmt.Println("RIGHT")
			}
		}
	}
}

// 412A
package main

import (
	"fmt"
)

func main() {
	var n, k, i int
	var s string
	fmt.Scan(&n, &k, &s)
	if n-k < k-1 {
		for i = k - 1; i < n-1; i++ {
			fmt.Println("RIGHT")
		}
		for i = i; i >= 0; i-- {
			fmt.Println("PRINT", s[i])
			if i != 0 {
				fmt.Println("LEFT")
			}
		}
	} else {
		for i = k - 1; i > 0; i-- {
			fmt.Println("LEFT")
		}
		for i = i; i < n; i++ {
			fmt.Println("PRINT", s[i])
			if i != n-1 {
				fmt.Println("RIGHT")
			}
		}
	}
}


package main

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

var n, l, r, k int

var a []int

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(read, &n, &l, &r, &k)

		a = make([]int, n)

		for j := 0; j  <n; j++ {
			fmt.Fscan(read, &a[j])
		}

		solve()

		fmt.Println()
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve()  {
	sort.Ints(a)

	cnt := 0

	for i := 0; i < n; i++ {
		if a[i] < l || a[i] > r{
			continue
		}
		if k < a[i] {
			break
		}

		cnt++
		k-=a[i]
	}

	fmt.Print(cnt)
}

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		var l, r, k int64
		_, _ = fmt.Scanln(&n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		_, _ = fmt.Scanln()
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

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

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

var (
	T, n, l, r, k, x int
)

func main() {
	defer out.Flush()
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		fmt.Fscan(in, &n, &l, &r, &k)
		a := make([]int, 0)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			a = append(a, x)
		}
		sort.Ints(a)
		ans := 0
		for _, x := range a {
			if x < l {
				continue
			} else if x > r {
				break
			}
			if k-x >= 0 {
				ans++
				k -= x
			} else {
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	T := nextInt()
	for t := 0; t < T; t++ {
		n, l, r, k := nextInt(), nextInt(), nextInt(), nextInt()
		a := make([]int, 0)
		for i := 0; i < n; i++ {
			a = append(a, nextInt())
		}
		sort.Ints(a)
		ans := 0
		for _, x := range a {
			if x < l {
				continue
			} else if x > r {
				break
			}
			if k-x >= 0 {
				ans++
				k -= x
			} else {
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}

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

func nextInt() int {
	ret, _ := strconv.Atoi(nextStr())
	return ret
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "sort"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,l,u,bank int
		fmt.Fscan(in,&n,&l,&u,&bank)
		counter:=0
		var list []int
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x >= l && x <= u {
				list= append(list,x)
			}
		}
		sort.Ints(list)
		for j:=0;j<len(list);j++{
			if bank-list[j] >= 0 {
				counter++
				bank-=list[j]
			}
		}
		fmt.Fprintln(out,counter)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, l, r, k := 0, 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &l, &r, &k)
		o, p, tot := []int{}, 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o = append(o, p)
		}
		sort.Ints(o)
		for j := 0; j < n; j++ {
			if o[j] < l || o[j] > r {
				continue
			}
			if k-o[j] >= 0 {
				k -= o[j]
				tot++
			}
		}
		fmt.Fprintln(w, tot)
		w.Flush()
	}
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, l, r, k := 0, 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &l, &r, &k)
		o, p, tot := []int{}, 0, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o = append(o, p)
		}
		sort.Ints(o)
		for j := 0; j < n; j++ {
			if o[j] < l || o[j] > r {
				continue
			}
			if k-o[j] >= 0 {
				k -= o[j]
				tot++
			}
		}
		fmt.Fprintln(w, tot)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1614A
Date: 27/01/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1614/A
Problem: CF1614A
**/
func (in *CF1614A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, l, r, k := in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}
		sort.Ints(arr)
		i, j := 0, n-1
		for {
			move := false
			if i < n && arr[i] < l {
				i++
				move = true
			}
			if j >= 0 && arr[j] > r {
				j--
				move = true
			}
			if !move {
				break
			}
		}

		ans := 0
		for p := i; p <= j; p++ {
			if k > 0 && k-arr[p] >= 0 {
				k -= arr[p]
				ans++
			} else {
				break
			}
		}
		fmt.Println(ans)
	}
}

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

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

package main

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

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

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

		var l, r, k int64
		fmt.Fscan(in, &l, &r, &k)

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

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

		var c int
		idx := sort.Search(n, func(i int) bool {
			return nums[i] >= l
		})

		for i := idx; i < n; i++ {
			if k-nums[i] < 0 || nums[i] > r {
				break
			}
			k -= nums[i]
			c++
		}

		fmt.Fprintln(out, c)
	}
}

package main

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

func main() {

	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

	t := 0
	fmt.Fscan(f, &t)

	for t > 0 {

		n, l, r, k := 10, 50, 69, 100
		a := []int{}

		fmt.Fscan(f, &n, &l, &r, &k)

		for n > 0 {
			temp := 0
			fmt.Fscan(f, &temp)
			a = append(a, temp)
			n--
		}

		fmt.Fprintln(w, solve(n, l, r, k, a))
		w.Flush()

		t--
	}

	// n, l, r, k := 10, 50, 69, 100
	// a := []int{20, 30, 40, 77, 1, 1, 12, 4, 70, 10000}
	// fmt.Println(solve(n, l, r, k, a))
}

func solve(n, l, r, k int, a []int) int {

	chocolate := []int{}
	count := 0
	sum := 0

	for i := range a {
		if a[i] >= l && a[i] <= r {
			chocolate = append(chocolate, a[i])
		}
	}

	sort.Ints(chocolate)

	for i := range chocolate {
		sum += chocolate[i]

		if sum > k {
			break
		} else {
			count++
		}
	}

	return count
}

func min(a []int, l int) int {
	min := math.MaxInt

	for i := range a {
		if a[i] > l && a[i] < min {
			min = a[i]
		}
	}

	return min
}

package main

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

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

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func A(a []int, l, r, k int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	x, cnt := 0, 0
	for _, i := range a {
		if l <= i && i <= r && x+i <= k {
			cnt++
			x += i
		}
	}
	printf("%d\n", cnt)
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n, l, r, k int
		scan(&n, &l, &r, &k)
		a := make([]int, n)
		for i := range a {
			scan(&a[i])
		}
		A(a, l, r, k)
	}
}

package main

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

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

func solveCase() {
	var n, low, high, budget int
	fmt.Fscan(in, &n, &low, &high, &budget)
	var a []int = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	sort.Ints(a)
	var ans = 0
	for i := 0; i < n; i++ {
		if a[i] >= low && a[i] <= high && a[i] <= budget {
			budget -= a[i]
			ans++
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
	out.Flush()
}

package main

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

func main(){
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	N_INPS,_ := strconv.Atoi(scanner.Text())
	var choc_nums, lower_lims, upper_lims, budgets []int
	var prices [][]int
	var n, l, r, k int
	for i:=0; i<N_INPS; i++{
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d %d %d", &n,&l,&r,&k)
		choc_nums = append(choc_nums, n)
		lower_lims = append(lower_lims, l)
		upper_lims = append(upper_lims, r)
		budgets = append(budgets, k)

		price := make([]int, n)
		scanner.Scan()
		for _, s := range strings.Split(scanner.Text()," "){
			newprice, _ := strconv.Atoi(s)
			price = append(price, newprice)
		}
		prices = append(prices, price)
	}
	for i:=0; i<N_INPS;i++{
		fmt.Println(count_purchases(choc_nums[i],lower_lims[i],upper_lims[i],budgets[i],prices[i]))
	}
}

func count_purchases(n, l, r, k int, price []int) int{
	sort.Ints(price)
	var count int = 0
	for _, p := range price{
		if l <= p && p <= r && k >= p{
			count++
			k -= p
		}
	}
	return count
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt8() int8 {
	i, err := strconv.ParseInt(scan(), 10, 8)
	if err != nil {
		panic(err)
	}
	return int8(i)
}

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

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

func min(ints ...int) int {
	a := ints[0]
	n := len(ints)
	for i := 1; i < n; i++ {
		if ints[i] < a {
			a = ints[i]
		}
	}
	return a
}

func max(ints ...int) int {
	a := ints[0]
	n := len(ints)
	for i := 1; i < n; i++ {
		if ints[i] > a {
			a = ints[i]
		}
	}
	return a
}

type Noop struct{}

var noop = Noop{}

func proc() {
	n, l, r, k := scanInt(), scanInt(), scanInt(), scanInt()
	mas := make([]int, n)
	for i := 0; i < n; i++ {
		mas[i] = scanInt()
	}
	sort.Ints(mas)
	i := 0
	for i < n && mas[i] < l {
		i++
	}
	ans := 0
	for i < n && k >= mas[i] && mas[i] <= r {
		k -= mas[i]
		ans++
		i++
	}
	fmt.Println(ans)
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		proc()
	}
}

package main

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

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

func solve(n, l, r, k int, a []int) int {
	sort.Ints(a)
	count := 0
	for i := 0; i < n && k >= 0; i++ {
		if a[i] >= l && a[i] <= r && k >= a[i] {
			k -= a[i]
			count++
		}
	}
	return count
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

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

	solve := func(Case int) {
		var n,l,r,k int
		Fscan(in, &n,&l,&r,&k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		ans := 0
		for _, v := range a {
			if v >= l && v <= r {
				if k >= v {
					k-=v
					ans++
				}
			}
		}
		Fprintln(out, ans)
	}

	T := 1
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}

}

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

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		var l, r, k int64
		_, _ = fmt.Scanln(&n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		_, _ = fmt.Scanln()
		fmt.Println(n, l, r, k, a)
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		var l, r, k int64
		_, _ = fmt.Scanf("%d %d %d %d\n", &n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		fmt.Println(n, l, r, k, a)
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		var l, r, k int64
		_, _ = fmt.Scanf("%d %d %d %d\n", &n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		//fmt.Println(n, l, r, k, a)
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		var l, r, k int64
		_, _ = fmt.Scanf("%d %d %d %d", &n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		fmt.Println(n, l, r, k, a)
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		var l, r, k int64
		_, _ = fmt.Scanf("%d %d %d %d", &n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t, n int
	var l, r, k int64
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		_, _ = fmt.Scanf("%d %d %d %d", &n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			fmt.Println(sum, a[j], r, k)
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t, n int
	var l, r, k int64
	_, _ = fmt.Scan(&t)
	for i := 0; i < t; i++ {
		_, _ = fmt.Scanf("%d %d %d %d", &n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			//fmt.Println(sum, a[j], r, k)
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t, n int
	var l, r, k int64
	_, _ = fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		_, _ = fmt.Scanf("%d %d %d %d", &n, &l, &r, &k)
		a := make([]int64, n)
		for j := 0; j < n; j++ {
			_, _ = fmt.Scan(&a[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt := 0
		sum := int64(0)
		for j := 0; j < n; j++ {
			if a[j] < l {
				continue
			}
			if a[j] > r || sum+a[j] > k {
				break
			}
			sum += a[j]
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,l,u,bank int
		fmt.Fscan(in,&n,&l,&u,&bank)
		counter:=0
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x >= l && x <= u {
				if bank-x >= 0 {
					counter++
					bank-=x
				}
			}
		}
		fmt.Fprintln(out,counter)
	}
}