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


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


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

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

}

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


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


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

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


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

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


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


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


package main

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

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

func readInt(delim byte) (int, error) {
	s, err := in.ReadString(delim)
	if err != nil {
		return 0, err

	}
	s = strings.TrimRight(s, " \r\n")
	n, err := strconv.Atoi(s)
	if err != nil {
		return 0, err
	}

	return n, nil
}

func main() {
	defer out.Flush()
	t, err := readInt('\n')
	if err != nil {
		out.WriteString("Error received in reading t: " + err.Error() + "\n")
	} else {
		for {
			if t == 0 {
				break
			}
			t--
			n, err := readInt('\n')
			if err != nil {
				out.WriteString("Error received in reading n: " + err.Error() + "\n")
			}
			s, err := in.ReadString('\n')
			if err != nil {
				out.WriteString("Error in reading string: " + err.Error())
				break
			}
			s = strings.TrimRight(s, " \r\n")
			if len(s) != n {
				out.WriteString("Not enough length\n")
				break
			}
			a := make([]int, 26)

			done := make([]bool, 26)
			tail := make([]int, 26)
			lens := make([]int, 26)
			head := make([]int, 26)
			for i := 0; i < 26; i++ {
				tail[i] = i
				lens[i] = 1
				a[i] = -1
				head[i] = i
			}
			for i := 0; i < n; i++ {
				cur := int(s[i] - 'a')
				//out.WriteRune(rune(cur + 'a'))
				if a[cur] == -1 {
					for j := 0; j < 26; j++ {
						if !done[j] && (tail[cur] != j || lens[cur] == 26) {
							a[cur] = j
							done[j] = true
							tail[head[j]] = tail[cur]
							head[tail[cur]] = head[j]
							lens[head[j]] += lens[cur]
							break
						}
					}
				}
				//out.WriteString(" " + string(a[cur]+'a') + "\n")
				out.WriteRune(rune(a[cur] + 'a'))
			}
			out.WriteString("\n")
		}
	}
}

package main

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

func get_cycle_length(next *map[string]string, root string) int {
	i := 1
	v := (*next)[root]
	for v != root {
		i++
		_, prs := (*next)[v]
		if !prs {
			i = -1
			break
		}
		v = (*next)[v]
	}
	return i
}

func get_new_parent(next *map[string]string, excl string) string {
	alpha := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	for _, a := range alpha {
		if _, prs := (*next)[a]; !prs && a != excl {
			(*next)[a] = excl
			cl := get_cycle_length(next, a)
			delete(*next, a)
			if cl != -1 && cl != 26 {
				continue
			}
			return a
		}
	}
	return "a"
}

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

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

		fmt.Fscan(r, &t)
		t_slice := strings.Split(t, "")

		next := make(map[string]string)
		parent := make(map[string]string)

		var s_slice []string
		for _, c := range t_slice {
			v, prs := parent[c]
			if !prs {
				v = get_new_parent(&next, c)
				parent[c] = v
				next[v] = c
			}
			s_slice = append(s_slice, v)
		}

		s = strings.Join(s_slice, "")
		fmt.Fprintln(w, s)
	}
}

package main

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

func get_cycle_length(next *map[string]string, root string) int {
	i := 1
	v := (*next)[root]
	for v != root && i < 30 {
		i++
		_, prs := (*next)[v]
		if !prs {
			i = -1
			break
		}
		v = (*next)[v]
	}
	return i
}

