You are given $$$k$$$ sequences of integers. The length of the $$$i$$$-th sequence equals to $$$n_i$$$.You have to choose exactly two sequences $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $$$i$$$ (its length will be equal to $$$n_i - 1$$$) equals to the sum of the changed sequence $$$j$$$ (its length will be equal to $$$n_j - 1$$$).Note that it's required to remove exactly one element in each of the two chosen sequences.Assume that the sum of the empty (of the length equals $$$0$$$) sequence is $$$0$$$.

The first line contains an integer $$$k$$$ ($$$2 \le k \le 2 \cdot 10^5$$$) — the number of sequences. Then $$$k$$$ pairs of lines follow, each pair containing a sequence. The first line in the $$$i$$$-th pair contains one integer $$$n_i$$$ ($$$1 \le n_i < 2 \cdot 10^5$$$) — the length of the $$$i$$$-th sequence. The second line of the $$$i$$$-th pair contains a sequence of $$$n_i$$$ integers $$$a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$$$. The elements of sequences are integer numbers from $$$-10^4$$$ to $$$10^4$$$. The sum of lengths of all given sequences don't exceed $$$2 \cdot 10^5$$$, i.e. $$$n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$$$.

If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $$$i$$$, $$$x$$$ ($$$1 \le i \le k, 1 \le x \le n_i$$$), in the third line — two integers $$$j$$$, $$$y$$$ ($$$1 \le j \le k, 1 \le y \le n_j$$$). It means that the sum of the elements of the $$$i$$$-th sequence without the element with index $$$x$$$ equals to the sum of the elements of the $$$j$$$-th sequence without the element with index $$$y$$$. Two chosen sequences must be distinct, i.e. $$$i \ne j$$$. You can print them in any order. If there are multiple possible answers, print any of them.

NoteIn the first example there are two sequences $$$[2, 3, 1, 3, 2]$$$ and $$$[1, 1, 2, 2, 2, 1]$$$. You can remove the second element from the first sequence to get $$$[2, 1, 3, 2]$$$ and you can remove the sixth element from the second sequence to get $$$[1, 1, 2, 2, 2]$$$. The sums of the both resulting sequences equal to $$$8$$$, i.e. the sums are equal.

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 (
	"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 (
	. "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")

}


Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1), (n, 1), (1, m), (n, m).Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table. Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (x1, y1), an arbitrary corner of the table (x2, y2) and color all cells of the table (p, q), which meet both inequations: min(x1, x2) ≤ p ≤ max(x1, x2), min(y1, y2) ≤ q ≤ max(y1, y2).Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.

The first line contains exactly two integers n, m (3 ≤ n, m ≤ 50). Next n lines contain the description of the table cells. Specifically, the i-th line contains m space-separated integers ai1, ai2, ..., aim. If aij equals zero, then cell (i, j) isn't good. Otherwise aij equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.

Print a single number — the minimum number of operations Simon needs to carry out his idea.

NoteIn the first sample, the sequence of operations can be like this:    For the first time you need to choose cell (2, 2) and corner (1, 1).  For the second time you need to choose cell (2, 2) and corner (3, 3).  For the third time you need to choose cell (2, 2) and corner (3, 1).  For the fourth time you need to choose cell (2, 2) and corner (1, 3). In the second sample the sequence of operations can be like this:    For the first time you need to choose cell (3, 1) and corner (4, 3).  For the second time you need to choose cell (2, 3) and corner (1, 1).

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

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

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


The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 1310 = 11012, so it has 3 bits set and 13 will be reduced to 3 in one operation.He calls a number special if the minimum number of operations to reduce it to 1 is k.He wants to find out how many special numbers exist which are not greater than n. Please help the Travelling Salesman, as he is about to reach his destination!Since the answer can be large, output it modulo 109 + 7.

The first line contains integer n (1 ≤ n < 21000). The second line contains integer k (0 ≤ k ≤ 1000). Note that n is given in its binary representation without any leading zeros.

Output a single integer — the number of special numbers not greater than n, modulo 109 + 7.

NoteIn the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2).

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


Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 ≤ xi ≤ yi ≤ m). That means that one should apply operations with numbers xi, xi + 1, ..., yi to the array.Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.

The first line contains integers n, m, k (1 ≤ n, m, k ≤ 105). The second line contains n integers: a1, a2, ..., an (0 ≤ ai ≤ 105) — the initial array. Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 ≤ li ≤ ri ≤ n), (0 ≤ di ≤ 105). Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 ≤ xi ≤ yi ≤ m). The numbers in the lines are separated by single spaces.

On a single line print n integers a1, a2, ..., an — the array after executing all the queries. Separate the printed numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.

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


