There is an infinite set generated as follows:  $$$1$$$ is in this set.  If $$$x$$$ is in this set, $$$x \cdot a$$$ and $$$x+b$$$ both are in this set. For example, when $$$a=3$$$ and $$$b=6$$$, the five smallest elements of the set are:  $$$1$$$,  $$$3$$$ ($$$1$$$ is in this set, so $$$1\cdot a=3$$$ is in this set),  $$$7$$$ ($$$1$$$ is in this set, so $$$1+b=7$$$ is in this set),  $$$9$$$ ($$$3$$$ is in this set, so $$$3\cdot a=9$$$ is in this set),  $$$13$$$ ($$$7$$$ is in this set, so $$$7+b=13$$$ is in this set). Given positive integers $$$a$$$, $$$b$$$, $$$n$$$, determine if $$$n$$$ is in this set.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 10^5$$$) — the number of test cases. The description of the test cases follows. The only line describing each test case contains three integers $$$n$$$, $$$a$$$, $$$b$$$ ($$$1\leq n,a,b\leq 10^9$$$) separated by a single space.

For each test case, print "Yes" if $$$n$$$ is in this set, and "No" otherwise. You can print each letter in any case.

NoteIn the first test case, $$$24$$$ is generated as follows:  $$$1$$$ is in this set, so $$$3$$$ and $$$6$$$ are in this set;  $$$3$$$ is in this set, so $$$9$$$ and $$$8$$$ are in this set;  $$$8$$$ is in this set, so $$$24$$$ and $$$13$$$ are in this set. Thus we can see $$$24$$$ is in this set.The five smallest elements of the set in the second test case is described in statements. We can see that $$$10$$$ isn't among them.

package main

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

// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var testCount int
	fmt.Fscan(in, &testCount)

	for i := 0; i < testCount; i++ {
		var n, a, b int64
		fmt.Fscan(in, &n, &a, &b)

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var testCount int
	fmt.Fscan(in, &testCount)

	for i := 0; i < testCount; i++ {
		var n, a, b int64
		fmt.Fscan(in, &n, &a, &b)

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)

	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

	var testCount int
	_, _ = fmt.Fscan(in, &testCount)

	for i := 0; i < testCount; i++ {
		yes := false
		var n, a, b int64

		_, _ = fmt.Fscan(in, &n, &a, &b)

		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}

			if a == 1 {
				break
			}
		}

		if yes {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

var in *bufio.Reader

func solve() {
	var n, a, b int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &a)
	fmt.Fscan(in, &b)

	var x int64 = 1
	for x <= n {
		if x%b == n%b {
			fmt.Println("Yes")
			return
		}
		if a == 1 {
			break
		}
		x *= a
	}
	fmt.Println("No")
}

func main() {
	in = bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

const N = int(1e5 + 10)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	t := 1
	t = io.NextInt()

	for tt := 0; tt < t; tt++ {
		solve := func() {
			n, a, b := io.NextInt(), io.NextInt(), io.NextInt()
			val := int64(1)
			for {
				if val > int64(n) {
					break
				}
				if (int64(n)-val)%int64(b) == 0 {
					io.Println("Yes")
					return
				}
				val *= int64(a)
				if a == 1 {
					break
				}
			}
			io.Println("No")
		}
		solve()
	}
}

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

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

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	solve = func() {
		var a, b, n int64
		Fscan(in, &n, &a, &b)
		if n == 1 || b == 1 {
			Fprintln(out, "Yes")
			return
		}
		if a == 1 {
			if n%b == 1 {
				Fprintln(out, "Yes")
			} else {
				Fprintln(out, "No")
			}
			return
		}
		var base int64 = 1
		for base <= n {
			if base%b == n%b {
				Fprintln(out, "Yes")
				return
			}
			base *= a
		}
		Fprintln(out, "No")
	}
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}

}

package main

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

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

	var T int
	var n, a, b int64
	f := func() bool {
		if a == 1 {
			return (n-1)%b == 0
		}
		for i := int64(1); i <= n; i *= a {
			if (n-i)%b == 0 {
				return true
			}
		}
		return false
	}
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &a, &b)
		if f() {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

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

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

	solve := func(Case int) (_b bool) {
		var n, a, b int64
		Fscan(in, &n, &a, &b)

		if a == 1 {
			return (n-1)%b == 0
		}
		for i := int64(1); i <=n; i*=a {
			if (n-i)%b ==0 {
				return true
			}
		}

		return
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		if solve(Case) {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}

	_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 int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

// 1542B: Plus and Multiply

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		// if number is divisible by a, then divide by a; else subtract by b
		// the final result shall be 1
		pln,_ := Readln(reader)
		ln := strings.Split(pln, " ")
		n,_ := strconv.Atoi(ln[0])
		a,_ := strconv.Atoi(ln[1])
		b,_ := strconv.Atoi(ln[2])

		if b==1 {
			fmt.Println("yes")
			continue
		}
		if a==1 {
			if (n-1) % b ==0 {
				fmt.Println("yes")
				continue
			}
			fmt.Println("no")
			continue
		}

		//pretty much in the form of: a**p + q*b ?

		ok := false
		i:= float64(0)
		for float64(n)- math.Pow(float64(a),i) >= 0 {
			if int(float64(n)- math.Pow(float64(a),i)) % b ==0 {
				ok = true
				//fmt.Println(i)
				break
			}
			i++
		}

		if ok{
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}

	}

}

package main

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

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

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int64 {
	var res int64
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	t := io.ReadInt()
	for ; t > 0; t-- {
		sl := io.ReadIntSlice(3)
		n, a, b := int64(sl[0]), int64(sl[1]), int64(sl[2])
		st := int64(1)
		done := false
		for st <= n {
			if (n - st) % b == 0 {
				io.Println("Yes")
				done = true
				break
			}
			st *= a
			if a == 1 {
				break
			}
		}
		if !done {
			io.Println("No")
		}
	}
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

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

		var ans bool

		for ap := int64(1); ap <= n; ap *= a {
			if (n-ap)%b == 0 {
				ans = true
				break
			}

			if a == 1 {
				break
			}
		}

		if ans {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}

	}

	_ = out.Flush()
}

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, a, b int64
	res bool
)

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() {
	res = false
}

