package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	type pair struct{ i, j int }

	var k, n int
	Fscan(in, &k)
	mp := map[int]pair{}
	for i := 1; i <= k; i++ {
		Fscan(in, &n)
		a := make([]int, n)
		s := 0
		for j := range a {
			Fscan(in, &a[j])
			s += a[j]
		}
		for j, v := range a {
			if p := mp[s-v]; p.i > 0 && p.i < i {
				Println("YES")
				Println(p.i, p.j+1)
				Print(i, j+1)
				return
			}
			mp[s-v] = pair{i, j}
		}
	}
	Print("NO")
}

package main

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

func Init() {}
func Solve(io *FastIO) {
	var n, s, b int
	var a [][]int
	c := make(map[int][2]int)
	k := io.NextInt()
	for i := 0; i < k; i++ {
		s = 0
		n = io.NextInt()
		a = append(a, make([]int, 0))
		for j := 0; j < n; j++ {
			b = io.NextInt()
			a[i] = append(a[i], -b)
			s += b
		}
		for j := 0; j < n; j++ {
			a[i][j] += s
			if h, ok := c[a[i][j]]; ok {
				//io.Println(a[i][j], h)
				if h[0] != i+1 {
					io.Println("YES")
					io.Printf("%d %d\n", h[0], h[1])
					io.Printf("%d %d\n", i+1, j+1)
					return
				}
			}
			c[a[i][j]] = [2]int{i + 1, j + 1}
		}
	}
	io.Println("NO")
}

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

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}
func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = res*10 + int(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = int64(-1)
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = res*10 + int64(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}
func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}
func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}
func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}
func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}
func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}
func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}
func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}
func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}
func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

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

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

type ii struct {
	index, pos int
}

func main() {
	defer writer.Flush()
    scanner.Split(bufio.ScanWords)

    n := ReadInt()

    mapa := make(map[int]ii)

    for idx := 1; idx <= n; idx++ {

    	m := ReadInt()

    	v := make([]int, m)

    	sum := 0

    	for i := 0; i < m; i++ {
    		v[i] = ReadInt()
    		sum += v[i]
    	}

    	for i := 0; i < m; i++ {
    		sum -= v[i]

    		if _, ok := mapa[sum]; ok && mapa[sum].index != idx {
    			writer.WriteString("YES\n")
    			writer.WriteString(strconv.Itoa(idx))
    			writer.WriteString(" ")
    			writer.WriteString(strconv.Itoa(i+1))
    			writer.WriteString("\n")
    			writer.WriteString(strconv.Itoa(mapa[sum].index))
    			writer.WriteString(" ")
    			writer.WriteString(strconv.Itoa(mapa[sum].pos))
    			writer.WriteString("\n")
    			return
    		}

    		mapa[sum] = ii{idx, i+1}
    		sum += v[i]
    	}

    }
    writer.WriteString("NO\n")
}

package main

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

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

type pair struct {
	i, x int
}

const N = int(2e5+10)

func main() {
	defer out.Flush()

	var k, n int
	mp := make(map[int]pair)
	a := make([]int, N)
	fmt.Fscan(in, &k)
	var flag = false
	for i := 1; i <= k; i++ {
		fmt.Fscan(in, &n)
		sum := 0
		for j := 1; j <= n; j++ {
			fmt.Fscan(in, &a[j])
			sum += a[j]
		}
		for j := 1; j <= n; j++ {
			sum -= a[j]
			if r, ok := mp[sum]; ok && r.i != i {
				flag = true
				fmt.Fprintln(out, "YES")
				fmt.Fprintln(out, r.i, r.x)
				fmt.Fprintln(out, i, j)
				break
			} else {
				mp[sum] = pair{i, j}
			}
			if flag {
				break
			}
			sum += a[j]
		}
		if flag {
			break
		}
	}
	if !flag {
		fmt.Fprintln(out, "NO")
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF988C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ i, j int }

	var k, n int
	Fscan(in, &k)
	mp := map[int]pair{}
	for i := 1; i <= k; i++ {
		Fscan(in, &n)
		a := make([]int, n)
		s := 0
		for j := range a {
			Fscan(in, &a[j])
			s += a[j]
		}
		for j, v := range a {
			if p := mp[s-v]; p.i > 0 && p.i < i {
				Fprintln(out, "YES")
				Fprintln(out, p.i, p.j+1)
				Fprint(out, i, j+1)
				return
			}
			mp[s-v] = pair{i, j}
		}
	}
	Fprint(out, "NO")
}

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

package main

import (
	. "fmt"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	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()
		neg := false
		for ; '0' > b; b = rc() {
			if b == '-' {
				neg = true
			}
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		if neg {
			return -x
		}
		return
	}
	type pair struct{ i, j int }

	mp := map[int]pair{}
	k := r()
	for i := 1; i <= k; i++ {
		a := make([]int, r())
		s := 0
		for j := range a {
			a[j] = r()
			s += a[j]
		}
		for j, v := range a {
			if p := mp[s-v]; p.i > 0 && p.i < i {
				Println("YES")
				Println(p.i, p.j+1)
				Print(i, j+1)
				return
			}
			mp[s-v] = pair{i, j}
		}
	}
	Print("NO")
}

package main

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

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

	var K, n int
	Fscan(in, &K)
	a := make([][]int, K)
	mp := map[int]int{}
	for i := range a {
		Fscan(in, &n)
		a[i] = make([]int, n)
		s := 0
		for j := range a[i] {
			Fscan(in, &a[i][j])
			s += a[i][j]
		}
		for j, v := range a[i] {
			if p := mp[s-v]; p > 0 && p-1 != i {
				s2 := 0
				for _, w := range a[p-1] {
					s2 += w
				}
				for k, w := range a[p-1] {
					if s2-w == s-v {
						Fprintln(out, "YES")
						Fprintln(out, p, k+1)
						Fprint(out, i+1, j+1)
						return
					}
				}
			}
			mp[s-v] = i + 1
		}
	}
	Fprint(out, "NO")
}

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

package main

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

type (
	Sum struct {
		seq, idx, Val int
	}

	Sums []*Sum
)

func (s Sum) String() string {
	return fmt.Sprintf("(%d,%d)-%d", s.seq, s.idx, s.Val)
}

func (s Sums) Len() int {
	return len(s)
}

func (s Sums) Less(i, j int) bool {
	return s[i].Val < s[j].Val
}

func (s Sums) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	sums := input()
	sort.Sort(sums)
	//fmt.Printf("%v\n", sums)

	for i := 1; i < len(sums); i++ {
		if sums[i].Val == sums[i-1].Val && sums[i].seq != sums[i-1].seq {
			fmt.Printf("YES\n%d %d\n%d %d", sums[i-1].seq+1, sums[i-1].idx+1, sums[i].seq+1, sums[i].idx+1)
			return
		}
	}
	fmt.Println("NO")
}

func input() (sums Sums) {
	rd := bufio.NewReader(os.Stdin)

	var k int
	if _, err := fmt.Fscanf(rd, "%d\n", &k); err != nil {
		panic("cannot read k from stdin")
	}

	for i := 0; i < k; i++ {
		var n int
		if _, err := fmt.Fscanf(rd, "%d\n", &n); err != nil {
			panic(fmt.Sprintf("cannot read n%d from stdin", i))
		}

		// deal with codeforces' broken scanf
		nums := make([]int, n)
		sum := 0
		for j := 0; j < n-1; j++ {
			if _, err := fmt.Fscanf(rd, "%d", &nums[j]); err != nil {
				panic(fmt.Sprintf("cannot read seqs[%d].nums[%d] from stdin", i, j))
			}
			sum += nums[j]
		}
		if _, err := fmt.Fscanf(rd, "%d\n", &nums[n-1]); err != nil {
			panic(fmt.Sprintf("cannot read seqs[%d].nums[%d] from stdin", i, n-1))
		}
		sum += nums[n-1]

		for j := 0; j < n; j++ {
			sums = append(sums, &Sum{
				seq: i,
				idx: j,
				Val: sum - nums[j],
			})
		}
	}

	return
}

package main

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

type troyka struct {
	seqNum int
	sum    int64
	el     int
}

type bySum []troyka

func (s bySum) Len() int {
	return len(s)
}
func (s bySum) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s bySum) Less(i, j int) bool {
	return s[i].sum < s[j].sum
}

func main() {
	var tt = make([]troyka, 0)
	reader := bufio.NewReader(os.Stdin)
	n := int(readOneInt64(reader))
	for i := 0; i < n; i++ {
		k := int(readOneInt64(reader))
		mm := readInt64Slice(reader, k)
		var summ int64
		for j := 0; j < k; j++ {
			summ += mm[j]
		}
		for l := 0; l < k; l++ {
			tt = append(tt, troyka{
				seqNum: i+1,
				sum:    summ - mm[l],
				el:     l+1,
			})
		}
	}
	sort.Sort(bySum(tt))
	tl := len(tt)-1
	for i:=0;i<tl;i++{
		if tt[i].sum == tt[i+1].sum && tt[i].seqNum != tt[i+1].seqNum{
			fmt.Println("YES")
			fmt.Printf("%d %d\n", tt[i].seqNum, tt[i].el)
			fmt.Printf("%d %d\n", tt[i+1].seqNum, tt[i+1].el)
			os.Exit(0)
		}
	}
	fmt.Println("NO")
}

func readOneInt64(r *bufio.Reader) (n int64) {
	bytes, _ := r.ReadBytes('\n')
	n, _ = strconv.ParseInt(string(bytes[:len(bytes)-2]), 10, 64)
	return
}

func readInt64Slice(r *bufio.Reader, n int) (slice []int64) {
	var bytes []byte
	slice = make([]int64, n)
	n--
	for i := 0; i < n; i++ {
		bytes, _ = r.ReadBytes(' ')
		slice[i], _ = strconv.ParseInt(string(bytes[:len(bytes)-1]), 10, 64)
	}
	slice[n] = readOneInt64(r)
	return
}

func readOneString(r *bufio.Reader) string {
	bytes, _ := r.ReadBytes('\n')
	return string(bytes[:len(bytes)-2])
}

func abs(i int) int {
	if i < 0 {
		return i * -1
	}
	return i
}

func BinarySearch(target_map []int, value int) int {

	start_index := 0
	end_index := len(target_map) - 1

	for start_index <= end_index {

		median := (start_index + end_index) / 2

		if target_map[median] < value {
			start_index = median + 1
		} else {
			end_index = median - 1
		}

	}

	if start_index == len(target_map) || target_map[start_index] != value {
		return -1
	} else {
		return start_index
	}

}

package main

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

type AA struct {
	s int
	i int
}

func main() {
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &n)

	var input = make([][]int, n)
	var sum2 = make(map[int]AA)

	var a1, a2, b1, b2 int
	var ret bool
	for i := 0; i < n; i++ {
		var len int
		fmt.Fscanln(reader, &len)
		var arr = make([]int, len)
		sumx := 0
		for j := 0; j < len; j++ {
			fmt.Fscan(reader, &arr[j])
			sumx += arr[j]
		}
		fmt.Fscanln(reader)
		input[i] = arr

		if ret {
			continue
		}
		for j := 0; j < len; j++ {
			sum0 := sumx - arr[j]
			if aa, ok := sum2[sum0]; ok {
				if aa.s != i {
					ret = true
					a1 = aa.s
					a2 = aa.i
					b1 = i
					b2 = j
				}

			} else {
				sum2[sum0] = AA{
					s: i,
					i: j,
				}
			}

		}
	}
	//fmt.Println(input)
	//fmt.Println(sum)
	// o(n2)
	//for i := 0; i < n-1; i++ {
	//	for j := i + 1; j < n; j++ {
	//		if ok, x1, x2 := isSolve2(sum1[i], sum1[j]); ok {
	if ret {
		fmt.Println("YES")
		fmt.Println(a1+1, a2+1)
		fmt.Println(b1+1, b2+1)
		return
	}

	//}
	//}
	//}
	fmt.Println("NO")
}