A permutation is a sequence of $$$n$$$ integers from $$$1$$$ to $$$n$$$, in which all the numbers occur exactly once. For example, $$$[1]$$$, $$$[3, 5, 2, 1, 4]$$$, $$$[1, 3, 2]$$$ are permutations, and $$$[2, 3, 2]$$$, $$$[4, 3, 1]$$$, $$$[0]$$$ are not.Polycarp was given four integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le l \le r \le n)$$$ and $$$s$$$ ($$$1 \le s \le \frac{n (n+1)}{2}$$$) and asked to find a permutation $$$p$$$ of numbers from $$$1$$$ to $$$n$$$ that satisfies the following condition:   $$$s = p_l + p_{l+1} + \ldots + p_r$$$. For example, for $$$n=5$$$, $$$l=3$$$, $$$r=5$$$, and $$$s=8$$$, the following permutations are suitable (not all options are listed):   $$$p = [3, 4, 5, 2, 1]$$$;  $$$p = [5, 2, 4, 3, 1]$$$;  $$$p = [5, 2, 1, 3, 4]$$$.  But, for example, there is no permutation suitable for the condition above for $$$n=4$$$, $$$l=1$$$, $$$r=1$$$, and $$$s=5$$$.Help Polycarp, for the given $$$n$$$, $$$l$$$, $$$r$$$, and $$$s$$$, find a permutation of numbers from $$$1$$$ to $$$n$$$ that fits the condition above. If there are several suitable permutations, print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$). Then $$$t$$$ test cases follow. Each test case consist of one line with four integers $$$n$$$ ($$$1 \le n \le 500$$$), $$$l$$$ ($$$1 \le l \le n$$$), $$$r$$$ ($$$l \le r \le n$$$), $$$s$$$ ($$$1 \le s \le \frac{n (n+1)}{2}$$$). It is guaranteed that the sum of $$$n$$$ for all input data sets does not exceed $$$500$$$.

For each test case, output on a separate line:    $$$n$$$ integers — a permutation of length $$$n$$$ that fits the condition above if such a permutation exists;  -1, otherwise.  If there are several suitable permutations, print any of them.

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


Polycarp came up with a new programming language. There are only two types of statements in it:   "x := s": assign the variable named x the value s (where s is a string). For example, the statement var := hello assigns the variable named var the value hello. Note that s is the value of a string, not the name of a variable. Between the variable name, the := operator and the string contains exactly one space each. "x = a + b": assign the variable named x the concatenation of values of two variables a and b. For example, if the program consists of three statements a := hello, b := world, c = a + b, then the variable c will contain the string helloworld. It is guaranteed that the program is correct and the variables a and b were previously defined. There is exactly one space between the variable names and the = and + operators. All variable names and strings only consist of lowercase letters of the English alphabet and do not exceed $$$5$$$ characters.The result of the program is the number of occurrences of string haha in the string that was written to the variable in the last statement.Polycarp was very tired while inventing that language. He asks you to implement it. Your task is — for given program statements calculate the number of occurrences of string haha in the last assigned variable.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of statements in the program. All variable names and strings are guaranteed to consist only of lowercase letters of the English alphabet and do not exceed $$$5$$$ characters. This is followed by $$$n$$$ lines describing the statements in the format described above. It is guaranteed that the program is correct.

For each set of input data, output the number of occurrences of the haha substring in the string that was written to the variable in the last statement.

4
6
a := h
b := aha
c = a + b
c = c + c
e = c + c
d = a + c
15
x := haha
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
1
haha := hah
5
haahh := aaaha
ahhhh = haahh + haahh
haahh = haahh + haahh
ahhhh = ahhhh + haahh
ahhaa = haahh + ahhhh

NoteIn the first test case the resulting value of d is hhahahaha.

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";."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"
	"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"
)

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


Alice got an array of length $$$n$$$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.Bob has chosen $$$m$$$ changes of the following form. For some integer numbers $$$x$$$ and $$$d$$$, he chooses an arbitrary position $$$i$$$ ($$$1 \le i \le n$$$) and for every $$$j \in [1, n]$$$ adds $$$x + d \cdot dist(i, j)$$$ to the value of the $$$j$$$-th cell. $$$dist(i, j)$$$ is the distance between positions $$$i$$$ and $$$j$$$ (i.e. $$$dist(i, j) = |i - j|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$).For example, if Alice currently has an array $$$[2, 1, 2, 2]$$$ and Bob chooses position $$$3$$$ for $$$x = -1$$$ and $$$d = 2$$$ then the array will become $$$[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$$$ = $$$[5, 2, 1, 3]$$$. Note that Bob can't choose position $$$i$$$ outside of the array (that is, smaller than $$$1$$$ or greater than $$$n$$$).Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.What is the maximum arithmetic mean value Bob can achieve?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of elements of the array and the number of changes. Each of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$d_i$$$ ($$$-10^3 \le x_i, d_i \le 10^3$$$) — the parameters for the $$$i$$$-th change.

Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$.

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"
)

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