func input() {
	n = getInt64()
	a = getInt64()
	b = getInt64()
}

func count() {
	if a == 1 {
		res = (n - 1) % b == 0
		return
	}
	var i int64 = 1
	for {
		if (n - i) % b == 0 {
			res = true
			return
		}
		i *= a
		if i > n {
			return
		}
	}
}

func output() {
	yes(res, false)
}

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 (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, a, b := readThreeNums(reader)
		res := solve(a, b, n)
		if res {
			buf.WriteString("Yes\n")
		} else {
			buf.WriteString("No\n")
		}
	}

	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
}

func solve(a, b, n int) bool {
	if a == 1 {
		return (n - 1) % b == 0
	}

	B := int64(b)
	N := int64(n)
	A := int64(a)

	var t int64 = 1

	for t <= N {

		if N%B == t%B {
			return true
		}
		t *= A

	}
	return false
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n, a, b int64
		fmt.Fscan(input, &n, &a, &b)
		if b == 1 {
			fmt.Println("YES")
		} else {
			if a == 1 {
				if n%b == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			} else {
				var begin, Aim int64
				Aim = n
				begin = 1
				ww := 0
				for i := 0; Aim-begin > -1; i++ {
					qq := Aim - begin
					if qq%b == 0 {
						ww = 1
						break
					} else {
						begin = begin * a
					}
				}
				if ww == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}
	}

}

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n, a, b := sint64(), sint64(), sint64()
		printf("%s\n", sol(n, a, b))
	}
}

func sol(n, a, b int64) string {
	if a == 1 {
		if (n-1)%b == 0 {
			return "Yes"
		}
		return "No"
	}
	curr := int64(1)
	for curr <= n {
		if (n-curr)%b == 0 {
			return "Yes"
		}
		curr = curr * a
	}
	return "No"
}

package main

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

// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var testCount int
	fmt.Fscan(in, &testCount)

	for i := 0; i < testCount; i++ {
		var n, a, b int32
		fmt.Fscan(in, &n, &a, &b)

		var prev int32
		var yes bool
		var sumG int32 = 1
		for ; sumG <= n; sumG *= a {
			if prev > sumG {
				break
			}

			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}

			prev = sumG
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var testCount int
	fmt.Fscan(in, &testCount)

	for i := 0; i < testCount; i++ {
		var n, a, b int32
		fmt.Fscan(in, &n, &a, &b)

		var prev int32
		var yes bool
		var sumG int32 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 || prev > sumG {
				break
			}

			prev = sumG
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var testCount int
	fmt.Fscan(in, &testCount)

	for i := 0; i < testCount; i++ {
		var n, a, b int64
		fmt.Fscan(in, &n, &a, &b)

		var yes bool
		var sumG int64 = 1
		for ; sumG < n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)

	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)
next:
	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		var sumG int64 = 1
		for ; sumG < n; sumG *= a {
			if (n-sumG)%b == 0 {
				fmt.Println("Yes")
				continue next
			}
			if a == 1 {
				fmt.Println("No")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)
next:
	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 || b == 1 {
			fmt.Println("Yes")
			continue
		}

		var sumG int64 = 1
		for ; sumG < n; sumG *= a {
			if (n-sumG)%b == 0 {
				fmt.Println("Yes")
				continue next
			}
			if a == 1 {
				fmt.Println("No")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)
next:
	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 || b == 1 {
			fmt.Println("Yes")
			continue
		}

		if a == 1 {
			fmt.Println("No")
			continue
		}

		var sumG, prevSum int64 = 1, 1
		for sumG < n {
			prevSum = sumG
			sumG = prevSum * a

			if (n-sumG)%b == 0 {
				fmt.Println("Yes")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int, 0, 3)

	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.Atoi(p)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 || b == 1 {
			fmt.Println("Yes")
			continue
		}

		if a == 1 {
			fmt.Println("No")
			continue
		}
		var yes bool
		sumG := 1
		prevSum := 1
		for sumG < n {
			prevSum = sumG
			sumG = prevSum * a

			if (n-sumG)%b == 0 {
				break
			}
		}

		if yes {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

next:
	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input := scanner.Text()

		inputList := make([]int, 0, 3)
		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.Atoi(p)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 {
			fmt.Println("Yes")
			continue
		}

		for i := 1; i < a; i++ {
			sumG := n / (i * a)
			if sumG/b > 0 && sumG%b == 1 {
				fmt.Println("Yes")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// посчитать сумму геометрической прогрессии n / ((a - 1) * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

next:
	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input := scanner.Text()

		inputList := make([]int, 0, 3)
		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.Atoi(p)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 {
			fmt.Println("Yes")
			continue
		}

		for i := 0; i < a; i++ {
			sum := n / ((a - i) * a)
			if sum / b > 0 && sum%b == 1 {
				fmt.Println("Yes")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

var in *bufio.Reader

func solve() {
	var n, a, b int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &a)
	fmt.Fscan(in, &b)

	var x int64 = 1
	for x < n {
		if x%b == n%b {
			fmt.Println("Yes")
			return
		}
		if a == 1 {
			break
		}
		x *= a
	}
	fmt.Println("No")
}

func main() {
	in = bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

const N = int(1e5 + 10)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	t := 1
	t = io.NextInt()

	for tt := 0; tt < t; tt++ {
		solve := func() {
			n, a, b := io.NextInt(), io.NextInt(), io.NextInt()
			val := int64(1)
			for {
				val *= int64(a)
				if val > int64(n) {
					break
				}
				if (int64(n)-val)%int64(b) == 0 {
					io.Println("Yes")
					return
				}
				if a == 1 {
					break
				}
			}
			io.Println("No")
		}
		solve()
	}
}

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

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

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

const N = int(1e5 + 10)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	t := 1
	t = io.NextInt()

	for tt := 0; tt < t; tt++ {
		solve := func() {
			n, a, b := io.NextInt(), io.NextInt(), io.NextInt()
			val := int64(1)
			for i := 1; i < 30; i++ {
				val *= int64(a)
				if val > int64(n) {
					break
				}
				if (int64(n)-val)%int64(b) == 0 {
					io.Println("Yes")
					return
				}
			}
			io.Println("No")
		}
		solve()
	}
}

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

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

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	solve = func() {
		var a, b, n int64
		Fscan(in, &n, &a, &b)
		if n == 1 || b == 1 {
			Fprintln(out, "Yes")
			return
		}
		if a == 1 {
			if n%b == 1 {
				Fprintln(out, "Yes")
			} else {
				Fprintln(out, "No")
			}
			return
		}
		var base int64 = 1
		for base < n {
			if base%b == n%b {
				Fprintln(out, "Yes")
				return
			}
			base *= a
		}
		Fprintln(out, "No")
	}
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}

}

package main

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

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

	solve := func(Case int) (_b bool) {
		var n, a, b int64
		Fscan(in, &n, &a, &b)

		if a == 1 {
			return (n-1)%b == 0
		}
		for i := a; i <=n; i*=a {
			if (n-i)%b ==0 {
				return true
			}
		}

		return
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		if solve(Case) {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}

	_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 int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

// 1542B: Plus and Multiply

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		// if number is divisible by a, then divide by a; else subtract by b
		// the final result shall be 1
		pln,_ := Readln(reader)
		ln := strings.Split(pln, " ")
		n,_ := strconv.Atoi(ln[0])
		a,_ := strconv.Atoi(ln[1])
		b,_ := strconv.Atoi(ln[2])

		if b==1 {
			fmt.Println("yes")
			continue
		}
		if a==1 {
			if (n-1) % b ==0 {
				fmt.Println("yes")
				continue
			}
			fmt.Println("no")
			continue
		}

		//pretty much in the form of: a**p + q*b ?

		ok := false
		i:= float64(0)
		for float64(n)- math.Pow(float64(a),i) > 0 {
			if int(float64(n)- math.Pow(float64(a),i)) % b ==0 {
				ok = true
				//fmt.Println(i)
				break
			}
			i++
		}

		if ok{
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}

	}

}

package main

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

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

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int64 {
	var res int64
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	t := io.ReadInt()
	for ; t > 0; t-- {
		sl := io.ReadIntSlice(3)
		n, a, b := int64(sl[0]), int64(sl[1]), int64(sl[2])
		st := int64(1)
		done := false
		for st < n {
			if (n - st) % b == 0 {
				io.Println("Yes")
				done = true
				break
			}
			st *= a
			if a == 1 {
				break
			}
		}
		if !done {
			io.Println("No")
		}
	}
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

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

		var ans bool

		if a == 1 {
			_, _ = fmt.Fprintln(out, "Yes")
			continue
		}

		for ap := int64(1); ap <= n; ap *= a {
			if (n-ap)%b == 0 {
				ans = true
				break
			}
		}

		if ans {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}

	}

	_ = out.Flush()
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, a, b := readThreeNums(reader)
		res := solve(a, b, n)
		if res {
			buf.WriteString("Yes\n")
		} else {
			buf.WriteString("No\n")
		}
	}

	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
}

func solve(a, b, n int) bool {
	if a == 1 {
		return n%b == 1
	}

	B := int64(b)
	N := int64(n)
	A := int64(a)

	var t int64 = 1

	for t <= N {

		if N%B == t%B {
			return true
		}
		t *= A

	}
	return false
}


Zane the wizard is going to perform a magic show shuffling the cups.There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = ui and x = vi. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations.Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5 at any moment during the operation.  Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.

The first line contains three integers n, m, and k (2 ≤ n ≤ 106, 1 ≤ m ≤ n, 1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains m distinct integers h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there is a hole on the table. Each of the next k lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the positions of the cups to be swapped.

Print one integer — the final position along the x-axis of the bone.

NoteIn the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively.In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.

package main

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

func solve() {
	n := readInt()
	m := readInt()
	k := readInt()
	h := make([]bool, n)
	for i := 0; i < m; i++ {
		h[readInt()-1] = true
	}
	pos := 0
	if !h[pos] {
		for i := 0; i < k; i++ {
			u := readInt() - 1
			v := readInt() - 1
			if pos == u {
				pos = v
			} else if v == pos {
				pos = u
			}

			if h[pos] {
				break
			}
		}
	}
	fmt.Println(pos + 1)
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Fscanf(in,"%d",&x)
        //fmt.Println(x)
        table[x]=1
    }
    fmt.Fscanf(in,"\n")
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Fscanf(in,"%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

package main

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}

	N := io.NextInt()
	M := io.NextInt()
	K := io.NextInt()
	H := io.NextIntArray(M)

	U := make([]int, K)
	V := make([]int, K)
	for i := 0; i < K; i++ {
		U[i] = io.NextInt()
		V[i] = io.NextInt()
	}

	hole := make([]bool, N + 1)
	for _, pos := range H {
		hole[pos] = true
	}

	pos := 1
	for i := 0; i < K; i++ {
		if hole[pos] {
			break
		}
		if pos == U[i] {
			pos = V[i]
		} else if pos == V[i] {
			pos = U[i]
		}
	}
	io.Printf("%d\n", pos)

	io.FlushOutput()
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

package main

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

func main() {
	sc := NewScanner()
	_, _, K := sc.NextInt(), sc.NextInt(), sc.NextInt()
	h := sc.NextMap()
	b := 1

	for i := 0; i < K; i++ {
		if h[b] {
			fmt.Println(b)
			return
		}

		u, v := sc.NextInt(), sc.NextInt()

		if b == u {
			b = v
		} else if b == v {
			b = u
		}

	}
	fmt.Println(b)

}

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

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

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

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

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

	return mp
}

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

package main
import "fmt"

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Scanf("%d\n",&x)
        table[x]=1
    }
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Scanf("%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u{
                cur=v
            }else{
                cur=u
            }
        }
    }
    fmt.Println(cur)
}