// o(m2)
func isSolve(a1 []int, sum1 int, a2 []int, sum2 int) (bool, int, int) {
	for i := 0; i < len(a1); i++ {
		for j := 0; j < len(a2); j++ {
			if sum1-a1[i] == sum2-a2[j] {
				return true, i, j
			}
		}
	}
	return false, 0, 0
}

func isSolve2(a1 []int, a2 []int) (bool, int, int) {
	xMap := make(map[int]int)
	for i := 0; i < len(a1); i++ {
		xMap[a1[i]] = i
	}
	for j := 0; j < len(a2); j++ {
		if y, ok := xMap[a2[j]]; ok {
			return true, y, j
		}
	}
	return false, 0, 0
}

package main

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

const (
	MaxN = 200005
)

type ind struct {
	sequencePos, index int
}

var index map[int]ind
var a [MaxN]int
var k int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &k)
	index = make(map[int]ind)
	for i := 0; i < k; i++ {
		var n int
		fmt.Fscanf(buf, "%d\n", &n)
		sum := 0
		for j := 0; j < n; j++ {
			fmt.Fscanf(buf, "%d", &a[j])
			sum += a[j]
		}
		for j := 0; j < n; j++ {
			tmp := sum - a[j]
			if s, ok := index[tmp]; ok && s.sequencePos != i {
				fmt.Printf("YES\n%d %d\n%d %d\n", s.sequencePos+1, s.index+1, i+1, j+1)
				return
			}
			index[tmp] = ind{i, j}
		}
		fmt.Fscanf(buf, "\n")
	}
	fmt.Println("NO")
}

package main

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

type rem struct {
	seq int
	pos int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 10000000), 10000000)
	var k int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &k)

	m := map[int]rem{}
	for seq := 0; seq < k; seq++ {
		scanner.Scan()
		var le int
		fmt.Sscan(scanner.Text(), &le)
		scanner.Scan()
		vv := strings.Split(scanner.Text(), " ")
		total := 0
		vvv := make([]int, le)
		for i := range vvv {
			x, _ := strconv.Atoi(vv[i])
			vvv[i] = x
			total += x
		}
		for i := range vvv {
			val := total - vvv[i]
			prev, ok := m[val]
			if ok {
				if prev.seq == seq {
					continue
				}
				fmt.Println("YES")
				fmt.Println(prev.seq+1, prev.pos+1)
				fmt.Println(seq+1, i+1)
				os.Exit(0)
			}
			m[val] = rem{seq, i}
		}

	}
	fmt.Println("NO")

}

package main

import (
	"fmt"
	"sort"
)

type (
	Sum struct {
		seq, idx, Val int
	}

	Sums []*Sum
)

func (s Sum) String() string {
	return fmt.Sprintf("(%d,%d)-%d", s.seq, s.idx, s.Val)
}

func (s Sums) Grow(by int) {
	temp := make(Sums, len(s), len(s)+by)
	copy(temp, s)
	s = temp
}

func (s Sums) Len() int {
	return len(s)
}

func (s Sums) Less(i, j int) bool {
	return s[i].Val < s[j].Val
}

func (s Sums) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	sums := input()
	sort.Sort(sums)
	//fmt.Printf("%v\n", sums)

	for i := 1; i < len(sums); i++ {
		if sums[i].Val == sums[i-1].Val && sums[i].seq != sums[i-1].seq {
			fmt.Printf("YES\n%d %d\n%d %d", sums[i-1].seq+1, sums[i-1].idx+1, sums[i].seq+1, sums[i].idx+1)
			return
		}
	}
	fmt.Println("NO")
}

func input() (sums Sums) {
	var k int
	if _, err := fmt.Scanf("%d\n", &k); err != nil {
		panic("cannot read k from stdin")
	}

	for i := 0; i < k; i++ {
		var n int
		if _, err := fmt.Scanf("%d\n", &n); err != nil {
			panic(fmt.Sprintf("cannot read n%d from stdin", i))
		}

		// deal with codeforces' broken scanf
		nums := make([]int, n)
		sum := 0
		for j := 0; j < n-1; j++ {
			if _, err := fmt.Scanf("%d", &nums[j]); err != nil {
				panic(fmt.Sprintf("cannot read seqs[%d].nums[%d] from stdin", i, j))
			}
			sum += nums[j]
		}
		if _, err := fmt.Scanf("%d\n", &nums[n-1]); err != nil {
			panic(fmt.Sprintf("cannot read seqs[%d].nums[%d] from stdin", i, n-1))
		}

		sums.Grow(n)
		for j := 0; j < n; j++ {
			sums = append(sums, &Sum{
				seq: i,
				idx: j,
				Val: sum - nums[j],
			})
		}
	}

	return
}

package main

import (
	"fmt"
	"sort"
)

type (
	Sum struct {
		seq, idx, Val int
	}

	Sums []*Sum
)

func (s Sum) String() string {
	return fmt.Sprintf("(%d,%d)-%d", s.seq, s.idx, s.Val)
}

func (s Sums) Grow(by int) {
	temp := make(Sums, len(s), len(s)+by)
	copy(temp, s)
	s = temp
}

func (s Sums) Len() int {
	return len(s)
}

func (s Sums) Less(i, j int) bool {
	return s[i].Val < s[j].Val
}

func (s Sums) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	sums := input()
	sort.Sort(sums)
	//fmt.Printf("%v\n", sums)

	for i := 1; i < len(sums); i++ {
		if sums[i].Val == sums[i-1].Val && sums[i].seq != sums[i-1].seq {
			fmt.Println(sums[i-1], sums[i])
			fmt.Printf("YES\n%d %d\n%d %d", sums[i-1].seq+1, sums[i-1].idx+1, sums[i].seq+1, sums[i].idx+1)
			return
		}
	}
	fmt.Println("NO")
}

func input() (sums Sums) {
	var k int
	if _, err := fmt.Scanf("%d\n", &k); err != nil {
		panic("cannot read k from stdin")
	}

	for i := 0; i < k; i++ {
		var n int
		if _, err := fmt.Scanf("%d\n", &n); err != nil {
			panic(fmt.Sprintf("cannot read n%d from stdin", i))
		}

		// deal with codeforces' broken scanf
		nums := make([]int, n)
		sum := 0
		for j := 0; j < n-1; j++ {
			if _, err := fmt.Scanf("%d", &nums[j]); err != nil {
				panic(fmt.Sprintf("cannot read seqs[%d].nums[%d] from stdin", i, j))
			}
			sum += nums[j]
		}
		if _, err := fmt.Scanf("%d\n", &nums[n-1]); err != nil {
			panic(fmt.Sprintf("cannot read seqs[%d].nums[%d] from stdin", i, n-1))
		}
		sum += nums[n-1]

		sums.Grow(n)
		for j := 0; j < n; j++ {
			sums = append(sums, &Sum{
				seq: i,
				idx: j,
				Val: sum - nums[j],
			})
		}
	}

	return
}

package main

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

type rem struct {
	seq int
	pos int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 10000000), 10000000)
	var k int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &k)

	m := map[int]rem{}
	for seq := 0; seq < k; seq++ {
		scanner.Scan()
		var le int
		fmt.Sscan(scanner.Text(), &le)
		scanner.Scan()
		vv := strings.Split(scanner.Text(), " ")
		total := 0
		vvv := make([]int, le)
		for i := range vvv {
			x, _ := strconv.Atoi(vv[i])
			vvv[i] = x
			total += x
		}
		for i := range vvv {
			val := total - vvv[i]
			prev, ok := m[val]
			if ok {
				if prev.seq == seq {
					continue
				}
				fmt.Println("YES")
				fmt.Println(prev.seq, prev.pos)
				fmt.Println(seq, i)
				os.Exit(0)
			}
			m[val] = rem{seq, i}
		}

	}
	fmt.Println("NO")

}


package main

import "fmt"

func main() {
    var n,m,a int
    fmt.Scan(&n,&m)
    ans := 4
    for i := 1; i <= n; i++ {
        for j := 1; j <= m; j++ {
            fmt.Scan(&a)
            if (a == 1) && ((i == 1) || (i == n) || (j == 1) || (j == m)) {
                ans = 2
            }
        }
    }
    fmt.Println(ans)
}

package main
import (
	"fmt"
)
func main() {
	var i,m,n,t int
	c:=4
	fmt.Scan(&n,&m)
	for ;i<m*n;i++ {
		fmt.Scan(&t)
		if t!=0 {
			if i<m || i>m*n-m || i%m==0 || i%m==m-1 {
				c=2
			}
		}
	}
	fmt.Println(c)
}

// 359A-mic
package main

import (
	"fmt"
)

func main() {
	var n, m, i, j, x, flag int
	fmt.Scan(&n, &m)
	flag = 0
	for i = 1; i <= n; i++ {
		for j = 1; j <= m; j++ {
			fmt.Scan(&x)
			if x == 1 && (i == 1 || i == n || j == 1 || j == m) {
				flag = 1
			}
		}
	}
	if flag == 1 {
		fmt.Println("2")
	} else {
		fmt.Println("4")
	}
}

package main
import (
	"fmt"
)
func main() {
	var i,m,n,t int
	c:=4
	fmt.Scan(&n,&m)
	for ;i<m*n;i++ {
		fmt.Scan(&t)
		if t!=0 {
			if i<m || i>m*n-m || i%m==0 || i%m==n {
				c=2
			}
		}
	}
	fmt.Println(c)
}


package main

import "fmt"

func find(x int) int {
	ans := 0
	for x != 1 {
		ans++
		y := 0
		for x > 0 {
			if x%2 == 1 {
				y++
			}
			x /= 2
		}
		x = y
	}
	return ans
}

const mod = 1e9 + 7

func main() {
	var n string
	var k int
	c := make([][]int, 1001)
	for i := range c {
		c[i] = make([]int, 1001)
		c[i][0] = 1
		c[i][i] = 1
		if i > 0 {
			for j := range c[i] {
				c[i][j] = c[i-1][j]
				if j > 0 {
					c[i][j] = (c[i][j] + c[i-1][j-1]) % mod
				}
			}
		}
	}

	numOp := make([]int, 1001)
	for i := 1; i <= 1000; i++ {
		numOp[i] = find(i)
	}

	fmt.Scan(&n, &k)
	if k == 0 {
		fmt.Println(1)
		return
	}
	if n == "1" {
		fmt.Println(0)
		return
	}

	ones := 0
	ans := 0
	for i := range n {
		if n[i] == '1' {
			for no, c := range c[len(n)-1-i][:len(n)-i] {
				if ones + no == 0 {
					continue
				}
				if numOp[ones+no]+1 == k {
					if ones == 0 && no == 1 {
						c--
					}
					ans = (ans + c) % mod
				}
			}
			ones++
		}
	}
	if numOp[ones]+1 == k {
		ans = (ans + 1) % mod
	}
	fmt.Println(ans)
}

package main

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

const (
	MOD = int64(1000000007)
)

var (
	C = ComputeCombinations(1001, MOD)
)

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()
	K := io.NextInt()

	N := len(S)

	if K == 0 {
		io.Println(1)
		return
	}

	var cnt int64
	for i := 1; i <= N; i++ {
		if CountOperations(i) == K - 1 {
			ways := CountWays(S, i)
			if i == 1 {
				ways--
			}
			cnt = (cnt + ways) % MOD
		}
	}
	io.Println(cnt)
}

func CountWays(S string, k int) int64 {
	n := len(S)
	if n < k || k < 0{
		return 0
	}
	if n == 0 {
		if k == 0 {
			return 1
		}
		return 0
	}

	if S[0] == '0' {
		return CountWays(S[1:], k)
	}
	return (C[n - 1][k] + CountWays(S[1:], k - 1)) % MOD
}

