Polycarp was given a row of tiles. Each tile contains one lowercase letter of the Latin alphabet. The entire sequence of tiles forms the string $$$s$$$.In other words, you are given a string $$$s$$$ consisting of lowercase Latin letters.Initially, Polycarp is on the first tile of the row and wants to get to the last tile by jumping on the tiles. Jumping from $$$i$$$-th tile to $$$j$$$-th tile has a cost equal to $$$|index(s_i) - index(s_j)|$$$, where $$$index(c)$$$ is the index of the letter $$$c$$$ in the alphabet (for example, $$$index($$$'a'$$$)=1$$$, $$$index($$$'b'$$$)=2$$$, ..., $$$index($$$'z'$$$)=26$$$) .Polycarp wants to get to the $$$n$$$-th tile for the minimum total cost, but at the same time make maximum number of jumps.In other words, among all possible ways to get to the last tile for the minimum total cost, he will choose the one with the maximum number of jumps.Polycarp can visit each tile at most once.Polycarp asks you to help — print the sequence of indices of string $$$s$$$ on which he should jump.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Each test case is given by the string $$$s$$$ ($$$2 \le |s| \le 2 \cdot 10^5$$$), where $$$|s|$$$ — is the length of string $$$s$$$. The string $$$s$$$ consists of lowercase Latin letters. It is guaranteed that the sum of string lengths $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

The answer to each test case consists of two lines. In the first line print two integers $$$cost$$$, $$$m$$$, where $$$cost$$$ is the minimum total cost of the path, and $$$m$$$ is the maximum number of visited tiles Polycarp can make to get to $$$n$$$-th tiles for the minimum total cost $$$cost$$$ (i.e. the number of jumps is $$$m-1$$$). In the next line print $$$m$$$ different numbers $$$j_1, j_2, \dots, j_m$$$ ($$$1 \le j_i \le |s|$$$) — the sequence of indices of the tiles Polycarp will jump on. The first number in the sequence must be $$$1$$$ (that is, $$$j_1=1$$$) and the last number must be the value of $$$|s|$$$ (that is, $$$j_m=|s|$$$). If there are multiple answers, print any of them.

6

logic

codeforces

bca

aaaaaaaaaaa

adbaadabad

to

NoteIn the first test case, the required path corresponds to the picture:  In this case, the minimum possible total cost of the path is achieved. Since $$$index($$$'l'$$$)=12$$$, $$$index($$$'o'$$$)=15$$$, $$$index($$$'g'$$$)=7$$$, $$$index($$$'i'$$$)=9$$$, $$$index($$$'c'$$$)=3$$$, then the total cost of the path is $$$|12-9|+|9-7|+|7-3|=3+2+4=9$$$.

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 2
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str), " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	m = 2
	if s > e {
		cost = int(s - e)
		for i := s; i >= e; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		o := fmt.Sprintf("%v", path)
		fmt.Println(o[1 : len(o)-1])
	}
}

package main
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)

	defer out.Flush()

	abs := func(i int) int {
		if (i > 0) {
			return i;
		} else {
			return -i;
		}
	}

	var T int
	for Fscan(in, &T); T > 0; T-- {
		var s string
		Fscan(in, &s)

		n := len(s)
		a := [26][]int{}
		for i, c := range s {
			d := int(c - 'a')
			a[d] = append(a[d], i+1)
		}

		d := 1
		if (s[0] > s[n - 1]) {
			d = -1
		}

		ans := []int{}
		for i := int(s[0]) - 'a'; ; i += d {
			if (i == int(s[n - 1]) - 'a' + d || i == 26 || i == -1) {
				break
			}
			for _, j := range a[i] {
				ans = append(ans, j)
			}
		}
		Fprintln(out, abs(int(s[0]) - int(s[n - 1])), len(ans))
		for _, i := range ans {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}
}
func main() { solve(os.Stdin, os.Stdout) }

package main
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
func CF1729C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var s string
	Fscan(in, &T)

	for ; T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		a := [26][]int{}
		for i, c := range s {
			d := int(c - 'a')
			a[d] = append(a[d], i+1)
		}
		d := 1
		if (s[0] > s[n - 1]) {
			d = -1
		}
		ans := []int{}
		for i := int(s[0] - 'a'); ; i += d {
			ans = append(ans, a[i]...)
			if (i == int(s[n - 1] - 'a')) {
				break
			}
		}
		al := int(s[0]) - int(s[n - 1])
		if (al < 0) {
			al = -al
		}
		Fprintln(out, al, len(ans))
		for _, h := range ans {
			Fprint(out, h, " ")
		}
		Fprintln(out)
	}
}
func main() { CF1729C(os.Stdin, os.Stdout) }

package main

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

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

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

	var T int
	var s string
	Fscan(in, &T)
	for ; T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		pos := [26][]int{}
		for i, b := range s {
			b -= 'a'
			pos[b] = append(pos[b], i+1)//pos[b].push_back(i+1)
		}
		d := 1
		if s[0] > s[n - 1] {
			d = -1
		}
		ans := []int{}
		for i := int(s[0] - 'a'); ; i += d {
			ans = append(ans, pos[i]...)
			if i == int(s[n - 1] - 'a') {
				break
			}
		}
		Fprintln(out, abs(int(s[0]) - int(s[n - 1])), len(ans))
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m1 := make(Nodes, 0)

		for i := range s {
			m1 = append(m1, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m1[0]
		tail := m1[len(m1)-1]

		m := m1.GetInterval(head.value, tail.value)

		if head.value < tail.value {
			sort.Slice(m, func(a, b int) bool { return m[a].value < m[b].value })
		} else {
			sort.Slice(m, func(a, b int) bool { return m[a].value > m[b].value })
		}

		sid := -1
		for i := 0; i < len(m); i++ {
			if sid < 0 && m[i].value == head.value {
				sid = i
			}
			if m[i] == head {
				m[sid], m[i] = m[i], m[sid]
				break
			}
		}

		eid := -1
		for i := len(m) - 1; i > sid; i-- {
			if eid < 0 && m[i].value == tail.value {
				eid = i
			}
			if m[i] == tail {
				m[eid], m[i] = m[i], m[eid]
			}
		}
		m = m[sid : eid+1]

		sum := 0
		path := make([]int, 0)

		for i := 1; i < len(m); i++ {
			sum += Abs(m[i].value - m[i-1].value)
		}
		for i := range m {
			path = append(path, m[i].id)
		}
		fmt.Fprintln(writer, sum, len(path))
		s = fmt.Sprintf("%v", path)
		s = s[1 : len(s)-1]
		fmt.Fprintln(writer, s)
		Flush()
	}

}

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

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

