You are given an array $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ distinct integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ space separated integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot n$$$) — the array $$$a$$$. It is guaranteed that all elements are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_i \cdot a_j = i + j$$$.

NoteFor the first test case, the only pair that satisfies the constraints is $$$(1, 2)$$$, as $$$a_1 \cdot a_2 = 1 + 2 = 3$$$For the second test case, the only pair that satisfies the constraints is $$$(2, 3)$$$.For the third test case, the pairs that satisfy the constraints are $$$(1, 2)$$$, $$$(1, 5)$$$, and $$$(2, 3)$$$.

package main

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

func init() {
	log.SetFlags(0)
	// log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	a = append([]int{0}, a...)
	n := len(a)
	log.Printf("a = %#v\n", a)

Loop:
	for i := 1; i < n; i++ {
		for j := a[i] - i; j < n; j += a[i] {
			if a[i] == 0 {
				continue Loop
			}
			if !(i < j) {
				continue
			}
			// log.Printf("dddddddj a[i]= %#v i = %#v, j = %#v\n", a[i], i, j)
			if i < j && int64(a[i])*int64(a[j]) == int64(i+j) {
				res++
			}
		}
	}
	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size+10)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

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

/*
3
2
3 1
3
6 1 5
5
3 1 5 9 2
---
1
1
3
=========
1
3
1 2 3
---
0
=========
1
2
3 1
---
1
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	bld := strings.Builder{}

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		valToIdx := make(map[int]int)

		for i := 1; i <= n; i++ {
			var val int
			scanf("%d", &val)

			valToIdx[val] = i
		}
		scanf("\n")

		cnt := 0

		for a := 1; a < 2*n; a++ {
			i, ok := valToIdx[a]
			if !ok {
				continue
			}

			b := 1
			for a*b < 2*n {
				j, ok := valToIdx[b]
				if ok {
					if a*b == i+j && a != b {
						cnt++
					}
				}

				b++
			}
		}

		fmt.Fprintf(&bld, "%d\n", cnt/2)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst rune
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		ans := 0
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
			v = a[i]
			j := v - i
			if j <= 0 {
				j = j%v + v
			}
			for j < i {
				if v*a[j] == i+j {
					ans++
				}
				j += v
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		ans := 0
		Fscan(in, &n)
		pos := make([]int, n*2+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			for w := 1; w*v <= i*2-1; w++ {
				if pos[w] > 0 && w*v == pos[w]+i {
					ans++
				}
			}
			pos[v] = i
		}
		Fprintln(out, ans)
	}
}

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

package main

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

var (
	in = bufio.NewReader(os.Stdin)
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}
func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]pair, n)
	for i := 0; i < n; i++ {
		var currentVariable int64
		fmt.Fscan(in, &currentVariable)
		arr[i] = pair{
			a: currentVariable,
			b: int64(i),
		}
	}
	sortPair(arr)
	var count = 0

	for i := 0; i < len(arr); i++ {
		currentA := arr[i].a
		currentAPos:=arr[i].b
		for j := i + 1; j < len(arr); j++ {
			currentB := arr[j].a
			currentPosB:=arr[j].b
			if currentA*currentB == currentAPos+currentPosB+2{
				count++
			}

			if currentB*currentA > int64(2*n) {
				break
			}
		}
	}
	fmt.Println(count)

}

//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-TEMPLATE_STARTING-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-

type pair struct {
	a int64
	b int64
}

func sortPair(pairs []pair) {
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].a < pairs[j].a
	})
}
func max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

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

const LOCAL = false

func main() {
	r := bufio.NewReader(os.Stdin)

	rand.Seed(time.Now().UnixNano())

	if LOCAL {

		for t := 0; t < 1; t++ {
			var n int = 1e5

			a := make([]int, n)

			seen := make([]bool, 2 * n + 1)

			for i := 0; i < n; i++ {
				v := 1 + rand.Intn(2 * n)
				if seen[v] {
					continue
				}
				seen[v] = true
				a[i] = v
			}

			ans1 := solve_brute(a, n)
			ans2 := solve(a, n)
			if ans1 != ans2 {
				fmt.Println("ERROR")
				fmt.Println(a)
				fmt.Println(ans1)
				fmt.Println(ans2)
				break
			}
		}

	} else {
		var t int
		fmt.Fscan(r, &t)

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

			a := make([]int, n)

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

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

func solve_brute(a[]int, n int) int64 {
	var count int64
	for i := 1; i <= n; i++ {
		for j := i + 1 ; j <= n; j++ {

			if i + j == a[i - 1] * a[j - 1] {
				count++
			}
		}
	}

	return count
}

func solve(a []int, n int) int64 {
	var count int64

	maxSum := 2 * n - 1

	mp := make(map[int]bool)

	for i := 3; i <= maxSum; i++ {
		mp[i] = true
	}

	for i := 1; i <= n; i++ {
		cur := a[i - 1]

		for j := 1; j <= maxSum; j++ {
			if j * cur > maxSum {
				break
			}

			s := j * cur
			if _, ok := mp[s]; ok {
				index := s - i
				if index < 1 || index > n {
					continue
				}

				if a[index - 1] == j {
					if i != index {
						count++
					}
				}
			}
		}
	}

	return count/2
}

// 3 1 5 9 2
//min = 3
//max = 9

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		arr := make([]pair, n)
		for i := 0; i < n; i++ {
			p := pair{index: i + 1}
			_, _ = fmt.Fscan(in, &p.val)

			arr[i] = p
		}

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

		var ans int

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				mul := arr[i].val * arr[j].val

				if mul > int64(2*n) {
					break
				}

				if mul == int64(arr[i].index+arr[j].index) {
					ans++
				}
			}
		}

		fmt.Println(ans)
	}
}

type pair struct {
	val   int64
	index int
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	a = append([]int{0}, a...)
	n := len(a)
	log.Printf("a = %#v\n", a)

Loop:
	for i := 1; i < n; i++ {
		for j := a[i] - i; j < n; j += a[i] {
			if a[i] == 0 {
				continue Loop
			}
			if !(i < j) {
				continue
			}
			// log.Printf("dddddddj a[i]= %#v i = %#v, j = %#v\n", a[i], i, j)
			if i < j && a[i]*a[j] == i+j {
				res++
			}
		}
	}
	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size+10)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	a = append([]int{0}, a...)
	n := len(a)
	log.Printf("a = %#v\n", a)

	for i := 1; i < n; i++ {
		// for j := a[i] - i; j < n; j += a[i] {
		for j := i + 1; j < n; j += a[i] {
			if !(i < j) {
				continue
			}
			log.Printf("a[i]= %#v i = %#v, j = %#v\n", a[i], i, j)
			if i < j && a[i]*a[j] == i+j {
				res++
			}
		}
	}
	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

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

func init() {
	log.SetFlags(0)
	// log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	a = append([]int{0}, a...)
	n := len(a)
	log.Printf("a = %#v\n", a)

	for i := 1; i < n; i++ {
		for j := a[i] - i; j < n; j += a[i] {
			if i < j && a[i]*a[j] == i+j {
				res++
			}
		}
	}
	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	n := len(a)
	indx := make([]int, 2*n+2)
	for i, v := range a {
		indx[v] = i
	}
	sort.Ints(a)
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			mult := a[i] * a[j]
			if !(mult < 2*(n+1)-1) {
				break
			}
			if indx[a[i]]+indx[a[j]]+2 == mult {
				res++
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	n := len(a)
	indx := make([]int, 2*n+2)
	for i, v := range a {
		indx[v] = i
	}
	sort.Ints(a)
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			mult := a[i] * a[j]
			if mult < 2*n-2 && indx[a[i]]+indx[a[j]]+2 == mult {
				res++
			}
			if !(mult < 2*n-2) {
				break
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	n := len(a)
	indx := make([]int, 2*n+2)
	for i, v := range a {
		indx[v] = i
	}
	sort.Ints(a)
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			mult := a[i] * a[j]
			if mult < 2*n+3 && indx[a[i]]+indx[a[j]]+2 == mult {
				res++
			}
			if !(mult < 2*n+3) {
				break
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	n := len(a)
	indx := make([]int, 2*n+2)
	for i, v := range a {
		indx[v] = i
	}
	sort.Ints(a)
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			mult := a[i] * a[j]
			if mult < 2*n && indx[a[i]]+indx[a[j]]+2 == mult {
				res++
			}
			if !(mult < 2*n) {
				break
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	n := len(a)
	indx := make([]int, 2*n+2)
	for i, v := range a {
		indx[v] = i
	}
	sort.Ints(a)
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			mult := a[i] * a[j]
			if indx[a[i]]+indx[a[j]]+2 == mult {
				res++
			}
			if !(mult < 2*n) {
				break
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	// log.Printf("a = %#v\n", a)
	n := len(a)
	// a = append([]int{0}, a...)
	// log.Printf("a = %#v\n", a)
	indx := make([]int, 2*n+2)
	for i, v := range a {
		indx[v] = i
	}
	// log.Printf("indx = %#v\n", indx)
	sort.Ints(a)

	log.Printf("n = %#v\n", n)
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			// log.Printf("i, j = %#v %#v\n", i, j)
			mult := a[i] * a[j]
			if mult >= 2*n {
				break
			}
			if indx[a[i]]+indx[a[j]]+2 == mult {
				res++
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	// log.Printf("a = %#v\n", a)
	a = append([]int{0}, a...)
	// log.Printf("a = %#v\n", a)
	indx := make([]int, 2*len(a))
	for i, v := range a {
		indx[v] = i
	}
	// log.Printf("indx = %#v\n", indx)
	sort.Ints(a)

	n := len(a)
	log.Printf("n = %#v\n", n)
	for i := 1; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			// log.Printf("i, j = %#v %#v\n", i, j)
			mult := a[i] * a[j]
			if mult >= 2*n {
				break
			}
			if indx[a[i]]+indx[a[j]] == mult {
				res++
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	// log.Printf("a = %#v\n", a)
	a = append([]int{0}, a...)
	log.Printf("a = %#v\n", a)
	indx := make([]int, 2*len(a)+39343)
	for i, v := range a {
		indx[v] = i
	}
	// log.Printf("indx = %#v\n", indx)
	sort.Ints(a)

	n := len(a)
	log.Printf("n = %#v\n", n)
	for i := 1; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			// log.Printf("i, j = %#v %#v\n", i, j)
			mult := a[i] * a[j]
			if indx[a[i]]+indx[a[j]] == mult {
				res++
			}
			if mult >= 2*n {
				break
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	// log.Printf("a = %#v\n", a)
	a = append([]int{0}, a...)
	log.Printf("a = %#v\n", a)
	indx := make([]int, 2*len(a)+39343)
	for i, v := range a {
		indx[v] = i
	}
	// log.Printf("indx = %#v\n", indx)
	sort.Ints(a)

	n := len(a)
	log.Printf("n = %#v\n", n)
	for i := 1; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			// log.Printf("i, j = %#v %#v\n", i, j)
			mult := a[i] * a[j]
			if indx[a[i]]+indx[a[j]] == mult {
				res++
			}
			if mult > 2*n {
				break
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	indx := make([]int, 2*len(a)+2)
	for i, v := range a {
		indx[v] = i + 1
	}
	log.Printf("indx = %#v\n", indx)

	sort.Ints(a)

	n2 := int64(2 * len(a))
	for i := 0; i < len(a); i++ {
		if int64(a[i]) > n2 {
			return res
		}
		for j := i + 1; j < len(a); j += a[i] {
			mult := int64(a[i] * a[j])
			if mult > n2 {
				break
			}
			if mult == int64(indx[a[i]]+indx[a[j]]) {
				res++
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))
		out.Flush()
		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	indx := make([]int, 2*len(a)+2)
	for i, v := range a {
		indx[v] = i
	}
	sort.Ints(a)

	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			mult := a[i] * a[j]
			if a[i]*a[j] > 2*len(a)+3 {
				break
			}
			if mult == indx[a[i]]+indx[a[j]]+2 {
				res++
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))

		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"sort"
)

func init() {
	log.SetFlags(0)
	log.SetOutput(ioutil.Discard)
}

func solve(a []int) int {
	res := 0
	indx := make([]int, 2*len(a)+2)
	for i, v := range a {
		indx[v] = i
	}
	sort.Ints(a)

Loop:
	for i := 0; i < len(a); i++ {
		for j := i + 1; j < len(a); j++ {
			mult := a[i] * a[j]
			if a[i]*a[j] > 2*len(a)+3 {
				continue Loop
			}
			if mult == indx[a[i]]+indx[a[j]]+2 {
				res++
			}
		}
	}

	return res
}

func main() {
	log.Println("start")

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

	num := 0
	fmt.Fscan(in, &num)
	for i := 0; i < num; i++ {
		var size int
		fmt.Fscan(in, &size)
		a := make([]int, size)
		for i := 0; i < size; i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fprintf(out, "%d\n", solve(a))

		// log.Printf("a = %#v\n", a)
		// for _, v := range a {
		// 	fmt.Fprintf(out, "%d ", v)
		// }
		// fmt.Fprintf(out, "\n")
	}
	log.Println("__end__")
}

package main

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

/*
3
2
3 1
3
6 1 5
5
3 1 5 9 2
---
1
1
3
=========
1
3
1 2 3
---
0
=========
1
2
3 1
---
1
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	bld := strings.Builder{}

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		valToIdx := make(map[int]int)

		for i := 1; i <= n; i++ {
			var val int
			scanf("%d", &val)

			valToIdx[val] = i
		}
		scanf("\n")

		cnt := 0

		for a := 1; a <= 2*n; a++ {
			i, ok := valToIdx[a]
			if !ok {
				continue
			}

			max := int(math.Sqrt(float64(n)))
			for b := 1; b <= max; b++ {
				j, ok := valToIdx[b]
				if !ok {
					continue
				}

				if a*b == i+j && a != b {
					cnt++
				}
			}
		}

		fmt.Fprintf(&bld, "%d\n", cnt)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst rune
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

/*
3
2
3 1
3
6 1 5
5
3 1 5 9 2
---
1
1
3
=========
1
3
1 2 3
---
0
=========
1
2
3 1
---
1
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	bld := strings.Builder{}

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		valToIdx := make(map[int]int)

		for i := 1; i <= n; i++ {
			var val int
			scanf("%d", &val)

			valToIdx[val] = i
		}
		scanf("\n")

		cnt := 0

		for a := 1; a < 2*n; a++ {
			i, ok := valToIdx[a]
			if !ok {
				continue
			}

			max := int(math.Sqrt(float64(n)))
			for b := 1; b <= max; b++ {
				j, ok := valToIdx[b]
				if !ok {
					continue
				}

				if a*b == i+j && a != b {
					cnt++
				}
			}
		}

		fmt.Fprintf(&bld, "%d\n", cnt)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst rune
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

const LOCAL = false

func main() {
	r := bufio.NewReader(os.Stdin)

	rand.Seed(time.Now().UnixNano())

	if LOCAL {

		var n int = 1e5

		a := make([]int, n)

		for i := 0; i < n; i++ {
			a[i] = 1 + rand.Intn(2 * n)
		}

		fmt.Println(solve(a, n))

	} else {
		var t int
		fmt.Fscan(r, &t)

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

			a := make([]int, n)

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

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

func solve(a []int, n int) int64 {
	var count int64

	maxSum := 2 * n - 1

	mp := make(map[int]bool)

	for i := 3; i <= maxSum; i++ {
		mp[i] = true
	}

	for i := 1; i <= n; i++ {
		c := a[i - 1]

		for j := 1;; j++ {
			s := c * j
			if c * j > maxSum {
				break
			}

			if _, ok := mp[s]; ok {
				index := s - i

				if index < 1 || index > n {
					continue
				}

				if a[index - 1] == j {
					count++
				}
			}

		}

	}

	return count/2
}

// 3 7 2 4 5 6 9
// i = 1 j = 2  s= 3
// i = 5 j == 6 s= 13

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		arr := make([]pair, n)
		for i := 0; i < n; i++ {
			p := pair{index: i + 1}
			_, _ = fmt.Fscan(in, &p.val)

			arr[i] = p
		}

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

		var ans int

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				mul := arr[i].val * arr[j].val

				if mul > 2*n {
					break
				}

				if mul == arr[i].index+arr[j].index {
					ans++
				}
			}
		}

		fmt.Println(ans)
	}
}

type pair struct {
	val   int
	index int
}


You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!An array $$$a$$$ of length $$$n$$$ is called complete if all elements are positive and don't exceed $$$1000$$$, and for all indices $$$x$$$,$$$y$$$,$$$z$$$ ($$$1 \leq x,y,z \leq n$$$), $$$a_{x}+a_{y} \neq a_{z}$$$ (not necessarily distinct).You are given one integer $$$n$$$. Please find any complete array of length $$$n$$$. It is guaranteed that under given constraints such array exists.

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Description of the test cases follows. The only line of each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$.

For each test case, print a complete array on a single line. All elements have to be integers between $$$1$$$ and $$$1000$$$ and for all indices $$$x$$$,$$$y$$$,$$$z$$$ ($$$1 \leq x,y,z \leq n$$$) (not necessarily distinct), $$$a_{x}+a_{y} \neq a_{z}$$$ must hold. If multiple solutions exist, you may print any.

NoteIt can be shown that the outputs above are valid for each test case. For example, $$$44+44 \neq 384$$$.Below are some examples of arrays that are NOT complete for the 1st test case:$$$[1,2,3,4,5]$$$ Notice that $$$a_{1}+a_{2} = a_{3}$$$.$$$[1,3000,1,300,1]$$$ Notice that $$$a_{2} = 3000 > 1000$$$.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i][1] > pq[j][1]
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.([2]int))
}

func (pq *priorityQueue) Pop() (res interface{}) {
	res = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	return res
}

var err error

func NextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func NextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}
func Euclid(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	gcd, s1, s2 := Euclid(b, a%b)
	return gcd, s2, s1 - s2*(a/b)
}

func main() {
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	if false {
		file, err := os.Open("in")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file, 8192)
	} else {
		in = bufio.NewReaderSize(os.Stdin, 8192)
	}
	for cases := NextInt(); cases > 0; cases-- {
		n := NextInt()
		for i := 0; i < n; i++ {
			printf("1 ")
		}
		printf("\n")
	}
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		ans := 1
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", ans)
		}
		fmt.Println()
	}
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		var buf bytes.Buffer
		for i := 0; i < n; i++ {
			buf.WriteString("1 ")
		}
		fmt.Println(buf.String())
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.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)
    for i := 0; i < n; i++ {
        if i == 0 {
            fmt.Print(1)
        } else {
            fmt.Print(" ", 1)
        }
    }
	fmt.Println()
}

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

package main

import "fmt"

func main() {
	var n, t int

	fmt.Scan(&t)

	for t > 0 {
		t--
		fmt.Scan(&n)

		for n > 0 {
			n--
			fmt.Print(1, " ")
		}
		fmt.Println()
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		for j := 0; j < n; j++ {
			fmt.Print(1, " ")
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for j := 0; j < n; j++ {
			fmt.Print("1 ")
		}
		fmt.Print("\n")
	}
}

package main
import (
        "fmt"
        "os"
        "bufio"
)
func main(){
    var t, n int
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var s string = "1 "
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &n)
        for ; n != 0; n-- {
            fmt.Fprint(out, s);
        }
        fmt.Fprintln(out);
    }
}

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		con.Scan(&n)
		for i := 0; i < n; i++ {
			con.Print("1 ")
		}
		con.Println()
	}
	return nil
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		for j := 0; j < n; j++ {
			fmt.Print("1 ")
		}
		fmt.Println("")
	}
}

//2020-07-29 18:02:31.261

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		ans := 1
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", ans)
			ans += 2
		}
		fmt.Println()
	}
}


The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array a, only if array a can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.Help the Little Elephant, determine if he could have accidentally changed the array a, sorted by non-decreasing, himself.

The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a. Note that the elements of the array are not necessarily distinct numbers.

In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.

NoteIn the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".

package main
import (
	"fmt"
	//"bufio"
	//"os"
	//"strconv"
	"sort"
)

func main() {
	var n,i int
	conter:=0
	fmt.Scan(&n)
	a:=make([]int,n)
	b:=make([]int,n)
	for i=0;i<n;i++ {
		fmt.Scan(&a[i])
		b[i]=a[i]
	}
	sort.Ints(b)
	for i=0;i<n;i++ {
		if a[i]!=b[i] {
			conter++
		}
	}
	if conter>2 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    a,b := make([]int,n), make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
        b[i] = a[i]
    }
    sort.Ints(b)
    cnt := 0
    for i := 0; i < n; i++ {
        if a[i] != b[i] { cnt++ }
    }
    if cnt <= 2 { fmt.Println("YES") } else { fmt.Println("NO") }
}

// 220A-mic
package main

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

func main() {
    s := bufio.NewScanner(os.Stdin)
    s.Split(bufio.ScanWords)
    var n, cou int
    fmt.Scan(&n)
    a := make([]int, n)
    b := make([]int, n)
    for i := 0; i < n; i++ {
        s.Scan()
        k, _ := strconv.Atoi(s.Text())
        a[i] = k
        b[i] = a[i]
    }
    sort.Sort(sort.IntSlice(a))
    for i := 0; i < n; i++ {
        if a[i] != b[i] {
            cou++
        }
        if cou > 2 {
            fmt.Println("NO")
            return
        }
    }
    fmt.Println("YES")
}


Pig is visiting a friend.Pig's house is located at point 0, and his friend's house is located at point m on an axis.Pig can use teleports to move along the axis.To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds.  Determine if Pig can visit the friend using teleports only, or he should use his car.

The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house. The next n lines contain information about teleports. The i-th of these lines contains two integers ai and bi (0 ≤ ai ≤ bi ≤ m), where ai is the location of the i-th teleport, and bi is its limit. It is guaranteed that ai ≥ ai - 1 for every i (2 ≤ i ≤ n).

Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).

NoteThe first example is shown on the picture below:  Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.The second example is shown on the picture below:  You can see that there is no path from Pig's house to his friend's house that uses only teleports.

package main

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

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Scan()
	input := strings.Split(in.Text(), " ")
	n, _ := strconv.Atoi(input[0])
	m, _ := strconv.Atoi(input[1])
	kray := 0
	for i := 1; i <= n; i++ {
		in.Scan()
		input = strings.Split(in.Text(), " ")
		koord, _ := strconv.Atoi(input[0])
		daln, _ := strconv.Atoi(input[1])
		if !(koord <= kray) {
			break
		}
		if daln > kray {
			kray = daln
		}
	}
	if m <= kray {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

type teleport struct {
	start, limit int
}

func solve() {
	n := readInt()
	m := readInt()

	teleports := make([]teleport, n)
	reachable := make([]bool, m+1)
	for i, _ := range teleports {
		teleports[i].start = readInt()
		teleports[i].limit = readInt()
	}

	for _, t := range teleports {
		for i := t.start + 1; i <= t.limit; i++ {
			reachable[i] = true
		}
		if t.start == 0 {
			reachable[0] = true
		}
	}

	for i, r := range reachable {
		if r && i == m {
			fmt.Println("YES")
			return
		}
		if !r {
			break
		}
	}
	fmt.Println("NO")
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

var (
    f [100]bool
)

var reader SReader

func main() {
    reader.Init()
	n := reader.ReadInt()
	m := reader.ReadInt()
	for i := int32(0); i < n; i++ {
		a := reader.ReadInt()
		b := reader.ReadInt()
		for ; a < b; a++ {
			f[a] = true;
		}
	}

	for i := int32(0); i < m; i++ {
		if !f[i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

// reader
type SReader struct {
    file *os.File
    scanner *bufio.Scanner
}

func (this *SReader) Init() {
    this.file = os.Stdin
    this.scanner = bufio.NewScanner(this.file)
    this.scanner.Split(bufio.ScanWords)
}

func (this *SReader) ReadInt() int32 {
    this.scanner.Scan()
    n, err:= strconv.ParseInt(this.scanner.Text(), 10, 0)
    if err != nil {
        panic(err)
    }
    return int32(n)
}

package main

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

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	field := make([]int, M+2)
	for i := 0; i < N; i++ {
		a, b := sc.NextInt(), sc.NextInt()
		field[a] += 1
		field[b] -= 1
	}

	s := 0
	for i := 0; i < len(field); i++ {
		if i == M {
			fmt.Println("YES")
			return
		}
		s += field[i]
		if s == 0 {
			fmt.Println("NO")
			return
		}
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

type MyReader struct{
	reader *bufio.Reader
}

func (r *MyReader) readLine() ([]string){
	input, _ := r.reader.ReadString('\n')
	input = strings.TrimRight(input, "\r\n")
	return strings.Split(input, " ")
}

func main() {
	reader := MyReader{bufio.NewReader(os.Stdin)}
	s := reader.readLine()

	n, _ := strconv.Atoi(s[0])
	m, _ := strconv.Atoi(s[1])
	reach := true

	maxBlink := 0
	for i := 0; i < n; i++{
		s = reader.readLine()
		aTemp, _ := strconv.Atoi(s[0])
		bTemp, _ := strconv.Atoi(s[1])

		if maxBlink < aTemp{
			reach = false
			break
		}

		if bTemp > maxBlink{
			maxBlink = bTemp
		}
	}

	if reach && m <= maxBlink{
		fmt.Println("YES")
	}else{
		fmt.Println("NO")
	}
}

package main

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

type MyReader struct{
	reader *bufio.Reader
}

func (r *MyReader) readLine() ([]string){
	input, _ := r.reader.ReadString('\n')
	input = strings.TrimRight(input, "\r\n")
	return strings.Split(input, " ")
}

func main() {
	reader := MyReader{bufio.NewReader(os.Stdin)}
	s := reader.readLine()

	n, _ := strconv.Atoi(s[0])
	m, _ := strconv.Atoi(s[1])
	reach := true

	b := 0
	for i := 0; i < n; i++{
		s = reader.readLine()
		aTemp, _ := strconv.Atoi(s[0])
		bTemp, _ := strconv.Atoi(s[1])

		if b < aTemp{
			reach = false
			break
		}

		b = bTemp
	}

	if reach && m <= b{
		fmt.Println("YES")
	}else{
		fmt.Println("NO")
	}
}


We're giving away nice huge bags containing number tiles! A bag we want to present to you contains $$$n$$$ tiles. Each of them has a single number written on it — either $$$1$$$ or $$$2$$$.However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.Can you win the prize? Hurry up, the bags are waiting!

The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 200\,000$$$) — the number of number tiles in the bag. The following line contains $$$n$$$ space-separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{1, 2\}$$$) — the values written on the tiles.

Output a permutation $$$b_1, b_2, \dots, b_n$$$ of the input sequence $$$(a_1, a_2, \dots, a_n)$$$ maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.

NoteThe first solution produces the prefix sums $$$1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}}$$$ (four primes constructed), while the prefix sums in the second solution are $$$1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}}$$$ (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.

/*
URL:
https://codeforces.com/problemset/problem/1149/A
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	n int
	A []int
)

func main() {
	n = ReadInt()
	A = ReadIntSlice(n)

	one, two := 0, 0
	for i := 0; i < n; i++ {
		if A[i] == 1 {
			one++
		} else {
			two++
		}
	}

	if one == n || two == n {
		fmt.Println(PrintIntsLine(A...))
		return
	}

	B := []int{2, 1}
	one--
	two--
	for i := 0; i < two; i++ {
		B = append(B, 2)
	}
	for i := 0; i < one; i++ {
		B = append(B, 1)
	}
	fmt.Println(PrintIntsLine(B...))
}

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

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

// Author: sighduck
// URL: https://codeforces.com/contest/1150/problem/C

package main

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

func Solve(n int, a []int) []int {
	count := make(map[int]int)
	for _, elem := range a {
		count[elem] += 1
	}
	solution := []int{}
	if count[1] == 0 {
		for i := 0; i < count[2]; i++ {
			solution = append(solution, 2)
		}
		return solution
	} else if count[2] == 0 {
		for i := 0; i < count[1]; i++ {
			solution = append(solution, 1)
		}
		return solution
	}
	solution = append(solution, 2)
	solution = append(solution, 1)
	for i := 0; i < count[2]-1; i++ {
		solution = append(solution, 2)
	}
	for i := 0; i < count[1]-1; i++ {
		solution = append(solution, 1)
	}
	return solution
}

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

	var n int
	fmt.Fscan(reader, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}
	b := Solve(n, a)
	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%d ", b[i])
	}
	fmt.Fprintf(writer, "\n")
}


The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.Polycarp is a very famous freelancer. His current rating is $$$r$$$ units.Some very rich customers asked him to complete some projects for their companies. To complete the $$$i$$$-th project, Polycarp needs to have at least $$$a_i$$$ units of rating; after he completes this project, his rating will change by $$$b_i$$$ (his rating will increase or decrease by $$$b_i$$$) ($$$b_i$$$ can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.Polycarp can choose the order in which he completes projects. Furthermore, he can even skip some projects altogether.To gain more experience (and money, of course) Polycarp wants to choose the subset of projects having maximum possible size and the order in which he will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.Your task is to calculate the maximum possible size of such subset of projects.

The first line of the input contains two integers $$$n$$$ and $$$r$$$ ($$$1 \le n \le 100, 1 \le r \le 30000$$$) — the number of projects and the initial rating of Polycarp, respectively. The next $$$n$$$ lines contain projects, one per line. The $$$i$$$-th project is represented as a pair of integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i \le 30000$$$, $$$-300 \le b_i \le 300$$$) — the rating required to complete the $$$i$$$-th project and the rating change after the project completion.

Print one integer — the size of the maximum possible subset (possibly, empty) of projects Polycarp can choose.

package main
import "fmt"
import "os"
import "bufio"
import "sort"

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

type Node struct{
     x, y int
}

type Nodes []Node

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

func (s Nodes) Less(i, j int) bool {
    return s[i].x+s[i].y > s[j].x+s[j].y
}

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

func main(){
    input := bufio.NewReader(os.Stdin)
    var n, r int;
    fmt.Fscanf(input, "%d%d\n", &n, &r)

    var a,b Nodes

    for i:=1; i<=n; i++ {
        var x, y int
        fmt.Fscanf(input, "%d%d\n", &x, &y)
        if y>=0 {
            a = append(a, Node{x, y})
        } else {
            b = append(b, Node{x, y})
        }
    }

    cnta := 0
    for update:=true; update; {
        update = false
        for i:=0; i<len(a); i++ {
            if a[i].x == 0 {
                continue
            }
            if r>=a[i].x {
                r += a[i].y
                cnta++; a[i].x = 0
                update = true
            }
        }
    }
    /*
    if cnta != len(a) {
        fmt.Println("NO")
        return
    }
    */

    sort.Sort(b)
    /*
    for i:=0; i<len(b); i++ {
        fmt.Printf("%d %d\n", b[i].x, b[i].y)
    }
    */

    var dp [105][60005]int

    for i:=len(b)-1; i>=0; i-- {
        for j:=0; j<=r; j++ {
            dp[i][j]=dp[i+1][j]
            if j>=b[i].x && j+b[i].y>=0 {
                dp[i][j]=max(dp[i][j], dp[i+1][j+b[i].y]+1)
            }
        }
    }
    ans := cnta + dp[0][r]
    fmt.Println(ans)
}


