Pay attention to the non-standard memory limit in this problem.In order to cut off efficient solutions from inefficient ones in this problem, the time limit is rather strict. Prefer to use compiled statically typed languages (e.g. C++). If you use Python, then submit solutions on PyPy. Try to write an efficient solution.The array $$$a=[a_1, a_2, \ldots, a_n]$$$ ($$$1 \le a_i \le n$$$) is given. Its element $$$a_i$$$ is called special if there exists a pair of indices $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) such that $$$a_i = a_l + a_{l+1} + \ldots + a_r$$$. In other words, an element is called special if it can be represented as the sum of two or more consecutive elements of an array (no matter if they are special or not).Print the number of special elements of the given array $$$a$$$.For example, if $$$n=9$$$ and $$$a=[3,1,4,1,5,9,2,6,5]$$$, then the answer is $$$5$$$:  $$$a_3=4$$$ is a special element, since $$$a_3=4=a_1+a_2=3+1$$$;  $$$a_5=5$$$ is a special element, since $$$a_5=5=a_2+a_3=1+4$$$;  $$$a_6=9$$$ is a special element, since $$$a_6=9=a_1+a_2+a_3+a_4=3+1+4+1$$$;  $$$a_8=6$$$ is a special element, since $$$a_8=6=a_2+a_3+a_4=1+4+1$$$;  $$$a_9=5$$$ is a special element, since $$$a_9=5=a_2+a_3=1+4$$$. Please note that some of the elements of the array $$$a$$$ may be equal — if several elements are equal and special, then all of them should be counted in the answer.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given in two lines. The first line contains an integer $$$n$$$ ($$$1 \le n \le 8000$$$) — the length of the array $$$a$$$. The second line contains integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that the sum of the values of $$$n$$$ for all test cases in the input does not exceed $$$8000$$$.

Print $$$t$$$ numbers — the number of special elements for each of the given arrays.

package main

import (
	"bufio"
	"fmt"
	"os"

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

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

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

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

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

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

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

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

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

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

}

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

	stub := struct{}{}

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

			sums[sum] = stub
		}
	}

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

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

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

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

func main() {
	var (
		T int
	)

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

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

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

	fmt.Println(ans)
}

package main

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

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

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

	dp := make([]bool, 8001)

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

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

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

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

		s := 0

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

		fmt.Println(s)
	}
}

package main

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

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

	return t
}

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

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

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

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

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

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

		fmt.Println(c)
	}
}

package main

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

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

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

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

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

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

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

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

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

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

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

	sums[0] = nums[0]

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

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

		v := numsMap[sums[i]]

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

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

			v := numsMap[s]

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

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

	return count
}

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int
	n int
	A []int
)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

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

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

package main

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

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

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

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

}

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

package main

import "fmt"

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

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

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

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

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

package main

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

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

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

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

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

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

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

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

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

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

	sums[0] = nums[0]

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

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

		current := nums[j]

		var found bool

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

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

		seenSum[sums[j - 1]] = true

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

			seenSum[s] = true
		}
	}

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

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

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

	return count
}

package main

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

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

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

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

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

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

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

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

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

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

	sums[0] = nums[0]

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

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

		current := nums[j]

		var found bool

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

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

		seenSum[sums[j - 1]] = true

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

			seenSum[s] = true
		}
	}

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

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

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

	return count
}

package main

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

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

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

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

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

		scanner.Scan()

		ll := scanner.Text()

		l, err := strconv.Atoi(ll)

		if err != nil {
			panic(err)
		}

		scanner.Scan()

		nn := scanner.Text()

		p := strings.Fields(nn)

		var nums []int

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

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

			if err != nil {
				panic(err)
			}

			nums = append(nums, num)
		}

		ans := solve5(nums)

		fmt.Println(ans)
	}
}

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

	sums[0] = nums[0]

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

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

		current := nums[j]

		var found bool

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

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

		seenSum[sums[j - 1]] = true

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

			seenSum[s] = true
		}
	}

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

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

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

	return count
}

package main

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

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

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

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


The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!

The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 100) — the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.