package main
import "fmt"

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Scanf("%d\n",&x)
        table[x]=1
    }
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Scanf("%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

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

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Fscanf(in,"%d",&x)
        //fmt.Println(x)
        table[x]=1
    }
    fmt.Scanf("\n")
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Fscanf(in,"%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

package main
import "fmt"

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Scanf("%d",&x)
        //fmt.Println(x)
        table[x]=1
    }
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Scanf("%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

package main

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

func main() {
	sc := NewScanner()
	_, _, K := sc.NextInt(), sc.NextInt(), sc.NextInt()
	h := sc.NextMap()
	b := 1

	for i := 0; i < K; i++ {
		u, v := sc.NextInt(), sc.NextInt()
		if h[u] {
			fmt.Println(u)
			return
		}
		if h[v] {
			fmt.Println(v)
			return
		}

		if b == u {
			b = v
		} else {
			b = u
		}
	}
	fmt.Println(b)

}

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	sc := NewScanner()
	_, _, K := sc.NextInt(), sc.NextInt(), sc.NextInt()
	h := sc.NextMap()
	b := 1

	for i := 0; i < K; i++ {
		u, v := sc.NextInt(), sc.NextInt()
		if h[u] {
			fmt.Println(u)
			return
		}
		if h[v] {
			fmt.Println(v)
			return
		}

		if b == u {
			b = v
		} else if b == v {
			b = u
		}
	}
	fmt.Println(b)

}

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

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

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

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

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

	return mp
}

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


You are given an array of $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$.You have to create an array of $$$n$$$ integers $$$b_1,b_2,\dots,b_n$$$ such that:   The array $$$b$$$ is a rearrangement of the array $$$a$$$, that is, it contains the same values and each value appears the same number of times in the two arrays. In other words, the multisets $$$\{a_1,a_2,\dots,a_n\}$$$ and $$$\{b_1,b_2,\dots,b_n\}$$$ are equal.For example, if $$$a=[1,-1,0,1]$$$, then $$$b=[-1,1,1,0]$$$ and $$$b=[0,1,-1,1]$$$ are rearrangements of $$$a$$$, but $$$b=[1,-1,-1,0]$$$ and $$$b=[1,0,2,-3]$$$ are not rearrangements of $$$a$$$.  For all $$$k=1,2,\dots,n$$$ the sum of the first $$$k$$$ elements of $$$b$$$ is nonzero. Formally, for all $$$k=1,2,\dots,n$$$, it must hold $$$$$$b_1+b_2+\cdots+b_k\not=0\,.$$$$$$ If an array $$$b_1,b_2,\dots, b_n$$$ with the required properties does not exist, you have to print NO.

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t \le 1000$$$) — the number of test cases. The description of the test cases follows. The first line of each testcase contains one integer $$$n$$$ ($$$1\le n\le 50$$$)  — the length of the array $$$a$$$. The second line of each testcase contains $$$n$$$ integers $$$a_1,a_2,\dots, a_n$$$ ($$$-50\le a_i\le 50$$$)  — the elements of $$$a$$$.

For each testcase, if there is not an array $$$b_1,b_2,\dots,b_n$$$ with the required properties, print a single line with the word NO. Otherwise print a line with the word YES, followed by a line with the $$$n$$$ integers $$$b_1,b_2,\dots,b_n$$$.  If there is more than one array $$$b_1,b_2,\dots,b_n$$$ satisfying the required properties, you can print any of them.

NoteExplanation of the first testcase: An array with the desired properties is $$$b=[1,-2,3,-4]$$$. For this array, it holds:   The first element of $$$b$$$ is $$$1$$$.  The sum of the first two elements of $$$b$$$ is $$$-1$$$.  The sum of the first three elements of $$$b$$$ is $$$2$$$.  The sum of the first four elements of $$$b$$$ is $$$-2$$$. Explanation of the second testcase: Since all values in $$$a$$$ are $$$0$$$, any rearrangement $$$b$$$ of $$$a$$$ will have all elements equal to $$$0$$$ and therefore it clearly cannot satisfy the second property described in the statement (for example because $$$b_1=0$$$). Hence in this case the answer is NO.Explanation of the third testcase: An array with the desired properties is $$$b=[1, 1, -1, 1, -1]$$$. For this array, it holds:   The first element of $$$b$$$ is $$$1$$$.  The sum of the first two elements of $$$b$$$ is $$$2$$$.  The sum of the first three elements of $$$b$$$ is $$$1$$$.  The sum of the first four elements of $$$b$$$ is $$$2$$$.  The sum of the first five elements of $$$b$$$ is $$$1$$$. Explanation of the fourth testcase: An array with the desired properties is $$$b=[-40,13,40,0,-9,-31]$$$. For this array, it holds:   The first element of $$$b$$$ is $$$-40$$$.  The sum of the first two elements of $$$b$$$ is $$$-27$$$.  The sum of the first three elements of $$$b$$$ is $$$13$$$.  The sum of the first four elements of $$$b$$$ is $$$13$$$.  The sum of the first five elements of $$$b$$$ is $$$4$$$.  The sum of the first six elements of $$$b$$$ is $$$-27$$$.

package main

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

func main() {
	defer writer.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		solve(n, a)
	}
}

func solve(n int, a []int) {
	sum := Sum(a...)
	if sum == 0 {
		Println("NO")
		return
	}
	Println("YES")
	if sum > 0 {
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
	} else {
		sort.Ints(a)
	}
	for i := 0; i < n; i++ {
		if i > 0 {
			Print(" ")
		}
		Print(a[i])
	}
	Println()
}

func Sum(slice ...int) int {
	sum := 0
	for _, v := range slice {
		sum += v
	}
	return sum
}

var writer = bufio.NewWriter(os.Stdout)

func Print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		s := 0
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			s+=a[i]
		}
		if s ==0 {
			Fprintln(out, "NO")
			return
		}
		sort.Ints(a)
		Fprintln(out, "YES")
		if s < 0 {
			for _, v := range a {
				Fprint(out, v, " ")
			}
		} else {
			for i := len(a) - 1; i >= 0; i-- {
				Fprint(out, a[i], " ")
			}
		}
		Fprintln(out)

		return
	}

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

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


