You are given three positive (greater than zero) integers $$$c$$$, $$$d$$$ and $$$x$$$. You have to find the number of pairs of positive integers $$$(a, b)$$$ such that equality $$$c \cdot lcm(a, b) - d \cdot gcd(a, b) = x$$$ holds. Where $$$lcm(a, b)$$$ is the least common multiple of $$$a$$$ and $$$b$$$ and $$$gcd(a, b)$$$ is the greatest common divisor of $$$a$$$ and $$$b$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing three integer $$$c$$$, $$$d$$$ and $$$x$$$ ($$$1 \le c, d, x \le 10^7$$$).

For each test case, print one integer — the number of pairs ($$$a, b$$$) such that the above equality holds.

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	primes := make([]int, 0, 1270607)
	const mx int = 2e7
	o := make([]int8, mx+1)
	o[mx] = 0
	for i := 2; i <= mx; i++ {
		if o[i] == 0 {
			o[i] = 1
			primes = append(primes, i)
		}
		for _, p := range primes {
			if p*i > mx {
				break
			}
			if i%p == 0 {
				o[p*i] = o[i]
				break
			}
			o[p*i] = o[i] + 1
		}
	}

	for T := r(); T > 0; T-- {
		C, D, X := r(), r(), r()
		s, d := 0, 1
		for ; d*d < X; d++ {
			if X%d == 0 {
				if (D+d)%C == 0 {
					s += 1<<o[(D+d)/C]
				}
				if (D+X/d)%C == 0 {
					s += 1<<o[(D+X/d)/C]
				}
			}
		}
		if d*d == X && (D+d)%C == 0 {
			s += 1<<o[(D+d)/C]
		}
		Fprintln(out, s)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	primes := make([]int, 0, 1270607)
	const mx int = 2e7
	o := make([]int, mx+1)
	o[1] = 1
	o[mx] = 0
	for i := 2; i <= mx; i++ {
		if o[i] == 0 {
			o[i] = 2
			primes = append(primes, i)
		}
		for _, p := range primes {
			if p*i > mx {
				break
			}
			if i%p == 0 {
				o[p*i] = o[i]
				break
			}
			o[p*i] = o[i] << 1
		}
	}

	for T := r(); T > 0; T-- {
		C, D, X := r(), r(), r()
		s, d := 0, 1
		for ; d*d < X; d++ {
			if X%d == 0 {
				if (D+d)%C == 0 {
					s += o[(D+d)/C]
				}
				if (D+X/d)%C == 0 {
					s += o[(D+X/d)/C]
				}
			}
		}
		if d*d == X && (D+d)%C == 0 {
			s += o[(D+d)/C]
		}
		Fprintln(out, s)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<15, make([]byte, 1<<15)
	rc := func() byte {
		if _i == 1<<15 {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx int = 2e7
	o := make([]int, mx+1)
	o[1] = 1
	primes := make([]int, 0, 1270607)
	for i := 2; i <= mx; i++ {
		if o[i] == 0 {
			o[i] = 2
			primes = append(primes, i)
		}
		for _, p := range primes {
			if p*i > mx {
				break
			}
			if i%p == 0 {
				o[p*i] = o[i]
				break
			}
			o[p*i] = o[i] << 1
		}
	}

	for T := r(); T > 0; T-- {
		C, D, X := r(), r(), r()
		s, d := 0, 1
		for ; d*d < X; d++ {
			if X%d == 0 {
				if (D+d)%C == 0 {
					s += o[(D+d)/C]
				}
				if (D+X/d)%C == 0 {
					s += o[(D+X/d)/C]
				}
			}
		}
		if d*d == X && (D+d)%C == 0 {
			s += o[(D+d)/C]
		}
		Fprintln(out, s)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx int = 2e7
	o := make([]int, mx+1)
	o[1] = 1
	primes := make([]int, 0, 1270607)
	for i := 2; i <= mx; i++ {
		if o[i] == 0 {
			o[i] = 2
			primes = append(primes, i)
		}
		for _, p := range primes {
			if p*i > mx {
				break
			}
			if i%p == 0 {
				o[p*i] = o[i]
				break
			}
			o[p*i] = o[i] << 1
		}
	}

	for T := r(); T > 0; T-- {
		C, D, X := r(), r(), r()
		s, d := 0, 1
		for ; d*d < X; d++ {
			if X%d == 0 {
				if (D+d)%C == 0 {
					s += o[(D+d)/C]
				}
				if (D+X/d)%C == 0 {
					s += o[(D+X/d)/C]
				}
			}
		}
		if d*d == X && (D+d)%C == 0 {
			s += o[(D+d)/C]
		}
		Fprintln(out, s)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const M int = 2e7
	o := make([]int, M+1)
	for i := 2; i <= M; i++ {
		if o[i] == 0 {
			for j := i; j <= M; j += i {
				o[j]++
			}
		}
	}
	for T := r(); T > 0; T-- {
		C, D, X, s := r(), r(), r(), 0
		d := 1
		for ; d*d < X; d++ {
			if X%d == 0 {
				if (D+d)%C == 0 {
					s += 1 << o[(D+d)/C]
				}
				if (D+X/d)%C == 0 {
					s += 1 << o[(D+X/d)/C]
				}
			}
		}
		if d*d == X && (D+d)%C == 0 {
			s += 1 << o[(D+d)/C]
		}
		Fprintln(out, s)
	}
}

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	const M int = 2e7
	o := make([]int, M+1)
	for i := 2; i <= M; i++ {
		if o[i] == 0 {
			for j := i; j <= M; j += i {
				o[j]++
			}
		}
	}
	var T, c, D, x int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &c, &D, &x)
		a := []int{}
		for d := 1; d*d <= x; d++ {
			if x%d == 0 {
				a = append(a, d)
				if d*d < x {
					a = append(a, x/d)
				}
			}
		}
		s := 0
		for _, d := range a {
			if (D+d)%c == 0 {
				s += 1 << o[(D+d)/c]
			}
		}
		Println(s)
	}
}

package main

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

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

	const mx int = 2e7
	omega := make([]int, mx+1)
	for i := 2; i <= mx; i++ {
		if omega[i] == 0 {
			for j := i; j <= mx; j += i {
				omega[j]++
			}
		}
	}

	solve := func(Case int) {
		var c, D, x, ans int
		Fscan(in, &c, &D, &x)
		ds := []int{}
		for d := 1; d*d <= x; d++ {
			if x%d == 0 {
				ds = append(ds, d)
				if d*d < x {
					ds = append(ds, x/d)
				}
			}
		}
		for _, dv := range ds {
			if (D+dv)%c == 0 {
				ans += 1 << omega[(D+dv)/c]
			}
		}
		Fprintln(out, ans)
	}

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

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

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

package main

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

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

	const mx int = 1e6
	phi := [mx + 1]int{}
	for i := 1; i <= mx; i++ {
		phi[i] = i
	}
	for i := 2; i <= mx; i++ {
		if phi[i] == i {
			for j := i; j <= mx; j += i {
				phi[j] = phi[j] / i * (i - 1)
			}
		}
	}

	const mx2 int = 2e7
	lpf := make([]int, mx2+1)
	for i := 2; i <= mx2; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx2; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	o := func(x int) int {
		c := 1
		for x > 1 {
			p := lpf[x]
			for x /= p; lpf[x] == p; x /= p {
			}
			c++
		}
		return c
	}

	solve := func(Case int) {
		var c, d, x int
		Fscan(in, &c, &d, &x)
		ans := 0

		ds := []int{}
		for d := 1; d*d <= x; d++ {
			if x%d == 0 {
				ds = append(ds, d)
				if d*d < x {
					ds = append(ds, x/d)
				}
			}
		}
		for _, dv := range ds {
			if (d+dv)%c != 0 {
				continue
			}
			k := (d + dv) / c
			ans += phi[1<<o(k)]
		}
		Fprintln(out, ans)
	}

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

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

func main() { run(os.Stdin, os.Stdout) }
func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

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

var _rbuf = bufio.NewReader(os.Stdin)
var _wbuf = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { _wbuf.Flush(); fmt.Fscan(_rbuf, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_wbuf, f, a...) }

var T time.Time

func main() {
	defer _wbuf.Flush()

	var t int
	scan(&t)

	var factors []factor
	var divisors []int
	for ; t > 0; t-- {
		factors = factors[:0]
		divisors = divisors[:0]

		var c, d, x int
		scan(&c, &d, &x)

		sqx := int(math.Sqrt(float64(x)))
		n := x
		for i := 0; n > 1; i++ {
			p := primes[i]
			if p > sqx {
				break
			}
			if n%p == 0 {
				num := 1
				for n /= p; n%p == 0; n /= p {
					num++
				}
				factors = append(factors, factor{p, num})
			}
		}
		if n > 1 {
			factors = append(factors, factor{n, 1})
		}

		var res int
		divisors = dfs(factors, divisors)
		for _, f := range divisors {
			if (d+f)%c == 0 {
				m := (d + f) / c
				res += 1 << numdivs[m]
			}
		}
		printf("%d\n", res)
	}

	println("time:", time.Since(T).Milliseconds())
}

func dfs(factors []factor, divisors []int) []int {
	if len(factors) == 0 {
		return append(divisors, 1)
	}
	divisors = dfs(factors[1:], divisors)
	p := factors[0]
	n := len(divisors)
	for i := 0; i < n; i++ {
		f := 1
		for j := 0; j < p.num; j++ {
			f *= p.prime
			divisors = append(divisors, divisors[i]*f)
		}
	}
	return divisors
}

type factor struct {
	prime int
	num   int
}

const N = 20000001

var primes []int
var numdivs [N]int

func init() {
	T = time.Now()

	isPrime := make([]bool, N)
	for i := 2; i < N; i++ {
		isPrime[i] = true
	}
	primes = make([]int, 0, N/10)
	mindiv := make([]struct{ min, max int }, N)
	for i := 2; i < N; i++ {
		if isPrime[i] {
			primes = append(primes, i)
			mindiv[i].min = i
			mindiv[i].max = i
			numdivs[i] = 1
			k := 2
			for j := i + i; j < N; j += i {
				if isPrime[j] {
					mindiv[j].min = i
					mindiv[j].max = k
				}
				isPrime[j] = false
				k++
			}
		}
	}
	for i := 2; i < N; i++ {
		if isPrime[i] {
			continue
		}
		j := mindiv[i].max
		numdivs[i] = numdivs[j]
		if mindiv[i].min != mindiv[j].min {
			numdivs[i]++
		}
	}

	println("time:", time.Since(T).Milliseconds())
}

package main

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

var _rbuf = bufio.NewReader(os.Stdin)
var _wbuf = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { _wbuf.Flush(); fmt.Fscan(_rbuf, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_wbuf, f, a...) }

var T time.Time

func main() {
	defer _wbuf.Flush()

	var t int
	scan(&t)

	var factors []factor
	var divisors []int
	for ; t > 0; t-- {
		factors = factors[:0]
		divisors = divisors[:0]

		var c, d, x int
		scan(&c, &d, &x)

		sqx := int(math.Sqrt(float64(x)))
		n := x
		for i := 0; n > 1; i++ {
			p := primes[i]
			if p > sqx {
				break
			}
			if n%p == 0 {
				num := 1
				for n /= p; n%p == 0; n /= p {
					num++
				}
				factors = append(factors, factor{p, num})
			}
		}
		if n > 1 {
			factors = append(factors, factor{n, 1})
		}

		var res int
		divisors = dfs(factors, divisors)
		for _, f := range divisors {
			if m := (d + f) / c; (d+f)%c == 0 {
				res += 1 << numdivs[m]
			}
		}
		printf("%d\n", res)
	}

	println("time:", time.Since(T).Milliseconds())
}

func dfs(factors []factor, divisors []int) []int {
	if len(factors) == 0 {
		return append(divisors, 1)
	}
	divisors = dfs(factors[1:], divisors)
	p := factors[0]
	n := len(divisors)
	for i := 0; i < n; i++ {
		f := 1
		for j := 0; j < p.num; j++ {
			f *= p.prime
			divisors = append(divisors, divisors[i]*f)
		}
	}
	return divisors
}

type factor struct {
	prime int
	num   int
}

const N = 20000001

var primes []int
var numdivs [N]int

func init() {
	T = time.Now()

	mindiv := make([]int, N)
	maxdiv := make([]int, N)
	isPrime := make([]bool, N)
	for i := 2; i < N; i++ {
		isPrime[i] = true
	}
	primes = make([]int, 0, N/10)
	for i := 2; i < N; i++ {
		if isPrime[i] {
			primes = append(primes, i)
			mindiv[i] = i
			maxdiv[i] = i
			numdivs[i] = 1
			k := 2
			for j := i + i; j < N; j += i {
				if isPrime[j] {
					mindiv[j] = i
					maxdiv[j] = k
				}
				isPrime[j] = false
				k++
			}
		}
	}
	for i := 2; i < N; i++ {
		if isPrime[i] {
			continue
		}
		j := maxdiv[i]
		numdivs[i] = numdivs[j]
		if mindiv[i] != mindiv[j] {
			numdivs[i]++
		}
	}

	println("time:", time.Since(T).Milliseconds())
}

package main

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

var _rbuf = bufio.NewReader(os.Stdin)
var _wbuf = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { _wbuf.Flush(); fmt.Fscan(_rbuf, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_wbuf, f, a...) }

func main() {
	defer _wbuf.Flush()

	T := time.Now()

	var t int
	scan(&t)

	var factors []factor
	var divisors []int
	for ; t > 0; t-- {
		factors = factors[:0]
		divisors = divisors[:0]

		var c, d, x int
		scan(&c, &d, &x)

		sqx := int(math.Sqrt(float64(x)))
		n := x
		for i := 0; n > 1; i++ {
			p := primes[i]
			if p > sqx {
				break
			}
			if n%p == 0 {
				num := 1
				for n /= p; n%p == 0; n /= p {
					num++
				}
				factors = append(factors, factor{p, num})
			}
		}
		if n > 1 {
			factors = append(factors, factor{n, 1})
		}

		var res int
		divisors = dfs(factors, divisors)
		for _, f := range divisors {
			if m := (d + f) / c; (d+f)%c == 0 {
				res += 1 << numdivs[m]
			}
		}
		printf("%d\n", res)
	}

	println("time:", time.Since(T).Milliseconds())
}

func dfs(factors []factor, divisors []int) []int {
	if len(factors) == 0 {
		return append(divisors, 1)
	}
	divisors = dfs(factors[1:], divisors)
	p := factors[0]
	n := len(divisors)
	for i := 0; i < n; i++ {
		f := 1
		for j := 0; j < p.num; j++ {
			f *= p.prime
			divisors = append(divisors, divisors[i]*f)
		}
	}
	return divisors
}

type factor struct {
	prime int
	num   int
}

var N = 20000001
var primes []int
var mindiv []int
var numdivs []int

func init() {
	mindiv = make([]int, N)
	numdivs = make([]int, N)
	isPrime := make([]bool, N)
	for i := 2; i < N; i++ {
		isPrime[i] = true
	}
	for i := 2; i < N; i++ {
		if !isPrime[i] {
			continue
		}
		primes = append(primes, i)
		mindiv[i] = i
		for j := i + i; j < N; j += i {
			if isPrime[j] {
				mindiv[j] = i
			}
			isPrime[j] = false
		}
	}
	for i := 2; i < N; i++ {
		if isPrime[i] {
			numdivs[i] = 1
		} else {
			j := i / mindiv[i]
			numdivs[i] = numdivs[j]
			if mindiv[i] != mindiv[j] {
				numdivs[i]++
			}
		}
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		c, d, x := readThreeNums(reader)
		res := solve(c, d, x)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(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
}

const MAX_X = 20000010

var V [MAX_X]int

func init() {
	mind := make([]int, MAX_X)
	for i := 0; i < MAX_X; i++ {
		mind[i] = -1
	}
	for i := 2; i < MAX_X; i++ {
		if mind[i] < 0 {
			for j := i; j < MAX_X; j += i {
				if mind[j] < 0 {
					mind[j] = i
				}
			}
		}
	}
	for i := 2; i < MAX_X; i++ {
		j := i / mind[i]
		V[i] = V[j]
		if mind[i] != mind[j] {
			V[i]++
		}
	}
}

func solve(c, d, x int) int {
	var res int
	for i := 1; i*i <= x; i++ {
		if x%i != 0 {
			continue
		}
		k1 := x/i + d
		if k1%c == 0 {
			res += 1 << V[k1/c]
		}
		if i*i == x {
			continue
		}
		k2 := i + d
		if k2%c == 0 {
			res += 1 << V[k2/c]
		}
	}

	return res
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mx int = 2e7
	o := make([]int, mx+1)
	primes := make([]int, 0, 1270607)
	for i := 2; i <= mx; i++ {
		if o[i] == 0 {
			o[i] = 2
			primes = append(primes, i)
		}
		for _, p := range primes {
			if p*i > mx {
				break
			}
			if i%p == 0 {
				o[p*i] = o[i]
				break
			}
			o[p*i] = o[i] << 1
		}
	}

	for T := r(); T > 0; T-- {
		C, D, X := r(), r(), r()
		s, d := 0, 1
		for ; d*d < X; d++ {
			if X%d == 0 {
				if (D+d)%C == 0 {
					s += o[(D+d)/C]
				}
				if (D+X/d)%C == 0 {
					s += o[(D+X/d)/C]
				}
			}
		}
		if d*d == X && (D+d)%C == 0 {
			s += o[(D+d)/C]
		}
		Fprintln(out, s)
	}
}

package main

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

var _rbuf = bufio.NewReader(os.Stdin)
var _wbuf = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { _wbuf.Flush(); fmt.Fscan(_rbuf, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_wbuf, f, a...) }

func main() {
	defer _wbuf.Flush()

	T := time.Now()

	var t int
	scan(&t)

	var factors []factor
	var all []int
	for ; t > 0; t-- {
		factors = factors[:0]
		all = all[:0]

		var c, d, x int
		scan(&c, &d, &x)

		sqx := int(math.Sqrt(float64(x)))
		n := x
		for i := 1; n > 1; i++ {
			p := primes[i]
			if p > sqx {
				break
			}
			if n%p == 0 {
				num := 1
				for n /= p; n%p == 0; n /= p {
					num++
				}
				factors = append(factors, factor{p, num})
			}
		}
		if n > 1 {
			factors = append(factors, factor{n, 1})
		}

		var res int
		all = dfs(factors, all)
		for _, f := range all {
			if m := (d + f) / c; (d+f)%c == 0 {
				res += numPairs(m)
			}
		}
		printf("%d\n", res)
	}

	println("time:", time.Since(T).Milliseconds())
}

func dfs(factors []factor, all []int) []int {
	if len(factors) == 0 {
		return append(all, 1)
	}
	all = dfs(factors[1:], all)
	prev := all
	p := factors[0]
	f := 1
	for i := 0; i < p.num; i++ {
		f *= p.prime
		for j := range prev {
			all = append(all, prev[j]*f)
		}
	}
	return all
}

type factor struct {
	prime int
	num   int
}

func numPairs(n int) int {
	if saves[n] != -1 {
		return saves[n]
	}
	m := n
	pow := 0
	sqn := int(math.Sqrt(float64(n)))
	for i := 0; n > 1; i++ {
		p := primes[i]
		if p > sqn {
			break
		}
		if n%p == 0 {
			pow++
			for n /= p; n%p == 0; n /= p {
			}
		}
	}
	if n > 1 {
		pow++
	}
	saves[m] = 1 << pow
	return saves[m]
}

var N = 20000001
var primes []int
var saves []int

func init() {
	saves = make([]int, N)
	for i := 0; i < N; i++ {
		saves[i] = -1
	}

	isPrime := make([]bool, N)
	for i := 2; i < N; i++ {
		isPrime[i] = true
	}
	for i := 2; i < N; i++ {
		if !isPrime[i] {
			continue
		}
		primes = append(primes, i)
		for j := i + i; j < N; j += i {
			isPrime[j] = false
		}
	}
}


This is the hard version of the problem. The only difference is that here $$$2\leq k\leq 100$$$. You can make hacks only if both the versions of the problem are solved.This is an interactive problem!Every decimal number has a base $$$k$$$ equivalent. The individual digits of a base $$$k$$$ number are called $$$k$$$-its. Let's define the $$$k$$$-itwise XOR of two $$$k$$$-its $$$a$$$ and $$$b$$$ as $$$(a + b)\bmod k$$$.The $$$k$$$-itwise XOR of two base $$$k$$$ numbers is equal to the new number formed by taking the $$$k$$$-itwise XOR of their corresponding $$$k$$$-its. The $$$k$$$-itwise XOR of two decimal numbers $$$a$$$ and $$$b$$$ is denoted by $$$a\oplus_{k} b$$$ and is equal to the decimal representation of the $$$k$$$-itwise XOR of the base $$$k$$$ representations of $$$a$$$ and $$$b$$$. All further numbers used in the statement below are in decimal unless specified.You have hacked the criminal database of Rockport Police Department (RPD), also known as the Rap Sheet. But in order to access it, you require a password. You don't know it, but you are quite sure that it lies between $$$0$$$ and $$$n-1$$$ inclusive. So, you have decided to guess it. Luckily, you can try at most $$$n$$$ times without being blocked by the system. But the system is adaptive. Each time you make an incorrect guess, it changes the password. Specifically, if the password before the guess was $$$x$$$, and you guess a different number $$$y$$$, then the system changes the password to a number $$$z$$$ such that $$$x\oplus_{k} z=y$$$. Guess the password and break into the system.

The first line of input contains a single integer $$$t$$$ ($$$1\leq t\leq 10\,000$$$) denoting the number of test cases. $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ ($$$1\leq n\leq 2\cdot 10^5$$$) and $$$k$$$ $$$(2\leq k\leq 100)$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

NoteTest Case 1:In this case, the hidden password is $$$2$$$.The first query is $$$3$$$. It is not equal to the current password. So, $$$0$$$ is returned, and the password is changed to $$$1$$$ since $$$2\oplus_2 1=3$$$.The second query is $$$4$$$. It is not equal to the current password. So, $$$0$$$ is returned, and the password is changed to $$$5$$$ since $$$1\oplus_2 5=4$$$.The third query is $$$5$$$. It is equal to the current password. So, $$$1$$$ is returned, and the job is done.Test Case 2:In this case, the hidden password is $$$3$$$.The first query is $$$1$$$. It is not equal to the current password. So, $$$0$$$ is returned, and the password is changed to $$$7$$$ since $$$3\oplus_3 7=1$$$. $$$[3=(10)_3$$$, $$$7=(21)_3$$$, $$$1=(01)_3$$$ and $$$(10)_3\oplus_3 (21)_3 = (01)_3]$$$.The second query is $$$4$$$. It is not equal to the current password. So, $$$0$$$ is returned, and the password is changed to $$$6$$$ since $$$7\oplus_3 6=4$$$. $$$[7=(21)_3$$$, $$$6=(20)_3$$$, $$$4=(11)_3$$$ and $$$(21)_3\oplus_3 (20)_3 = (11)_3]$$$.The third query is $$$6$$$. It is equal to the current password. So, $$$1$$$ is returned, and the job is done.Note that these initial passwords are taken just for the sake of explanation. In reality, the grader might behave differently because it is adaptive.

package main

import (
	"fmt"
)

var n, k int

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &k)
		solve()
	}
}

func solve() {
	var q int
	for i := 0; i < n; i++ {
		if i == 0 {
			q = 0
		} else {
			q = ask(i - 1)
		}
		fmt.Println(q)
		var r int
		fmt.Scan(&r)
		if r == 1 {
			break
		}

	}
}

func ask(x int) int {
	sum := 0
	p := 1
	y := x + 1
	if x % 2 == 0 {
		x, y = y, x
	}
	for x != 0 || y != 0 {
		sum += p * ((y%k + k - x % k) % k)
		p *= k
		x /= k
		y /= k
	}
	return sum
}

func abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func fabs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

func min(nums ...int64) int64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}