In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of $$$n$$$ students doing yet another trick. Let's assume that all these students are numbered from $$$1$$$ to $$$n$$$. The teacher came to student $$$a$$$ and put a hole in his badge. The student, however, claimed that the main culprit is some other student $$$p_a$$$.After that, the teacher came to student $$$p_a$$$ and made a hole in his badge as well. The student in reply said that the main culprit was student $$$p_{p_a}$$$.This process went on for a while, but, since the number of students was finite, eventually the teacher came to the student, who already had a hole in his badge.After that, the teacher put a second hole in the student's badge and decided that he is done with this process, and went to the sauna.You don't know the first student who was caught by the teacher. However, you know all the numbers $$$p_i$$$. Your task is to find out for every student $$$a$$$, who would be the student with two holes in the badge if the first caught student was $$$a$$$.

The first line of the input contains the only integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of the naughty students. The second line contains $$$n$$$ integers $$$p_1$$$, ..., $$$p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ indicates the student who was reported to the teacher by student $$$i$$$.

For every student $$$a$$$ from $$$1$$$ to $$$n$$$ print which student would receive two holes in the badge, if $$$a$$$ was the first student caught by the teacher.

NoteThe picture corresponds to the first example test case.  When $$$a = 1$$$, the teacher comes to students $$$1$$$, $$$2$$$, $$$3$$$, $$$2$$$, in this order, and the student $$$2$$$ is the one who receives a second hole in his badge.When $$$a = 2$$$, the teacher comes to students $$$2$$$, $$$3$$$, $$$2$$$, and the student $$$2$$$ gets a second hole in his badge. When $$$a = 3$$$, the teacher will visit students $$$3$$$, $$$2$$$, $$$3$$$ with student $$$3$$$ getting a second hole in his badge.For the second example test case it's clear that no matter with whom the teacher starts, that student would be the one who gets the second hole in his badge.