func (n Nodes) GetInterval(a, b int) Nodes {
	if a > b {
		return n.GetInterval(b, a)
	}

	m := make(Nodes, 0)
	for i := 0; i < len(n); i++ {
		if a <= n[i].value && n[i].value <= b {
			m = append(m, n[i])
		}
	}
	return m
}

package main

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

func distance(a, b byte) byte {
	if a < b {
		return b - a
	}
	return a - b
}

func printInts(arr []int) {
	buf := bytes.NewBuffer(nil)

	for i, v := range arr {
		if i > 0 {
			fmt.Fprint(buf, " ")
		}
		fmt.Fprint(buf, v)
	}
	fmt.Println(buf.String())
}

func main() {
	var cases int

	fmt.Scanln(&cases)

	buf := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var str string
		fmt.Fscanln(buf, &str)

		fc := str[0]
		lc := str[len(str)-1]

		m := make([][]int, 256)
		for j := 0; j < len(str); j++ {
			c := str[j]

			m[c] = append(m[c], j+1)
		}

		step := 1
		if fc > lc {
			step = -1
		}

		path := make([]int, 0, len(str))
		for c := fc; c != lc; c += byte(step) {
			path = append(path, m[c]...)
		}
		path = append(path, m[lc]...)

		fmt.Println(distance(fc, lc), len(path))
		printInts(path)
	}

}

package main

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

const N = 3e5
const inf = 1e9

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }

func main() {
	in := os.Stdin
	out := os.Stdout
	// if isLocal() {
	// 	in, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	// }
	iost = NewIost(in, out)
	defer func() {
		iost.Writer.Flush()
	}()
	t := iost.GetNextInt()
	for t > 0 {
		t--
		s := iost.Text()
		n := len(s)
		var a [26][]int
		for i := 0; i < n; i++ {
			a[s[i]-'a'] = append(a[s[i]-'a'], i)
		}
		var x, y byte
		var o []int
		o = append(o, 1)
		if s[0] < s[n-1] {
			x = s[0]
			y = s[n-1]
			for i := x; i <= y; i++ {
				for j := 0; j < len(a[i-'a']); j++ {
					if a[i-'a'][j] != 0 && a[i-'a'][j] != n-1 {
						o = append(o, a[i-'a'][j]+1)
					}
				}
			}
		} else {
			x = s[n-1]
			y = s[0]
			for i := y; i >= x; i-- {
				for j := 0; j < len(a[i-'a']); j++ {
					if a[i-'a'][j] != 0 && a[i-'a'][j] != n-1 {
						o = append(o, a[i-'a'][j]+1)
					}
				}
			}
		}
		o = append(o, n)
		iost.Println(y-x, " ", len(o))
		for i := 0; i < len(o); i++ {
			iost.Print(o[i], " ")
		}
		iost.Println()
	}
}

package main

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

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