func fmin(nums ...float64) float64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)
var n, k, x int

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

func solve() {
	fmt.Fscan(reader, &n, &k)
	writer.Flush()
	for i := 0; i < n; i++ {
		var temp int
		if i != 0 {
			temp = get(i, (i & 1) != 0)
		} else {
			temp = 0
		}
		fmt.Fprintln(writer, temp)
		i = temp
		writer.Flush()
		fmt.Fscan(reader, &x)
		if x != 0 {
			break
		}
	}
}

func get(x int, tag bool) int {
	y := x - 1
	z := 0
	sum := 1
	for x != 0 || y != 0 {
		if tag {
			z += sum * ((y%k + k - x%k) & k)
		} else {
			z += sum * ((x%k + k - y%k) % k)
		}
		x /= k
		y /= k
		sum *= k
	}
	return z
}

func abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func fabs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

func min(nums ...int64) int64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}

func fmin(nums ...float64) float64 {
	l := len(nums)
	mn := nums[0]
	for i := 0; i < l; i++ {
		if nums[i] < mn {
			mn = nums[i]
		}
	}
	return mn
}


The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. n·(n - 1) / 2 games were played during the tournament, and each participant had a match with each other participant. The rules of the game are quite simple — the participant who falls asleep first wins. The secretary made a record of each game in the form «xi yi», where xi and yi are the numbers of participants. The first number in each pair is a winner (i.e. xi is a winner and yi is a loser). There is no draws.Recently researches form the «Institute Of Sleep» have found that every person is characterized by a value pj — the speed of falling asleep. The person who has lower speed wins. Every person has its own value pj, constant during the life. It is known that all participants of the tournament have distinct speeds of falling asleep. Also it was found that the secretary made records about all the games except one. You are to find the result of the missing game.