func BitCount(n int) int {
	cnt := 0
	for n > 0 {
		n = n & (n - 1)
		cnt++
	}
	return cnt
}

func CountOperations(n int) int {
	cnt := 0
	for n > 1 {
		n = BitCount(n)
		cnt++
	}
	return cnt
}

func MakeLongMatrix(rows, cols int) [][]int64 {
	mat := make([][]int64, rows)
	for i := range mat {
		mat[i] = make([]int64, cols)
	}
	return mat
}

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

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

func ComputeCombinations(n int, mod int64) [][]int64 {
	combos := make([][]int64, n + 1)
	combos[0] = []int64{1, 0}
	for r := 1; r <= n; r++ {
		combos[r] = make([]int64, r + 2)
		combos[r][0] = 1
		for c := 1; c <= r; c++ {
			combos[r][c] = (combos[r - 1][c - 1] + combos[r - 1][c]) % mod
		}
	}
	return combos
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

import "fmt"

func find(x int) int {
	ans := 0
	for x != 1 {
		ans++
		y := 0
		for x > 0 {
			if x%2 == 1 {
				y++
			}
			x /= 2
		}
		x = y
	}
	return ans
}

const mod = 1e9 + 7

func main() {
	var n string
	var k int
	c := make([][]int, 1001)
	for i := range c {
		c[i] = make([]int, 1001)
		c[i][0] = 1
		c[i][i] = 1
		if i > 0 {
			for j := range c[i] {
				c[i][j] = c[i-1][j]
				if j > 0 {
					c[i][j] = (c[i][j] + c[i-1][j-1]) % mod
				}
			}
		}
	}

	numOp := make([]int, 1001)
	for i := 1; i <= 1000; i++ {
		numOp[i] = find(i)
	}

	fmt.Scan(&n, &k)
	if k == 0 {
		fmt.Println(1)
		return
	}
	if n == "1" {
		fmt.Println(0)
		return
	}

	ones := 0
	ans := 0
	for i := range n {
		if n[i] == '1' {
			if i + 1 < len(n) {
				for no, c := range c[len(n)-1-i][:len(n)-i] {
					if ones + no == 0 {
						continue
					}
					if numOp[ones+no]+1 == k {
						ans = (ans + c) % mod
					}
				}
			}
			ones++
		}
	}
	if ones > 1 && numOp[ones]+1 == k {
		ans = (ans + 1) % mod
	}
	fmt.Println(ans)
}

package main

import "fmt"

func find(x int) int {
	ans := 0
	for x != 1 {
		ans++
		y := 0
		for x > 0 {
			if x%2 == 1 {
				y++
			}
			x /= 2
		}
		x = y
	}
	return ans
}

const mod = 1e9 + 7

func main() {
	var n string
	var k int
	c := make([][]int, 1001)
	for i := range c {
		c[i] = make([]int, 1001)
		c[i][0] = 1
		c[i][i] = 1
		if i > 0 {
			for j := range c[i] {
				c[i][j] = c[i-1][j]
				if j > 0 {
					c[i][j] = (c[i][j] + c[i-1][j-1]) % mod
				}
			}
		}
	}

	numOp := make([]int, 1001)
	for i := 1; i <= 1000; i++ {
		numOp[i] = find(i)
	}

	fmt.Scan(&n, &k)

	ones := 0
	ans := 0
	for i := range n {
		if n[i] == '1' {
			for no, c := range c[len(n)-1-i][:len(n)-i] {
				if numOp[ones+no]+1 == k {
					ans = (ans + c) % mod
				}
			}
			ones++
		}
	}
	if numOp[ones]+1 == k {
		ans = (ans + 1) % mod
	}
	fmt.Println(ans)
}

package main

import "fmt"

func find(x int) int {
	ans := 0
	for x != 1 {
		ans++
		y := 0
		for x > 0 {
			if x%2 == 1 {
				y++
			}
			x /= 2
		}
		x = y
	}
	return ans
}

const mod = 1e9 + 7

func main() {
	var n string
	var k int
	c := make([][]int, 1001)
	for i := range c {
		c[i] = make([]int, 1001)
		c[i][0] = 1
		c[i][i] = 1
		if i > 0 {
			for j := range c[i] {
				c[i][j] = c[i-1][j]
				if j > 0 {
					c[i][j] = (c[i][j] + c[i-1][j-1]) % mod
				}
			}
		}
	}

	numOp := make([]int, 1001)
	for i := 1; i <= 1000; i++ {
		numOp[i] = find(i)
	}

	fmt.Scan(&n, &k)
	if k == 0 {
		fmt.Println(1)
		return
	}
	if n == "1" {
		fmt.Println(0)
		return
	}

	ones := 0
	ans := -1
	for i := range n {
		if n[i] == '1' {
			for no, c := range c[len(n)-1-i][:len(n)-i] {
				if ones + no == 0 {
					continue
				}
				if numOp[ones+no]+1 == k {
					ans = (ans + c) % mod
				}
			}
			ones++
		}
	}
	if numOp[ones]+1 == k {
		ans = (ans + 1) % mod
	}
	fmt.Println(ans)
}

package main

import "fmt"

func find(x int) int {
	ans := 0
	for x != 1 {
		ans++
		y := 0
		for x > 0 {
			if x%2 == 1 {
				y++
			}
			x /= 2
		}
		x = y
	}
	return ans
}

const mod = 1e9 + 7

func main() {
	var n string
	var k int
	c := make([][]int, 1001)
	for i := range c {
		c[i] = make([]int, 1001)
		c[i][0] = 1
		c[i][i] = 1
		if i > 0 {
			for j := range c[i] {
				c[i][j] = c[i-1][j]
				if j > 0 {
					c[i][j] = (c[i][j] + c[i-1][j-1]) % mod
				}
			}
		}
	}

	numOp := make([]int, 1001)
	for i := 1; i <= 1000; i++ {
		numOp[i] = find(i)
	}

	fmt.Scan(&n, &k)

	ones := 0
	ans := 0
	for i := range n {
		if n[i] == '1' {
			if i + 1 < len(n) {
				for no, c := range c[len(n)-1-i][:len(n)-i] {
					if numOp[ones+no]+1 == k {
						ans = (ans + c) % mod
					}
				}
			}
			ones++
		}
	}
	if numOp[ones]+1 == k {
		ans = (ans + 1) % mod
	}
	fmt.Println(ans)
}

package main

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

const (
	MOD = int64(1000000007)
)

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()
	K := io.NextInt()

	N := len(S)

	// dp := MakeLongMatrix(N, N + 1)
	// for i := 0; i < N; i++ {
	// 	dp[i][1] = 1
	// }
	// for j := 2; j <= N; j++ {
	// 	sum := int64(0)
	// 	for i := 1; i < N; i++ {
	// 		sum = (sum + dp[i - 1][j - 1]) % MOD

	// 	}
	// }

	bits := make([]int, 1024)
	for i := range bits {
		bits[i] = BitCount(i)
	}

	ops := make([]int, 1024)
	for i := range ops {
		ops[i] = CountOperations(i)
	}

	combos := ComputeCombinations(N, MOD)
	// fmt.Println("HERE")
	gg := MakeLongMatrix(N + 2, N + 2)
	gg[1][1] = 1
	for i := 2; i <= N; i++ {
		for j := 0; j <= i; j++ {
			gg[i][1 + ops[j + 1]] = (gg[i][1 + ops[j + 1]] + combos[i - 1][j]) % MOD
			// if ops[j] == K - 1 {

			// 	gg[i] = (gg[i] + combos[i][j - 1]) % MOD
			// }
		}
		// fmt.Printf("gg[%d] = %d\n", i, gg[i])
	}

	for i := 1; i < 16; i++ {
		// fmt.Printf("i = %d, bits = %d, ops = %d\n", i, BitCount(i), CountOperations(i))
	}

	var fml int64
	for i := 1; i <= N; i++ {
		if CountOperations(i) == K - 1 {
			cnt := BCC(S, i, combos)
			// fmt.Printf("i = %d, bcc = %d\n", i, cnt)
			fml += cnt
			fml %= MOD
		}
	}
	io.Println(fml)

	wtf := 0
	for i := 1; i <= 507; i++ {
		if BitCount(i) == 8 && CountOperations(i) == K {
			wtf++
		}
	}
	// fmt.Printf("WANT: %d\n", wtf)

	// x := Get(S, K, gg)
	// io.Println(x)

	// ss := make([]int64, N)
	// ss[0] = gg[0]
	// for i := 1; i < N; i++ {
	// 	ss[i] = (ss[i - 1] + gg[i]) % MOD
	// }

	// ans := Ans([]byte(S), ss)
	// io.Println(ans)
}

func BCC(S string, k int, combos [][]int64) int64 {
	n := len(S)
	if n < k || k < 0{
		return 0
	}
	if n == 0 {
		if k == 0 {
			return 1
		}
		return 0
	}

	if S[0] == '0' {
		return BCC(S[1:], k, combos)
	}

	var ans int64
	ans += BCC(S[1:], k - 1, combos)
	ans += combos[n - 1][k]
	ans %= MOD
	// fmt.Printf("BCC(%s, %d) = %d\n", S, k, ans)
	return ans
}

func Get(S string, k int, gg [][]int64) int64 {
	n := len(S)
	if n == 0 || k < 0 {
		return 0
	}

	if S[0] == '0' {
		return Get(S[1:], k, gg)
	}

	var ans int64
	for i := 1; i < n; i++ {
		ans += gg[i][k]
		ans %= MOD
	}
	ans += Get(S[1:], k - 1, gg)
	ans %= MOD
	// fmt.Printf("S = '%s', k = %d, GET = %d\n", S, k, ans)
	return ans
}

func Ans(n []byte, ss []int64) int64 {
	sz := len(n)
	if sz == 0 {
		return 0
	}

	var nx []byte
	for i := 1; i < sz; i++ {
		if n[i] == '1' {
			nx = n[i:]
			break
		}
	}

	return (ss[sz - 1] + Ans(nx, ss)) % MOD
}

func BitCount(n int) int {
	cnt := 0
	for n > 0 {
		n = n & (n - 1)
		cnt++
	}
	return cnt
}

func CountOperations(n int) int {
	cnt := 0
	for n > 1 {
		n = BitCount(n)
		cnt++
	}
	return cnt
}

func MakeLongMatrix(rows, cols int) [][]int64 {
	mat := make([][]int64, rows)
	for i := range mat {
		mat[i] = make([]int64, cols)
	}
	return mat
}

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

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