package main
import(
	"fmt"
)

var res []int
var p []int
var ch chan int
var curr map[int]struct{} //used as a set

func main()  {
	var n int
	fmt.Scan(&n)
	p = make([]int, n+1)
	res = make([]int, n+1)
	ch = make(chan int,n+1)
	curr = make(map[int]struct{})
	for i:=1; i <= n; i++{
		fmt.Scan(&p[i])
	}

	for i:=1; i <= n; i++{
		if res[i] != 0 {continue} //already know

		ch <- i //enqueue
		curr[i] = struct{}{}
		t := i //current item
		for{
			if res[p[t]] != 0{ //already know
				ln := len(ch)
				for i := 0; i < ln; i++{
					tmp := <- ch
					res[tmp] = res[p[t]]
					delete(curr,i)
				}
				break
			}
			ch <- p[t] //enqueue
			t = p[t]
			if _,ok := curr[t]; !ok{ //not in the set
				curr[t] = struct{}{} //add to the set
			}else{
				for{ //dequeue
					tmp := <- ch
					res[tmp] = t //first parts point to the first occurence
					delete(curr,tmp)
					if(tmp == t){break}
				}
				ln := len(ch)
				for i := 0; i < ln; i++{ //second parts point to self
					tmp := <- ch
					res[tmp] = tmp
					delete(curr,tmp)
				}
				break
			}
		}
	}
	fmt.Printf("%d",res[1])
	for i:=2; i <= n; i++{
		fmt.Printf(" %d",res[i])
	}
}