In t lines, print the actions the programmers need to make. In the i-th line print:   "LEFT" (without the quotes), if the i-th action was "move the ladder to the left";  "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right";  "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder".  The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.

RIGHT
RIGHT
PRINT !
LEFT
PRINT O
LEFT
PRINT G
LEFT
PRINT ?
LEFT
PRINT O
LEFT
PRINT G

NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.

package main

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

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

package main

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

var scanner *bufio.Scanner

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

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

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

// 412A
package main

import (
	"fmt"
)

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

// 412A
package main

import (
	"fmt"
)

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

// 412A
package main

import (
	"fmt"
)

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


Businessman Divan loves chocolate! Today he came to a store to buy some chocolate. Like all businessmen, Divan knows the value of money, so he will not buy too expensive chocolate. At the same time, too cheap chocolate tastes bad, so he will not buy it as well.The store he came to has $$$n$$$ different chocolate bars, and the price of the $$$i$$$-th chocolate bar is $$$a_i$$$ dollars. Divan considers a chocolate bar too expensive if it costs strictly more than $$$r$$$ dollars. Similarly, he considers a bar of chocolate to be too cheap if it costs strictly less than $$$l$$$ dollars. Divan will not buy too cheap or too expensive bars.Divan is not going to spend all his money on chocolate bars, so he will spend at most $$$k$$$ dollars on chocolates.Please determine the maximum number of chocolate bars Divan can buy.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The description of each test case consists of two lines. The first line contains integers $$$n$$$, $$$l$$$, $$$r$$$, $$$k$$$ ($$$1 \le n \le 100$$$, $$$1 \le l \le r \le 10^9$$$, $$$1 \le k \le 10^9$$$) — the lowest acceptable price of a chocolate, the highest acceptable price of a chocolate and Divan's total budget, respectively. The second line contains a sequence $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) integers — the prices of chocolate bars in the store.

For each test case print a single integer — the maximum number of chocolate bars Divan can buy.

NoteIn the first example Divan can buy chocolate bars $$$1$$$ and $$$3$$$ and spend $$$100$$$ dollars on them.In the second example Divan can buy chocolate bars $$$3$$$ and $$$4$$$ and spend $$$7$$$ dollars on them.In the third example Divan can buy chocolate bars $$$3$$$, $$$4$$$, and $$$5$$$ for $$$12$$$ dollars.In the fourth example Divan cannot buy any chocolate bar because each of them is either too cheap or too expensive.In the fifth example Divan cannot buy any chocolate bar because he considers the first bar too cheap, and has no budget for the second or third.In the sixth example Divan can buy all the chocolate bars in the shop.

package main

import (
	"fmt"
	"sort"
)

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

package main

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

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

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

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

package main

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

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

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

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

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

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

package main

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

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

func main() {
	solve()
}

package main

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

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

func main() {
	solve()
}

package main

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

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

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

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

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

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

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

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

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

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

package main

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

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

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

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

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

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

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

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

		fmt.Fprintln(out, c)
	}
}

package main

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

var n, l, r, k int

var a []int

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(read, &t)

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

		a = make([]int, n)

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

		solve()

		fmt.Println()
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

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

const MAX int = 1e6

func solve()  {
	sort.Ints(a)

	cnt := 0

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

		cnt++
		k-=a[i]
	}

	fmt.Print(cnt)
}

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

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

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

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

func main() {

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

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

	for t > 0 {

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

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

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

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

		t--
	}

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

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

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

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

	sort.Ints(chocolate)

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

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

	return count
}

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

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

	return min
}

package main

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

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

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

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

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

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

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

package main

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

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

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

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

package main

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

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

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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

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

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

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

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

type Noop struct{}

var noop = Noop{}

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

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

package main

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

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

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

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

package main

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

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

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

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

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

}

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

package main

import (
	"fmt"
	"sort"
)

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

package main

import (
	"fmt"
	"sort"
)

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

package main

import (
	"fmt"
	"sort"
)

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

package main

import (
	"fmt"
	"sort"
)

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

package main

import (
	"fmt"
	"sort"
)

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

package main

import (
	"fmt"
	"sort"
)

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