func ComputeCombinations(n int, mod int64) [][]int64 {
	combos := make([][]int64, n + 1)
	combos[0] = []int64{1, 0}
	for r := 1; r <= n; r++ {
		// fmt.Println(r)
		combos[r] = make([]int64, r + 2)
		combos[r][0] = 1
		for c := 1; c <= r; c++ {
			// fmt.Println(" ", c)
			combos[r][c] = (combos[r - 1][c - 1] + combos[r - 1][c]) % mod
			// fmt.Println(" ", c)
		}
		// fmt.Println(r)
	}
	return combos
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

package main

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

const (
	MOD = int64(1000000007)
)

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()
	K := io.NextInt()

	N := len(S)

	if K == 0 {
		io.Println(1)
		return
	}

	// dp := MakeLongMatrix(N, N + 1)
	// for i := 0; i < N; i++ {
	// 	dp[i][1] = 1
	// }
	// for j := 2; j <= N; j++ {
	// 	sum := int64(0)
	// 	for i := 1; i < N; i++ {
	// 		sum = (sum + dp[i - 1][j - 1]) % MOD

	// 	}
	// }

	bits := make([]int, 1024)
	for i := range bits {
		bits[i] = BitCount(i)
	}

	ops := make([]int, 1024)
	for i := range ops {
		ops[i] = CountOperations(i)
	}

	combos := ComputeCombinations(N, MOD)
	// fmt.Println("HERE")
	gg := MakeLongMatrix(N + 2, N + 2)
	gg[1][1] = 1
	for i := 2; i <= N; i++ {
		for j := 0; j <= i; j++ {
			gg[i][1 + ops[j + 1]] = (gg[i][1 + ops[j + 1]] + combos[i - 1][j]) % MOD
			// if ops[j] == K - 1 {

			// 	gg[i] = (gg[i] + combos[i][j - 1]) % MOD
			// }
		}
		// fmt.Printf("gg[%d] = %d\n", i, gg[i])
	}

	for i := 1; i < 16; i++ {
		// fmt.Printf("i = %d, bits = %d, ops = %d\n", i, BitCount(i), CountOperations(i))
	}

	var fml int64
	for i := 1; i <= N; i++ {
		if CountOperations(i) == K - 1 {
			cnt := BCC(S, i, combos)
			// fmt.Printf("i = %d, bcc = %d\n", i, cnt)
			fml += cnt
			fml %= MOD
		}
	}
	io.Println(fml)

	wtf := 0
	for i := 1; i <= 507; i++ {
		if BitCount(i) == 8 && CountOperations(i) == K {
			wtf++
		}
	}
	// fmt.Printf("WANT: %d\n", wtf)

	// x := Get(S, K, gg)
	// io.Println(x)

	// ss := make([]int64, N)
	// ss[0] = gg[0]
	// for i := 1; i < N; i++ {
	// 	ss[i] = (ss[i - 1] + gg[i]) % MOD
	// }

	// ans := Ans([]byte(S), ss)
	// io.Println(ans)
}

func BCC(S string, k int, combos [][]int64) int64 {
	n := len(S)
	if n < k || k < 0{
		return 0
	}
	if n == 0 {
		if k == 0 {
			return 1
		}
		return 0
	}

	if S[0] == '0' {
		return BCC(S[1:], k, combos)
	}

	var ans int64
	ans += BCC(S[1:], k - 1, combos)
	ans += combos[n - 1][k]
	ans %= MOD
	// fmt.Printf("BCC(%s, %d) = %d\n", S, k, ans)
	return ans
}

func Get(S string, k int, gg [][]int64) int64 {
	n := len(S)
	if n == 0 || k < 0 {
		return 0
	}

	if S[0] == '0' {
		return Get(S[1:], k, gg)
	}

	var ans int64
	for i := 1; i < n; i++ {
		ans += gg[i][k]
		ans %= MOD
	}
	ans += Get(S[1:], k - 1, gg)
	ans %= MOD
	// fmt.Printf("S = '%s', k = %d, GET = %d\n", S, k, ans)
	return ans
}

func Ans(n []byte, ss []int64) int64 {
	sz := len(n)
	if sz == 0 {
		return 0
	}

	var nx []byte
	for i := 1; i < sz; i++ {
		if n[i] == '1' {
			nx = n[i:]
			break
		}
	}

	return (ss[sz - 1] + Ans(nx, ss)) % MOD
}

func BitCount(n int) int {
	cnt := 0
	for n > 0 {
		n = n & (n - 1)
		cnt++
	}
	return cnt
}

func CountOperations(n int) int {
	cnt := 0
	for n > 1 {
		n = BitCount(n)
		cnt++
	}
	return cnt
}

func MakeLongMatrix(rows, cols int) [][]int64 {
	mat := make([][]int64, rows)
	for i := range mat {
		mat[i] = make([]int64, cols)
	}
	return mat
}

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

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

func ComputeCombinations(n int, mod int64) [][]int64 {
	combos := make([][]int64, n + 1)
	combos[0] = []int64{1, 0}
	for r := 1; r <= n; r++ {
		// fmt.Println(r)
		combos[r] = make([]int64, r + 2)
		combos[r][0] = 1
		for c := 1; c <= r; c++ {
			// fmt.Println(" ", c)
			combos[r][c] = (combos[r - 1][c - 1] + combos[r - 1][c]) % mod
			// fmt.Println(" ", c)
		}
		// fmt.Println(r)
	}
	return combos
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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


package main

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

type Op struct {
	l, r, d int
}

type Pair struct {
	l, r int
}

type BITTree struct {
	n int
	s []int64
}

func NewBITTree(n int) *BITTree {
	t := BITTree{n: n, s: make([]int64, n+1)}
	return &t
}

func (t *BITTree) Update(x int, val int64) {
	x++
	for ; x <= t.n; x += x & -x {
		t.s[x] += val
	}
}

func (t *BITTree) GetSum(x int) int64 {
	x++
	var sum int64 = 0
	for ; x > 0; x -= x & -x {
		sum += t.s[x]
	}
	return sum
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)

	var n, m, k int
	for true {
		if _, err := fmt.Fscan(stdin, &n, &m, &k); err != nil {
			break
		}
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(stdin, &a[i])
		}
		ops := make([]Op, m)
		for i := 0; i < m; i++ {
			fmt.Fscan(stdin, &ops[i].l, &ops[i].r, &ops[i].d)
			ops[i].l--
			ops[i].r--
		}
		queries := make([]Pair, k)
		for i := 0; i < k; i++ {
			fmt.Fscan(stdin, &queries[i].l, &queries[i].r)
			queries[i].l--
			queries[i].r--
		}
		t := NewBITTree(m)
		for _, q := range queries {
			t.Update(q.l, 1)
			if q.r + 1 < m {
				t.Update(q.r + 1, -1)
			}
		}
		addT := NewBITTree(n)
		for i, op := range ops {
			count := t.GetSum(i)
			val := int64(count) * int64(op.d)
			//fmt.Printf("count of op %d = %d, val = %d\n", i, count, val)
			addT.Update(op.l, val)
			if op.r + 1 < n {
				addT.Update(op.r + 1, -val)
			}
		}
		for i := 0; i < n; i++ {
			add := addT.GetSum(i)
			//fmt.Printf("add of a[%d] = %d\n", i, add)
			a[i] += add
			if i > 0 {
				fmt.Fprintf(stdout, " ")
			}
			fmt.Fprintf(stdout, "%d", a[i])
		}
		fmt.Fprintf(stdout, "\n")
		stdout.Flush()
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

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

func main() {
	defer w.Flush()
	var n int64
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int64) {
	var m, k int64
	I(&m, " ")
	I(&k, "\n")
	in, ii := make([]int64, n+10), make([]int64, n+10)
	for i := int64(1); i <= n; i++ {
		o := " "
		if i == n {
			o = "\n"
		}
		I(&in[i], o)
	}
	op := make([][4]int64, m+10)
	for i := int64(1); i <= m; i++ {
		I(&op[i][0], " ")
		I(&op[i][1], " ")
		I(&op[i][2], "\n")
	}
	for i := int64(1); i <= k; i++ {
		var x, y int
		I(&x, " ")
		I(&y, "\n")
		op[x][3]++
		op[y+1][3]--
	}
	for i := int64(1); i <= m; i++ {
		op[i][3] += op[i-1][3]
		oo := op[i][3] * op[i][2]
		ii[op[i][0]] += oo
		ii[op[i][1]+1] -= oo
	}
	for i := int64(1); i <= n; i++ {
		ii[i] += ii[i-1]
		o := " "
		if i == n {
			o = "\n"
		}
		O(in[i]+ii[i], o)
	}
}

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.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int64
	for I(&n) == nil {
		solve(n)
	}
}

func solve(n int64) {
	var m, k int64
	I(&m, &k)
	in, ii := make([]int64, n+10), make([]int64, n+10)
	for i := int64(1); i <= n; i++ {
		I(&in[i])
	}
	op := make([][4]int64, m+10)
	for i := int64(1); i <= m; i++ {
		I(&op[i][0], &op[i][1], &op[i][2])
	}
	for i := int64(1); i <= k; i++ {
		var x, y int
		I(&x, &y)
		op[x][3]++
		op[y+1][3]--
	}
	for i := int64(1); i <= m; i++ {
		op[i][3] += op[i-1][3]
		oo := op[i][3] * op[i][2]
		ii[op[i][0]] += oo
		ii[op[i][1]+1] -= oo
	}
	for i := int64(1); i <= n; i++ {
		ii[i] += ii[i-1]
		o := " "
		if i == n {
			o = "\n"
		}
		O(in[i]+ii[i], o)
	}
}

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)
func main() {
	var a,aux,op,d,l,r [100005]int64
	var x,y,i,k,m,n int64
	fmt.Scan(&n,&m,&k)
	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i=1;i<=n;i++ {
		input.Scan()
		bb,_:=strconv.ParseInt(input.Text(),0,64)
		a[i]=bb
	}
	for i=1;i<=m;i++ {
		input.Scan()
		dd,_:=strconv.ParseInt(input.Text(),0,64)
		l[i]=dd
		input.Scan()
		cc,_:=strconv.ParseInt(input.Text(),0,64)
		r[i]=cc
		input.Scan()
		ee,_:=strconv.ParseInt(input.Text(),0,64)
		d[i]=ee
	}
	for i=1;i<=k;i++ {
	        input.Scan()
	        ff,_:=strconv.ParseInt(input.Text(),0,64)
	        x=ff
	        input.Scan()
	        gg,_:=strconv.ParseInt(input.Text(),0,64)
	        y=gg
	        op[x]++
	        op[y+1]--
	}
	for i=1;i<=m;i++ {
		op[i]+=op[i-1]
		aux[l[i]]+=d[i]*op[i]
		aux[r[i]+1]-=d[i]*op[i]
	}
	for i=1;i<=n;i++ {
		aux[i]+=aux[i-1]
		fmt.Print(aux[i]+a[i]," ")
	}
}

package main

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