package main

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

func main()  {

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d ", &arr[i])
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", findPos(i, arr))
	}

}

func findPos(i int, arr []int) int {

	x := make([]int, len(arr))

	x[i]++
	pos := arr[i] - 1
	for {
		x[pos]++
		if x[pos] == 2 {
			break
		}
		pos = arr[pos] - 1
	}

	return pos + 1

}

package main

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

var (
	g    [][]int
	used []bool
)

func cycle(v int) int {
	if used[v] || len(g[v]) == 0 {
		return v
	}
	used[v] = true
	return cycle(g[v][0])
}

func main() {
	var (
		n   int
		s   []string
		err error
	)

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		n, err = strconv.Atoi(scanner.Text())
		if err != nil {
			panic(err)
		}
	}
	if scanner.Scan() {
		s = strings.Fields(scanner.Text())
	}
	nums := make([]int, n)
	for i := range s {
		nums[i], err = strconv.Atoi(s[i])
		if err != nil {
			panic(err)
		}
		nums[i]--
	}
	g = make([][]int, n)
	used = make([]bool, n)
	for i := range nums {
		g[i] = append(g[i], nums[i])
	}
	for i := 0; i < n; i++ {
		used = make([]bool, n)
		fmt.Printf("%d ", cycle(i)+1)
	}
	fmt.Printf("\n")
}