func get_new_parent(next *map[string]string, excl string) string {
	alpha := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	for _, a := range alpha {
		if _, prs := (*next)[a]; !prs && a != excl && (*next)[excl] != a {
			(*next)[a] = excl
			cl := get_cycle_length(next, a)
			delete(*next, a)
			// fmt.Println("%%% Alpha ", a) // ***
			// fmt.Println("%%% length of cycle ", cl) // ***
			if cl != -1 && cl != 26 {
				continue
			}
			return a
		}
	}
	return "a"
}

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

	var T, n int
	fmt.Fscan(r, &T)
	for i := 0; i < T; i++ {
		// fmt.Println("### TC ", i+1) // ***
		fmt.Fscan(r, &n)
		var t, s string

		fmt.Fscan(r, &t)
		t_slice := strings.Split(t, "")
		// fmt.Println("### t_slice ", t_slice) // ***

		next := make(map[string]string)
		parent := make(map[string]string)

		var s_slice []string
		for _, c := range t_slice {
			// fmt.Println("### Looping through t_slice, c ", c) // ***
			v, prs := parent[c]
			if !prs {
				v = get_new_parent(&next, c)
				parent[c] = v
				next[v] = c
			}
			// fmt.Println("### Looping through t_slice, parent of c ", parent[c]) // ***
			s_slice = append(s_slice, v)
			// fmt.Println("### Looping through t_slice, contents of s_slice ", s_slice) // ***
		}

		s = strings.Join(s_slice, "")
		fmt.Fprintln(w, s)
	}
}

package main

import (
	"bufio"
	"bytes"
	"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 s string
		fmt.Fscan(in, &n, &s)

		aa := make([]int, 26)
		bb := make([]int, 26)
		for i := range aa {
			aa[i] = -1
			bb[i] = 1
		}

		next := func(x int) int {
			var c int
			g := x
			for g != -1 {
				c++
				g = aa[g]
				if g == x {
					return c
				}
			}
			return -1
		}

		for _, ch := range s {
			if aa[ch-'a'] < 0 {
				for i := 0; i < 26; i++ {
					if bb[i] != 0 && i != int(ch-'a') {
						aa[ch-'a'] = i
						z := next(i)
						if z == -1 || z == 26 {
							bb[i] = 0
							break
						}
					}
				}
			}
		}

		var buf bytes.Buffer
		for _, ch := range s {
			buf.WriteRune(rune(aa[ch-'a'] + 'a'))
		}
		fmt.Fprintln(out, buf.String())
	}
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]byte, n)
	fmt.Fscan(in, &arr)
	transitions := make(map[byte]byte)
	var taken set[byte]
	ans := make([]byte, n)
loop:
	for i, char := range arr {
		val, ok := transitions[char]
		if ok {
			ans[i] = val
			continue
		}

		for ch := "a"[0]; ch <= "z"[0]; ch++ {
			if ch == char || taken.has(ch) {
				continue
			}
			res, ok := transitions[ch]
			transCnt := 1
			for ok && transCnt <= 26 {
				next, ok := transitions[res]
				if !ok {
					break
				}
				res = next
				transCnt++
				if res == char {
					break
				}
			}
			if ok && res == char && transCnt != 25 {
				continue
			}
			transitions[char] = ch
			ans[i] = ch
			taken.add(ch)
			continue loop
		}
	}
	fmt.Fprintln(out, string(ans))
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

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()
		ts := _string()
		printf("%s\n", sol(n, ts))
	}
}

func sol(n int, t string) string {
	sm := make26()
	tm := make26()
	count := 0
	for i := range t {
		// printf("mapping ch:%v\n", i)
		ch := int(t[i] - 'a')
		if tm[ch] != -1 {
			continue
		}
		// try each letter
		for i := range sm {
			// printf("trying candidate=%v->%v\n", i, ch)
			if i == ch {
				continue
			}
			// found candidate
			if sm[i] == -1 {
				if count != 25 { // special case last letter
					// printf("sm=%v\n", sm)
					cyc := false
					to := sm[ch]
					for {
						// printf("to=%v\n", to)
						if to == -1 {
							break
						}
						if to == i {
							cyc = true
							break
						}
						to = sm[to]
					}
					// printf("cyc=%v\n", cyc)
					if cyc {
						// printf("cycle detected \n")
						continue
					}
				}
				sm[i] = ch
				tm[ch] = i
				count++
				break
			}
		}
	}
	ret := make([]rune, len(t))
	for i := range t {
		ch := t[i] - 'a'
		ret[i] = rune(tm[ch] + 'a')
	}
	return string(ret)
}