type Operation struct {
    l,r,d int
}

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

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,k,x,y int
    ScanInts(&n,&m,&k)
    a, ca := make([]int,n), make([]int64,n)
    for i := 0; i < n; i++ {
        ScanInts(&a[i])
    }
    o, co := make([]Operation,m), make([]int,m)
    for i := 0; i < m; i++ {
        ScanInts(&o[i].l,&o[i].r,&o[i].d)
        o[i].l--; o[i].r--;
    }
    for i := 0; i < k; i++ {
        ScanInts(&x,&y)
        x--; y--;
        co[x]++
        if y+1 < m { co[y+1]-- }
    }
    for i := 0; i < m; i++ {
        if i != 0 { co[i] += co[i-1] }
        ca[o[i].l] += int64(o[i].d)*int64(co[i])
        if o[i].r+1 < n { ca[o[i].r+1] -= int64(o[i].d)*int64(co[i]) }
    }
    for i := 0; i < n; i++ {
        if i != 0 { ca[i] += ca[i-1] }
        writer.WriteString(strconv.FormatInt(ca[i]+int64(a[i]),10))
        if i == n-1 { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

package main

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

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

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

type Op struct {
    l, r int
    d int64
}

type Node struct {
    left, right *Node
    leftBound, rightBound int
    value int64
}

func node(data []int64, left int, right int) *Node {
    res := &Node{}

    res.leftBound = left
    res.rightBound = right

    if left == right {
        res.value = data[left]
        return res
    }

    med := (res.leftBound + res.rightBound) / 2
    res.left = node(data, left, med)
    res.right = node(data, med + 1, right)

    return res
}

func segmentsTree(data []int64) *Node {
    return node(data, 0, len(data) - 1)
}

func (this *Node) add(left int, right int, value int64) {
    if left > right {
        return
    }

    if left == this.leftBound && right == this.rightBound {
        this.value += value
        return
    }

    med := (this.leftBound + this.rightBound) / 2
    if left <= med {
        this.left.add(left, min(right, med), value)
    }
    if right > med {
        this.right.add(max(left, med + 1), right, value)
    }
}

func (this *Node) get(i int) int64 {
    if this.leftBound == this.rightBound {
        return this.value
    }
    med := (this.leftBound + this.rightBound) / 2
    if i <= med {
        return this.left.get(i) + this.value
    } else {
        return this.right.get(i) + this.value
    }
}

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

    var n, m, k int
    fmt.Fscan(in, &n, &m, &k)

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

    ops := make([]Op, m)
    for i := 0; i < m; i++ {
        fmt.Fscan(in, &ops[i].l, &ops[i].r, &ops[i].d)
    }

    applies := segmentsTree(make([]int64, m))
    for i := 0; i < k; i++ {
        var x, y int
        fmt.Fscan(in, &x, &y)
        applies.add(x - 1, y - 1, 1)
    }

    res := segmentsTree(a[:])
    for i, op := range ops {
        res.add(op.l - 1, op.r - 1, op.d * applies.get(i))
    }

    for i := 0; i < n; i++ {
        fmt.Fprintf(out, "%d ", res.get(i))
    }
    fmt.Fprintf(out, "\n")
    out.Flush()
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

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

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

func solve(n int) {
	var m, k int
	I(&m, " ")
	I(&k, "\n")
	in := make([]int, n)
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		I(&in[i], o)
	}
	op := make([][4]int, m)
	for i := 0; i < m; i++ {
		I(&op[i][0], " ")
		I(&op[i][1], " ")
		I(&op[i][2], "\n")
	}
	for i := 0; i < k; i++ {
		var x, y int
		I(&x, " ")
		I(&y, "\n")
		for j := x; j <= y; j++ {
			op[j-1][3]++
		}
	}
	for i := 0; i < m; i++ {
		o := op[i][2] * op[i][3]
		for j := op[i][0]; j <= op[i][1]; j++ {
			in[j-1] += o
		}
	}
	for i := 0; i < n; i++ {
		o := " "
		if i == n-1 {
			o = "\n"
		}
		O(in[i], o)
	}
}


package main

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

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

	var T, n, l, r, s int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &l, &r, &s)
		l--
		k := r - l
		mi := (1 + k) * k / 2
		mx := (2*n - k + 1) * k / 2
		if s < mi || s > mx {
			Fprintln(out, -1)
			continue
		}

		a := make([]int, n)
		for i := l; i < r; i++ {
			a[i] = i - l + 1
		}
		cur := mi
		for i := r - 1; i >= l && cur < s; i-- {
			d := r - 1 - i
			mx := n - d
			if cur+mx-a[i] >= s {
				a[i] += s - cur
				break
			}
			cur += mx - a[i]
			a[i] = mx
		}

		vis := make([]bool, n+1)
		for i := l; i < r; i++ {
			vis[a[i]] = true
		}
		cur = 1
		for i, v := range a {
			if v == 0 {
				for ; vis[cur]; cur++ {
				}
				a[i] = cur
				cur++
			}
		}
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

import "fmt"

func solve() {
	var n, l, r, s int
	fmt.Scan(&n)
	fmt.Scan(&l)
	fmt.Scan(&r)
	fmt.Scan(&s)

	d := r - l + 1
	minV := (1 + d) * d / 2
	maxV := (n + (n - d + 1)) * d / 2
	if s < minV || maxV < s {
		fmt.Println(-1)
		return
	}
	chunkSize := n - d
	if chunkSize == 0 {
		for i := 1; i <= n; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		return
	}

	right := (s - minV) / chunkSize
	step := (s - minV) % chunkSize
	left := d - right - 1
	x := left + 1 + step

	selected := make([]bool, n+1)
	for i := 1; i <= left; i++ {
		selected[i] = true
	}
	selected[x] = true
	for i := 0; i < right; i++ {
		selected[n-i] = true
	}

	include, exclude := make([]int, 0), make([]int, 0)
	for i := 1; i <= n; i++ {
		if selected[i] {
			include = append(include, i)
		} else {
			exclude = append(exclude, i)
		}
	}

	for i := 1; i <= n; i++ {
		if i < l || r < i {
			fmt.Printf("%d ", exclude[len(exclude)-1])
			exclude = exclude[:len(exclude)-1]
		} else {
			fmt.Printf("%d ", include[len(include)-1])
			include = include[:len(include)-1]
		}
	}
	fmt.Println()
}

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

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"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, s int
		Fscan(in, &n, &l, &r, &s)
		l--
		k := r - l
		mi := (1 + k) * k / 2
		mx := (2*n - k + 1) * k / 2
		if s < mi || s > mx {
			Fprintln(out, -1)
			return
		}

		a := make([]int, n)
		for i := l; i < r; i++ {
			a[i] = i - l + 1
		}
		cur := mi
		for i := r - 1; i >= l && cur < s; i-- {
			d := r - 1 - i
			mx := n - d
			if cur+mx-a[i] >= s {
				a[i] += s - cur
				break
			}
			cur += mx - a[i]
			a[i] = mx
		}

		vis := make([]bool, n+1)
		for i := l; i < r; i++ {
			vis[a[i]] = true
		}
		cur = 1
		for i, v := range a {
			if v == 0 {
				for ; vis[cur]; cur++ {
				}
				a[i] = cur
				cur++
			}
		}
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

	var T int
	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"
	"bufio"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n,l,r,s int
		fmt.Fscan(in, &n,&l,&r,&s)
		sol := []int{-1}
		for i := 0; i<=n; i++ {
			for j := 0; j<= n-i; j++ {
				prefix := i*(i+1)/2
				suffix := n*(n+1)/2 - (n-j)*(n-j+1)/2
				rem := s - prefix - suffix
				count := i + j
				if rem != 0 {
					count++
				}
				if count != r-l+1 {
					continue
				}
				if rem == 0 || rem > i && rem <= n-j {
					sol = []int{}
					l--
					for k := 1; l>0 && k <= n; k++ {
						if k == rem || k<=i || k>n-j {
							continue
						}
						sol = append(sol, k)
						l--
					}
					if rem != 0 {
						sol = append(sol, rem)
					}
					for k := 1; k<=i; k++ {
						sol = append(sol, k)
					}
					for k := n-j+1; k<=n; k++ {
						sol = append(sol, k)
					}
					r = n-r
					for k := n; r>0 && k > 0; k-- {
						if k == rem || k<=i || k>n-j {
							continue
						}
						sol = append(sol, k)
						r--
					}
					i = n
					break
				}
			}
		}
		for _, x := range sol {
			fmt.Printf("%d ", x)
		}
		fmt.Println("")
	}
}

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	rb     = bufio.NewReader(os.Stdin)
	wb     = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n, l, r, s int
)

func solve() bool {
	c := r - l + 1
	lo := c * (c + 1) / 2
	hi := (n-c)*c + lo

	// fmt.Printf("n %d c %d lo %d hi %d\n", n, c, lo, hi)

	if s < lo || s > hi {
		return false
	}

	ans := []int{}
	step := 0
	oldS := s
	for i := c; i > 0; i-- {
		res := i * (i - 1) / 2 // save for next round
		can := s - res

		sub := min(can, n-step)
		step++
		ans = append(ans, sub)
		s -= sub
	}

	sum := 0
	for i := 0; i < len(ans); i++ {
		sum += ans[i]
	}
	check(sum == oldS)

	used := make(map[int]struct{})
	for _, x := range ans {
		used[x] = exists
	}

	for i := 1; i <= n; i++ {
		if _, ok := used[i]; !ok {
			ans = append(ans, i)
		}
	}

	rv := make([]int, n)
	for i := 0; i < n; i++ {
		rv[(i+l-1)%n] = ans[i]
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(wb, "%d ", rv[i])
	}
	fmt.Fprintln(wb)

	return true
}

func main() {
	defer wb.Flush()

	var tc int
	fmt.Fscan(rb, &tc)
	for ; tc > 0; tc-- {
		fmt.Fscan(rb, &n, &l, &r, &s)

		if !solve() {
			fmt.Fprintf(wb, "%d\n", INIT)
		}

	}
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

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

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

	for o := 0; o < t; o++ {
		var n, l, r, s int
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &l)
		fmt.Fscan(input, &r)
		fmt.Fscan(input, &s)
		length := r - l + 1
		var min, max int
		for i := 1; i <= length; i++ {
			min = min + i
		}
		for i := n; i >= n-length+1; i-- {
			max = max + i
		}

		if s < min || s > max {
			fmt.Println(-1)
		} else {
			remain := (s - min) % length
			quantity := int((s - min - remain) / length)
			first := make([]int, 0)
			between := make([]int, 0)
			for i := 1; i < n+1; i++ {
				if remain != 0 {
					if i > quantity && i < quantity+length-remain+1 {
						between = append(between, i)
					} else {
						if i > quantity+length-remain+1 && i <= quantity+length+1 {
							between = append(between, i)
						} else {
							first = append(first, i)
						}
					}

				} else {
					if i > quantity && i < quantity+length+1 {
						between = append(between, i)
					} else {
						first = append(first, i)
					}
				}
			}

			for i := 0; i < l-1; i++ {
				fmt.Println(first[i])
			}
			for j := 0; j < length; j++ {
				fmt.Println(between[j])
			}
			p := n - length
			for k := l - 1; k < p; k++ {
				fmt.Println(first[k])
			}

		}

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n,l,r,s int
		fmt.Fscan(in, &n,&l,&r,&s)
		sol := []int{-1}
		for i := 0; i<=n; i++ {
			for j := 0; j<= n-i; j++ {
				prefix := i*(i+1)/2
				suffix := n*(n+1)/2 - (n-j)*(n-j+1)/2
				rem := s - prefix - suffix
				count := i + j
				if rem != 0 {
					count++
				}
				if count != r-l+1 {
					continue
				}
				if rem == 0 || rem > i && rem <= n-j {
					sol = []int{}
					l--
					for k := 1; l>0 && k <= n; k++ {
						if k == rem || k<=i || k>n-j {
							continue
						}
						sol = append(sol, k)
						l--
					}
					if rem != 0 {
						sol = append(sol, rem)
					}
					for k := 1; k<=i; k++ {
						sol = append(sol, k)
					}
					for k := n-j+1; k<=n; k++ {
						sol = append(sol, k)
					}
					r = n-r
					for k := n; r>0 && k > 0; k-- {
						if k == rem || k<=i || k>n-j {
							continue
						}
						sol = append(sol, k)
						r--
					}
					break
				}
			}
		}
		for _, x := range sol {
			fmt.Printf("%d ", x)
		}
		fmt.Println("")
	}
}