Peter has a sequence of integers a1, a2, ..., an. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l, r]": add one to all elements of the sequence with indices from l to r (inclusive). At that, Peter never chooses any element as the beginning of the segment twice. Similarly, Peter never chooses any element as the end of the segment twice. In other words, for any two segments [l1, r1] and [l2, r2], where Peter added one, the following inequalities hold: l1 ≠ l2 and r1 ≠ r2.How many distinct ways are there to make all numbers in the sequence equal h? Print this number of ways modulo 1000000007 (109 + 7). Two ways are considered distinct if one of them has a segment that isn't in the other way.

The first line contains two integers n, h (1 ≤ n, h ≤ 2000). The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 2000).

Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).

package main

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

var (
	iptr int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

func Abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

const (
	MOD = 1000000007
	MAX_N = 1100
)

var (
	n, h, p int
	a []int
	memo = make(map[int]int64)
)

func dfs(i int, x int) int64 {
	k := i * MAX_N + x
	if val, ok := memo[k]; ok {
		return val
	}
	if i == n {
		if x == 0 {
			memo[k] = 1
		} else {
			memo[k] = 0
		}
		return memo[k]
	}
	memo[k] = int64(0)
	if a[i] + x + 1 == h {
		memo[k] += dfs(i + 1, x) * int64(x + 1) % MOD
		memo[k] += dfs(i + 1, x + 1) * int64(x + 1) % MOD
	}
	if a[i] + x == h {
		memo[k] += dfs(i + 1, x)
		if x > 0 {
			memo[k] += dfs(i + 1, x - 1) % MOD
		}
	}
	memo[k] %= MOD
	return memo[k]
}

func main() {
	n, h = ReadInt(), ReadInt()
	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ReadInt()
	}
	fmt.Println(dfs(0, 0))
}

package main

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

var (
	iptr int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

func Abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

const (
	MOD = 1000000007
	MAX_N = 1100
)

var (
	n, h, p int
	a []int
	memo = make(map[int]int64)
)

func dfs(i int, x int) int64 {
	k := i * MAX_N + x
	if val, ok := memo[k]; ok {
		return val
	}
	if i == n {
		if x == 0 {
			memo[k] = 1
		} else {
			memo[k] = 0
		}
		return memo[k]
	}
	memo[k] = int64(0)
	if a[i] + x + 1 == h {
		memo[k] += dfs(i + 1, x)
		memo[k] += dfs(i + 1, x + 1)
	}
	if a[i] + x == h {
		memo[k] += dfs(i + 1, x)
		if x > 0 {
			memo[k] += dfs(i + 1, x - 1)
		}
	}
	memo[k] %= MOD
	return memo[k]
}

func main() {
	n, h = ReadInt(), ReadInt()
	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ReadInt()
	}
	fmt.Println(dfs(0, 0))
}

package main

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

var (
	iptr int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

func Abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

const (
	MOD = 1000000007
	MAX_N = 1100
)

var (
	n, h, p int
	a []int
	memo = make(map[int]int64)
)

func dfs(i int, x int) int64 {
	k := i * MAX_N + x
	if val, ok := memo[k]; ok {
		return val
	}
	if i == n {
		if x == 0 {
			memo[k] = 1
		} else {
			memo[k] = 0
		}
		return memo[k]
	}
	memo[k] = int64(0)
	if a[i] + x + 1 == h {
		memo[k] += dfs(i + 1, x)
		memo[k] += dfs(i + 1, x + 1) * int64(x + 1) % MOD
	}
	if a[i] + x == h {
		memo[k] += dfs(i + 1, x)
		if x > 0 {
			memo[k] += dfs(i + 1, x - 1) * int64(x) % MOD
		}
	}
	memo[k] %= MOD
	return memo[k]
}

func main() {
	n, h = ReadInt(), ReadInt()
	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ReadInt()
	}
	fmt.Println(dfs(0, 0))
}

package main

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

var (
	iptr int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

func Abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

const (
	MOD = 1000000007
	MAX_N = 1100
)

var (
	n, h, p int
	a []int64
	memo = make(map[int64]int64)
)

func dfs(i int, x int64) int64 {
	k := int64(i) * MAX_N + x
	if val, ok := memo[k]; ok {
		return val
	}
	if i == n {
		if x == 0 {
			memo[k] = 1
		} else {
			memo[k] = 0
		}
		return memo[k]
	}
	memo[k] = int64(0)
	if a[i] + x + int64(1) == int64(h) {
		memo[k] += dfs(i + 1, x + 1)
	}
	if a[i] + x == int64(h) {
		memo[k] += dfs(i + 1, x)
		if x > 0 {
			memo[k] += dfs(i + 1, x - 1) * x % MOD
		}
	}
	memo[k] %= MOD
	return memo[k]
}

func main() {
	n, h = ReadInt(), ReadInt()
	a = make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = ReadInt64()
	}
	fmt.Println(dfs(0, 0))
}

package main

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

var (
	iptr int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

func Abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

const (
	MOD = 1000000007
	MAX_N = 1100
)

var (
	n, h, p int
	a []int
	memo = make(map[int]int64)
)

func dfs(i int, x int) int64 {
	k := i * MAX_N + x
	if val, ok := memo[k]; ok {
		return val
	}
	if i == n {
		if x == 0 {
			memo[k] = 1
		} else {
			memo[k] = 0
		}
		return memo[k]
	}
	memo[k] = int64(0)
	if a[i] + x + 1 == h {
		memo[k] += dfs(i + 1, x)
		memo[k] += dfs(i + 1, x + 1) * int64(x + 1) % MOD
	}
	if a[i] + x == h {
		memo[k] += dfs(i + 1, x)
		if x > 0 {
			memo[k] += dfs(i + 1, x - 1) % MOD
		}
	}
	memo[k] %= MOD
	return memo[k]
}

func main() {
	n, h = ReadInt(), ReadInt()
	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ReadInt()
	}
	fmt.Println(dfs(0, 0))
}