func main() {

	defer out.Flush()

	t := 0
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

	for ; t > 0; t-- {
		s := ""
		if _, err := fmt.Fscan(in, &s); err != nil {
			return
		}
		mp := make(map[uint8][]int)
		for i := 0; i < len(s); i++ {
			mp[s[i]] = append(mp[s[i]], i)
		}
		a, b := s[0], s[len(s)-1]
		count := 0
		if a < b {
			for i := a; i <= b; i++ {
				count += len(mp[i])
			}
			fmt.Fprintln(out, b-a, count)
			for i := a; i <= b; i++ {
				for _, j := range mp[i] {
					fmt.Fprintf(out, "%v ", j+1)
				}
			}
		} else {
			for i := a; i >= b; i-- {
				count += len(mp[i])
			}
			fmt.Fprintln(out, a-b, count)
			for i := a; i >= b; i-- {
				for _, j := range mp[i] {
					fmt.Fprintf(out, "%v ", j+1)
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main

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

// https://space.bilibili.com/206214
func CF1729C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
		n := len(s)
		pos := [26][]int{}
		for i, b := range s {
			b -= 'a'
			pos[b] = append(pos[b], i+1)
		}
		d := 1
		if s[0] > s[n-1] {
			d = -1
		}
		ans := []int{}
		for i := int(s[0] - 'a'); ; i += d {
			ans = append(ans, pos[i]...)
			if i == int(s[n-1]-'a') {
				break
			}
		}
		Fprintln(out, abs(int(s[0])-int(s[n-1])), len(ans))
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}
func main() { CF1729C(os.Stdin, os.Stdout) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

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 scanws(a ...interface{})           { fmt.Fscan(reader, a...) }

func main() {

	defer writer.Flush()
	var tc int
	var s string
	var idx [27][]int
	var ans []int
	var cost int

	scanws(&tc)
	for t := 1; t <= tc; t++ {
		scanws(&s)
		ans = nil
		for i := 0; i <= 26; i++ {
			idx[i] = nil
		}
		n := len(s)
		for i := 0; i < n; i++ {
			a := byte(s[i] - 'a' + 1)
			temp := idx[a]
			temp = append(temp, i+1)
			idx[a] = temp
		}
		var st int = int(s[0] - 'a' + 1)
		var ed int = int(s[n-1] - 'a' + 1)
		if st < ed {
			cost = ed - st
			for ; st <= ed; st++ {
				nn := len(idx[st])
				for j := 0; j < nn; j++ {
					ans = append(ans, idx[st][j])
				}
			}
		} else {
			cost = st - ed
			for ; st >= ed; st-- {
				nn := len(idx[st])
				for j := 0; j < nn; j++ {
					ans = append(ans, idx[st][j])
				}
			}
		}
		nn := len(ans)
		printf("%d %d\n", cost, nn)
		for i := 0; i < nn; i++ {
			if i != 0 {
				printf(" ")
			}
			printf("%d", ans[i])
		}
		printf("\n")
	}

}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		aa := make([][]int, 26)
		for i, ch := range s {
			aa[ch-'a'] = append(aa[ch-'a'], i)
		}

		a, b := int(s[0]-'a'), int(s[len(s)-1]-'a')
		var c int
		if a > b {
			for i := a; i >= b; i-- {
				c += len(aa[i])
			}
			fmt.Fprintln(out, abs(a-b), c)
			for i := a; i >= b; i-- {
				for _, v := range aa[i] {
					fmt.Fprintf(out, "%d ", v+1)
				}
			}
		} else {
			for i := a; i <= b; i++ {
				c += len(aa[i])
			}

			fmt.Fprintln(out, abs(a-b), c)
			for i := a; i <= b; i++ {
				for _, v := range aa[i] {
					fmt.Fprintf(out, "%d ", v+1)
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		aa := make([][]int, 26)
		for i, ch := range s {
			aa[ch-'a'] = append(aa[ch-'a'], i)
		}

		bb := []int{}
		a, b := int(s[0]-'a'), int(s[len(s)-1]-'a')
		if a > b {
			for i := a; i >= b; i-- {
				for _, v := range aa[i] {
					bb = append(bb, v+1)
				}
			}
		} else {
			for i := a; i <= b; i++ {
				for _, v := range aa[i] {
					bb = append(bb, v+1)
				}
			}
		}

		fmt.Fprintln(out, abs(a-b), len(bb))
		for _, v := range bb {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func index(r rune) int {
	return int(r-'a') + 1
}

type pair struct {
	r rune
	i int
}

func solve() string {
	var s string
	fmt.Fscan(in, &s)
	var runes = []rune(s)
	var l, r = runes[0], runes[len(runes)-1]
	var reverse bool

	if l > r {
		l, r = r, l
		reverse = true
	}

	var res = make([]pair, 0, len(runes))

	for i, x := range runes {
		if x >= l && x <= r {
			res = append(res, pair{r: x, i: i + 1})
		}
	}

	if reverse {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return false
			}
			return true
		})
	} else {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return true
			}
			return false
		})
	}

	str1 := fmt.Sprintf("%d %d\n", abs(int(l-r)), len(res))
	var strArr = make([]string, 1, len(res))
	strArr[0] = "1"
	for i := 0; i < len(res); i++ {
		if res[i].i != 1 && res[i].i != len(runes) {
			strArr = append(strArr, strconv.Itoa(res[i].i))
		}
	}
	strArr = append(strArr, strconv.Itoa(len(runes)))

	return str1 + strings.Join(strArr, " ")
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

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

	var run_case func()
	run_case = func() {
		var n int
		var ans = []int{}
		//Fscan(in, &n)
		a := make([][]int, 0)

		var ss string
		Fscan(in, &ss)
		s := []byte(ss)
		n = len(s)
		for i := 1; i < n-1; i++ {
			if s[i] <= max(s[0], s[n-1]) && s[i] >= min(s[0], s[n-1]) {
				a = append(a, []int{int(s[i]), i})
			}
		}
		sort.Slice(a, func(i, j int) bool {
			if a[i][0] == a[j][0] {
				return i < j
			}
			if s[0] > s[n-1] {
				return a[i][0] > a[j][0]
			} else {
				return a[i][0] < a[j][0]
			}
		})
		for _, v := range a {
			ans = append(ans, v[1])
		}
		Fprintln(out, abs(s[0], s[n-1]), len(ans)+2)
		Fprint(out, 1, " ")
		for _, v := range ans {
			Fprint(out, v+1)
			Fprint(out, " ")
		}
		Fprint(out, len(s))
		Fprintln(out)
	}

	for i := 0; i < tests; i++ {
		run_case()
	}
}
func max(a, b byte) byte {
	if a > b {
		return a
	}
	return b
}
func min(a, b byte) byte {
	if a < b {
		return a
	}
	return b
}
func abs(a, b byte) byte {
	if a > b {
		return a - b
	}
	return b - a
}

package main

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

type T struct {
	index int
	value byte
}

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	var s string
	Fscan(in, &t)
	for t > 0 {
		t--
		Fscan(in, &s)
		b := []byte(s)
		a := make([]T, 0)
		if b[0] <= b[len(b)-1] {
			for i := 1; i < len(b)-1; i++ {
				if b[i] >= b[0] && b[i] <= b[len(b)-1] {
					a = append(a, T{i, b[i]})
				}
			}
			sort.Slice(a, func(i, j int) bool {
				return a[i].value < a[j].value
			})
			Fprintln(out, int(b[len(b)-1]-b[0]), len(a)+2)
			result := make([]int, 0)
			result = append(result, 1)
			for i := range a {
				result = append(result, a[i].index+1)
			}
			result = append(result, len(b))
			for i := range result {
				if i != len(result)-1 {
					Fprint(out, result[i], " ")
				} else {
					Fprint(out, result[i], "\n")
				}
			}
		} else {
			for i := 1; i < len(b)-1; i++ {
				if b[i] <= b[0] && b[i] >= b[len(b)-1] {
					a = append(a, T{i, b[i]})
				}
			}
			sort.Slice(a, func(i, j int) bool {
				return a[i].value > a[j].value
			})
			Fprintln(out, b[0]-b[len(b)-1], len(a)+2)
			result := make([]int, 0)
			result = append(result, 1)
			for i := range a {
				result = append(result, a[i].index+1)
			}
			result = append(result, len(b))
			for i := range result {
				if i != len(result)-1 {
					Fprint(out, result[i], " ")
				} else {
					Fprint(out, result[i], "\n")
				}
			}
		}
	}
}

package main

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

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

////////////////////////////////////////////////

func solve() {
	s := ReadString()
	n := len(s)

	Print(Abs(int(s[0]) - int(s[n-1])))

	ans := make([]int, 0)
	if s[0] < s[n-1] {
		for i := s[0]; i <= s[n-1]; i++ {
			for j := 0; j < n; j++ {
				if s[j] == i {
					ans = append(ans, j+1)
				}
			}
		}
	} else {
		for i := s[0]; i >= s[n-1]; i-- {
			for j := 0; j < n; j++ {
				if s[j] == i {
					ans = append(ans, j+1)
				}
			}
		}
	}
	Println("", len(ans))
	for _, i := range ans {
		Print(i, " ")
	}
	Println()
}

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

	t := 1
	t = ReadInt()

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

func ReadInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}

func ReadInts(n int) []int {
	a := make([]int, n)
	for i, _ := range a {
		a[i] = ReadInt()
	}
	return a
}

func ReadString() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}