package main

import (
	"fmt"
	"sort"
)

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

package main

import (
	"fmt"
	"sort"
)

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

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


Let's say string $$$s$$$ has period $$$k$$$ if $$$s_i = s_{i + k}$$$ for all $$$i$$$ from $$$1$$$ to $$$|s| - k$$$ ($$$|s|$$$ means length of string $$$s$$$) and $$$k$$$ is the minimum positive integer with this property.Some examples of a period: for $$$s$$$="0101" the period is $$$k=2$$$, for $$$s$$$="0000" the period is $$$k=1$$$, for $$$s$$$="010" the period is $$$k=2$$$, for $$$s$$$="0011" the period is $$$k=4$$$.You are given string $$$t$$$ consisting only of 0's and 1's and you need to find such string $$$s$$$ that:  String $$$s$$$ consists only of 0's and 1's;  The length of $$$s$$$ doesn't exceed $$$2 \cdot |t|$$$;  String $$$t$$$ is a subsequence of string $$$s$$$;  String $$$s$$$ has smallest possible period among all strings that meet conditions 1—3. Let us recall that $$$t$$$ is a subsequence of $$$s$$$ if $$$t$$$ can be derived from $$$s$$$ by deleting zero or more elements (any) without changing the order of the remaining elements. For example, $$$t$$$="011" is a subsequence of $$$s$$$="10101".

The first line contains single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains string $$$t$$$ ($$$1 \le |t| \le 100$$$) consisting only of 0's and 1's.

Print one string for each test case — string $$$s$$$ you needed to find. If there are multiple solutions print any one of them.

NoteIn the first and second test cases, $$$s = t$$$ since it's already one of the optimal solutions. Answers have periods equal to $$$1$$$ and $$$2$$$, respectively.In the third test case, there are shorter optimal solutions, but it's okay since we don't need to minimize the string $$$s$$$. String $$$s$$$ has period equal to $$$1$$$.

package main

import "fmt"

func main(){

	var T int
	fmt.Scanln(&T)
	for i:=0;i<T;i++{
		var str string
		fmt.Scanln(&str)
		//fmt.Println(len(str))
		c := str[0]
		var flag int
		for i:=0;i<len(str);i++{
			if str[i]!=c{
				flag = 1
			}
		}
		if flag == 1{
			for i:=0;i<len(str);i++{
				fmt.Print("01")
			}
			fmt.Println()
		}else{
			fmt.Println(str)
		}
	}
}

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		str := s.NextString()

		var ones int
		for _, c := range str {
			if c == '1' {
				ones++
			}
		}

		if ones == 0 || ones == len(str) {
			fmt.Println(str)
			continue
		}

		res := make([]string, len(str))
		if str[0] == '1' {
			for j := 0; j < len(str); j++ {
				res[j] = "10"
			}
		} else {
			for j := 0; j < len(str); j++ {
				res[j] = "01"
			}
		}

		fmt.Println(strings.Join(res, ""))
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1342/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscanln(input, &s)
		fmt.Println(solve(s))
	}
}