package main

import (
    "fmt"
)

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

var reader SReader

var (
	p [1001]int
	m [1001]int
	n int
)

func run(a int) {
	for i := range m {
		m[i] = 0
	}

	m[a] += 1
	for {
		a = p[a]
		if m[a] == 1 {
			fmt.Println(a)
			return
		} else {
			m[a] += 1
		}
	}
}

func main() {
    reader.Init()
	n := int(reader.ReadInt())
	for i := 1; i <= n; i++ {
		p[i] = int(reader.ReadInt())
	}

	for i := 1; i <= n; i++ {
		run(i)
	}

}

// a,b,m > 0
func pow(a, b, m int64) (res int64) {
	res = 1
	a2 := a // base a^1/a^2/a^4...
	for b > 0 {
		if b & 1 == 1 {
			res *= a2
			res %= m
		}

		a2 *= a2
		a2 %= m
		b >>= 1
	}

	return
}

// reader
type SReader struct {
    file *os.File
    scanner *bufio.Scanner
}

func (this *SReader) Init() {
    this.file = os.Stdin
    this.scanner = bufio.NewScanner(this.file)
    this.scanner.Split(bufio.ScanWords)
}

func (this *SReader) ReadInt() int64 {
    this.scanner.Scan()
    n, err:= strconv.ParseInt(this.scanner.Text(), 10, 64)
    if err != nil {
        panic(err)
    }
    return int64(n)
}

package main

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

func main()  {

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d ", &arr[i])
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", find(i, arr))
	}

}

func find(i int, arr []int) int {

	x := make([]int, len(arr))
	pos := arr[i] - 1

	for x[pos] < 1 {
		x[pos]++
		pos = arr[pos] - 1
	}

	return pos + 1

}

package main

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

func main()  {

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)

	arr := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d ", &arr[i])
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", findPos(i, arr))
	}

}

func findPos(i int, arr []int) int {

	x := make([]int, len(arr))
	pos := arr[i] - 1

	for x[pos] < 1 {
		x[pos]++
		pos = arr[pos] - 1
	}

	return pos + 1

}

package main

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

var (
	g    [][]int
	used []bool
)

func cycle(v int) int {
	if used[v] {
		return v
	}
	used[v] = true
	for i := range g[v] {
		used[g[v][i]] = true
		return cycle(g[v][i])
	}
	return v
}

func main() {
	var (
		n   int
		s   []string
		err error
	)

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		n, err = strconv.Atoi(scanner.Text())
		if err != nil {
			panic(err)
		}
	}
	if scanner.Scan() {
		s = strings.Fields(scanner.Text())
	}
	nums := make([]int, n)
	for i := range s {
		nums[i], err = strconv.Atoi(s[i])
		if err != nil {
			panic(err)
		}
	}
	g = make([][]int, n)
	used = make([]bool, n)
	idx := 0
	for i := range nums {
		if nums[i] == i+1 {
			continue
		}
		g[idx] = append(g[idx], nums[i]-1)
		idx = nums[i] - 1
	}
	for i := 0; i < n; i++ {
		used = make([]bool, n)
		fmt.Printf("%d ", cycle(i)+1)
	}
	fmt.Printf("\n")
}

package main

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

var (
	g    [][]int
	used []bool
)

func cycle(v int) int {
	if used[v] {
		return v
	}
	used[v] = true
	if len(g[v]) > 0 {
		return cycle(g[v][0])
	}
	return v
}

func main() {
	var (
		n   int
		s   []string
		err error
	)

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		n, err = strconv.Atoi(scanner.Text())
		if err != nil {
			panic(err)
		}
	}
	if scanner.Scan() {
		s = strings.Fields(scanner.Text())
	}
	nums := make([]int, n)
	for i := range s {
		nums[i], err = strconv.Atoi(s[i])
		if err != nil {
			panic(err)
		}
	}
	g = make([][]int, n)
	used = make([]bool, n)
	idx := 0
	for i := range nums {
		if nums[i] == i+1 {
			continue
		}
		g[idx] = append(g[idx], nums[i]-1)
		idx = nums[i] - 1
	}
	for i := 0; i < n; i++ {
		used = make([]bool, n)
		fmt.Printf("%d ", cycle(i)+1)
	}
	fmt.Printf("\n")
}


Today is a holiday in the residence hall — Oleh arrived, in honor of which the girls gave him a string. Oleh liked the gift a lot, so he immediately thought up and offered you, his best friend, the following problem.You are given a string $$$s$$$ of length $$$n$$$, which consists of the first $$$17$$$ lowercase Latin letters {$$$a$$$, $$$b$$$, $$$c$$$, $$$\ldots$$$, $$$p$$$, $$$q$$$} and question marks. And $$$q$$$ queries. Each query is defined by a set of pairwise distinct lowercase first $$$17$$$ letters of the Latin alphabet, which can be used to replace the question marks in the string $$$s$$$.The answer to the query is the sum of the number of distinct substrings that are palindromes over all strings that can be obtained from the original string $$$s$$$ by replacing question marks with available characters. The answer must be calculated modulo $$$998\,244\,353$$$.Pay attention! Two substrings are different when their start and end positions in the string are different. So, the number of different substrings that are palindromes for the string aba will be $$$4$$$: a, b, a, aba.Consider examples of replacing question marks with letters. For example, from the string aba??ee when querying {$$$a$$$, $$$b$$$} you can get the strings ababaee or abaaaee but you cannot get the strings pizza,  abaee, abacaba, aba?fee, aba47ee, or abatree.Recall that a palindrome is a string that reads the same from left to right as from right to left.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1\,000$$$) — the length of the string $$$s$$$. The second line contains the string $$$s$$$, which consists of $$$n$$$ lowercase Latin letters and question marks. It is guaranteed that all letters in the string belong to the set {$$$a$$$, $$$b$$$, $$$c$$$, $$$\ldots$$$, $$$p$$$, $$$q$$$}. The third line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. This is followed by $$$q$$$ lines, each containing a single line $$$t$$$ — a set of characters that can replace question marks ($$$1 \le |t| \le 17$$$). It is guaranteed that all letters in the string belong to the set {$$$a$$$, $$$b$$$, $$$c$$$, $$$\ldots$$$, $$$p$$$, $$$q$$$} and occur at most once.