Let's call an undirected graph $$$G = (V, E)$$$ relatively prime if and only if for each edge $$$(v, u) \in E$$$  $$$GCD(v, u) = 1$$$ (the greatest common divisor of $$$v$$$ and $$$u$$$ is $$$1$$$). If there is no edge between some pair of vertices $$$v$$$ and $$$u$$$ then the value of $$$GCD(v, u)$$$ doesn't matter. The vertices are numbered from $$$1$$$ to $$$|V|$$$.Construct a relatively prime graph with $$$n$$$ vertices and $$$m$$$ edges such that it is connected and it contains neither self-loops nor multiple edges.If there exists no valid graph with the given number of vertices and edges then output "Impossible".If there are multiple answers then print any of them.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^5$$$) — the number of vertices and the number of edges.

If there exists no valid graph with the given number of vertices and edges then output "Impossible". Otherwise print the answer in the following format: The first line should contain the word "Possible". The $$$i$$$-th of the next $$$m$$$ lines should contain the $$$i$$$-th edge $$$(v_i, u_i)$$$ of the resulting graph ($$$1 \le v_i, u_i \le n, v_i \neq u_i$$$). For each pair $$$(v, u)$$$ there can be no more pairs $$$(v, u)$$$ or $$$(u, v)$$$. The vertices are numbered from $$$1$$$ to $$$n$$$. If there are multiple answers then print any of them.