The first line contains one integer n (3 ≤ n ≤ 50) — the number of participants. The following n·(n - 1) / 2 - 1 lines contain the results of the games. Each game is described in a single line by two integers xi, yi (1 ≤ xi, yi ≤ n, xi ≠ yi), where xi и yi are the numbers of the opponents in this game. It is known that during the tournament each of the n participants played n - 1 games, one game with each other participant.

Output two integers x and y — the missing record. If there are several solutions, output any of them.

package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func main() {
	defer w.Flush()

	var n int
	var x, y int
	fmt.Fscanf(r, "%d\n", &n)
	cnt, wins := make([]int, n), make([]int, n)
	for i, m := 0, n*(n-1)/2-1; i < m; i++ {
		fmt.Fscanf(r, "%d%d\n", &x, &y)
		x--
		y--
		cnt[x]++
		cnt[y]++
		wins[x]++
	}

	x, y = -1, -1
	for i := 0; i < n; i++ {
		if cnt[i] == n - 2 {
			if x == -1 {
				x = i
			} else {
				y = i
				break
			}
		}
	}
	if wins[x] < wins[y] {
		x, y = y, x
	}
	fmt.Fprintf(w, "%v %v", x+1, y+1)
}


The only difference between easy and hard versions is the constraint on $$$k$$$.Gildong loves observing animals, so he bought two cameras to take videos of wild animals in a forest. The color of one camera is red, and the other one's color is blue.Gildong is going to take videos for $$$n$$$ days, starting from day $$$1$$$ to day $$$n$$$. The forest can be divided into $$$m$$$ areas, numbered from $$$1$$$ to $$$m$$$. He'll use the cameras in the following way:   On every odd day ($$$1$$$-st, $$$3$$$-rd, $$$5$$$-th, ...), bring the red camera to the forest and record a video for $$$2$$$ days.  On every even day ($$$2$$$-nd, $$$4$$$-th, $$$6$$$-th, ...), bring the blue camera to the forest and record a video for $$$2$$$ days.  If he starts recording on the $$$n$$$-th day with one of the cameras, the camera records for only one day. Each camera can observe $$$k$$$ consecutive areas of the forest. For example, if $$$m=5$$$ and $$$k=3$$$, he can put a camera to observe one of these three ranges of areas for two days: $$$[1,3]$$$, $$$[2,4]$$$, and $$$[3,5]$$$.Gildong got information about how many animals will be seen in each area each day. Since he would like to observe as many animals as possible, he wants you to find the best way to place the two cameras for $$$n$$$ days. Note that if the two cameras are observing the same area on the same day, the animals observed in that area are counted only once.