For each query print one number — the total numbers of palindromic substrings in all strings that can be obtained from the string $$$s$$$, modulo $$$998\,244\,353$$$.

7
ab??aba
8
a
b
ab
abc
abcd
abcde
abcdef
abcdefg

11
???????????
6
abcdefghijklmnopq
ecpnkhbmlidgfjao
olehfan
codef
glhf
q

NoteConsider the first example and the first query in it. We can get only one string as a result of replacing the question marks  — abaaaba. It has the following palindrome substrings:   a  — substring [$$$1$$$; $$$1$$$].  b  — substring [$$$2$$$; $$$2$$$].  a  — substring [$$$3$$$; $$$3$$$].  a  — substring [$$$4$$$; $$$4$$$].  a  — substring [$$$5$$$; $$$5$$$].  b  — substring [$$$6$$$; $$$6$$$].  a  — substring [$$$7$$$; $$$7$$$].  aa  — substring [$$$3$$$; $$$4$$$].  aa  — substring [$$$4$$$; $$$5$$$].  aba  — substring [$$$1$$$; $$$3$$$].  aaa  — substring [$$$3$$$; $$$5$$$].  aba  — substring [$$$5$$$; $$$7$$$].  baaab  — substring [$$$2$$$; $$$6$$$].  abaaaba  — substring [$$$1$$$; $$$7$$$]. In the third request, we get 4 lines: abaaaba, abababa, abbaaba, abbbaba.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
const MOD int64 = 998244353
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N := gi(); S := gs(); Q := gi(); QS := make([]string,Q); for i:=0;i<Q;i++ { QS[i] = gs() }
	cumq := make([]int,N); numq := 0; for i,c := range S { if c == '?' { numq++ }; cumq[i] = numq }
	powarr := make([][]int64,18); for i:=0;i<=17;i++ { powarr[i] = make([]int64,N+1) }
	for i:=int64(1);i<=17;i++ { v := int64(1); powarr[i][0] = v; for j:=1;j<=N;j++ { v *= i; v %= MOD; powarr[i][j] = v } }
	bm := make([][]int,N);  for i:=0;i<N;i++ { bm[i] = make([]int,N) }
	free := make([][]int,N);  for i:=0;i<N;i++ { free[i] = make([]int,N) }
	outside := make([][]int,N); for i:=0;i<N;i++ { outside[i] = make([]int,N) }
	A := make([][]int64,18); for i:=1;i<=17;i++ { A[i] = make([]int64,1<<17) }
	for sz:=1;sz<=N;sz++ {
		for i:=0;i<N-sz+1;i++ {
			j := i + sz - 1
			outside[i][j] = numq - cumq[j]; if i-1 >= 0 { outside[i][j] += cumq[i-1] }
			if sz == 1 {
				if S[i] == '?' {
					free[i][j] = 1; bm[i][j] = 0
				} else {
					free[i][j] = 0; bm[i][j] = 0
				}
			} else if sz == 2 {
				if S[i] == '?' && S[j] == '?' {
					free[i][j] = 1; bm[i][j] = 0
				} else if S[i] == '?' {
					free[i][j] = 0; bm[i][j] = 1 << uint(S[j]-'a')
				} else if S[j] == '?' {
					free[i][j] = 0; bm[i][j] = 1 << uint(S[i]-'a')
				} else if S[i] == S[j] {
					free[i][j] = 0; bm[i][j] = 0
				} else {
					free[i][j] = -1
				}
			} else {
				if free[i+1][j-1] < 0 {
					free[i][j] = -1
				} else if S[i] == '?' && S[j] == '?' {
					free[i][j] = free[i+1][j-1]+1; bm[i][j] = bm[i+1][j-1];
				} else if S[i] == '?' {
					free[i][j] = free[i+1][j-1]; bm[i][j] = bm[i+1][j-1] | (1 << uint(S[j]-'a'));
				} else if S[j] == '?' {
					free[i][j] = free[i+1][j-1]; bm[i][j] = bm[i+1][j-1] | (1 << uint(S[i]-'a'));
				} else if S[i] == S[j] {
					free[i][j] = free[i+1][j-1]; bm[i][j] = bm[i+1][j-1]
				} else {
					free[i][j] = -1
				}
			}
			if free[i][j] >= 0 {
				lbm := bm[i][j]
				myexp := free[i][j] + outside[i][j]
				for q:=1;q<=17;q++ { A[q][lbm] += powarr[q][myexp]; A[q][lbm] %= MOD }
			}
		}
	}
	// Now for sum of subsets
	F := make([][]int64,18); for i:=1;i<=17;i++ { F[i] = make([]int64,1<<17) }
	for q:=1;q<=17;q++ {
		for bm:=0;bm<1<<17;bm++ { F[q][bm] = A[q][bm] }
		for i:=uint(0);i<17;i++ {
			for bm:=0;bm<1<<17;bm++ {
				if bm & (1<<i) != 0 {
					F[q][bm] += F[q][bm ^ (1<<i)]
					F[q][bm] %= MOD
				}
			}
		}
	}
	for _,s := range QS {
		bm := 0; for _,c := range s { bm = bm | (1 << uint(c-'a')) }
		ls := len(s)
		ans := F[ls][bm]
		fmt.Fprintln(wrtr,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
const MOD int64 = 998244353
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N := gi(); S := gs(); Q := gi(); QS := make([]string,Q); for i:=0;i<Q;i++ { QS[i] = gs() }
	cumq := make([]int,N); numq := 0; for i,c := range S { if c == '?' { numq++ }; cumq[i] = numq }
	powarr := make([][]int64,18); for i:=0;i<=17;i++ { powarr[i] = make([]int64,N+1) }
	for i:=int64(1);i<=17;i++ { v := int64(1); powarr[i][0] = v; for j:=1;j<=N;j++ { v *= i; v %= MOD; powarr[i][j] = v } }
	bm := make([][]int,N);  for i:=0;i<N;i++ { bm[i] = make([]int,N) }
	free := make([][]int,N);  for i:=0;i<N;i++ { free[i] = make([]int,N) }
	outside := make([][]int,N); for i:=0;i<N;i++ { outside[i] = make([]int,N) }
	A := make([][]int64,18); for i:=1;i<=17;i++ { A[i] = make([]int64,1<<17) }
	for sz:=1;sz<=N;sz++ {
		for i:=0;i<N-sz+1;i++ {
			j := i + sz - 1
			outside[i][j] = numq - cumq[j]; if i-1 >= 0 { outside[i][j] += cumq[i-1] }
			if sz == 1 {
				if S[i] == '?' {
					free[i][j] = 1; bm[1][j] = 0
				} else {
					free[i][j] = 0; bm[i][j] = 0
				}
			} else if sz == 2 {
				if S[i] == '?' && S[j] == '?' {
					free[i][j] = 1; bm[i][j] = 0
				} else if S[i] == '?' {
					free[i][j] = 0; bm[i][j] = 1 << uint(S[j]-'a')
				} else if S[j] == '?' {
					free[i][j] = 0; bm[i][j] = 1 << uint(S[i]-'a')
				} else if S[i] == S[j] {
					free[i][j] = 0; bm[i][j] = 0
				} else {
					free[i][j] = -1
				}
			} else {
				if free[i+1][j-1] < 0 {
					free[i][j] = -1
				} else if S[i] == '?' && S[j] == '?' {
					free[i][j] = free[i+1][j-1]+1; bm[i][j] = bm[i+1][j-1];
				} else if S[i] == '?' {
					free[i][j] = free[i+1][j-1]; bm[i][j] = bm[i+1][j-1] | (1 << uint(S[j]-'a'));
				} else if S[j] == '?' {
					free[i][j] = free[i+1][j-1]; bm[i][j] = bm[i+1][j-1] | (1 << uint(S[i]-'a'));
				} else if S[i] == S[j] {
					free[i][j] = free[i+1][j-1]; bm[i][j] = bm[i+1][j-1]
				} else {
					free[i][j] = -1
				}
			}
			if free[i][j] >= 0 {
				lbm := bm[i][j]
				myexp := free[i][j] + outside[i][j]
				for q:=1;q<=17;q++ { A[q][lbm] += powarr[q][myexp]; A[q][lbm] %= MOD }
			}
		}
	}
	// Now for sum of subsets
	F := make([][]int64,18); for i:=1;i<=17;i++ { F[i] = make([]int64,1<<17) }
	for q:=1;q<=17;q++ {
		for bm:=0;bm<1<<17;bm++ { F[q][bm] = A[q][bm] }
		for i:=uint(0);i<17;i++ {
			for bm:=0;bm<1<<17;bm++ {
				if bm & (1<<i) != 0 {
					F[q][bm] += F[q][bm ^ (1<<i)]
				}
			}
		}
	}
	for _,s := range QS {
		bm := 0; for _,c := range s { bm = bm | (1 << uint(c-'a')) }
		ls := len(s)
		ans := F[ls][bm]
		fmt.Fprintln(wrtr,ans)
	}
}


You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers.Consider a number axis. The capital of your empire is initially at $$$0$$$. There are $$$n$$$ unconquered kingdoms at positions $$$0<x_1<x_2<\ldots<x_n$$$. You want to conquer all other kingdoms.There are two actions available to you:   You can change the location of your capital (let its current position be $$$c_1$$$) to any other conquered kingdom (let its position be $$$c_2$$$) at a cost of $$$a\cdot |c_1-c_2|$$$.  From the current capital (let its current position be $$$c_1$$$) you can conquer an unconquered kingdom (let its position be $$$c_2$$$) at a cost of $$$b\cdot |c_1-c_2|$$$. You cannot conquer a kingdom if there is an unconquered kingdom between the target and your capital. Note that you cannot place the capital at a point without a kingdom. In other words, at any point, your capital can only be at $$$0$$$ or one of $$$x_1,x_2,\ldots,x_n$$$. Also note that conquering a kingdom does not change the position of your capital.Find the minimum total cost to conquer all kingdoms. Your capital can be anywhere at the end.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. The description of each test case follows. The first line of each test case contains $$$3$$$ integers $$$n$$$, $$$a$$$, and $$$b$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$1 \leq a,b \leq 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \ldots, x_n$$$ ($$$1 \leq x_1 < x_2 < \ldots < x_n \leq 10^8$$$). The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer  — the minimum cost to conquer all kingdoms.

NoteHere is an optimal sequence of moves for the second test case:  Conquer the kingdom at position $$$1$$$ with cost $$$3\cdot(1-0)=3$$$.  Move the capital to the kingdom at position $$$1$$$ with cost $$$6\cdot(1-0)=6$$$.  Conquer the kingdom at position $$$5$$$ with cost $$$3\cdot(5-1)=12$$$.  Move the capital to the kingdom at position $$$5$$$ with cost $$$6\cdot(5-1)=24$$$.  Conquer the kingdom at position $$$6$$$ with cost $$$3\cdot(6-5)=3$$$.  Conquer the kingdom at position $$$21$$$ with cost $$$3\cdot(21-5)=48$$$.  Conquer the kingdom at position $$$30$$$ with cost $$$3\cdot(30-5)=75$$$. The total cost is $$$3+6+12+24+3+48+75=171$$$. You cannot get a lower cost than this.

package main

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

func main() {
	// this problem looks soooooo boring
	var reader *bufio.Reader = bufio.NewReader(os.Stdin)
	var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var T int
	fmt.Scan(&T)
	var n int
	var a, b int64

	for t := 0; t < T; t++ {
		fmt.Fscan(reader, &n, &a, &b)
		xs := make([]int64, n+1)
		xs[0] = 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &xs[i+1])
		}
		var ans int64 = 10000000000000000
		var prev int64 = -1
		var cnt int64 = 0
		var sm int64 = 0
		for i := n; i >= 0; i-- {
			if i != n {
				sm += cnt * (prev - xs[i])
			}
			val := xs[i]*a + xs[i]*b
			val += b * sm
			if val < ans {
				ans = val
			}
			prev = xs[i]
			cnt++
		}
		fmt.Fprintln(writer, ans)
	}
}