package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"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()
	type data struct {
		pre, suf string
		haha     int64
	}

	solve := func(Case int) {
		var n int
		var name, op, v, w string
		Fscan(in, &n)
		ans := int64(0)

		mp := map[string]data{}
		for ; n > 0; n-- {
			Fscan(in, &name, &op)
			if op[0] == ':' {
				Fscan(in, &v)
				haha := int64(0)
				if strings.Contains(v, "haha") {
					haha = 1
				}
				mp[name] = data{v, v, haha}
				if n == 1 {
					ans = haha
				}
			} else {
				Fscan(in, &v, &op, &w)
				x, y := mp[v], mp[w]
				s, t := x.suf, y.pre
				newD := data{x.pre, y.suf, x.haha + y.haha}
				if len(newD.pre) < 3 || len(y.suf) < 3 {
					merge := x.pre + y.suf
					newD.pre =  merge
					newD.suf = merge
				}
				if strings.HasSuffix(s, "hah") && strings.HasPrefix(t, "a") {
					newD.haha++
				}
				if strings.HasSuffix(s, "ha") && strings.HasPrefix(t, "ha") {
					newD.haha++
				}
				if strings.HasSuffix(s, "h") && strings.HasPrefix(t, "aha") {
					newD.haha++
				}

				//for i := 0; i < len(x.suf); i++ {
				//	if i+4 >= len(x.suf) && strings.HasPrefix(s[i:], "haha") {
				//		if y.pre[0] == 'h' {
				//			newD.haha++
				//		} else {
				//			newD.haha += 2
				//		}
				//		break
				//	}
				//}
				mp[name] = newD
				if n == 1 {
					ans = newD.haha
				}
			}
		}

		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("bufio";."fmt";."os";."strings")

// github.com/EndlessCheng/codeforces-go
type ha struct{p,s string;c int64}
func main(){
	in:=bufio.NewReader(Stdin)
	H,T,n,s,v,w:="haha",0,0,"","",""
	for Fscan(in,&T);T>0;T--{
		Fscan(in,&n)
		m:=map[string]ha{}
		for;n>0;n--{
			if Fscan(in,&s,&w,&v);w!="="{
				c:=0;if Contains(v,H){c++}
				m[s]=ha{v,v,int64(c)}
			}else{
				Fscan(in,&w,&w)
				x,y:=m[v],m[w]
				h:=ha{x.p,y.s,x.c+y.c}
				if len(x.p)<3||len(y.s)<3{t:=x.p+y.s;h.p=t;h.s=t}
				for i:=1;i<4;i++{if HasSuffix(x.s,H[:i])&&HasPrefix(y.p,H[i:]){h.c++}}
				m[s]=h
			}
		}
		Println(m[s].c)
	}
}

package main

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

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

func main() {
	defer writer.Flush()

	calc := func(s string) int {
		var ret int = 0
		for i := 0; i+3 < len(s); i++ {
			if s[i:i+4] == "haha" {
				ret += 1
			}
		}
		return ret
	}

	var T int
	fmt.Fscan(reader, &T)
	for ; T > 0; T-- {
		var n int
		fmt.Fscan(reader, &n)

		variablesPool := make(map[string]uint64)
		prefix := make(map[string]string)
		suffix := make(map[string]string)

		var ans uint64

		for ; n > 0; n-- {
			var name, op string
			fmt.Fscan(reader, &name, &op)
			if op == ":=" {
				var val string
				fmt.Fscan(reader, &val)
				variablesPool[name] = uint64(calc(val))
				if len(val) >= 3 {
					prefix[name] = val[:3]
					suffix[name] = val[len(val)-3:]
				} else {
					prefix[name] = val
					suffix[name] = val
				}
			} else {
				var lhs, rhs string
				fmt.Fscan(reader, &lhs, &op, &rhs)

				concat := suffix[lhs] + prefix[rhs]
				variablesPool[name] = variablesPool[lhs] + variablesPool[rhs]
				variablesPool[name] += uint64(calc(concat))

				prefix[name] = prefix[lhs]
				if len(prefix[lhs]) < 3 {
					if len(concat) >= 3 {
						prefix[name] = concat[0:3]
					}
				}

				suffix[name] = suffix[rhs]
				if len(suffix[rhs]) < 3 {
					if len(concat) >= 3 {
						suffix[name] = concat[len(concat)-3:]
					}
				}
			}
			ans = variablesPool[name]
		}

		fmt.Fprintf(writer, "%v\n", ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	type data struct {
		pref, suf string
		haha      int64
	}
	solve := func(Case int) {
		var n int
		var name, op, v string
		ans := int64(0)
		fmt.Fscan(in, &n)
		dict := map[string]data{}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &name, &op, &v)
			if op != "=" {
				haha := int64(0)
				if strings.Contains(v, "haha") {
					haha = 1
				}
				dict[name] = data{v, v, haha}
				if i == n-1 {
					ans = haha
				}
			} else {
				var w string
				fmt.Fscan(in, &op, &w)
				left, right := dict[v], dict[w]
				p, q := left.suf, right.pref

				newElement := data{left.pref, right.suf, left.haha + right.haha}
				if len(newElement.pref) < 3 || len(newElement.suf) < 3 {
					join := left.pref + right.suf
					newElement.pref, newElement.suf = join, join
				}
				pref, suf := []string{"a", "ha", "aha"}, []string{"hah", "ha", "h"}
				for j := range pref {
					if strings.HasSuffix(p, suf[j]) && strings.HasPrefix(q, pref[j]) {
						newElement.haha++
					}
				}

				if i == n-1 {
					ans = newElement.haha
				}
				dict[name] = newElement
			}
		}
		fmt.Fprintln(out, ans)
	}

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

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

func min(a []int) int {
	mn := int(1e9)
	for i := range a {
		if a[i] < mn {
			mn = a[i]
		}
	}
	return mn
}
func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func reverse(s []byte) []byte {
	a := []byte(s)
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return a
}

package main

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

type elem struct {
	prefix, suffix string
	cnt            int64
}

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

	var t int
	for fmt.Fscan(reader, &t); t > 0; t-- {
		var n int
		var a, b, c, op string
		dict := map[string]elem{}

		for fmt.Fscan(reader, &n); n > 0; n-- {
			fmt.Fscan(reader, &a, &op, &b)
			if op == ":=" {
				cnt := 0
				if strings.Contains(b, target) {
					cnt++
				}
				dict[a] = elem{b, b, int64(cnt)}
			} else {
				fmt.Fscan(reader, &op, &c)
				x, y := dict[b], dict[c]
				e := elem{x.prefix, y.suffix, x.cnt + y.cnt}
				if len(x.prefix) < 3 || len(y.suffix) < 3 {
					t := x.prefix + y.suffix
					e.prefix, e.suffix = t, t
				}
				for i := 1; i < 4; i++ {
					if strings.HasSuffix(x.suffix, target[:i]) && strings.HasPrefix(y.prefix, target[i:]) {
						e.cnt++
					}
				}
				dict[a] = e
			}
		}

		fmt.Println(dict[a].cnt)
	}
}

package main

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

var target = "haha"
var reader = bufio.NewReader(os.Stdin)

type elem struct {
	p, s string
	c    int64
}

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		fmt.Println(funnySubstrings())
	}
}

func funnySubstrings() int64 {
	var n int
	fmt.Fscan(reader, &n)

	var a, b, c, op string
	dict := map[string]elem{}
	for ; n > 0; n-- {
		fmt.Fscan(reader, &a, &op, &b)
		if op == ":=" {
			c := 0
			if strings.Contains(b, target) {
				c++
			}
			dict[a] = elem{b, b, int64(c)}
		} else {
			fmt.Fscan(reader, &op, &c)
			x, y := dict[b], dict[c]
			nha := elem{x.p, y.s, x.c + y.c}
			if len(x.p) < 3 || len(y.s) < 3 {
				t := x.p + y.s
				nha.p = t
				nha.s = t
			}
			for i := 1; i < 4; i++ {
				if strings.HasSuffix(x.s, target[:i]) && strings.HasPrefix(y.p, target[i:]) {
					nha.c++
				}
			}
			dict[a] = nha
		}
	}

	return dict[a].c
}

package main

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

const HAHA = "haha"
const LOCAL = false

func main() {
	rand.Seed(time.Now().UnixNano())

	if !LOCAL {
		r := bufio.NewScanner(os.Stdin)

		var t int

		//fmt.Fscan(r, &t)
		r.Scan()
		t, _ = strconv.Atoi(r.Text())

		for i := 0; i < t; i++ {
			var n int
			//fmt.Fscan(r, &n)
			r.Scan()
			n, _ = strconv.Atoi(r.Text())

			st := make([]string, n)

			for k := 0; k < n; k++ {
				r.Scan()
				l := r.Text()
				st[k] = l
			}

			//a := solve(st, n)
			//b := solve_2(st, n)

			/*if a != b {
				fmt.Println("ERROR")
				fmt.Println(a)
				fmt.Println(b)

				fmt.Println(st)
			}*/

			fmt.Println(solve(st, n))
		}

	}
}

func solve_2(st []string, n int) int64 {
	mp := make(map[string]string)

	var last string

	for i := 0; i < n ; i++ {
		s := st[i]

		if strings.Contains(s, ":=") {
			parts := strings.Split(s, ":=")
			parts[0] = strings.TrimSpace(parts[0])
			parts[1] = strings.TrimSpace(parts[1])

			mp[parts[0]] = parts[1]

		} else {
			parts := strings.Split(s, "=")
			name := strings.TrimSpace(parts[0])

			if i == n - 1 {
				last = name
			}

			exp := strings.TrimSpace(parts[1])

			expParts := strings.Split(exp, "+")
			a := strings.TrimSpace(expParts[0])
			b := strings.TrimSpace(expParts[1])

			mp[name] = mp[a] + mp[b]
		}
	}

	str := mp[last]

	return int64(strings.Count(str, HAHA))
}

func solve(st []string, n int) int64 {

	mp := make(map[string]string)
	mpLen := make(map[string]int64)

	var finalName string

	for i := 0; i < n; i++ {
		s := st[i]

		if strings.Contains(s, ":=") {
			parts := strings.Split(s, ":=")
			parts[0] = strings.TrimSpace(parts[0])
			parts[1] = strings.TrimSpace(parts[1])

			if i == n - 1 {
				finalName = parts[0]
			}

			var c int
			for j := 0; j <= len(parts[1]) - 4; j++ {
				chunk := parts[1][j : j + 4]

				if chunk == HAHA {
					c++
				}
			}

			mp[parts[0]] = parts[1]

			mpLen[parts[0]] = int64(c)

		} else {
			parts := strings.Split(s, "=")
			name := strings.TrimSpace(parts[0])
			if i == n - 1 {
				finalName = name
			}
			exp := strings.TrimSpace(parts[1])

			expParts := strings.Split(exp, "+")
			a := strings.TrimSpace(expParts[0])
			b := strings.TrimSpace(expParts[1])

			aString := mp[a]
			aCount := mpLen[a]
			bString := mp[b]
			bCount := mpLen[b]

			var aLast3 string
			if len(aString) < 3 {
				aLast3 = aString
			} else {
				aLast3 = aString[len(aString) - 3 : ]
			}

			var bFirst3 string
			if len(bString) < 3 {
				bFirst3 = bString
			} else {
				bFirst3 = bString[ : 3]
			}

			str := aLast3 + bFirst3

			var c int
			for j := 0; j <= len(str) - 4; j++ {
				chunk := str[j : j + 4]

				if chunk == HAHA {
					c++
				}
			}

			mpLen[name] = int64(c) + int64(aCount) + int64(bCount)

			toSave := aString + bString

			if len(toSave) < 6 {
				mp[name] = toSave
			} else {

				first3 := toSave[0 : 3]
				last3 := toSave[len(toSave) - 3:]

				mp[name] = first3 + last3

			}
		}
	}

	return mpLen[finalName]
}

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

// github.com/EndlessCheng/codeforces-go
type ha struct{p,s string;c int64}
func main(){
	in:=bufio.NewReader(Stdin)
	H,T,n,s,v,w:="haha",0,0,"","",""
	for Fscan(in,&T);T>0;T--{
		Fscan(in,&n)
		m:=map[string]ha{}
		for;n>0;n--{
			if Fscan(in,&s,&w,&v);w!="="{
				c:=0;if Contains(v,H){c++}
				m[s]=ha{v,v,int64(c)}
			}else{
				Fscan(in,&w,&w)
				x,y:=m[v],m[w]
				h:=ha{x.p,y.s,x.c+y.c}
				if len(h.p)<3{h.p+=y.p}
				if len(h.s)<3{h.s=x.s+h.s}
				for i:=1;i<4;i++{if HasSuffix(x.s,H[:i])&&HasPrefix(y.p,H[i:]){h.c++}}
				m[s]=h
			}
		}
		Println(m[s].c)
	}
}