NoteHere is the representation of the graph from the first example:

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1009D(in io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	var n, m int
	Fscan(in, &n, &m)
	if m < n-1 {
		Fprint(out, "Impossible")
		return
	}
	ans := make([][2]int, 0, m)
o:
	for i := 1; i < n; i++ {
		for j := i + 1; j <= n; j++ {
			if gcd(i, j) == 1 {
				ans = append(ans, [2]int{i, j})
				if len(ans) == m {
					break o
				}
			}
		}
	}
	if len(ans) < m {
		Fprint(out, "Impossible")
		return
	}
	Fprintln(out, "Possible")
	for _, e := range ans {
		Fprintln(out, e[0], e[1])
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}
// head

func main() {
	defer writer.Flush()
	var n, m int
	scan(&n, &m)
	if m < n - 1 {
		println("Impossible")
		return
	}
	edges := make([][]int, n + 1)
	edges[1] = append(edges[1], 0)
	cnt := 0
	for i := 1; i < n + 1; i++ {
		for _, j := range edges[i] {
			for k := 1;;k++ {
				t := j + k*i
				if t <= i {
					continue
				}
				if t > n {
					break
				}
				edges[t] = append(edges[t], i)
				cnt++
				if cnt >= m {
					goto output
				}
			}
		}
	}
	output:
	if cnt < m {
		println("Impossible")
		return
	}
	println("Possible")
	for i := 2; i < n + 1; i++ {
		for _, j := range edges[i] {
			println(i, j)
		}
	}
}


Do you know the story about the three musketeers? Anyway, you must help them now.Richelimakieu is a cardinal in the city of Bearis. He found three brave warriors and called them the three musketeers. Athos has strength a, Borthos strength b, and Caramis has strength c.The year 2015 is almost over and there are still n criminals to be defeated. The i-th criminal has strength ti. It's hard to defeat strong criminals — maybe musketeers will have to fight together to achieve it.Richelimakieu will coordinate musketeers' actions. In each hour each musketeer can either do nothing or be assigned to one criminal. Two or three musketeers can be assigned to the same criminal and then their strengths are summed up. A criminal can be defeated in exactly one hour (also if two or three musketeers fight him). Richelimakieu can't allow the situation where a criminal has strength bigger than the sum of strengths of musketeers fighting him — a criminal would win then!In other words, there are three ways to defeat a criminal.  A musketeer of the strength x in one hour can defeat a criminal of the strength not greater than x. So, for example Athos in one hour can defeat criminal i only if ti ≤ a.  Two musketeers can fight together and in one hour defeat a criminal of the strength not greater than the sum of strengths of these two musketeers. So, for example Athos and Caramis in one hour can defeat criminal i only if ti ≤ a + c. Note that the third remaining musketeer can either do nothing or fight some other criminal.  Similarly, all three musketeers can fight together and in one hour defeat a criminal of the strength not greater than the sum of musketeers' strengths, i.e. ti ≤ a + b + c. Richelimakieu doesn't want musketeers to fight during the New Year's Eve. Thus, he must coordinate their actions in order to minimize the number of hours till all criminals will be defeated.Find the minimum number of hours to defeat all criminals. If musketeers can't defeat them all then print "-1" (without the quotes) instead.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of criminals. The second line contains three integers a, b and c (1 ≤ a, b, c ≤ 108) — strengths of musketeers. The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 108) — strengths of criminals.

Print one line with the answer. If it's impossible to defeat all criminals, print "-1" (without the quotes). Otherwise, print the minimum number of hours the three musketeers will spend on defeating all criminals.

NoteIn the first sample Athos has strength 10, Borthos 20, and Caramis 30. They can defeat all criminals in two hours:  Borthos and Caramis should together fight a criminal with strength 50. In the same hour Athos can fight one of four criminals with strength 1.  There are three criminals left, each with strength 1. Each musketeer can fight one criminal in the second hour.  In the second sample all three musketeers must together fight a criminal with strength 51. It takes one hour. In the second hour they can fight separately, each with one criminal. In the third hour one criminal is left and any of musketeers can fight him.

package main

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

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

func Scan(args ...interface{}) (e error)             { _, e = fmt.Fscan(in, args...); return }
func Scanf(ft string, args ...interface{}) (e error) { _, e = fmt.Fscanf(in, ft, args...); return }
func Scanln(args ...interface{}) (e error)           { _, e = fmt.Fscanln(in, args...); return }
func Print(args ...interface{})                      { out.WriteString(fmt.Sprint(args...)) }
func Printf(ft string, args ...interface{})          { out.WriteString(fmt.Sprintf(ft, args...)) }
func Println(args ...interface{})                    { out.WriteString(fmt.Sprintln(args...)) }

var (
	dataIn = "data.in"
	in     = bufio.NewReader(os.Stdin)
	//in, _ = os.Open(dataIn)
	out = bufio.NewWriter(os.Stdout)
)
var n, sum int
var musk, crim []int

func read() {
	sum = 0
	musk = make([]int, 6)
	crim = make([]int, n)
	for i := 0; i < 3; i++ {
		Scan(&musk[i])
		sum += musk[i]
	}
	musk[3] = musk[0] + musk[1]
	musk[4] = musk[0] + musk[2]
	musk[5] = musk[1] + musk[2]
	for i := 0; i < n; i++ {
		Scan(&crim[i])
	}
	sort.Ints(musk)
	sort.Ints(crim)
}

func solve() {
	if sum < crim[n-1] {
		Println("-1")
		return
	}

	off := 0
	for ; n >= 1 && crim[n-1] > musk[5]; n-- {
		off++
	}
	loc := make([]int, 6)
	for i := 0; i < 6; i++ {
		loc[i] = sort.Search(n, func(j int) bool { return crim[j] > musk[i] })
	}

	cnt := n
	for c012 := 0; c012 < n; c012++ {
		c12 := loc[5] - loc[4]
		c02 := loc[4] - loc[3]
		c01 := 0
		if musk[0]+musk[1] == musk[2] && musk[2] < musk[3] {
			// 0 < 1 < 01 < 2 < 02 < 12 < 012
			c01 = Max(0, loc[3]-loc[2]-c012)
		} else {
			// 0 < 1 < 2 < 01 < 02 < 12 < 012
			c01 = Max(0, loc[3]-loc[2])
		}
		c01 = Max(c01, (loc[3]-loc[1]-c012+1)/2)
		c01 = Max(c01, (loc[3]-loc[0]-2*c012-c02+1)/2)
		c01 = Max(c01, (loc[3]-3*c012-c02-c12+1)/2)

		cnt = Min(cnt, c012+c01+c02+c12)
	}

	Println(off + cnt)
}

func main() {
	defer out.Flush()
	for Scan(&n) != io.EOF {
		read()
		solve()
	}
	return
}

package main

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

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

func Scan(args ...interface{}) (e error)             { _, e = fmt.Fscan(in, args...); return }
func Scanf(ft string, args ...interface{}) (e error) { _, e = fmt.Fscanf(in, ft, args...); return }
func Scanln(args ...interface{}) (e error)           { _, e = fmt.Fscanln(in, args...); return }
func Print(args ...interface{})                      { out.WriteString(fmt.Sprint(args...)) }
func Printf(ft string, args ...interface{})          { out.WriteString(fmt.Sprintf(ft, args...)) }
func Println(args ...interface{})                    { out.WriteString(fmt.Sprintln(args...)) }

var (
	dataIn = "data.in"
	in     = bufio.NewReader(os.Stdin)
	//in, _ = os.Open(dataIn)
	out = bufio.NewWriter(os.Stdout)
)
var n, sum int
var musk, crim []int
var vis []bool

func read() {
	sum = 0
	musk = make([]int, 3)
	crim = make([]int, n)
	vis = make([]bool, n)
	for i := 0; i < 3; i++ {
		Scan(&musk[i])
		sum += musk[i]
	}
	for i := 0; i < n; i++ {
		Scan(&crim[i])
	}
	sort.Ints(musk)
	sort.Ints(crim)
}

func findLoc(loc *[]int, idx int, pos int) {
	for ; (*loc)[idx] >= pos; (*loc)[idx]-- {
		if !vis[(*loc)[idx]] {
			break
		}
	}
}

func updateLoc(loc *[]int, idx int, pos int) {
	if (*loc)[idx] > pos {
		vis[(*loc)[idx]] = true
		(*loc)[idx]--
	}
}

func solve() {
	if sum < crim[n-1] {
		Println("-1")
		return
	}

	loc := make([]int, 5)
	loc[0] = sort.Search(n, func(i int) bool { return crim[i] > musk[1] }) - 1
	loc[1] = sort.Search(n, func(i int) bool { return crim[i] > musk[2] }) - 1
	loc[2] = sort.Search(n, func(i int) bool { return crim[i] > musk[0]+musk[1] }) - 1
	loc[3] = sort.Search(n, func(i int) bool { return crim[i] > musk[0]+musk[2] }) - 1
	loc[4] = sort.Search(n, func(i int) bool { return crim[i] > musk[1]+musk[2] }) - 1
	cnt := 0
	for pos := 0; pos < n; pos++ {
		if vis[pos] {
			continue
		}
		for i := 0; i < 5; i++ {
			findLoc(&loc, i, pos)
		}

		if musk[0] >= crim[pos] {
			if loc[1] != loc[4] {
				updateLoc(&loc, 4, pos)
			} else {
				updateLoc(&loc, 1, pos)
				findLoc(&loc, 0, pos)
				updateLoc(&loc, 0, pos)
			}
		} else if musk[1] >= crim[pos] {
			updateLoc(&loc, 3, pos)
		} else if Min(musk[0]+musk[1], musk[2]) >= crim[pos] {
			if musk[0]+musk[1] <= musk[2] {
				updateLoc(&loc, 1, pos)
			} else {
				updateLoc(&loc, 2, pos)
			}
		}
		cnt++
	}

	Println(cnt)
}

func main() {
	defer out.Flush()
	for Scan(&n) != io.EOF {
		read()
		solve()
	}

	return
}


Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m wrong solutions and for each wrong solution he knows its running time (in seconds).Let's suppose that Valera will set v seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most v seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, a seconds, an inequality 2a ≤ v holds.As a result, Valera decided to set v seconds TL, that the following conditions are met:  v is a positive integer;  all correct solutions pass the system testing;  at least one correct solution passes the system testing with some "extra" time;  all wrong solutions do not pass the system testing;  value v is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist.

The first line contains two integers n, m (1 ≤ n, m ≤ 100). The second line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the running time of each of the n correct solutions in seconds. The third line contains m space-separated positive integers b1, b2, ..., bm (1 ≤ bi ≤ 100) — the running time of each of m wrong solutions in seconds.

If there is a valid TL value, print it. Otherwise, print -1.

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
	"sort"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	c := make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&c[i])
	}
	w := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&w[i])
	}
	sort.Ints(c)
	sort.Ints(w)
	a :=2*c[0]
	if a<c[n-1] {
		a=c[n-1]
	}
	if a>=w[0] {
		a=-1
	}
	fmt.Println(a)
}