The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n \le 50$$$, $$$1 \le m \le 2 \cdot 10^4$$$, $$$1 \le k \le min(m,20)$$$) – the number of days Gildong is going to record, the number of areas of the forest, and the range of the cameras, respectively. Next $$$n$$$ lines contain $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i+1$$$-st line is the number of animals that can be seen on the $$$i$$$-th day in the $$$j$$$-th area. Each number of animals is between $$$0$$$ and $$$1000$$$, inclusive.

Print one integer – the maximum number of animals that can be observed.

NoteThe optimal way to observe animals in the four examples are as follows:Example 1:   Example 2:   Example 3:   Example 4:

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

type Tree struct {
	a  []int
	sz int
}

func (t *Tree) At(i int) int {
	if i < 0 {
		return 0
	}
	if i >= t.sz {
		return 0
	}
	return int(t.a[t.sz+i])
}

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

func (t *Tree) Update(i, v int) {
	i += t.sz
	t.a[i] = int(v)
	i >>= 1
	for ; i > 0; i >>= 1 {
		t.a[i] = maxi16(t.a[i<<1], t.a[(i<<1)|1])
	}
}

func (t *Tree) Max(l, r int) int {
	if l > r {
		return 0
	}
	l += t.sz
	r += t.sz
	res := int(0)
	for l <= r {
		if l&1 > 0 {
			res = maxi16(res, t.a[l])
			l++
		}
		if r&1 == 0 {
			res = maxi16(res, t.a[r])
			r--
		}
		l >>= 1
		r >>= 1
	}
	return int(res)
}

func NewTree(n int) *Tree {
	sz := 1
	for sz < n {
		sz <<= 1
	}
	a := make([]int, 2*sz+1)
	return &Tree{a, sz}
}

func main() {
	inf := os.Stdin
	out := os.Stdout
	// f, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)
	n := NextInt()
	m := NextInt()
	k := NextInt()
	a := make([][]int, n+1)

	a[0] = make([]int, m)
	for i := 1; i <= n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			a[i][j] = NextInt()
		}
	}

	var f [2]*Tree
	f[0] = NewTree(m + 1)
	f[1] = NewTree(m + 1)
	total := 0

	for i := 1; i <= n; i++ {
		ind := i & 1
		pind := ind ^ 1
		bs := 0
		ns := 0
		r := 0
		for l := 0; l <= m; l++ {
			if l > 0 {
				bs -= a[i][l-1]
				if i < n {
					ns -= a[i+1][l-1]
				}
			}
			for r < l+k && r < m {
				bs += a[i][r]
				if i < n {
					ns += a[i+1][r]
				}
				r++
			}
			res := f[pind].Max(0, l-k) + bs
			res = max(res, f[pind].Max(l+k, m)+bs)
			s := 0
			rs := bs
			for cov := l; cov < m && cov <= l+k-1; cov++ {
				s += a[i][cov]
				res = max(res, f[pind].At(cov-k+1)+bs-s)
				res = max(res, f[pind].At(cov)+bs-rs)
				rs -= a[i][cov]
			}
			f[ind].Update(l, res+ns)
			// stderr("res", i, l, "is ", res, "bs", bs, "ns", ns, "k=", k)
			total = max(total, res+ns)
		}
	}
	fmt.Fprintln(out, total)
}


Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.

NoteIn the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.To reach the answer to the second sample case one must not decrease any of the array elements.

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	merge_sort(array, 0, n-1)

	current := 1
	for i := 0; i < n; i++ {
		if array[i] >= current {
			array[i] = current
			current++
		}
	}
	fmt.Println(current)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 10000000)
	byte, _, _ := reader.ReadLine()
	n , _ := strconv.Atoi(string(byte))
	li := make([]int , n+1)
	byte, _, _ = reader.ReadLine()
	strs := strings.Split(string(byte), " ")
	for i:=1; i<=  n; i++ {
		li[i], _ = strconv.Atoi(strs[i-1])
	}
	sort.Ints(li[:n+1])
	for i:=1; i<= n; i++ {
		if li[i] > li[i-1] {
			li[i] = li[i-1] + 1
		}
	}
	fmt.Println(li[n] + 1)
}

package main

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

func main() {
	var n int
	fmt.Scan(&n)
	array := make([]int, n)

	// new way to read arrays
	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		array[i], _ = strconv.Atoi(bs.Text())
	}

	sort.Ints(array)
	mex := 1
	for i := 0; i < n; i++ {
		if array[i] >= mex {
			mex++
		}
	}
	fmt.Print(mex)
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"sort"
)
var (
	r *bufio.Scanner
	w *bufio.Writer
)

const ISDEBUG = false

func readLine() string {
	r.Scan()
	return r.Text()
}

func readInt() int {
	r.Scan()
	x, _ := strconv.Atoi(r.Text())
	return x
}

func readInts(n int) []int {
	var res []int
	for i:=0; i<n; i++ {
		if !r.Scan() {
			fmt.Println(r.Err())
		}
		x, _ := strconv.Atoi(r.Text())
		res = append(res, x)
	}
	return res
}

func main() {
	if ISDEBUG {
		fi, err := os.Open("input100000.txt")
		if err != nil {
			panic(err)
		}
		fo, _ := os.OpenFile("output.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
		r = bufio.NewScanner(fi)
		w = bufio.NewWriter(fo)

		defer fi.Close()
		defer fo.Close()
	} else {
		r = bufio.NewScanner(os.Stdin)
		w = bufio.NewWriter(os.Stdout)
	}
	r.Split(bufio.ScanWords)
	defer w.Flush()

	n := readInt()
	a := readInts(n)
	sort.Ints(a)

	result := 1
	for _, i := range a {
		if i >= result {
			result += 1
		}
	}
	w.WriteString(fmt.Sprintf("%v", result))
}

package main

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

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

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	an := make([]int, n, n)
	for i := 0; i < n; i++ {
		bs.Scan()
		an[i], _ = strconv.Atoi(bs.Text())
	}

	sort.Sort(sort.IntSlice(an))
	cur := 1
	for i := 0; i < n; i++ {
		if cur <= an[i] {
			cur++
		}
	}

	fmt.Println(cur)
}

package main

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