package main

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

const HAHA = "haha"
const LOCAL = false

func main() {
	rand.Seed(time.Now().UnixNano())

	if !LOCAL {
		r := bufio.NewScanner(os.Stdin)

		var t int

		//fmt.Fscan(r, &t)
		r.Scan()
		t, _ = strconv.Atoi(r.Text())

		for i := 0; i < t; i++ {
			var n int
			//fmt.Fscan(r, &n)
			r.Scan()
			n, _ = strconv.Atoi(r.Text())

			st := make([]string, n)

			for k := 0; k < n; k++ {
				r.Scan()
				l := r.Text()
				st[k] = l
			}

			//a := solve(st, n)
			//b := solve_2(st, n)

			/*if a != b {
				fmt.Println("ERROR")
				fmt.Println(a)
				fmt.Println(b)

				fmt.Println(st)
			}*/

			fmt.Println(solve(st, n))
		}

	}
}

func solve_2(st []string, n int) int64 {
	mp := make(map[string]string)

	var last string

	for i := 0; i < n ; i++ {
		s := st[i]

		if strings.Contains(s, ":=") {
			parts := strings.Split(s, ":=")
			parts[0] = strings.TrimSpace(parts[0])
			parts[1] = strings.TrimSpace(parts[1])

			mp[parts[0]] = parts[1]

		} else {
			parts := strings.Split(s, "=")
			name := strings.TrimSpace(parts[0])

			if i == n - 1 {
				last = name
			}

			exp := strings.TrimSpace(parts[1])

			expParts := strings.Split(exp, "+")
			a := strings.TrimSpace(expParts[0])
			b := strings.TrimSpace(expParts[1])

			mp[name] = mp[a] + mp[b]
		}
	}

	str := mp[last]

	return int64(strings.Count(str, HAHA))
}

func solve(st []string, n int) int64 {

	mp := make(map[string]string)
	mpLen := make(map[string]int64)

	var finalName string

	for i := 0; i < n; i++ {
		s := st[i]

		if strings.Contains(s, ":=") {
			parts := strings.Split(s, ":=")
			parts[0] = strings.TrimSpace(parts[0])
			parts[1] = strings.TrimSpace(parts[1])

			var c int
			for j := 0; j <= len(parts[1]) - 4; j++ {
				chunk := parts[1][j : j + 4]

				if chunk == HAHA {
					c++
				}
			}

			mp[parts[0]] = parts[1]

			mpLen[parts[0]] = int64(c)

		} else {
			parts := strings.Split(s, "=")
			name := strings.TrimSpace(parts[0])
			if i == n - 1 {
				finalName = name
			}
			exp := strings.TrimSpace(parts[1])

			expParts := strings.Split(exp, "+")
			a := strings.TrimSpace(expParts[0])
			b := strings.TrimSpace(expParts[1])

			aString := mp[a]
			aCount := mpLen[a]
			bString := mp[b]
			bCount := mpLen[b]

			var aLast3 string
			if len(aString) < 3 {
				aLast3 = aString
			} else {
				aLast3 = aString[len(aString) - 3 : ]
			}

			var bFirst3 string
			if len(bString) < 3 {
				bFirst3 = bString
			} else {
				bFirst3 = bString[ : 3]
			}

			str := aLast3 + bFirst3

			var c int
			for j := 0; j <= len(str) - 4; j++ {
				chunk := str[j : j + 4]

				if chunk == HAHA {
					c++
				}
			}

			mpLen[name] = int64(c) + int64(aCount) + int64(bCount)

			toSave := aString + bString

			if len(toSave) < 6 {
				mp[name] = toSave
			} else {

				first3 := toSave[0 : 3]
				last3 := toSave[len(toSave) - 3:]

				mp[name] = first3 + last3

			}
		}
	}

	return mpLen[finalName]
}

package main

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

const HAHA = "haha"

func main() {

	r := bufio.NewScanner(os.Stdin)

	var t int

	//fmt.Fscan(r, &t)
	r.Scan()
	t, _ = strconv.Atoi(r.Text())

	for i := 0; i < t; i++ {
		var n int
		//fmt.Fscan(r, &n)
		r.Scan()
		n, _ = strconv.Atoi(r.Text())

		st := make([]string, n)

		for k := 0; k < n; k++ {
			r.Scan()
			l := r.Text()
			st[k] = l
		}

		fmt.Println(solve(st, n))
	}
}

func solve(st []string, n int) int64 {

	mp := make(map[string]string)
	mpLen := make(map[string]int64)

	var finalName string

	for i := 0; i < n; i++ {
		s := st[i]

		if strings.Contains(s, ":=") {
			parts := strings.Split(s, ":=")
			parts[0] = strings.TrimSpace(parts[0])
			parts[1] = strings.TrimSpace(parts[1])

			c := strings.Count(parts[1], HAHA)
			mp[parts[0]] = parts[1]

			mpLen[parts[0]] = int64(c)

		} else {
			parts := strings.Split(s, "=")
			name := strings.TrimSpace(parts[0])
			if i == n - 1 {
				finalName = name
			}
			exp := strings.TrimSpace(parts[1])

			expParts := strings.Split(exp, "+")
			a := strings.TrimSpace(expParts[0])
			b := strings.TrimSpace(expParts[1])

			aString := mp[a]
			aCount := mpLen[a]
			bString := mp[b]
			bCount := mpLen[b]

			var aLast3 string
			if len(aString) < 3 {
				aLast3 = aString
			} else {
				aLast3 = aString[len(aString) - 3 : ]
			}

			var bFirst3 string
			if len(bString) < 3 {
				bFirst3 = bString
			} else {
				bFirst3 = bString[ : 3]
			}

			str := aLast3 + bFirst3

			c := strings.Count(str, HAHA)

			mpLen[name] = int64(c) + int64(aCount) + int64(bCount)

			var aFirst4 string
			if len(aString) < 3 {
				aFirst4 = aString
			} else {
				aFirst4 = aString[ : 3]
			}

			var bLast4 string
			if len(bString) < 3 {
				bLast4 = bString
			} else {
				bLast4 = bString[len(bString) - 3 : ]
			}

			mp[name] = aFirst4 + bLast4
		}
	}

	return mpLen[finalName]
}

package main

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

const HAHA = "haha"

func main() {

	r := bufio.NewScanner(os.Stdin)

	var t int

	//fmt.Fscan(r, &t)
	r.Scan()
	t, _ = strconv.Atoi(r.Text())

	for i := 0; i < t; i++ {
		var n int
		//fmt.Fscan(r, &n)
		r.Scan()
		n, _ = strconv.Atoi(r.Text())

		st := make([]string, n)

		for k := 0; k < n; k++ {
			r.Scan()
			l := r.Text()
			st[k] = l
		}

		fmt.Println(solve(st, n))
	}
}

func solve(st []string, n int) int64 {

	mp := make(map[string]string)
	mpLen := make(map[string]int64)

	var finalName string

	for i := 0; i < n; i++ {
		s := st[i]

		if strings.Contains(s, ":=") {
			parts := strings.Split(s, ":=")
			parts[0] = strings.TrimSpace(parts[0])
			parts[1] = strings.TrimSpace(parts[1])

			c := strings.Count(parts[1], HAHA)
			mp[parts[0]] = parts[1]

			mpLen[parts[0]] = int64(c)

		} else {
			parts := strings.Split(s, "=")
			name := strings.TrimSpace(parts[0])
			if i == n - 1 {
				finalName = name
			}
			exp := strings.TrimSpace(parts[1])

			expParts := strings.Split(exp, "+")
			a := strings.TrimSpace(expParts[0])
			b := strings.TrimSpace(expParts[1])

			aString := mp[a]
			aCount := mpLen[a]
			bString := mp[b]
			bCount := mpLen[b]

			var aLast3 string
			if len(aString) < 3 {
				aLast3 = aString
			} else {
				aLast3 = aString[len(aString) - 3 : ]
			}

			var bFirst3 string
			if len(bString) < 3 {
				bFirst3 = bString
			} else {
				bFirst3 = bString[ : 3]
			}

			str := aLast3 + bFirst3

			c := strings.Count(str, HAHA)

			mpLen[name] = int64(c) + int64(aCount) + int64(bCount)

			var aFirst4 string
			if len(aString) < 4 {
				aFirst4 = aString
			} else {
				aFirst4 = aString[ : 4]
			}

			var bLast4 string
			if len(bString) < 4 {
				bLast4 = bString
			} else {
				bLast4 = bString[len(bString) - 4 : ]
			}

			mp[name] = aFirst4 + bLast4
		}
	}

	return mpLen[finalName]
}

package main

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

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

func main() {
	defer writer.Flush()

	calc := func(s string) int {
		var ret int = 0
		for i := 0; i+3 < len(s); i++ {
			if s[i:i+4] == "haha" {
				ret += 1
			}
		}
		return ret
	}

	var T int
	fmt.Fscan(reader, &T)
	for ; T > 0; T-- {
		var n int
		fmt.Fscan(reader, &n)

		variablesPool := make(map[string]uint64)
		prefix := make(map[string]string)
		suffix := make(map[string]string)

		var ans uint64

		for ; n > 0; n-- {
			var name, op string
			fmt.Fscan(reader, &name, &op)
			if op == ":=" {
				var val string
				fmt.Fscan(reader, &val)
				variablesPool[name] = uint64(calc(val))
				if len(val) >= 3 {
					prefix[name] = val[:3]
					suffix[name] = val[len(val)-3 : len(val)]
				} else {
					prefix[name] = val
					suffix[name] = val
				}
			} else {
				var lhs, rhs string
				fmt.Fscan(reader, &lhs, &op, &rhs)
				variablesPool[name] = variablesPool[lhs] + variablesPool[rhs]
				variablesPool[name] += uint64(calc(suffix[lhs] + prefix[rhs]))
				prefix[name] = prefix[lhs]
				suffix[name] = suffix[rhs]
			}
			ans = variablesPool[name]
		}

		fmt.Fprintf(writer, "%v\n", ans)
	}
}


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 scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func main() {

	var n, m int64
	scan(&n, &m)
	var sum1 int64 = (n - 1) * n / 2
	var sum2 int64
	if n&1 == 1 {
		h := n / 2
		sum2 = (1 + h) * h
	} else {
		h := (n - 1) / 2
		sum2 = (1+h)*h + h + 1
	}
	var ret int64
	for i := 0; i < int(m); i++ {
		var x, d int64
		scan(&x, &d)
		ret += x * n
		if d >= 0 {
			ret += sum1 * d
		} else {
			ret += sum2 * d
		}
	}
	fmt.Printf("%.9f", float64(ret)/float64(n))
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, m, s, x, d int64
	for Fscan(in, &n, &m); m > 0; m-- {
		Fscan(in, &x, &d)
		s += x * n
		if d > 0 {
			s += d * n * (n - 1) / 2
		} else {
			s += d * (n / 2) * (n/2 + n&1)
		}
	}
	Printf("%.7f", float64(s)/float64(n))
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, m, s, x, d int64
	Fscan(in, &n, &m)
	for ; m > 0; m-- {
		Fscan(in, &x, &d)
		s += x * n
		if d > 0 {
			s += d * n * (n - 1) / 2
		} else {
			s += d * n / 2 * (n/2 + n&1)
		}
	}
	Printf("%.7f", float64(s)/float64(n))
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1341D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	ds := [10]string{"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"}

	var n, k int
	var s []byte
	Fscan(in, &n, &k)
	a := make([][10]int, n)
	for i := range a {
		Fscan(in, &s)
		for j, d := range ds {
			for k, b := range s {
				if b > d[k] {
					a[i][j] = 1e9
					break
				}
				a[i][j] += int(d[k] - b)
			}
		}
	}

	dp := make([][]int8, n)
	for i := range dp {
		dp[i] = make([]int8, k+1)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}
	ans := make([]byte, n)
	var f func(int, int) int8
	f = func(p, left int) (res int8) {
		if p >= n {
			if left > 0 {
				return
			}
			return 1
		}
		v := &dp[p][left]
		if *v >= 0 {
			return *v
		}
		defer func() { *v = res }()
		for i := 9; i >= 0; i-- {
			if a[p][i] <= left {
				ans[p] = byte('0' + i)
				if f(p+1, left-a[p][i]) == 1 {
					return 1
				}
			}
		}
		return
	}
	if f(0, k) == 0 {
		Fprint(_w, -1)
	} else {
		Fprint(_w, string(ans))
	}
}

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