func solve(s string) string {
	z, o := 0, 0
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			z++
		} else {
			o++
		}
	}

	if z == 0 || o == 0 {
		return s
	}

	var buff bytes.Buffer
	buff.WriteByte(s[0])
	prev := s[0]
	i := 1
	for i < len(s) {
		if prev != s[i] {
			buff.WriteByte(s[i])
			prev = s[i]
			i++
			continue
		}
		if prev == '0' {
			prev = '1'
			o--
		} else {
			prev = '0'
			z--
		}
		buff.WriteByte(prev)
	}

	return buff.String()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"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) string {
		var s string
		Fscan(in, &s)
		n := len(s)
		if strings.Count(s, "0") == n || strings.Count(s, "1") == n {
			return s
		}

		//ans := []byte{}

		return strings.Repeat("10", n)
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, solve(_case))
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1342B(_r io.Reader, _w io.Writer) {
	var t int
	var s string
	for Fscan(_r, &t); t > 0; t-- {
		Fscan(_r, &s)
		n := len(s)
		if strings.Count(s, "0") == n || strings.Count(s, "1") == n {
			Fprintln(_w, s)
		} else {
			Fprintln(_w, strings.Repeat("01", n))
		}
	}
}

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

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		var f = true
		for i := 0; i < n - 2; i ++ {
			if s[i] != s[i + 2] {
				break
			}
			if i == len(s) - 3 {
				f = false
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx>0; noEx-- {
		var s string
		fmt.Fscan(in, &s)
		r, isSame := rune(s[0]), true
		for _, ru := range s {if ru != r {isSame = false; break}}
		if isSame {
		    fmt.Fprint(out, s)
		    fmt.Fprint(out, "\n")
		    continue
		}
		var concat []string
		for i:=0; i<len(s); i++ {
		    concat = append(concat, "01")
		}
		fmt.Fprint(out, strings.Join(concat, ""))
		fmt.Fprint(out, "\n")
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%s\n", sol(s))
	}
}

func sol(t string) string {
	m := map[rune]int64{}
	for _, r := range t {
		m[r]++
	}
	if m['0'] == int64(len(t)) || m['1'] == int64(len(t)) {
		return t
	}
	ret := ""
	repeat := len(t)
	for ; repeat > 0; repeat-- {
		ret += "10"
	}
	return ret
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for T := stdin.ReadInt(); T > 0; T-- {
		t := []rune(stdin.Read())

		d := map[rune]bool{}
		for _, ch := range t {
			d[ch] = true
		}
		if len(d) == 1 {
			stdout.Println(string(t))
			continue
		}

		stack := NewDeque()
		stack.AppendLast(t[0])

		x := 1
		for x < len(t) {
			ch := stack.PeekLast().(rune)
			if ch == t[x] {
				if ch == '0' {
					stack.AppendLast('1')
				} else {
					stack.AppendLast('0')
				}
			} else {
				stack.AppendLast(t[x])
				x++
			}
		}

		ans := []rune{}
		for !stack.IsEmpty() {
			ans = append(ans, stack.PopFirst().(rune))
		}
		stdout.Println(string(ans))
	}
}

type Deque struct {
	head []interface{}
	tail []interface{}
}

func NewDeque() *Deque {
	return &Deque{
		head: []interface{}{},
		tail: []interface{}{},
	}
}

func (d *Deque) AppendLast(v interface{}) {
	d.tail = append(d.tail, v)
}

func (d *Deque) AppendFirst(v interface{}) {
	d.head = append(d.head, v)
}

func (d *Deque) PopLast() interface{} {
	if len(d.tail) == 0 {
		v := d.head[0]
		d.head = d.head[1:]
		return v
	} else {
		v := d.tail[len(d.tail)-1]
		d.tail = d.tail[:len(d.tail)-1]
		return v
	}
}

func (d *Deque) PopFirst() interface{} {
	if len(d.head) == 0 {
		v := d.tail[0]
		d.tail = d.tail[1:]
		return v
	} else {
		v := d.head[len(d.head)-1]
		d.head = d.head[:len(d.head)-1]
		return v
	}
}

func (d *Deque) IsEmpty() bool {
	return len(d.head) == 0 && len(d.tail) == 0
}

func (d *Deque) PeekFirst() interface{} {
	if len(d.head) == 0 {
		return d.tail[0]
	} else {
		return d.head[len(d.head)-1]
	}
}

func (d *Deque) PeekLast() interface{} {
	if len(d.tail) == 0 {
		return d.head[0]
	} else {
		return d.tail[len(d.tail)-1]
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

// ========================================
//      FOR int64
// ========================================

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

// https://codeforces.com/contest/1342/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		n int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscanln(input, &s)
		fmt.Println(solve(s))
	}
}

func solve(s string) string {
	z, o := 0, 0
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			z++
		} else {
			o++
		}
	}

	if z == 0 || o == 0 {
		return s
	}

	var buff bytes.Buffer
	buff.WriteByte(s[0])
	prev := s[0]
	for i := 1; i < len(s); i++ {
		if prev != s[i] {
			buff.WriteByte(s[i])
			continue
		}
		if prev == '0' {
			prev = '1'
		} else {
			prev = '0'
		}
		buff.WriteByte(prev)
	}

	return buff.String()
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		if n % 2 == 1 && n >=3 {
			s += string(s[n - 2])
			n = n + 1
		}
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 3 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 3 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 2 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