func make26() [26]int {
	ret := [26]int{}
	for i := range ret {
		ret[i] = -1
	}
	return ret
}

package main

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

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

func main() {
	defer out.Flush()

	var tc, n int
	var q [1e5 + 1]byte
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		var s string
		fmt.Fscan(in, &n, &s)
		var prev [128]byte
		for i, c := range s {
			c := byte(c)
			if prev[c] != 0 {
				q[i] = prev[c]
				continue
			}
			for ch := byte('a'); ch <= 'z'; ch++ {
				if ch == byte(c) {
					continue
				}
				ok := true
				for och := 'a'; ok && och <= 'z'; och++ {
					ok = prev[och] != ch
				}
				if !ok {
					continue
				}
				if prev[ch] != 0 {
					// don't form bad cycles
					startch, cyclelen := prev[ch], 1
					for ; prev[startch] != 0; startch = prev[startch] {
						cyclelen++
					}
					if startch == c && cyclelen < 25 {
						continue
					}
				}
				prev[c] = ch
				q[i] = ch
				break
			}
			if prev[c] == 0 {
				panic("internal error")
			}
		}
		fmt.Fprintln(out, string(q[:len(s)]))
	}
}

package main

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

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

func readInt(delim byte) (int, error) {
	s, err := in.ReadString(delim)
	if err != nil {
		return 0, err

	}
	s = strings.TrimRight(s, " \r\n")
	n, err := strconv.Atoi(s)
	if err != nil {
		return 0, err
	}

	return n, nil
}

func main() {
	defer out.Flush()
	t, err := readInt('\n')
	if err != nil {
		out.WriteString("Error received in reading t: " + err.Error() + "\n")
	} else {
		for {
			if t == 0 {
				break
			}
			t--
			n, err := readInt('\n')
			if err != nil {
				out.WriteString("Error received in reading n: " + err.Error() + "\n")
			}
			s, err := in.ReadString('\n')
			if err != nil {
				out.WriteString("Error in reading string: " + err.Error())
				break
			}
			s = strings.TrimRight(s, " \r\n")
			if len(s) != n {
				out.WriteString("Not enough length\n")
				break
			}
			a := make([]int, 26)

			done := make([]bool, 26)
			rep := make([]int, 26)
			lens := make([]int, 26)
			for i := 0; i < 26; i++ {
				rep[i] = i
				lens[i] = 1
				a[i] = -1
			}
			for i := 0; i < n; i++ {
				cur := int(s[i] - 'a')
				//out.WriteRune(rune(cur + 'a'))
				if a[cur] == -1 {
					for j := 0; j < 26; j++ {
						if !done[j] && (rep[cur] != j || lens[cur] == 26) {
							a[cur] = j
							done[j] = true
							rep[j] = rep[cur]
							lens[j] += lens[cur]
							break
						}
					}
				}
				//out.WriteString(" " + string(a[cur]+'a') + "\n")
				out.WriteRune(rune(a[cur] + 'a'))
			}
			out.WriteString("\n")
		}
	}
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]byte, n)
	fmt.Fscan(in, &arr)
	transitions := make(map[byte]byte)
	var taken set[byte]
	ans := make([]byte, n)
loop:
	for i, ch := range arr {
		val, ok := transitions[ch]
		if ok {
			ans[i] = val
			continue
		}

		cha := "a"[0]
		if taken.has(ch) {
			cha = ch + 1
		}

		for ; cha <= "z"[0]; cha++ {
			if cha == ch {
				continue
			}
			if taken.has(cha) {
				continue
			}
			taken.add(cha)
			transitions[ch] = cha
			ans[i] = cha
			continue loop
		}
		tmp := cha
		for cha := "a"[0]; cha < tmp; cha++ {
			if cha == ch {
				continue
			}
			if taken.has(cha) {
				continue
			}
			taken.add(cha)
			transitions[ch] = cha
			ans[i] = cha
			continue loop
		}
	}
	fmt.Fprintln(out, string(ans))
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}