var digits = []string{"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"}

func main() {
	defer writer.Flush()
	n, k := reader.NextInt64(), reader.NextInt64()
	ss := make([]string, n)
	for i := int64(0); i < n; i++ {
		ss[i] = reader.NextString()
	}
	writer.Printf("%s\n", sol(k, ss))
}

func sol(k int64, ss []string) string {
	dist := make([][10]int64, len(ss))
	for i := range ss {
		for di, d := range digits {
			for j := range d {
				if ss[i][j] == '1' && d[j] == '0' {
					// not possible
					dist[i][di] = -1
					break
				}
				if ss[i][j] == '0' && d[j] == '1' {
					dist[i][di]++
				}
			}
		}
	}

	dp := make([][]bool, len(ss)+1)
	for i := range dp {
		dp[i] = make([]bool, k+1)
	}
	dp[len(ss)][0] = true
	for i := int64(len(ss)); i > 0; i-- {
		for j := int64(0); j <= k; j++ {
			if dp[i][j] {
				for d := range digits {
					nextDist := dist[i-1][d]
					if nextDist == -1 {
						continue
					}
					if j+nextDist <= k {
						dp[i-1][j+nextDist] = true
					}
				}
			}
		}
	}

	if !dp[0][k] {
		return "-1"
	}

	res := ""
	for i := 0; i < len(dp)-1; i++ {
		for d := int64(9); d >= 0; d-- {
			if dist[i][d] != -1 && k >= dist[i][d] && dp[i+1][k-dist[i][d]] {
				res += string(d + '0')
				k -= dist[i][d]
				break
			}
		}
	}
	if res == "" {
		return "-1"
	}
	return res
}

package main

import (
	"fmt"
	"sort"
)

type data struct {
	id int
	w  int
}
type datas []data

func (arr datas) Len() int {
	return len(arr)
}
func (arr datas) Less(i, j int) bool {
	return arr[i].id > arr[j].id
}

func (arr datas) Swap(i, j int) {
	arr[i], arr[j] = arr[j], arr[i]
}

var f [2002][2002]int
var a [2002]int
var s string
var nw = [11]int{119, 18, 93, 91, 58, 107, 111, 82, 127, 123}
var D [128]datas
var ans [2002]int

func init_() {
	var base [8]int
	for num := 0; num < 128; num++ {
		for i := 0; i < 7; i++ {
			if (num & (1 << i)) == 0 {
				base[i] = 0
			} else {
				base[i] = 1
			}
		}
		for k := 0; k <= 9; k++ {
			sum := 0
			for i := 0; i < 7; i++ {
				if (nw[k]&(1<<i)) == 0 && base[i] == 1 {
					sum = -1
					break
				}
				if (nw[k]&(1<<i)) > 0 && base[i] == 0 {
					sum++
				}
			}
			if sum >= 0 {
				D[num] = append(D[num], data{k, sum})
			}
		}
		if len(D[num]) > 0 {
			sort.Sort(D[num])
		}
	}

	for i := 0; i <= 2000; i++ {
		for j := 0; j <= 2000; j++ {
			f[i][j] = -1
		}
	}
}

func find(n int, i int, k int) bool {
	if i > n {
		return k == 0
	}
	if f[i][k] >= 0 {
		return f[i][k] == 1
	}
	for _, dt := range D[a[i]] {
		if k >= dt.w && find(n, i+1, k-dt.w) {
			ans[i] = dt.id
			f[i][k] = 1
			return true
		}
	}
	f[i][k] = 0
	return false
}

func main() {
	var n, k int
	init_()

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%s\n", &s)
		num := 0
		for j := 0; j < 7; j++ {
			if s[j] == '1' {
				num += 1
			}
			num <<= 1
		}
		num >>= 1
		a[i] = num
	}

	/*
		for i := 1; i <= n; i++ {
			fmt.Printf("%d\n", i)
			for _, dt := range D[a[i]] {
				fmt.Printf("%d %d\n", dt.id, dt.w)
			}
		}
		for i := 1; i <= n; i++ {
			for j := 0; j <= k; j++ {
				fmt.Printf("f[%d][%d]=%d\n", i, j, f[i][j])
			}
		}
	*/

	res := find(n, 1, k)
	if res {
		for i := 1; i <= n; i++ {
			fmt.Printf("%d", ans[i])
		}
		fmt.Printf("\n")
	} else {
		fmt.Printf("-1\n")
	}

}

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

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	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 (
	n, k int
	D    []string

	dpf     [2000 + 50][2000 + 50]bool
	samples [10]string
)

func main() {
	n, k = ReadInt2()
	for i := 0; i < n; i++ {
		str := ReadString()
		D = append(D, str)
	}
	D = ReverseStrs(D)

	samples = [10]string{
		"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011",
	}

	dpf[0][0] = true
	for i := 0; i < n; i++ {
		nums := [10]int{}
		for d := 0; d < 10; d++ {
			nums[d] = -1
		}

		str := D[i]
		for d := 0; d < 10; d++ {
			to := samples[d]
			ok, num := canMake(str, to)
			if ok {
				nums[d] = num
			}
		}
		// PrintfDebug("from: %s, nums: %v\n", str, nums)

		// jは遷移元
		for j := 0; j <= k; j++ {
			if !dpf[i][j] {
				continue
			}

			for d := 0; d < 10; d++ {
				if nums[d] < 0 {
					continue
				}

				num := nums[d]
				dpf[i+1][j+num] = true
			}
		}
	}

	if dpf[n][k] {
		answers := []rune{}
		nokori := k
		for i := n - 1; i >= 0; i-- {
			nums := [10]int{}
			for d := 0; d < 10; d++ {
				nums[d] = -1
			}

			str := D[i]
			for d := 0; d < 10; d++ {
				to := samples[d]
				ok, num := canMake(str, to)
				if ok {
					nums[d] = num
				}
			}

			maxi := 0
			for d := 0; d < 10; d++ {
				num := nums[d]
				if num >= 0 && nokori-num >= 0 {
					if dpf[i][nokori-num] {
						maxi = d
					}
				}
			}
			nokori -= nums[maxi]

			answers = append(answers, '0'+rune(maxi))
		}

		// fmt.Println(string(Reverse(answers)))
		fmt.Println(string(answers))
	} else {
		fmt.Println(-1)
	}
}

func Reverse(A []rune) []rune {
	res := []rune{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

func ReverseStrs(A []string) []string {
	res := []string{}

	n := len(A)
	for i := n - 1; i >= 0; i-- {
		res = append(res, A[i])
	}

	return res
}

// func main() {
// 	n, k = ReadInt2()
// 	for i := 0; i < n; i++ {
// 		str := ReadString()
// 		D = append(D, str)
// 	}
// 	samples = [10]string{
// 		"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011",
// 	}
// 	// for d := 0; d < 10; d++ {
// 	// 	_, num := canMake("1000000", samples[d])
// 	// 	PrintfDebug("digit %d: %d\n", d, num)
// 	// }

// 	dpf[0][0] = true
// 	for i := 0; i < n; i++ {
// 		nums := [10]int{}
// 		for d := 0; d < 10; d++ {
// 			nums[d] = -1
// 		}

// 		str := D[i]
// 		for d := 0; d < 10; d++ {
// 			to := samples[d]
// 			ok, num := canMake(str, to)
// 			if ok {
// 				nums[d] = num
// 			}
// 		}
// 		// PrintfDebug("from: %s, nums: %v\n", str, nums)

// 		// jは遷移元
// 		for j := 0; j <= k; j++ {
// 			if !dpf[i][j] {
// 				continue
// 			}

// 			for d := 0; d < 10; d++ {
// 				if nums[d] < 0 {
// 					continue
// 				}

// 				num := nums[d]
// 				dstr := strconv.Itoa(d)
// 				aft := dp[i][j] + dstr
// 				if len(dp[i][j]) == i && dp[i+1][j+num] < aft {
// 					dp[i+1][j+num] = aft
// 					dpf[i+1][j+num] = true
// 					// PrintfDebug("aft: %s, bef: %s\n", dp[i+1][j+num], dp[i][j])
// 				}
// 			}
// 		}
// 	}

// 	// for i := 0; i <= n; i++ {
// 	// 	for j := 0; j <= k; j++ {
// 	// 		PrintfDebug("dp[%d][%d]: %s\n", i, j, dp[i][j])
// 	// 	}
// 	// }

// 	if len(dp[n][k]) == n {
// 		fmt.Println(dp[n][k])
// 	} else {
// 		fmt.Println(-1)
// 	}
// }

func canMake(from, to string) (bool, int) {
	res := 0
	for i := 0; i < len(from); i++ {
		if from[i] == '1' && to[i] == '0' {
			return false, -1
		}
		if from[i] == '0' && to[i] == '1' {
			res++
		}
	}

	return true, res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
	"fmt"
	"sort"
)

type data struct {
	id int
	w  int
}
type datas []data

func (arr datas) Len() int {
	return len(arr)
}
func (arr datas) Less(i, j int) bool {
	return arr[i].id > arr[j].id
}

func (arr datas) Swap(i, j int) {
	arr[i], arr[j] = arr[j], arr[i]
}

var f [2002][2002]int
var a [2002]int
var s string
var nw = [11]int{119, 18, 93, 91, 58, 107, 111, 82, 127, 123}
var D [128]datas
var ans [2002]int

func init_() {
	var base [8]int
	for num := 0; num < 128; num++ {
		for i := 0; i < 7; i++ {
			if (num & (1 << i)) == 0 {
				base[i] = 0
			} else {
				base[i] = 1
			}
		}
		for k := 0; k <= 9; k++ {
			sum := 0
			for i := 0; i < 7; i++ {
				if (nw[k]&(1<<i)) == 0 && base[i] == 1 {
					sum = -1
					break
				}
				if (nw[k]&(1<<i)) > 0 && base[i] == 0 {
					sum++
				}
			}
			if sum >= 0 {
				D[num] = append(D[num], data{k, sum})
			}
		}
		if len(D[num]) > 0 {
			sort.Sort(D[num])
		}
	}

	for i := 1; i <= 2000; i++ {
		for j := 1; j <= 2000; j++ {
			f[i][j] = -1
		}
	}
	f[0][0] = -1
}

func find(n int, k int) bool {
	if n == 0 {
		return k == 0
	}
	if f[n][k] >= 0 {
		return f[n][k] == 1
	}
	for _, dt := range D[a[n]] {
		if k >= dt.w && find(n-1, k-dt.w) {
			ans[n] = dt.id
			f[n][k] = 1
			return true
		}
	}
	f[n][k] = 0
	return false
}

func main() {
	var n, k int
	init_()

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%s\n", &s)
		num := 0
		for j := 0; j < 7; j++ {
			if s[j] == '1' {
				num += 1
			}
			num <<= 1
		}
		num >>= 1
		a[i] = num
	}

	res := find(n, k)
	if res {
		for i := n; i >= 1; i-- {
			fmt.Printf("%d", ans[i])
		}
		fmt.Printf("\n")
	} else {
		fmt.Printf("-1\n")
	}
}