func main() {
	n := getInt()
	a := getNint(n)
	sort.Ints(a)

	mex := 1
	for _, x := range a {
		if mex <= x {
			mex++
		}
	}
	fmt.Println(mex)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

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

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	li := make([]int , 100001)
	fmt.Scanf("%d", &n)
	for i:=1; i<= n; i++ {
		fmt.Scanf("%d", &li[i])
	}
	sort.Ints(li[:n+1])
	for i:=1; i<= n; i++ {
		if li[i] > li[i-1] {
			li[i] = li[i-1] + 1
		}
	}
	fmt.Printf("%d", li[n] + 1)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	li := make([]int , 100001)
	fmt.Scanf("%d", &n)
	for i:=1; i<= n; i++ {
	 	fmt.Scanf("%d", &li[i])
	}
	sort.Ints(li[:n+1])
	for i:=1; i<= n; i++ {
		if li[i] > li[i-1] {
			li[i] = li[i-1] + 1
		}
	}
	fmt.Printf("%d", li[n] + 2)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	li := make([]int , 100001)
	byte, _, _ := reader.ReadLine()
	n , _ := strconv.Atoi(string(byte))
	byte, _, _ = reader.ReadLine()
	strs := strings.Split(string(byte), " ")
	for i:=1; i<  n; i++ {
		li[i], _ = strconv.Atoi(strs[i])
	}
	sort.Ints(li[:n+1])
	for i:=1; i<= n; i++ {
		if li[i] > li[i-1] {
			li[i] = li[i-1] + 1
		}
	}
	fmt.Printf("%d", li[n] + 1)
}

package main

import (
	"fmt"
	"sort"
)

func main(){
	var n int
	fmt.Scan(&n)
	array := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&array[i])
	}

	sort.Ints(array)
	var mex int
	for i := 0; i < n; i++ {
		if array[i] >= mex {
			mex++
		}
	}
	fmt.Print(mex)
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"strings"
	"sort"
)
var (
	r *bufio.Scanner
	w *bufio.Writer
)

const ISDEBUG = false

func readLine() string {
	r.Scan()
	return r.Text()
}

func readInt() int {
	r.Scan()
	x, _ := strconv.Atoi(r.Text())
	return x
}

func readInts() []int {
	r.Scan()
	res := make([]int, 0)
	for _, istr := range strings.Split(r.Text(), " ") {
		x, _ := strconv.Atoi(istr)
		res = append(res, x)
	}
	return res
}

func main() {
	if ISDEBUG {
		fi, err := os.Open("input.txt")
		if err != nil {
			panic(err)
		}
		fo, _ := os.OpenFile("output.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
		r = bufio.NewScanner(fi)
		w = bufio.NewWriter(fo)

		defer fi.Close()
		defer fo.Close()
	} else {
		r = bufio.NewScanner(os.Stdin)
		w = bufio.NewWriter(os.Stdout)
	}
	defer w.Flush()

	_ = readInt()
	a := readInts()
	sort.Ints(a)

	result := 1
	for _, i := range a {
		if i >= result {
			result += 1
		}
	}
	w.WriteString(fmt.Sprintf("%d", result))
}


Real stupidity beats artificial intelligence every time.— Terry Pratchett, Hogfather, DiscworldYou are given a string $$$s$$$ of length $$$n$$$ and a number $$$k$$$. Let's denote by $$$rev(s)$$$ the reversed string $$$s$$$ (i.e. $$$rev(s) = s_n s_{n-1} ... s_1$$$). You can apply one of the two kinds of operations to the string: replace the string $$$s$$$ with $$$s + rev(s)$$$ replace the string $$$s$$$ with $$$rev(s) + s$$$How many different strings can you get as a result of performing exactly $$$k$$$ operations (possibly of different kinds) on the original string $$$s$$$?In this statement we denoted the concatenation of strings $$$s$$$ and $$$t$$$ as $$$s + t$$$. In other words, $$$s + t = s_1 s_2 ... s_n t_1 t_2 ... t_m$$$, where $$$n$$$ and $$$m$$$ are the lengths of strings $$$s$$$ and $$$t$$$ respectively.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — number of test cases. Next $$$2 \cdot t$$$ lines contain $$$t$$$ test cases: The first line of a test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$, $$$0 \le k \le 1000$$$) — the length of the string and the number of operations respectively. The second string of a test case contains one string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters.

For each test case, print the answer (that is, the number of different strings that you can get after exactly $$$k$$$ operations) on a separate line. It can be shown that the answer does not exceed $$$10^9$$$ under the given constraints.

4

3 2

aab

3 3

aab

7 1

abacaba

2 0

ab

NoteIn the first test case of the example:After the first operation the string $$$s$$$ can become either aabbaa or baaaab. After the second operation there are 2 possibilities for $$$s$$$: aabbaaaabbaa and baaaabbaaaab.

package main

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

func isMirrored(str string) bool {
	half := len(str) / 2
	for i := 0; i < half; i++ {
		if str[i] != str[len(str)-1-i] {
			return false
		}
	}
	return true
}

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

	t, _ := reader.ReadString('\r')

	tCount, _ := strconv.Atoi(t[:len(t)-1])

	for i := 0; i < tCount; i++ {
		nAndKStr, _ := reader.ReadString('\r')
		nAndK := strings.Split(nAndKStr, " ")
		k, _ := strconv.Atoi(nAndK[1][:len(nAndK[1])-1])

		input, _ := reader.ReadString('\r')

		if k > 0 && !isMirrored(input[1:len(input)-1]) {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
	}
}

func main() {
	resultsCount()
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		var word string
		fmt.Fscan(in,&word)
		if y == 0 || x == 1 {
			fmt.Fprintln(out,1)
		} else {
			list:= strings.Split(word,"")
			for j,k:=0,len(list)-1;j<k;j,k=j+1,k-1{
				list[j],list[k] = list[k],list[j]
			}
			word2:= strings.Join(list,"")
			if word == word2 {
				fmt.Fprintln(out,1)
			} else {
				fmt.Fprintln(out,2)
			}
		}
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}
func solve() {
	var n, k int
	scan(&n, &k)
	var s string
	scan(&s)
	if k >= 1 {
		t := Reverse(s)
		s1 := t + s
		s2 := s + t
		if s1 != s2 {
			printf("2\n")
			return
		}
	}
	printf("1\n")

}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1634A
Date: 9/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1634/A
Problem: CF1634A
**/
func (in *CF1634A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		str := in.NextString()

		mapa := make(map[uint8]int)
		for i := 0; i < len(str); i++ {
			mapa[str[i]]++
		}

		rev := ""
		for i := n - 1; i >= 0; i-- {
			rev += string(str[i])
		}
		cant := len(mapa)
		ans := 1
		if k >= 1 && cant > 1 && rev != str{
			ans = 2
		}

		fmt.Println(ans)
	}

}

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

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

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt(in)
	for ; t != 0; t-- {
		solve()
	}
}

func solve() {
	input := readArrInt(in)
	n, k := input[0], input[1]
	s, _ := in.ReadString('\n')
	s = strings.Trim(s, " \n\r")
	flag := true
	for i := 0; i < n; i++ {
		if s[i] != s[n-1-i] {
			flag = false
		}
	}
	if k == 0 {
		fmt.Println(1)
	} else if flag {
		fmt.Println(1)
	} else {
		fmt.Println(2)
	}
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

import (
	"fmt"
)

func test() {
	var n, k int
	var x string
	fmt.Scan(&n, &k, &x)
	if k==0 {
		fmt.Println(1)
		return
	}
	for i, j := 0, len(x)-1; i < j; i, j = i+1, j-1 {
		if x[i] != x[j] {
			fmt.Println(2)
			return
		}
	}
	fmt.Println(1)
}
func main() {
	var no int
	fmt.Scan(&no)
	for i := 0; i < no; i++ {
		test()
	}
}

package main

import (
	"bufio"
	"crypto/rand"
	"fmt"
	"math"
	"math/big"
	"os"
	"sort"
	"strconv"
)

func main() {

	reader := bufio.NewReader(os.Stdin)
	writter := bufio.NewWriter(os.Stdout)
	defer writter.Flush()

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

	for t > 0 {
		n, k := 0, 0
		fmt.Fscan(reader, &n, &k)

		s := ""
		fmt.Fscan(reader, &s)

		fmt.Fprintln(writter, solve(n, k, s))

		t--
	}

	// n, k := 3, 1
	// s := "aab"
	// fmt.Println(solve(n, k, s))

	//getPower()

}

func solve(n, k int, s string) int {

	if k < 1 {
		return 1
	}

	if palindrome(s) {
		return 1
	}

	return 2
}

func palindrome(str string) bool {

	size := len(str)

	for i := 0; i < size/2; i++ {
		if str[i] != str[size-1-i] {
			return false
		}
	}

	return true

}

func reverseString(str string) string {
	result := ""

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

		result += string(str[i])

	}

	return result
}

func arraySum(array []int) int {
	sum := 0

	for i := range array {
		sum += array[i]
	}

	return sum
}

func numSum(num int) int {
	sum := 0

	for i := num; i > 0; i-- {
		sum += i
	}

	return sum
}

func strToint(str string) int {
	num, _ := strconv.Atoi(str)
	return num
}

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

	return b
}

func getFactor(num int) []int {
	result := []int{}

	for i := 1; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			result = append(result, i)
			result = append(result, num/i)
		}
	}

	return result
}