import "fmt"

func main() {
	var tot = 0
	_, _ = fmt.Scanln(&tot)
	for i := 0; i < tot; i++ {
		var s = ""
		_, _ = fmt.Scanln(&s)
		n := len(s)
		if n % 2 == 1 && n >=3 {
			s += string(s[n - 2])
			n = n + 1
		}
		var f = true
		for i := 0; i < n - 2; i ++ {
			if i == len(s) - 3 {
				f = false
			}
			if s[i] != s[i + 2] {
				break
			}
		}
		if n <= 2 {
			f = false
			if n == 1 {
				s += s
			}
		}
		if !f {
			fmt.Println(s)
		} else {
			for i := 0; i < n; i++ {
				if i == n - 1 {
					break
				}
				if s[i] == s[i + 1] {
					var add = "1"
					if s[i] == '1' {
						add = "0"
					}
					s = s[:i + 1] + add + s[i + 1:]
					n = n + 1
				}
			}
			fmt.Println(s)
		}
	}
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
	noEx := 0
	fmt.Fscan(in, &noEx)
	for ; noEx>0; noEx-- {
		var s string
		fmt.Fscan(in, &s)
		fmt.Fprint(out, s+s)
		fmt.Fprint(out, "\n")
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%s\n", sol(s))
	}
}

func sol(t string) string {
	m := map[rune]int64{}
	for _, r := range t {
		m[r]++
	}
	if m['0'] == int64(len(t)) || m['1'] == int64(len(t)) {
		return t
	}
	ret := ""
	repeat := max(m['0'], m['1']) + 1
	for ; repeat > 0; repeat-- {
		ret += "10"
	}
	return ret
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for T := stdin.ReadInt(); T > 0; T-- {
		t := []rune(stdin.Read())
		stack := NewDeque()
		stack.AppendLast(t[0])

		x := 1
		for x < len(t) {
			ch := stack.PeekLast().(rune)
			if ch == t[x] {
				if ch == '0' {
					stack.AppendLast('1')
				} else {
					stack.AppendLast('0')
				}
			} else {
				stack.AppendLast(t[x])
				x++
			}
		}

		ans := []rune{}
		for !stack.IsEmpty() {
			ans = append(ans, stack.PopFirst().(rune))
		}
		stdout.Println(string(ans))
	}
}

type Deque struct {
	head []interface{}
	tail []interface{}
}

func NewDeque() *Deque {
	return &Deque{
		head: []interface{}{},
		tail: []interface{}{},
	}
}

func (d *Deque) AppendLast(v interface{}) {
	d.tail = append(d.tail, v)
}

func (d *Deque) AppendFirst(v interface{}) {
	d.head = append(d.head, v)
}

func (d *Deque) PopLast() interface{} {
	if len(d.tail) == 0 {
		v := d.head[0]
		d.head = d.head[1:]
		return v
	} else {
		v := d.tail[len(d.tail)-1]
		d.tail = d.tail[:len(d.tail)-1]
		return v
	}
}

func (d *Deque) PopFirst() interface{} {
	if len(d.head) == 0 {
		v := d.tail[0]
		d.tail = d.tail[1:]
		return v
	} else {
		v := d.head[len(d.head)-1]
		d.head = d.head[:len(d.head)-1]
		return v
	}
}

func (d *Deque) IsEmpty() bool {
	return len(d.head) == 0 && len(d.tail) == 0
}

func (d *Deque) PeekFirst() interface{} {
	if len(d.head) == 0 {
		return d.tail[0]
	} else {
		return d.head[len(d.head)-1]
	}
}

func (d *Deque) PeekLast() interface{} {
	if len(d.tail) == 0 {
		return d.head[0]
	} else {
		return d.tail[len(d.tail)-1]
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

// ========================================
//      FOR int64
// ========================================

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}