func Print(a ...any) {
	fmt.Fprint(out, a...)
}

func Println(a ...any) {
	fmt.Fprintln(out, a...)
}

type IntPair struct {
	x int
	y int
}

func Iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func NextPermutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			Reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

func Reverse(a []int) {
	n := len(a)
	for i := 0; i < n/2; i++ {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}
}

func RemoveIf(a []int, cond func(int) bool) []int {
	n := len(a)
	pos := 0
	for i := 0; i < n; i++ {
		if !cond(a[i]) {
			a[pos] = a[i]
			pos++
		}
	}
	return a[0:pos]
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 2
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str)-1, " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str)-1, " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 1
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(len(str)-1, " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 1
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str)-1; j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Print(str[len(str)-1], " ")
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps = 1
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 1; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		fmt.Print(1, " ")
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int      { return len(a.els) }
func (a arr) Swap(i, j int) { a.els[i], a.els[j] = a.els[j], a.els[i] }
func (a arr) Less(i, j int) bool {
	if a.asc {
		return a.els[i].value < a.els[j].value
	} else {
		return a.els[i].value > a.els[j].value
	}
}

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 0; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := 0; j < len(str); j++ {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j + 1, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := range str {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index+1, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] <= str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := range str {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index+1, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] < str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

type el struct {
	index int
	value uint8
}

type arr struct {
	asc bool
	els []el
}

func (a arr) Len() int           { return len(a.els) }
func (a arr) Less(i, j int) bool { return a.asc == (a.els[i].value < a.els[j].value) }
func (a arr) Swap(i, j int)      { a.els[i], a.els[j] = a.els[j], a.els[i] }

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "logic"
		asc := isAsc(str)

		lb, ub := str[0], str[len(str)-1]
		if !asc {
			lb, ub = ub, lb
		}

		var jumps int
		var path = arr{
			asc: asc,
			els: make([]el, 0, len(str)),
		}
		for j := range str {
			if str[j] >= lb && str[j] <= ub {
				jumps++
				path.els = append(path.els, el{j, str[j]})
			}
		}

		sort.Sort(path)
		fmt.Println(ub-lb, jumps)
		for _, ell := range path.els {
			fmt.Print(ell.index, " ")
		}
		fmt.Println()
	}
}