func gcd(a, b int) int {
	if a == 0 {
		return b
	}

	return gcd(b%a, a)
}

func printMatrix(matrix [][]int) {
	for i := range matrix {

		for j := range matrix[i] {
			fmt.Printf("%d ", matrix[i][j])
		}

		fmt.Println()

	}
}

func checkPrime(num int) bool {

	if num < 2 {
		return false
	}

	for i := 2; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			return false
		}
	}

	return true
}

func getPower() {
	A := []int{}

	for i := 1; i <= 38; i++ {
		A = append(A, i)
	}

	for j := 0; j < 10000; j++ {
		for i := range A {
			target, _ := rand.Int(rand.Reader, big.NewInt(38))
			A[i], A[target.Int64()] = A[target.Int64()], A[i]
		}
	}

	B, _ := rand.Int(rand.Reader, big.NewInt(8))

	result := A[:6]
	sort.Ints(result)

	fmt.Println(result)
	fmt.Println(int(B.Int64()) + 1)
}

func xor(a, b int) int {
	aBit := strconv.FormatInt(int64(a), 2)
	bBit := strconv.FormatInt(int64(b), 2)

	size := max(len(aBit), len(bBit))

	for i := size - len(aBit); i > 0; i-- {
		aBit = "0" + aBit
	}
	for i := size - len(bBit); i > 0; i-- {
		bBit = "0" + bBit
	}

	result := ""
	for i := range aBit {
		if aBit[i] == bBit[i] {
			result += "0"
		} else {
			result += "1"
		}
	}

	//fmt.Println(result)
	num, _ := strconv.ParseInt(result, 2, 64)

	return int(num)
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var n, k int
		var s string
		fmt.Scan(&n, &k)
		fmt.Scan(&s)

		if same(s) || k < 1 {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

func same(s string) bool {
	for i := 0; i < len(s); i++ {
		if s[i] != s[len(s)-i-1] {
			return false
		}
	}
	return true
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n, k int
		scan(&n, &k)
		var s[]byte
		scan(&s)
		pal := true
		for i := 0; i < n-i-1; i++ {
			pal = pal && s[i] == s[n-i-1]
		}
		ans := 1
		if !pal && k >= 1 {
			ans = 2
		}
		printf("%d\n", ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"unicode/utf8"
)

func isPal(s string) bool {
	for len(s) > 0 {
		if len(s) == 1 {
			return true
		}
		r1, sz1 := utf8.DecodeRuneInString(s)
		r2, sz2 := utf8.DecodeLastRuneInString(s)
		if r1 != r2 {
			return false
		}
		s = s[sz1 : len(s)-sz2]
	}
	return true
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var tests int
	fmt.Fscan(in, &tests)
	for i := 0; i < tests; i++ {
		var n, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)
		if k == 0 || isPal(s) {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

package main

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

func isPalindrome(s string) bool {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		if s[i] != s[j] {
			return false
		}
	}
	return true
}

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

	for ; t > 0; t-- {
		var n, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)

		isDiff := false
		for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
			if s[i] != s[j] {
				isDiff = true
			}
		}

		if isDiff {
			if k == 0 {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

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

func check(s string) bool {
	n := len(s)
	for i := 0; i < n; i++ {
		if s[i] != s[n-1-i] {
			return false
		}
	}
	return true
}

func main() {
	defer out.Flush()
	var t, n, k int
	var s string
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &n, &k, &s)
		if check(s) || k == 0 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

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

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

	for ii := 0; ii < t; ii++ {
		var n, k int
		fmt.Fscan(in, &n, &k)
		var s string
		fmt.Fscan(in, &s)
		rev := true
		for i := 0; i < n/2; i++ {
			if s[i] != s[n-i-1] {
				rev = false
				break
			}
		}
		if rev || k == 0 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

// 1 0 1 2

//nolint
package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n, k int
	scan(&n, &k)
	var st string
	scan(&st)
	if !isPalindrome(st) && k > 0 {
		println(2)
	} else {
		println(1)
	}
}

func isPalindrome(st string) bool {
	for i := 0; len(st)-i-1 > i; i++ {
		if st[i] != st[len(st)-i-1] {
			return false
		}
	}
	return true
}

package main

import "fmt"

/*
In the first test case of the example:
Input
4
3 2
aab
3 3
aab
7 1
abacaba
2 0
ab

Output :
2
2
1
1
After the first operation the string s can become either aabbaa or baaaab.
After the second operation there are 2 possibilities for s: aabbaaaabbaa and baaaabbaaaab.
*/
/*
s = aab
rev = baa

pre = aabbaa
post = baaaab
*/

type testCase struct {
	length int
	layer  int
	str    string
}

func reverse(str string) (rev string) {
	l := len(str)
	for i := 0; i < l; i++ {
		rev = rev + str[l-i-1:l-i]
	}
	return rev
}

func possibilities(layer int, str, rev string) (count int) {
	if layer == 0 {
		return 1
	}

	pre := str + reverse(str)
	post := reverse(str) + str

	if pre == post {
		return 1
	}

	return 2
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	tests := []testCase{}
	for i := 0; i < n; i++ {
		test := testCase{}
		fmt.Scanf("%d %d\n", &test.length, &test.layer)
		fmt.Scanf("%s\n", &test.str)
		tests = append(tests, test)
	}

	for j := 0; j < n; j++ {
		str := tests[j].str
		layer := tests[j].layer
		rev := reverse(str)
		fmt.Println(possibilities(layer, str, rev))
	}
}

package main
import "fmt"

func main(){
    var t, n, k int
    var s string
    fmt.Scanln(&t)
    for t > 0 {
        fmt.Scanf("%d %d\n", &n, &k)
        //fmt.Println(n, k)
        fmt.Scanln(&s)
        ok := true
        for i := 0; i < n/2; i++ {
            ok = ok && s[i] == s[n - i - 1]
        }
        if k == 0 || ok {
            fmt.Println(1)
        } else {
            fmt.Println(2)
        }
        t--
    }
}

package main

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

const MOD int64 = 1000000007

var n, k int

var s string

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

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

		fmt.Fscan(read, &n, &k, &s)

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int {

	if k == 0 {
		return 1
	}

	isPal := true

	for i, j := 0, n - 1; i <= j; i, j = i + 1, j - 1 {
		if s[i] == s[j] {
			continue
		}
		isPal = false
		break
	}

	if isPal {
		return 1
	}

	return 2
}

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

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(in, f, a...) }
func print(a ...interface{})			{ fmt.Fprintln(out, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) { if !f { panic("gg") } }

func slove(cases int) {
	n, k := 0, 0
	str := ""
	scan(&n, &k, &str)
	flag := false
	for i := range str {
		if str[i] != str[n-i-1] {
			flag = true
			break
		}
	}

	if k > 0 {
		if flag {
			print(2)
		} else {
			print(1)
		}
	} else {
		print(1)
	}
}

func main() {
	defer flush()

	cases := 0
	scan(&cases)
	for i := 0; i < cases; i++ {
		slove(i)
	}
}

package main

import "fmt"

func main() {
	var _t int

	fmt.Scan(&_t)

	for _t > 0 {
		_t--

		var n int
		var k int
		var s string

		fmt.Scan(&n, &k)
		fmt.Scan(&s)

		pali := true

		for i, _ := range s {
			if s[i] != s[n - i - 1] {
				pali = false
			}
		}

		var res int

		if pali || k == 0 {
			res = 1
		} else {
			res = 2
		}

		fmt.Println(res)
	}
}

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	s string
	res int
)

func main() {
	initBuffer()
	var t int = 1
	t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
	s = getString()
}

func count() {
	if k == 0 || isPalind(s) {
		res = 1
	} else {
		res = 2
	}
}

func isPalind(s string) bool {
	for i := 0; i < len(s) / 2; i++ {
		if s[i] != s[len(s)-1-i] {
			return false
		}
	}
	return true
}

func output() {
	out.Write(intToBytes(res))
	out.WriteByte(NL)
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

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

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main
import "fmt"

func isPalin(s string) bool {
	for i:= 0; i < len(s); i++ {
		if s[i] != s[len(s) - i - 1] {
			return false
		}
	}
	return true
}

func solve() int {
	var (
		n int
		k int
		s string
	)
	fmt.Scanf("%v %v\n%v\n", &n, &k, &s)
	if k == 0 || isPalin(s) {
		return 1
	}
	return 2
}

func main() {
	var ntests int;
	fmt.Scanf("%v\n", &ntests)
	for i:= 0; i < ntests; i++ {
		fmt.Println(solve())
	}
}

package main

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

func parseCase(r *bufio.Reader) (int, int, string) {
	var n, k int
	{
		nkStr, _ := r.ReadString('\n')
		_, _ = fmt.Sscanf(nkStr, "%d %d", &n, &k)
	}
	word, _ := r.ReadString('\n')
	return n, k, strings.TrimSpace(word)
}

func parseHeader(r *bufio.Reader) int {
	tStr, _ := r.ReadString('\n')
	t, _ := strconv.Atoi(strings.TrimSpace(tStr))
	return t
}

func naiveTraverse(k int, s string, result map[string]interface{}) {
	if k == 0 {
		//fmt.Println(s)
		result[s] = struct{}{}
		return
	}
	runes := []rune(s)
	rs := make([]rune, 2 * len(s))
	sr := make([]rune, 2 * len(s))
	for i := 0; i < len(runes); i += 1 {
		rs[i] = runes[i]
		rs[len(runes) + i] = runes[len(runes) - 1 - i]
		sr[i] = runes[len(runes) - 1 - i]
		sr[len(runes) + i] = runes[i]
	}
	naiveTraverse(k - 1, string(rs), result)
	naiveTraverse(k - 1, string(sr), result)
}

func combine(s string) (string, string) {
	runes := []rune(s)
	rs := make([]rune, 2 * len(s))
	sr := make([]rune, 2 * len(s))
	for i := 0; i < len(runes); i += 1 {
		rs[i] = runes[i]
		rs[len(runes) + i] = runes[len(runes) - 1 - i]
		sr[i] = runes[len(runes) - 1 - i]
		sr[len(runes) + i] = runes[i]
	}
	return string(rs), string(sr)
}

func traverse(k int, s string, result map[string]interface{}, cache map[string]interface{}) {
	fmt.Println(k)
	if k == 0 {
		//fmt.Println(s)
		result[s] = struct{}{}
		return
	}
	cache[s] = struct{}{}
	_, rs := combine(s)
	traverse(k - 1, rs, result, cache)
	//if _, ok := cache[sr]; !ok {
	//	traverse(k - 1, sr, result, cache)
	//}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	t := parseHeader(r)
	for i := 0; i < t; i += 1 {
		result := map[string]interface{}{}
		//cache := map[string]interface{}{}
		//fmt.Println(fmt.Sprintf("Case %d", i))
		_, k, word := parseCase(r)
		//fmt.Println(fmt.Sprintf("n = %d, k = %d", n, k))
		//fmt.Println(fmt.Sprintf("word = %s", word))
		if k > 3 {
			k = 3
		}
		naiveTraverse(k, word, result)
		fmt.Println(len(result))
	}
}

package main

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

/*
4
3 0
123
3 1
123
3 2
123
4 3
1111
---
1
2
2
1
*/

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

	t := 1
	scanf("%d\n", &t)

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

		if k == 0 {
			fmt.Fprintln(writer, 1)
		} else {
			revS := reverse(s)
			if s+revS == revS+s {
				fmt.Fprintln(writer, 1)
			} else {
				fmt.Fprintln(writer, 2)
			}
		}
	}
}

func reverse(s string) (result string) {
	for _, v := range s {
		result = string(v) + result
	}
	return
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

func ishw(s string) bool {
	for i := 0; i < len(s); i++ {
		if s[i] != s[len(s)-i-1] {
			return false
		}
	}
	return true
}

func runcase(n, k int, s string) int {
	if k == 0 {
		return 1
	}
	if ishw(s) {
		return 1
	}
	return 2
}

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

	var t, n, k int
	var s string
	fmt.Fscanf(cin, "%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Fscanf(cin, "%d %d\n", &n, &k)
		fmt.Fscanf(cin, "%s\n", &s)
		fmt.Println(runcase(n, k, s))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	b := strings.Builder{}
	for i := 0; i < t; i++ {
		b.WriteString(solve(in) + "\n")
	}
	fmt.Println(b.String())
}

func solve(in *bufio.Reader) string {
	args := readArrInt(in)
	str := readString(in)

	k := args[1]

	count := 1

	for i := 0; i < k; i++ {
		if op1(str) == op2(str) {
			return strconv.Itoa(count)
		} else {
			return "2"
		}
	}
	return "1"
}

func op1(str string) string {
	return str + rev(str)
}

func op2(str string) string {
	return rev(str) + str
}

func rev(str string) string {
	b := strings.Builder{}
	for i := 0; i < len(str); i++ {
		b.WriteByte(str[len(str) - 1 - i])
	}
	return b.String()
}

func isPalindrome(str string) bool {
	for i := 0; i < len(str); i++ {
		if str[i] != str[len(str) - 1 - i] {
			return false
		}
	}

	return true
}

func readString(in *bufio.Reader) string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

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, k int
		fmt.Fscan(in, &n, &k)

		var s string
		fmt.Fscan(in, &s)

		isPalindrome := func(s string) bool {
			for i := 0; i < len(s)/2; i++ {
				if s[i] != s[len(s)-i-1] {
					return false
				}
			}
			return true
		}

		if k == 0 || isPalindrome(s) {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

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

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

	solve := func(curCase int) {
		var n, k int
		var s string
		Fscan(in, &n, &k, &s)
		if k == 0 {
			Fprintln(out, 1)
			return
		}
		for i, n := 0, len(s); i < n/2; i++ {
			v, w := s[i], s[n-1-i]
			if v != w {
				Fprintln(out, 2)
				return
			}
		}
		Fprintln(out, 1)
	}

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

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

}

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

package main

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

func isMirrored(str string) bool {
	half := len(str) / 2
	for i := 0; i < half; i++ {
		if str[i] != str[len(str)-1-i] {
			return false
		}
	}
	return true
}

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

	t, _ := reader.ReadString('\r')

	tCount, _ := strconv.Atoi(t[:len(t)-1])

	for i := 0; i < tCount; i++ {
		nAndKStr, _ := reader.ReadString('\r')
		nAndK := strings.Split(nAndKStr, " ")
		k, _ := strconv.Atoi(nAndK[1][:len(nAndK[1])-1])

		input, _ := reader.ReadString('\r')

		if k > 1 && !isMirrored(input[1:len(input)-1]) {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
	}
}

func main() {
	resultsCount()
}

package main

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

func isMirrored(str string) bool {
	half := len(str) / 2
	for i := 0; i < half; i++ {
		if str[i] != str[len(str)-1-i] {
			return false
		}
	}
	return true
}

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

	t, _ := reader.ReadString('\r')

	tCount, _ := strconv.Atoi(t[:len(t)-1])

	for i := 0; i < tCount; i++ {
		nAndKStr, _ := reader.ReadString('\r')
		nAndK := strings.Split(nAndKStr, " ")
		k, _ := strconv.Atoi(nAndK[1][:len(nAndK[1])-1])

		input, _ := reader.ReadString('\r')

		if k > 1 && !isMirrored(input[:len(input)-1]) {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
	}
}

func main() {
	resultsCount()
}

package main

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

func isMirrored(str string) bool {
	half := len(str) / 2
	for i := 0; i < half; i++ {
		if str[i] != str[len(str)-1-i] {
			return false
		}
	}
	return true
}

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

	t, _ := reader.ReadString('\n')

	tCount, _ := strconv.Atoi(t[:len(t)-1])

	for i := 0; i < tCount; i++ {
		nAndKStr, _ := reader.ReadString('\n')
		nAndK := strings.Split(nAndKStr, " ")
		k, _ := strconv.Atoi(nAndK[1][:len(nAndK[1])-1])

		input, _ := reader.ReadString('\n')

		if k > 1 && !isMirrored(input[:len(input)-1]) {
			println(2)
		} else {
			println(1)
		}
	}
}

func main() {
	resultsCount()
}

package main

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

func isMirrored(str string) bool {
	half := len(str) / 2
	for i := 0; i < half; i++ {
		if str[i] != str[len(str)-1-i] {
			return false
		}
	}
	return true
}

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

	t, _ := reader.ReadString('\n')

	tCount, _ := strconv.Atoi(t[:len(t)-1])

	for i := 0; i < tCount; i++ {
		nAndKStr, _ := reader.ReadString('\n')
		nAndK := strings.Split(nAndKStr, " ")
		k, _ := strconv.Atoi(nAndK[1][:len(nAndK[1])-1])

		input, _ := reader.ReadString('\n')

		if k > 1 && !isMirrored(input[:len(input)-1]) {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
	}
}

func main() {
	resultsCount()
}

package main

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

func isMirrored(str string) bool {
	half := len(str) / 2
	for i := 0; i < half; i++ {
		if str[i] != str[len(str)-1-i] {
			return false
		}
	}
	return true
}

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

	t, _ := reader.ReadString('\n')

	tCount, _ := strconv.Atoi(t[:len(t)-1])

	for i := 0; i < tCount; i++ {
		nAndKStr, _ := reader.ReadString('\n')
		nAndK := strings.Split(nAndKStr, " ")
		k, _ := strconv.Atoi(nAndK[1][:len(nAndK[1])-1])

		input, _ := reader.ReadString('\n')

		if k > 1 && !isMirrored(input) {
			fmt.Println(2)
		} else {
			fmt.Println(1)
		}
	}
}

func main() {
	resultsCount()
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		var word string
		fmt.Fscan(in,&word)
		if y == 0 || y == 1 || x == 1 {
			fmt.Fprintln(out,1)
		} else {
			list:= strings.Split(word,"")
			for j,k:=0,len(list)-1;j<k;j,k=j+1,k-1{
				list[j],list[k] = list[k],list[j]
			}
			word2:= strings.Join(list,"")
			if word == word2 {
				fmt.Fprintln(out,1)
			} else {
				fmt.Fprintln(out,2)
			}
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		var word string
		fmt.Fscan(in,&word)
		if y == 0 || y == 1 || x == 1 {
			fmt.Fprintln(out,1)
		} else {
			fmt.Fprintln(out,2)
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y int
		fmt.Fscan(in,&x,&y)
		var word string
		fmt.Fscan(in,&word)
		if y == 0 || y == 1 {
			fmt.Fprintln(out,1)
		} else {
			fmt.Fprintln(out,2)
		}
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}
func solve() {
	var n, k int
	scan(&n, &k)
	var s string
	scan(&s)
	if k > 1 {
		t := Reverse(s)
		s1 := t + s
		s2 := s + t
		if s1 != s2 {
			printf("2\n")
			return
		}
	}
	printf("1\n")

}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

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

func solve() {
	var n, k int
	scan(&n, &k)
	var s string
	scan(&s)
	if k > 1 {
		printf("2\n")
	} else {
		printf("1\n")
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1634A
Date: 9/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1634/A
Problem: CF1634A
**/
func (in *CF1634A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		_, k := in.NextInt(), in.NextInt()
		str := in.NextString()

		mapa := make(map[uint8]int)
		for i := 0; i < len(str); i++ {
			mapa[str[i]]++
		}

		cant := len(mapa)
		ans := 1
		if k > 1 && cant > 1 {
			ans = 2
		}

		fmt.Println(ans)
	}

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1634A
Date: 19/02/22
User: epradere
URL: https://codeforces.com/problemset/problem/1634/A
Problem: CF1634A
**/
func (in *CF1634A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		str := in.NextString()

		mapa := make(map[uint8]int)
		for i := 0; i < n; i++ {
			val := mapa[str[i]]
			mapa[str[i]] = val + 1
		}
		min := len(mapa)

		if min > k {
			min = k
		}
		if min == 0 {
			min = 1
		}

		fmt.Println(min)
	}
}

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

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

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt(in)
	for ; t != 0; t-- {
		solve()
	}
}

func solve() {
	input := readArrInt(in)
	n, k := input[0], input[1]
	s, _ := in.ReadString('\n')
	s = strings.Trim(s, " \n\r")
	flag := true
	for i := 0; i < n; i++ {
		if s[i] != s[n-1-i] {
			flag = false
		}
	}
	if k == 0 {
		fmt.Println(0)
	} else if flag {
		fmt.Println(1)
	} else {
		fmt.Println(2)
	}
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	t := readInt(in)
	for ; t != 0; t-- {
		solve()
	}
}

func solve() {
	n := readInt(in)
	k := readInt(in)
	s, _ := in.ReadString('\n')
	s = strings.Trim(s, " \n\r")
	flag := true
	for i := 0; i < n; i++ {
		if s[i] != s[n-1-i] {
			flag = false
		}
	}
	if k == 0 {
		fmt.Println(0)
	} else if flag {
		fmt.Println(1)
	} else {
		fmt.Println(2)
	}
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

import (
	"fmt"
)

func test() {
	var n, k int
	var x string
	fmt.Scan(&n, &k, &x)
	if k <= 1 {
		fmt.Println(1)
		return
	}
	for i, j := 0, len(x)-1; i < j; i, j = i+1, j-1 {
		if x[i] != x[j] {
			fmt.Println(2)
			return
		}
	}
	fmt.Println(1)
}
func main() {
	var no int
	fmt.Scan(&no)
	for i := 0; i < no; i++ {
		test()
	}
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var n, k int
		var s string
		fmt.Scan(&n, &k)
		fmt.Scan(&s)

		if same(s) || k < 2 {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

func same(s string) bool {
	for i := 0; i < len(s); i++ {
		if s[i] != s[len(s)-i-1] {
			return false
		}
	}
	return true
}

package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var n, k int
		var s string
		fmt.Scan(&n, &k)
		fmt.Scan(&s)

		if same(s) || k < 2 {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

func same(s string) bool {
	for i := 1; i < len(s); i++ {
		if s[i] != s[0] {
			return false
		}
	}
	return true
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n int
		var x, y, ai int64
		scan(&n, &x, &y)
		x %= 2
		y %= 2
		for i := 0; i < n; i++ {
			scan(&ai)
			if ai%2 == 1 {
				x ^= 1
			}
		}
		if x == y {
			printf("Alice\n")
		} else {
			printf("Bob\n")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"unicode/utf8"
)

func isPal(s string) bool {
	for len(s) > 0 {
		if len(s) == 1 {
			return true
		}
		r1, sz1 := utf8.DecodeRuneInString(s)
		r2, sz2 := utf8.DecodeLastRuneInString(s)
		if r1 != r2 {
			return false
		}
		s = s[sz1 : len(s)-sz2]
	}
	return true
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var tests int
	fmt.Fscan(in, &tests)
	for i := 0; i < tests; i++ {
		var n, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)
		if k < 2 || isPal(s) {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

package main

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

func isPalindrome(s string) bool {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		if s[i] != s[j] {
			return false
		}
	}
	return true
}

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

	for ; t > 0; t-- {
		var n, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)

		isDiff := false
		for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
			if s[i] != s[j] {
				isDiff = true
			}
		}

		if isDiff {
			fmt.Println(2)

		} else {
			fmt.Println(1)
		}
	}
}


It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be transferred from one accumulator to the other. Every time x units of energy are transferred (x is not necessarily an integer) k percent of it is lost. That is, if x units were transferred from one accumulator to the other, amount of energy in the first one decreased by x units and in other increased by  units.Your task is to help Petya find what maximum equal amount of energy can be stored in each accumulator after the transfers.

First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers. Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).

Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy. The absolute or relative error in the answer should not exceed 10 - 6.

package main

import (
	"fmt"
)

const N = 1e4
var n int
var k float64
var a [N]float64

func main() {
	fmt.Scanf("%d %f\n", &n, &k)
	for i := 0; i < n; i++ { fmt.Scanf("%f", &a[i]) }
	fmt.Scanf("\n")
	lo := 0.0
	hi := 1000.0
	for hi - lo > 1e-10 {
		m := (lo + hi) / 2
		pos := 0.0
		neg := 0.0
		for i := 0; i < n; i++ {
			d := a[i] - m
			if d > 0 {
				pos += d
			} else {
				neg -= d
			}
		}
		// if hi - lo < 1.0 {
		// 	fmt.Printf("lo=%f hi=%f pos=%f neg=%f\n", lo, hi, pos, neg)
		// }
		if pos == 0 || neg / pos > (100 - k) / 100 {
			hi = m
		} else {
			lo = m
		}
	}
	fmt.Printf("%.9f\n", lo)
}

package main

import (
	"fmt"
)

const N = 1e4
var n int
var k float64
var a [N]float64

func main() {
	fmt.Scanf("%d %f", &n, &k)
	for i := 0; i < n; i++ { fmt.Scanf("%f", &a[i]) }
	lo := 0.0
	hi := 1000.0
	for hi - lo > 1e-10 {
		m := (lo + hi) / 2
		pos := 0.0
		neg := 0.0
		for i := 0; i < n; i++ {
			d := a[i] - m
			if d > 0 {
				pos += d
			} else {
				neg -= d
			}
		}
		// fmt.Printf("m=%f pos=%f neg=%f\n", m, pos, neg)
		if pos == 0 || neg / pos > (100 - k) / 100 {
			hi = m
		} else {
			lo = m
		}
	}
	fmt.Printf("%.9f\n", lo)
}

package main

import (
	"fmt"
)

const N = 1e4
var n int
var k float64
var a [N]float64

func main() {
	fmt.Scanf("%d %f", &n, &k)
	for i := 0; i < n; i++ { fmt.Scanf("%f", &a[i]) }
	lo := 0.0
	hi := 1000.0
	for hi - lo > 1e-10 {
		m := (lo + hi) / 2
		pos := 0.0
		neg := 0.0
		for i := 0; i < n; i++ {
			d := a[i] - m
			if d > 0 {
				pos += d
			} else {
				neg -= d
			}
		}
		fmt.Printf("m=%f pos=%f neg=%f\n", m, pos, neg)
		if pos == 0 || neg / pos > (100 - k) / 100 {
			hi = m
		} else {
			lo = m
		}
	}
	fmt.Printf("%.9f\n", lo)
}