package main

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

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

	min_c := 0
	max_c := 0
	min_w := 0

	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
		}
		if a > max_c {
			max_c = a
		}
		if a < min_c || min_c == 0 {
			min_c = a
		}
	}
	for i := 0; i < m && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		if a < min_w || min_w == 0 {
			min_w = a
		}
	}

	v := -1
	for i := max_c; i < min_w; i++ {
		if 2*min_c <= i {
			v = i
			break
		}
	}

	fmt.Println(v)
}

package main

import "fmt"

func main() {
    var n,m,a int
    fmt.Scan(&n,&m)
    ac_min, ac_max := 101, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        if ac_min > a { ac_min = a }
        if ac_max < a { ac_max = a }
    }
    wa_min := 101
    for i := 0; i < m; i++ {
        fmt.Scan(&a)
        if wa_min > a { wa_min = a }
    }
    ans := -1
    for v := ac_max; v < wa_min; v++ {
        if (2*ac_min) <= v {
            ans = v
            break
        }
    }
    fmt.Println(ans)
}

// 350A-mic
package main

import (
    "fmt"
    "sort"
)

func main() {
    var n, m int
    fmt.Scan(&n, &m)
    a := make([]int, n)
    b := make([]int, m)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    for k := 0; k < m; k++ {
        fmt.Scan(&b[k])
    }
    sort.Sort(sort.IntSlice(a))
    sort.Sort(sort.IntSlice(b))
    for i := a[n-1]; i < b[0]; i++ {
        if 2*a[0] <= i {
            fmt.Println(i)
            return
        }
    }

    fmt.Println("-1")

}

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
	"sort"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	c := make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&c[i])
	}
	w := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&w[i])
	}
	sort.Ints(c)
	sort.Ints(w)
	a :=2*c[0]
	if a<c[n-1] {
		a=c[n-1]
	}
	if m>=w[0] {
		m=-1
	}
	fmt.Println(a)
}

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
	"sort"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	c := make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&c[i])
	}
	w := make([]int,m)
	for i:=0;i<m;i++ {
		fmt.Scan(&w[i])
	}
	sort.Ints(c)
	sort.Ints(w)
	m =2*c[0]
	if m<c[n-1] {
		m=c[n-1]
	}
	fmt.Println(m)
}


One warm and sunny day king Copa decided to visit the shooting gallery, located at the Central Park, and try to win the main prize — big pink plush panda. The king is not good at shooting, so he invited you to help him.The shooting gallery is an infinite vertical plane with Cartesian coordinate system on it. The targets are points on this plane. Each target is described by it's coordinates xi, and yi, by the time of it's appearance ti and by the number pi, which gives the probability that Copa hits this target if he aims at it.A target appears and disappears instantly, so Copa can hit the target only if at the moment ti his gun sight aimed at (xi, yi). Speed of movement of the gun sight on the plane is equal to 1. Copa knows all the information about the targets beforehand (remember, he is a king!). He wants to play in the optimal way, which maximizes the expected value of the amount of hit targets. He can aim at any target at the moment 0.

The first line contains integer n (1 ≤ n ≤ 1000) — amount of targets in the shooting gallery. Then n lines follow, each describing one target. Each description consists of four numbers xi, yi, ti, pi (where xi, yi, ti — integers,  - 1000 ≤ xi, yi ≤ 1000, 0 ≤ ti ≤ 109, real number pi is given with no more than 6 digits after the decimal point, 0 ≤ pi ≤ 1). No two targets may be at the same point.

Output the maximum expected value of the amount of targets that was shot by the king. Your answer will be accepted if it differs from the correct answer by not more than 10 - 6.

package main

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

type Target struct {
	x, y, t int
	p       float64
}

func dist(a, b Target) float64 {
	x := float64(a.x - b.x)
	y := float64(a.y - b.y)
	return math.Sqrt(x*x + y*y)
}

func Go(data []Target, i, last int, dp [][]float64) float64 {
	if i == len(data) {
		return float64(0)
	}
	if dp[i][last] != -1 {
		return dp[i][last]
	}
	best := Go(data, i+1, last, dp)
	if last >= len(data) || dist(data[i], data[last]) <= float64(data[i].t-data[last].t) {
		best = math.Max(best, Go(data, i+1, i, dp)+data[i].p)
	}
	dp[i][last] = best
	return best
}

func main() {
	cin := NewReader()
	n := cin.Int()
	data := make([]Target, n)
	for i := 0; i < n; i++ {
		data[i].x = cin.Int()
		data[i].y = cin.Int()
		data[i].t = cin.Int()
		data[i].p = cin.Float64()
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i].t < data[j].t
	})

	dp := make([][]float64, n+2)
	for i := range dp {
		dp[i] = make([]float64, n+2)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}
	fmt.Printf("%.10f\n", Go(data, 0, n+1, dp))
}

/* TEMPLATE */

type Reader struct {
	scanner *bufio.Scanner
	Ended   bool
}

func NewReader() *Reader {
	var reader Reader
	reader.scanner = bufio.NewScanner(os.Stdin)
	reader.scanner.Split(bufio.ScanWords)
	reader.Ended = false
	return &reader
}

func (r *Reader) Int() int {
	tmp := r.Next()
	if !r.Ended {
		res, _ := strconv.Atoi(tmp)
		return res
	}
	return 0
}

func (r *Reader) Float64() float64 {
	tmp := r.Next()
	if !r.Ended {
		res, _ := strconv.ParseFloat(tmp, 64)
		return res
	}
	return 0
}

func (r *Reader) Array(len int) []int {
	result := make([]int, len)
	for i := 0; i < len; i++ {
		result[i] = r.Int()
	}
	return result
}

func (r *Reader) Next() string {
	if r.scanner.Scan() {
		return r.scanner.Text()
	}
	r.Ended = true
	return ""
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func min64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}