func isAsc(str string) (up bool) {
	if str[0] < str[len(str)-1] {
		up = true
	}
	return
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

// https://codeforces.com/contest/1729/problem/C

package main

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

func main() {
	t := readInt64()
	//t := 1
	for i := 0; i < int(t); i++ {
		str := readString()
		//str := "abc"

		if str[0] < str[len(str)-1] {
			asc(str)
		} else {
			desc(str)
		}
	}
}

func asc(str string) {
	var firstLetter = str[0]
	var lastLetter = str[len(str)-1]

	var path = BinaryTree{}
	for j := range str {
		if str[j] >= firstLetter && str[j] <= lastLetter {
			path.insert(data{index: j, value: str[j]})
		}
	}

	indices := path.root.indices()
	fmt.Println(lastLetter-firstLetter, len(indices))
	for _, index := range indices {
		fmt.Print(index+1, " ")
	}
	fmt.Println()
}

func desc(str string) {
	var firstLetter = str[0]
	var lastLetter = str[len(str)-1]

	var path = LBinaryTree{}
	for j := range str {
		if str[j] <= firstLetter && str[j] >= lastLetter {
			path.insert(data{index: j, value: str[j]})
		}
	}

	indices := path.root.indices()
	fmt.Println(firstLetter-lastLetter, len(indices))
	for _, index := range indices {
		fmt.Print(index+1, " ")
	}
	fmt.Println()
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

type data struct {
	index int
	value uint8
}

type BinaryTree struct {
	root *BinaryNode
}

func (t *BinaryTree) insert(data data) *BinaryTree {
	if t.root == nil {
		t.root = &BinaryNode{data: data}
	} else {
		t.root.insert(data)
	}
	return t
}

type BinaryNode struct {
	left  *BinaryNode
	right *BinaryNode
	data  data
}

func (n *BinaryNode) insert(data data) {
	if n == nil {
		return
	} else if data.value < n.data.value {
		if n.left == nil {
			n.left = &BinaryNode{data: data}
		} else {
			n.left.insert(data)
		}
	} else {
		if n.right == nil {
			n.right = &BinaryNode{data: data}
		} else {
			n.right.insert(data)
		}
	}
}

func (n *BinaryNode) indices() []int {
	if n == nil {
		return nil
	}
	return append(n.left.indices(), append([]int{n.data.index}, n.right.indices()...)...)
}

type LBinaryTree struct {
	root *LBinaryNode
}

func (t *LBinaryTree) insert(data data) *LBinaryTree {
	if t.root == nil {
		t.root = &LBinaryNode{data: data}
	} else {
		t.root.insert(data)
	}
	return t
}

type LBinaryNode struct {
	left  *BinaryNode
	right *BinaryNode
	data  data
}

func (n *LBinaryNode) insert(data data) {
	if n == nil {
		return
	} else if data.value > n.data.value {
		if n.left == nil {
			n.left = &BinaryNode{data: data}
		} else {
			n.left.insert(data)
		}
	} else {
		if n.right == nil {
			n.right = &BinaryNode{data: data}
		} else {
			n.right.insert(data)
		}
	}
}

func (n *LBinaryNode) indices() []int {
	if n == nil {
		return nil
	}
	return append(n.left.indices(), append([]int{n.data.index}, n.right.indices()...)...)
}

// https://codeforces.com/contest/1729/problem/C

package main

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

func main() {
	t := readInt64()

	for i := 0; i < int(t); i++ {
		str := readString()

		var firstLetter = str[0]
		var lastLetter = str[len(str)-1]

		var cost uint8
		var up bool
		if firstLetter < lastLetter {
			cost = lastLetter - firstLetter
			up = true
		} else {
			cost = firstLetter - lastLetter
			up = false
		}

		var down = !up

		var path = BinaryTree{}
		for j := range str {
			if up && str[j] >= firstLetter && str[j] <= lastLetter ||
				down && str[j] <= firstLetter && str[j] >= lastLetter {

				path.insert(data{index: j, value: str[j]})
			}
		}

		indices := path.root.indices()
		if down {
			for j := range indices {
				if j == len(indices)/2 {
					break
				} else {
					indices[j], indices[len(indices)-1-j] = indices[len(indices)-1-j], indices[j]
				}
			}
		}
		fmt.Println(cost, len(indices))
		for _, index := range indices {
			fmt.Print(index+1, " ")
		}
		fmt.Println()
	}
}

var in = bufio.NewReader(os.Stdin)

func readInt64() int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}

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

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

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

type data struct {
	index int
	value uint8
}

type BinaryNode struct {
	left  *BinaryNode
	right *BinaryNode
	data  data
}

type BinaryTree struct {
	root *BinaryNode
}

func (t *BinaryTree) insert(data data) *BinaryTree {
	if t.root == nil {
		t.root = &BinaryNode{data: data, left: nil, right: nil}
	} else {
		t.root.insert(data)
	}
	return t
}

func (n *BinaryNode) insert(data data) {
	if n == nil {
		return
	} else if data.value <= n.data.value {
		if n.left == nil {
			n.left = &BinaryNode{data: data, left: nil, right: nil}
		} else {
			n.left.insert(data)
		}
	} else {
		if n.right == nil {
			n.right = &BinaryNode{data: data, left: nil, right: nil}
		} else {
			n.right.insert(data)
		}
	}
}

func (n *BinaryNode) indices() []int {
	if n == nil {
		return nil
	}
	return append(n.left.indices(), append([]int{n.data.index}, n.right.indices()...)...)
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	m = 2
	if s > e {
		cost = int(s - e)
		for i := e; i >= s; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	if s > e {
		cost = int(s - e)
		for i := s; i >= e; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	m = 2
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	if s > e {
		cost = int(s - e)
		for i := e; i >= s; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		cost = int(e - s)
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	m = 2
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}

	cost = int(e - s)
	if cost < 0 {
		cost *= 1
	}
	if s > e {
		for i := e; i >= s; i-- {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	} else {
		for i := s; i <= e; i++ {
			if v, ok := pos[i]; ok {
				m += len(v)
				path = append(path, v...)
			}
		}
	}
	m = 2
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}
	if s > e {
		s, e = e, s
	}
	cost = int(e - s)
	m = 2
	for i := s; i <= e; i++ {
		if v, ok := pos[i]; ok {
			m += len(v)
			path = append(path, v...)
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main

import (
	"fmt"
)

func work(n string) (cost, m int, path []int) {
	s := n[0]
	e := n[len(n)-1]
	cost = int(s - e)
	if cost < 0 {
		cost *= -1
	}

	path = []int{1}

	pos := map[byte][]int{}

	for i := 1; i < len(n)-1; i++ {
		c := n[i]
		if !((c >= s && c <= e) || (c >= e && c <= s)) {
			continue
		}
		if _, ok := pos[c]; !ok {
			pos[c] = []int{i + 1}
		} else {
			pos[c] = append(pos[c], i+1)
		}
	}
	if s > e {
		s, e = e, s
	}
	for i := s; i <= e; i++ {
		if v, ok := pos[i]; ok {
			path = append(path, v...)
		}
	}
	path = append(path, len(n))
	return
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n string
		fmt.Scanf("%s\n", &n)

		cost, m, path := work(n)

		fmt.Printf("%d %d\n", cost, m)
		for _, v := range path {
			fmt.Printf("%d ", v)
		}
		fmt.Println("")
	}
}

package main
import (
	"bufio"
	. "fmt"
	"io"
	"os"
)
func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)

	defer out.Flush()

	abs := func(i int) int {
		if (i > 0) {
			return i;
		} else {
			return -i;
		}
	}

	var T int
	for Fscan(in, &T); T > 0; T-- {
		var s string
		Fscan(in, &s)

		n := len(s)
		a := [26][]int{}
		for i, c := range s {
			d := int(c - 'a')
			a[d] = append(a[d], i+1)
		}

		d := 1
		if (s[0] > s[n - 1]) {
			d = -1
		}

		ans := []int{}
		for i := int(s[0]) - 'a'; ; i += d {
			if (i == 26 || i == -1) {
				break
			}
			for _, j := range a[i] {
				ans = append(ans, j)
			}
			if (i == int(s[n - 1]) - 'a' + d) {
				break
			}
		}
		Fprintln(out, abs(int(s[0]) - int(s[n - 1])), len(ans))
		for _, i := range ans {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}
}
func main() { solve(os.Stdin, os.Stdout) }

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		if path[0] != 1 {
			for i, j := 0, len(path)-1; i < j; i, j = i+1, j-1 {
				path[i], path[j] = path[j], path[i]
			}
		}
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

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

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p Path) String() string {
	s := ""
	for i := range p {
		s += fmt.Sprintf("%d ", p[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

func (n *Path) Len() int           { return len(*n) }
func (n *Path) Less(a, b int) bool { return (*n)[a] < (*n)[b] }
func (n *Path) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		for i := 0; i < len(path); i++ {
			if path[i] == 1 {
				path[0], path[i] = path[i], path[0]
				break
			}
		}
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

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

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p Path) String() string {
	s := ""
	for i := range p {
		s += fmt.Sprintf("%d ", p[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		sort.Ints(path)
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

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

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p *Path) String() string {
	s := ""
	for i := range *p {
		s += fmt.Sprintf("%d ", (*p)[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

package main

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

func main() {
	// f, err := os.OpenFile("data.txt", os.O_RDONLY, 0644)
	// if err != nil {
	// 	os.Exit(-2)
	// }

	// r := bufio.NewReader(f)
	w := bufio.NewWriter(os.Stdout)
	r := bufio.NewReader(os.Stdin)
	Solve(r, w, w.Flush)
}

func Solve(reader io.Reader, writer io.Writer, Flush func() error) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var s string
		fmt.Fscanln(reader, &s)
		offset := int('a' - 1)
		m := make(Nodes, 0)

		for i := range s {
			m = append(m, &Node{id: i + 1, value: int(s[i]) - offset})
		}
		head := m[0]
		tail := m[len(m)-1]
		sort.Sort(&m)
		sum := 0
		path := make(Path, 0)

		for i, a, b := 1, false, false; i < len(m)+1; i++ {
			if m[i-1] == tail {
				b = true
			}
			if m[i-1] == head {
				a = true
			}
			if a && b {
				path = append(path, m[i-1].id)
				break
			}
			v1, v2 := m[i].value, m[i-1].value
			sum += Abs(v1 - v2)
			path = append(path, m[i-1].id)
		}
		fmt.Fprintln(writer, sum, len(path))
		fmt.Fprintln(writer, &path)
		Flush()
	}

}

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

type Node struct {
	id    int
	value int
}

type Nodes []*Node

func (n *Nodes) Len() int           { return len(*n) }
func (n *Nodes) Less(a, b int) bool { return (*n)[a].value < (*n)[b].value }
func (n *Nodes) Swap(a, b int)      { (*n)[a], (*n)[b] = (*n)[b], (*n)[a] }

type Path []int

func (p *Path) String() string {
	s := ""
	for i := range *p {
		s += fmt.Sprintf("%d ", (*p)[i])
	}
	if len(s) > 0 {
		s = s[:len(s)-1]
	}
	return s
}

package main

import (
	"fmt"
)

const N = 3e5
const inf = 1e9

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var s string
		fmt.Scan(&s)
		n := len(s)
		var a [26][]int
		for i := 0; i < n; i++ {
			a[s[i]-'a'] = append(a[s[i]-'a'], i)
		}
		var x, y byte
		if s[0] < s[n-1] {
			x = s[0]
			y = s[n-1]
		} else {
			x = s[n-1]
			y = s[0]
		}
		var o []int
		o = append(o, 1)
		for i := x; i <= y; i++ {
			for j := 0; j < len(a[i-'a']); j++ {
				if a[i-'a'][j] != 0 && a[i-'a'][j] != n-1 {
					o = append(o, a[i-'a'][j]+1)
				}
			}
		}
		o = append(o, n)
		fmt.Println(y-x, " ", len(o))
		for i := 0; i < len(o); i++ {
			fmt.Print(o[i], " ")
		}
		fmt.Println()
	}
}

package main

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

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

func main() {

	defer out.Flush()

	t := 0
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

	for ; t > 0; t-- {
		s := ""
		if _, err := fmt.Fscan(in, &s); err != nil {
			return
		}
		mp := make(map[uint8][]int)
		for i := 0; i < len(s); i++ {
			mp[s[i]] = append(mp[s[i]], i)
		}
		a, b := s[0], s[len(s)-1]
		count := 0
		if a < b {
			for i := a; i <= b; i++ {
				count += len(mp[i])
			}
			fmt.Fprintln(out, b-a, count)
			for i := a; i <= b; i++ {
				for _, j := range mp[i] {
					fmt.Fprint(out, j+1, " ")
				}
			}
		} else {
			for i := a; i >= b; i-- {
				count += len(mp[i])
			}
			fmt.Fprintln(out, a-b, count)
			for i := a; i >= b; i-- {
				for _, j := range mp[i] {
					fmt.Fprint(out, j+1)
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main

import "fmt"

func main() {

	solute := func(s string) {
		left := 0
		unknown := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '(' {
				left++
			} else if s[i] == '?' {
				unknown++
			} else {
				if left > 0 {
					left--
				} else {
					unknown--
				}
			}
		}
		if unknown > 2 {
			fmt.Println("NO")
		} else if unknown == 2 && s[0] != '(' {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}

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

	for i := 0; i < n; i++ {
		var s string
		if _, err := fmt.Scanf("%s\n", &s); err != nil {
			return
		}
		solute(s)
	}

	return

}

package main

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

func distance(a, b byte) byte {
	if a < b {
		return b - a
	}
	return a - b
}

func printInts(arr []int) {
	buf := bytes.NewBuffer(nil)

	for i, v := range arr {
		if i > 0 {
			fmt.Fprint(buf, " ")
		}
		fmt.Fprint(buf, v)
	}
	fmt.Println(buf.String())
}

func main() {
	var cases int

	fmt.Scanln(&cases)

	buf := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var str string
		fmt.Fscanln(buf, &str)

		fc := str[0]
		lc := str[len(str)-1]

		m := make([][]int, 256)
		for j := 0; j < len(str); j++ {
			c := str[j]

			m[c] = append(m[c], j+1)
		}
		fmt.Println(m)

		step := 1
		if fc > lc {
			step = -1
		}

		path := make([]int, 0, len(str))
		for c := fc; c != lc; c += byte(step) {
			fmt.Println(path)
			path = append(path, m[c]...)
		}
		path = append(path, m[lc]...)

		fmt.Println(distance(fc, lc), len(path))
		printInts(path)
	}

}

package main

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

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

func index(r rune) int {
	return int(r-'a') + 1
}

type pair struct {
	r rune
	i int
}

func solve() string {
	var s string
	fmt.Fscan(in, &s)
	var runes = []rune(s)
	var l, r = runes[0], runes[len(runes)-1]
	var reverse bool

	if l > r {
		l, r = r, l
		reverse = true
	}

	var res = make([]pair, 0, len(runes))

	for i, x := range runes {
		if x >= l && x <= r {
			res = append(res, pair{r: x, i: i + 1})
		}
	}

	if reverse {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return false
			}
			return true
		})
	} else {
		sort.Slice(res, func(i, j int) bool {
			if res[i].r < res[j].r {
				return true
			}
			return false
		})
	}

	str1 := fmt.Sprintf("%d %d\n", abs(int(l-r)), len(res))
	var strArr = make([]string, len(res))
	for i := range res {
		strArr[i] = strconv.Itoa(res[i].i)
	}

	return str1 + strings.Join(strArr, " ")
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

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

	var run_case func()
	run_case = func() {
		var n int
		var ans = []int{}
		//Fscan(in, &n)
		a := make([][]int, 0)

		var ss string
		Fscan(in, &ss)
		s := []byte(ss)
		n = len(s)
		for i := 0; i < n; i++ {
			if s[i] <= max(s[0], s[n-1]) && s[i] >= min(s[0], s[n-1]) {
				a = append(a, []int{int(s[i]), i})
			}
		}
		sort.Slice(a, func(i, j int) bool {
			if a[i][0] == a[j][0] {
				return i < j
			}
			if s[0] > s[n-1] {
				return a[i][0] > a[j][0]
			} else {
				return a[i][0] < a[j][0]
			}
		})
		for _, v := range a {
			ans = append(ans, v[1])
		}
		Fprintln(out, abs(s[0], s[n-1]), len(ans))
		for _, v := range ans {
			Fprint(out, v+1)
			Fprint(out, " ")
		}
		Fprintln(out)
	}

	for i := 0; i < tests; i++ {
		run_case()
	}
}
func max(a, b byte) byte {
	if a > b {
		return a
	}
	return b
}
func min(a, b byte) byte {
	if a < b {
		return a
	}
	return b
}
func abs(a, b byte) byte {
	if a > b {
		return a - b
	}
	return b - a
}


After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points.At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs C roubles and decreases hunger by N points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.

The first line contains two integers hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59) — the time of Andrew's awakening. The second line contains four integers H, D, C and N (1 ≤ H ≤ 105, 1 ≤ D, C, N ≤ 102).

Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10 - 4. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .

NoteIn the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles.

package main

import (
	"fmt"
	"os"
)

func main() {
	var hh, mm,h,d,c,n,r1,r2,r3 float64 //h golod kota
	fmt.Scanf("%f %f\n", &hh, &mm)
	fmt.Scanf("%f %f %f %f", &h, &d, &c, &n)
	//esli srazu
	if hh >= 20 && hh <= 23{
		for h > 0 {
			r1+=c*0.8
			h-=n
		}
		fmt.Printf("%.4f", r1)
		os.Exit(0)
	} else {
		//probuem srazu
		h2:=h
		for h2 > 0 {
			r3+=c
			h2-=n
		}
		//zhdem 20 00
		for hh!=20{
			mm++
			if mm==60{
				mm=0
				hh++
			}
			h+=d
		}
		for h > 0 {
			r2+=c*0.8
			h-=n
		}
	}
	if r2 < r3{
		fmt.Printf("%.4f", r2)
		os.Exit(0)
	}
	fmt.Printf("%.4f", r3)
}


There is a $$$n \times m$$$ grid. You are standing at cell $$$(1, 1)$$$ and your goal is to finish at cell $$$(n, m)$$$.You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell $$$(x, y)$$$. You can:   move right to the cell $$$(x, y + 1)$$$ — it costs $$$x$$$ burles;  move down to the cell $$$(x + 1, y)$$$ — it costs $$$y$$$ burles. Can you reach cell $$$(n, m)$$$ spending exactly $$$k$$$ burles?

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first and only line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n, m \le 100$$$; $$$0 \le k \le 10^4$$$) — the sizes of grid and the exact amount of money you need to spend.

For each test case, if you can reach cell $$$(n, m)$$$ spending exactly $$$k$$$ burles, print YES. Otherwise, print NO. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first test case, you are already in the final cell, so you spend $$$0$$$ burles.In the second, third and fourth test cases, there are two paths from $$$(1, 1)$$$ to $$$(2, 2)$$$: $$$(1, 1)$$$ $$$\rightarrow$$$ $$$(1, 2)$$$ $$$\rightarrow$$$ $$$(2, 2)$$$ or $$$(1, 1)$$$ $$$\rightarrow$$$ $$$(2, 1)$$$ $$$\rightarrow$$$ $$$(2, 2)$$$. Both costs $$$1 + 2 = 3$$$ burles, so it's the only amount of money you can spend.In the fifth test case, there is the only way from $$$(1, 1)$$$ to $$$(1, 4)$$$ and it costs $$$1 + 1 + 1 = 3$$$ burles.

package main

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

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

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

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

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

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

var memo map[int]map[int]map[int]int

/**
Run solve the problem CF1519B
Date: 13/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1519/B
Problem: CF1519B
**/
func (in *CF1519B) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n, m, k := in.NextInt(), in.NextInt(), in.NextInt()

		memo = make(map[int]map[int]map[int]int)

		ans := f(n, m, k)
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func f(i, j, n int) bool {
	if i == 1 && j == 1 && n == 0 {
		return true
	}
	if i < 1 || j < 1 || n < 0 {
		return false
	}
	if val, ok := memo[i][j][n]; ok && val != 0 {
		return memo[i][j][n] == 1
	}

	ans := f(i, j-1, n-i) || f(i-1, j, n-j)
	if ans {
		save(i, j, n, 1)
	} else {
		save(i, j , n, 2)
	}
	return memo[i][j][n] == 1

}

func save(i, j, n, val int) {
	if _, ok := memo[i]; !ok {
		memo[i] = make(map[int]map[int]int)
	}
	if _, ok := memo[i][j]; !ok {
		memo[i][j] = make(map[int]int)
	}
		memo[i][j][n] = val
}

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

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

package main

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

// TAG: dp/math

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

		var k, m, n, i, j int64
		scanf("%d %d %d \n", &n, &m, &k)

		// base
		if n == 1 && m == 1 && k != 0 {
			printf("NO\n")
			continue
		}

		var matrix [][]int64
		for i = n; i > 0; i-- {
			matrix = append(matrix, make([]int64, m))
		}

		// matrix[1][1] = 1
		for i = 0; i < n; i++ {
			for j = 0; j < m; j++ {
				if i != 0 && j == 0 {
					matrix[i][j] += matrix[i-1][j] + 1
				} else if j != 0 {
					matrix[i][j] += matrix[i][j-1] + i + 1
				}
			}
		}

		if matrix[n-1][m-1] == k {
			printf("YES\n")
		} else {
			printf("NO\n")
		}

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n, m, k int
	fmt.Fscanln(in, &t)
	for t > 0 {
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		solve(n, m, k)
		t--
	}
}
func solve(n, m, k int) {
	if m*n-1 == k {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

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

package main

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

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	outputs := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		n, m, k := ScanInt(), ScanInt(), ScanInt()
		cost := make([][]map[int]bool, n+1)

		for x := range cost {
			cost[x] = make([]map[int]bool, m+1)

			for y := range cost[x] {
				cost[x][y] = make(map[int]bool)
			}
		}

		cost[1][1][0] = true

		for x := 1; x <= n; x++ {
			for y := 1; y <= m; y++ {
				for c := range cost[x][y-1] {
					cost[x][y][x+c] = true
				}

				for c := range cost[x-1][y] {
					cost[x][y][y+c] = true
				}
			}
		}

		fmt.Println(outputs[cost[n][m][k]])
	}
}

package main

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

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	outputs := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		n, m, k := ScanInt(), ScanInt(), ScanInt()
		cost := make([][]map[int]bool, n+1)

		for x := range cost {
			cost[x] = make([]map[int]bool, m+1)

			for y := range cost[x] {
				cost[x][y] = make(map[int]bool)
			}
		}

		cost[1][1][0] = true

		for x := 1; x <= n; x++ {
			for y := 1; y <= m; y++ {
				for c, _ := range cost[x][y-1] {
					cost[x][y][x+c] = true
				}

				for c, _ := range cost[x-1][y] {
					cost[x][y][y+c] = true
				}
			}
		}

		fmt.Println(outputs[cost[n][m][k]])
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Fscan(in,&a,&b,&c) // take inputs
		// always moving horizontally first, then vertically
		x:= b-1 // cost to move horizontally
		y:= b*(a-1) // cost to move vertically
		if x+y == c { // if total cost = c, yes; else no
			fmt.Fprintln(out,"YES")
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

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

func CF1519B(in io.Reader, out io.Writer) {
	_r := bufio.NewReader(in)
	_w := bufio.NewWriter(out)
	defer _w.Flush()

	var T int64
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n, m, k int64
		fmt.Fscan(_r, &n, &m, &k)
		if k == n * m -1 {
			fmt.Fprintln(_w, "YES")

		} else {
			fmt.Fprintln(_w, "NO")
		}

	}

}

package main

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

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

func solve(n, m, k int) string {
	if n*m == k+1 {
		return "YES"
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m, &k)
		fmt.Println(solve(n, m, k))
	}
}

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 main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	if len(os.Args[1:]) == 1 {
		file, _ := os.Open(os.Args[1])
		reader = bufio.NewReader(file)
	}

	var t, n, m, k int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		scanf("%d %d %d\n", &n, &m, &k)
		memo := make([][]int, n+1)
		for j := 0; j < n+1; j++ {
			memo[j] = make([]int, m+1)
			for k := 0; k < m+1; k++ {
				memo[j][k] = -1
			}
		}
		ans := solve(n, m, k, memo)
		if ans == 0 {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

func solve(n, m, k int, memo [][]int) int {
	//fmt.Println(n, m, k)
	if k < 0 {
		return -2
	}
	if n == 1 && m == 1 {
		if k == 0 {
			return 0
		} else {
			return -2
		}
	}
	if memo[n][m] != -1 {
		return memo[n][m]
	}
	if n > 1 {
		memo[n][m] = solve(n-1, m, k-m, memo)
	}
	if memo[n][m] == 0 {
		return 0
	}
	if m > 1 {
		memo[n][m] = solve(n, m-1, k-n, memo)
	}
	return memo[n][m]
}

package main

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

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

func main() {
    var T int
    for Fscan(in, &T); T > 0; T-- {
        var n, m, k int
        Fscan(in, &n, &m, &k)

        total := n - 1
        total += (m - 1) * n

        if total == k {
            Println("YES")
        } else {
            Println("NO")
        }
    }
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, m, k int
		fmt.Scan(&n, &m, &k)

		if n * m - 1 == k {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	solve := func() {
		var r, b, d int64
		fmt.Fscan(in, &r, &b, &d)

		if r*b-1 == d {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

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

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

		if n*m-1 == k {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

func solve() {
	var n, m, k float64
	fmt.Fscan(in, &n, &m, &k)
	var cost float64
	if n < m {
		//cost to reach at m cordinate
		numberOfSteps := m - 1
		cost += numberOfSteps

		second := n - 1
		cost += (second * m)
	} else {
		numberOfSteps := n - 1
		cost += numberOfSteps
		second := m - 1
		cost += (second * n)
	}
	if cost == k {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

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

package main

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

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

	var t, n, m, k int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m, &k)
		if n*m-1 == k {
			fmt.Println("YES")
			continue
		}
		fmt.Println("NO")
	}
}

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) {
		var n, m, k int
		Fscan(in, &n, &m, &k)
		res := n*m-1
		if res == k {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

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

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

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

package main

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

// TAG: dp/math

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

		var k, m, n, i, j int64
		scanf("%d %d %d \n", &n, &m, &k)

		// base
		if n == 1 && m == 1 && k != 0 {
			printf("NO\n")
		}

		var matrix [][]int64
		for i = n; i > 0; i-- {
			matrix = append(matrix, make([]int64, m))
		}

		// matrix[1][1] = 1
		for i = 0; i < n; i++ {
			for j = 0; j < m; j++ {
				if i != 0 && j == 0 {
					matrix[i][j] += matrix[i-1][j] + 1
				} else if j != 0 {
					matrix[i][j] += matrix[i][j-1] + i + 1
				}
			}
		}

		if matrix[n-1][m-1] == k {
			printf("YES\n")
		} else {
			printf("NO\n")
		}

	}
}

package main

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

// TAG: dp/math

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

		var k, m, n, i, j int64
		scanf("%d %d %d \n", &n, &m, &k)

		// base
		if n == 1 && m == 1 && k != 0 {
			printf("NO\n")
		}

		var matrix [][]int64
		for i = n; i > 0; i-- {
			matrix = append(matrix, make([]int64, m))
		}

		// fmt.Println(matrix)
		// matrix[1][1] = 1
		for i = 0; i < n; i++ {
			for j = 0; j < m; j++ {
				if i != 0 && j == 0 {
					matrix[i][j] += matrix[i-1][j] + 1
				} else if j != 0 {
					matrix[i][j] += matrix[i][j-1] + i + 1
				}
			}
		}

		// fmt.Println(matrix)
		if matrix[n-1][m-1] == k {
			printf("YES\n")
		} else {
			printf("NO\n")
		}

	}
}