package main

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

const (
	INF = 3e5 + 10
	L0  = int64(0)
	L1  = int64(1)
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, a, b int64
		Fscan(in, &n, &a, &b)

		d := make([]int64, n)
		for i := L0; i < n; i++ {
			Fscan(in, &d[i])
		}

		ans := L0
		cur := L0
		for i := L0; i < n; i++ {
			x := n - i - 1
			if x*b > a {
				ans += (a + b) * (d[i] - cur)
				cur = d[i]
			} else {
				ans += b * (d[i] - cur)
			}
		}
		Fprintln(out, ans)
	}

}

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

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

package main

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

//func main() {
//	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
//	defer out.Flush()
//	var t int
//	fmt.Fscan(in, &t)
//
//	for ii := 0; ii < t; ii++ {
//		var n, r, b int
//		fmt.Fscan(in, &n, &r, &b)
//
//		each := 1
//		for r > each*(b+1) {
//			each++
//		}
//		sb := strings.Builder{}
//		for r > 0 || b > 0 {
//			for i := 0; i < each && r > 0; i++ {
//				sb.WriteByte('R')
//				r--
//			}
//			if b > 0 {
//				b--
//				sb.WriteByte('B')
//			}
//		}
//		fmt.Fprintln(out, sb.String())
//	}
//
//}

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		var a, b int64
		fmt.Fscan(in, &n, &a, &b)
		nums := make([]int64, n)
		var sum, ans, all int64

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

		ans = b * all
		sum = nums[0]

		for i := 1; i < n; i++ {
			//fmt.Println(all, sum, i, (all-sum-int64(n-i)*nums[i-1])*b+a*nums[i-1])
			if ans > (all-sum-int64(n-i)*nums[i-1])*b+(b+a)*nums[i-1] {
				ans = (all-sum-int64(n-i)*nums[i-1])*b + (b+a)*nums[i-1]
			}
			sum += nums[i]
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

func main() {
	defer writer.Flush()

	const INF int64 = 10000000000000000
	var T int
	fmt.Fscan(reader, &T)

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

		var x []int64
		var sum []int64
		x = make([]int64, n+1)
		sum = make([]int64, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(reader, &x[i])
			sum[i] = sum[i-1] + x[i]
		}

		var ans int64 = INF
		for i := 0; i <= n; i++ {
			if ans > int64(a)*x[i]+int64(b)*(sum[n]-sum[i]-int64(n-i-1)*x[i]) {
				ans = int64(a)*x[i] + int64(b)*(sum[n]-sum[i]-int64(n-i-1)*x[i])
			}
		}
		fmt.Fprintf(writer, "%v\n", ans)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n, a, b int64
	fmt.Fscan(in, &n, &a, &b)
	arr := make([]int64, n+1)
	for i := int64(1); i <= n; i++ {
		fmt.Fscan(in, &arr[i])
	}
	n++
	prefix := make([]int64, n+1)
	for i := int64(0); i < n; i++ {
		prefix[i+1] = prefix[i] + arr[i]
	}
	ans := int64(1e18)
	for i := int64(0); i < n; i++ {
		ans = min(ans, (a+b)*(arr[i]-arr[0])+b*(prefix[n]-prefix[i+1]-arr[i]*(n-i-1)))
	}
	fmt.Fprintln(out, ans)
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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
		var a, b int64
		fmt.Fscan(in, &n, &a, &b)

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

		var mc int64
		var last int64
		max := d * b
		for i, v := range arr {
			mc += (v-last)*a + (v-last)*b
			d -= v
			c := mc + (d-(v*int64(n-i-1)))*b
			if c < max {
				max = c
			}
			last = v
		}

		fmt.Fprintln(out, max)
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n := _int()
		a := _int64()
		b := _int64()
		x := make([]int64, n)
		for i := range x {
			x[i] = _int64()
		}
		printf("%d\n", sol(n, a, b, x))
	}
}

func sol(n int, a, b int64, x []int64) int64 {
	ret := b * sum(x)
	curr := ret
	c := int64(0)
	for i, k := range x {
		curr += a * (k - c)
		curr -= b * int64(n-1-i) * (k - c)
		c = k
		ret = min(ret, curr)
	}
	return ret
}

func sum(x []int64) int64 {
	ret := int64(0)
	for _, i := range x {
		ret += i
	}
	return ret
}

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

package main

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

const (
	INF = 3e5 + 10
	L0  = int64(0)
	L1  = int64(1)
)

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

	var t int
	Fscan(in, &t)

	for k := 0; k < t; k++ {
		var n, a, b int64
		Fscan(in, &n, &a, &b)

		d := make([]int64, n)
		for i := L0; i < n; i++ {
			Fscan(in, &d[i])
		}

		ans := L0
		cur := L0
		for i := L0; i < n; i++ {
			if (n-i)*b > a && i != n-1 {
				ans += (a + b) * (d[i] - cur)
				cur = d[i]
			} else {
				ans += b * (d[i] - cur)
			}
		}
		Fprintln(out, ans)
	}

}

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

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

package main

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

//func main() {
//	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
//	defer out.Flush()
//	var t int
//	fmt.Fscan(in, &t)
//
//	for ii := 0; ii < t; ii++ {
//		var n, r, b int
//		fmt.Fscan(in, &n, &r, &b)
//
//		each := 1
//		for r > each*(b+1) {
//			each++
//		}
//		sb := strings.Builder{}
//		for r > 0 || b > 0 {
//			for i := 0; i < each && r > 0; i++ {
//				sb.WriteByte('R')
//				r--
//			}
//			if b > 0 {
//				b--
//				sb.WriteByte('B')
//			}
//		}
//		fmt.Fprintln(out, sb.String())
//	}
//
//}

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		var a, b int64
		fmt.Fscan(in, &n, &a, &b)
		nums := make([]int64, n)
		var sum, ans int64
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		if n == 1 {
			ans = b * nums[0]
		} else {
			change := 0
			sum = nums[0]
			for i := 1; i < n; i++ {
				sum += nums[i]
				if sum*b >= b*nums[i]+a*nums[i-1] {
					change = i - 1
				}
			}
			ans = b * sum
			if change != 0 {
				ans = a*nums[change] + b*nums[change]
				for i := change + 1; i < n; i++ {
					ans += (nums[i] - nums[change]) * b
				}
			}
			// 99  36+ 21*3
			//fmt.Println(change)

		}

		fmt.Fprintln(out, ans)
	}
}


This is an interactive problem.Ayush devised a new scheme to set the password of his lock. The lock has $$$k$$$ slots where each slot can hold integers from $$$1$$$ to $$$n$$$. The password $$$P$$$ is a sequence of $$$k$$$ integers each in the range $$$[1, n]$$$, $$$i$$$-th element of which goes into the $$$i$$$-th slot of the lock.To set the password of his lock, Ayush comes up with an array $$$A$$$ of $$$n$$$ integers each in the range $$$[1, n]$$$ (not necessarily distinct). He then picks $$$k$$$ non-empty mutually disjoint subsets of indices $$$S_1, S_2, ..., S_k$$$ $$$(S_i \underset{i \neq j} \cap S_j = \emptyset)$$$ and sets his password as $$$P_i = \max\limits_{j \notin S_i} A[j]$$$. In other words, the $$$i$$$-th integer in the password is equal to the maximum over all elements of $$$A$$$ whose indices do not belong to $$$S_i$$$.You are given the subsets of indices chosen by Ayush. You need to guess the password. To make a query, you can choose a non-empty subset of indices of the array and ask the maximum of all elements of the array with index in this subset. You can ask no more than 12 queries.

The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ $$$(2 \leq n \leq 1000, 1 \leq k \leq n)$$$ — the size of the array and the number of subsets. $$$k$$$ lines follow. The $$$i$$$-th line contains an integer $$$c$$$ $$$(1 \leq c \lt n)$$$ — the size of subset $$$S_i$$$, followed by $$$c$$$ distinct integers in the range $$$[1, n]$$$  — indices from the subset $$$S_i$$$. It is guaranteed that the intersection of any two subsets is empty.

NoteThe array $$$A$$$ in the example is $$$[1, 2, 3, 4]$$$. The length of the password is $$$2$$$. The first element of the password is the maximum of $$$A[2]$$$, $$$A[4]$$$ (since the first subset contains indices $$$1$$$ and $$$3$$$, we take maximum over remaining indices). The second element of the password is the maximum of $$$A[1]$$$, $$$A[3]$$$ (since the second subset contains indices $$$2$$$, $$$4$$$).Do not forget to read the string "Correct" / "Incorrect" after guessing the password.

package main

import (
	. "fmt"
	"sort"
)

func Q(q []int) (max int) {
	Print("? ", len(q))
	for _, v := range q {
		Print(" ", v)
	}
	Println()
	Scan(&max)
	return
}

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n, k, c int
	for Scan(&t); t > 0; t-- {
		Scan(&n, &k)
		a := make([][]int, k)
		for i := range a {
			Scan(&c)
			a[i] = make([]int, c)
			for j := range a[i] {
				Scan(&a[i][j])
			}
		}

		q := []int{}
		for i := 1; i <= n; i++ {
			q = append(q, i)
		}
		max := Q(q)
		ans := make([]int, k)
		for i := range ans {
			ans[i] = max
		}
		l, r := 0, k
		for r-l > 1 {
			m := (l + r) >> 1
			q = []int{}
			for _, ids := range a[l:m] {
				q = append(q, ids...)
			}
			if Q(q) < max {
				l = m
			} else {
				r = m
			}
		}
		sort.Ints(a[l])
		q = []int{}
		for i, j := 1, 0; i <= n; i++ {
			if j == len(a[l]) || i != a[l][j] {
				q = append(q, i)
			} else {
				j++
			}
		}
		ans[l] = Q(q)
		Print("!")
		for _, v := range ans {
			Print(" ", v)
		}
		Println()
		var s []byte
		Scan(&s)
	}
}

package main

import (
	. "fmt"
	"sort"
)

func Q(q []int) (max int) {
	Print("? ", len(q))
	for _, v := range q {
		Print(" ", v)
	}
	Println()
	Scan(&max)
	return
}

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n, k, c int
	for Scan(&t); t > 0; t-- {
		Scan(&n, &k)
		a := make([][]int, k)
		for i := range a {
			Scan(&c)
			a[i] = make([]int, c)
			for j := range a[i] {
				Scan(&a[i][j])
			}
		}

		ans := make([]int, k)
		q := []int{}
		for i := 1; i <= n; i++ {
			q = append(q, i)
		}
		max := Q(q)
		l, r := 0, k
		for r-l > 1 {
			m := (l + r) >> 1
			q = []int{}
			for _, ids := range a[l:m] {
				q = append(q, ids...)
			}
			if Q(q) < max {
				for i := l; i < m; i++ {
					ans[i] = max
				}
				l = m
			} else {
				for i := m; i < r; i++ {
					ans[i] = max
				}
				r = m
			}
		}
		sort.Ints(a[l])
		q = []int{}
		for i, j := 1, 0; i <= n; i++ {
			if j == len(a[l]) || i != a[l][j] {
				q = append(q, i)
			} else {
				j++
			}
		}
		ans[l] = Q(q)
		Print("!")
		for _, v := range ans {
			Print(" ", v)
		}
		Println()
		var s []byte
		Scan(&s)
	}
}

package main

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

type (
	input struct {
		n, k int
		a    [][]int
	}
	guess struct{ ans []int }
	qIn   struct{ q []int }
	qOut  struct{ max int }
)

// github.com/EndlessCheng/codeforces-go
func CF1363D(in input, Q func(qIn) qOut) (gs guess) {
	n, k, a := in.n, in.k, in.a
	gs.ans = make([]int, k)
	q := []int{}
	for i := 1; i <= n; i++ {
		q = append(q, i)
	}
	allMax := Q(qIn{q}).max
	l, r := 0, k
	for r-l > 1 {
		m := (l + r) >> 1
		q = []int{}
		for _, ids := range a[l:m] {
			q = append(q, ids...)
		}
		max := Q(qIn{q}).max
		if max == allMax {
			for i := m; i < r; i++ {
				gs.ans[i] = allMax
			}
			r = m
		} else {
			for i := l; i < m; i++ {
				gs.ans[i] = allMax
			}
			l = m
		}
	}
	sort.Ints(a[l])
	q = []int{}
	for i, j := 1, 0; i <= n; i++ {
		if j == len(a[l]) || i != a[l][j] {
			q = append(q, i)
		} else {
			j++
		}
	}
	gs.ans[l] = Q(qIn{q}).max
	return
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	Q := func(qi qIn) (resp qOut) {
		Fprint(out, "? ", len(qi.q))
		for _, v := range qi.q {
			Fprint(out, " ", v)
		}
		Fprintln(out)
		out.Flush()
		Fscan(in, &resp.max)
		return
	}
	var t, c int
	for Fscan(in, &t); t > 0; t-- {
		d := input{}
		Fscan(in, &d.n, &d.k)
		a := make([][]int, d.k)
		for i := range a {
			Fscan(in, &c)
			a[i] = make([]int, c)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
		}
		d.a = a
		gs := CF1363D(d, Q)
		Fprint(out, "!")
		for _, v := range gs.ans {
			Fprint(out, " ", v)
		}
		Fprintln(out)
		out.Flush()
		var s []byte
		Fscan(in, &s)
	}
}