Word $$$s$$$ of length $$$n$$$ is called $$$k$$$-complete if   $$$s$$$ is a palindrome, i.e. $$$s_i=s_{n+1-i}$$$ for all $$$1 \le i \le n$$$;  $$$s$$$ has a period of $$$k$$$, i.e. $$$s_i=s_{k+i}$$$ for all $$$1 \le i \le n-k$$$. For example, "abaaba" is a $$$3$$$-complete word, while "abccba" is not.Bob is given a word $$$s$$$ of length $$$n$$$ consisting of only lowercase Latin letters and an integer $$$k$$$, such that $$$n$$$ is divisible by $$$k$$$. He wants to convert $$$s$$$ to any $$$k$$$-complete word.To do this Bob can choose some $$$i$$$ ($$$1 \le i \le n$$$) and replace the letter at position $$$i$$$ with some other lowercase Latin letter.So now Bob wants to know the minimum number of letters he has to replace to convert $$$s$$$ to any $$$k$$$-complete word.Note that Bob can do zero changes if the word $$$s$$$ is already $$$k$$$-complete.You are required to answer $$$t$$$ test cases independently.

The first line contains a single integer $$$t$$$ ($$$1 \le t\le 10^5$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k < n \le 2 \cdot 10^5$$$, $$$n$$$ is divisible by $$$k$$$). The second line of each test case contains a word $$$s$$$ of length $$$n$$$. It is guaranteed that word $$$s$$$ only contains lowercase Latin letters. And it is guaranteed that the sum of $$$n$$$ over all test cases will not exceed $$$2 \cdot 10^5$$$.

For each test case, output one integer, representing the minimum number of characters he has to replace to convert $$$s$$$ to any $$$k$$$-complete word.

4
6 2
abaaba
6 3
abaaba
36 9
hippopotomonstrosesquippedaliophobia
21 7
wudixiaoxingxingheclp

NoteIn the first test case, one optimal solution is aaaaaa.In the second test case, the given word itself is $$$k$$$-complete.

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func ReadIntsAndTrim() []int {
	str, _ := reader.ReadString(lineDelim)
	str = strings.TrimSpace(str)
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.ParseInt(i, 10, 0)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

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

func ReadStringAndTrim() string {
	str, _ := reader.ReadString(lineDelim)
	str = strings.TrimSpace(str)

	return str
}

func CountSetsLetters(i, j int, a *[][]int) int {
	var sum int
	var max int
	b := *a
	for k := 0; k < 26; k++ {
		cSum := b[i][k] + b[j][k]
		sum += cSum
		max = Max(max, cSum)
	}

	return sum - max
}

func main() {
	nTestCases := ReadInt()
	for nTestCases != 0 {
		input := ReadIntsAndTrim()
		str := ReadStringAndTrim()
		n := input[0]
		k := input[1]
		r := []rune(str)
		var kSets [][]int
		for i := 0; i < k; i++ {
			lowercaseLettersCodes := make([]int, 26)
			kSets = append(kSets, lowercaseLettersCodes)
		}
		for i := 0; i < n; i++ {
			letterPos := int(r[i]) - int('a')
			kSets[i % k][letterPos] += 1
		}
		var sum int
		for i := 0; i < k; i++ {
			sum += CountSetsLetters(i, k - i - 1, &kSets)
		}
		fmt.Println(sum / 2)
		nTestCases -= 1
	}
}

package main

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

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

	defer out.Flush()
	var t int
	fmt.Fscanf(in,"%d\n",&t)
	for T := 0 ; T < t ; T ++ {
		var n, k int
		var s string
		fmt.Fscanf(in, "%d %d\n", &n, &k)
		fmt.Fscanf(in, "%s\n", &s)
		kit := n / k
		output := 0
		a := make([]int, n)
		for i := 0 ; i <= k / 2 ; i ++ {
			m := make(map[byte]int)
			cnt := 0
			for j := 0 ; j < kit ; j ++ {
				if a[j*k + i] == 0 {
					m[s[j*k + i]] ++
					a[j*k + i] = 1
					cnt ++
				}
				if a[j*k + k - i - 1] == 0 {
					m[s[j*k + k - i - 1]] ++
					a[j*k + k - i - 1] = 1
					cnt ++
				}
			}
			maxx := 0
			for _, val := range m {
				if val > maxx{
					maxx = val
				}
			}
			output += (cnt - maxx)
		}
		fmt.Println(output)
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		arrs := strings.Split(string(line), " ")
		n, _ := strconv.ParseInt(arrs[0], 10, 64)
		k, _ := strconv.ParseInt(arrs[1], 10, 64)
		flag := make([]bool, n)
		str := readLine(reader)
		result := 0
		for i := int64(0); i < k; i++ {
			m := make(map[byte]int)
			traverse(str, &flag, i, k, &m)
			sum, max := 0,0
			for _, v := range m {
				sum += v
				if v > max {
					max = v
				}
			}
			result += sum - max
		}
		fmt.Println(result)
	}
}

func traverse(str []byte, flag *[]bool, index, k int64, m *map[byte]int) {
	if index >= int64(len(str)) || index < 0 || (*flag)[index] {
		return
	}
	(*flag)[index] = true
	count := (*m)[str[index]]
	(*m)[str[index]] = count + 1
	traverse(str, flag, index+k, k, m)
	traverse(str, flag, index-k, k, m)
	traverse(str, flag, int64(len(str))-1-index, k, m)
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/problemset/problem/1332/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, k int
	S    []rune
	cnts [][30]int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, k = ReadInt2()
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	// uf := NewUnionFind(n)
	// for i := 0; i <= (n-1)/2; i++ {
	// 	j := n - 1 - i
	// 	uf.Unite(i, j)

	// 	for l := i + k; l < n; l += k {
	// 		uf.Unite(i, l)
	// 	}
	// }
	// for i := 0; i < n; i++ {
	// 	PrintfDebug("%d ", uf.Root(i))
	// }
	// PrintfDebug("\n")

	cnts = make([][30]int, n)

	for i := 0; i < n; i++ {
		cnts[i%k][S[i]-'a']++
	}
	ans := 0
	for i := 0; i < k; i++ {
		ans += differ(i, k-1-i)
	}
	fmt.Println(ans / 2)
}

func differ(u, v int) int {
	ret, mx := 0, 0
	for j := 0; j < 26; j++ {
		ret += cnts[u][j] + cnts[v][j]
		ChMax(&mx, cnts[u][j]+cnts[v][j])
	}
	return ret - mx
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// 0-based
// uf := NewUnionFind(n)
// uf.Root(x) 			// Get root node of the node x
// uf.Unite(x, y) 	// Unite node x and node y
// uf.Same(x, y) 		// Judge x and y are in the same connected component.
// uf.CcSize(x) 		// Get size of the connected component including node x
// uf.CcNum() 			// Get number of connected components

// UnionFind provides disjoint set algorithm.
// Node id starts from 0 (0-based setting).
type UnionFind struct {
	parents []int
}

// NewUnionFind returns a pointer of a new instance of UnionFind.
func NewUnionFind(n int) *UnionFind {
	uf := new(UnionFind)
	uf.parents = make([]int, n)

	for i := 0; i < n; i++ {
		uf.parents[i] = -1
	}

	return uf
}

// Root method returns root node of an argument node.
// Root method is a recursive function.
func (uf *UnionFind) Root(x int) int {
	if uf.parents[x] < 0 {
		return x
	}

	// route compression
	uf.parents[x] = uf.Root(uf.parents[x])
	return uf.parents[x]
}

// Unite method merges a set including x and a set including y.
func (uf *UnionFind) Unite(x, y int) bool {
	xp := uf.Root(x)
	yp := uf.Root(y)

	if xp == yp {
		return false
	}

	// merge: xp -> yp
	// merge larger set to smaller set
	if uf.CcSize(xp) > uf.CcSize(yp) {
		xp, yp = yp, xp
	}
	// update set size
	uf.parents[yp] += uf.parents[xp]
	// finally, merge
	uf.parents[xp] = yp

	return true
}

// Same method returns whether x is in the set including y or not.
func (uf *UnionFind) Same(x, y int) bool {
	return uf.Root(x) == uf.Root(y)
}

// CcSize method returns the size of a set including an argument node.
func (uf *UnionFind) CcSize(x int) int {
	return -uf.parents[uf.Root(x)]
}

// CcNum method returns the number of connected components.
// Time complextity is O(n)
func (uf *UnionFind) CcNum() int {
	res := 0
	for i := 0; i < len(uf.parents); i++ {
		if uf.parents[i] < 0 {
			res++
		}
	}
	return res
}

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

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

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

	var t, n, k int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k, &s)
		ans := 0
		for i := 0; i < k/2; i++ {
			cnt := [26]int{}
			for j := i; j < n; j += k {
				cnt[s[j]-'a']++
			}
			for j := k - 1 - i; j < n; j += k {
				cnt[s[j]-'a']++
			}
			max := 0
			for _, c := range cnt {
				if c > max {
					max = c
				}
			}
			ans += 2*n/k - max
		}
		if k&1 == 1 {
			cnt := [26]int{}
			for j := k / 2; j < n; j += k {
				cnt[s[j]-'a']++
			}
			max := 0
			for _, c := range cnt {
				if c > max {
					max = c
				}
			}
			ans += n/k - max
		}
		Fprintln(out, ans)
	}
}

func main() { CF1332C(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 printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func flush()                            { writer.Flush() }
func pp(a interface{})                  { fmt.Println(a) }

func solve(s string, k int) {
  res := 0
  for i := 0; i*2 < k; i++ {
    freq := make([]int, 26)
    for j := i; j < len(s); j += k {
      freq[int(s[j]-'a')]++
    }
    if k-1-i != i {
      for j := k - 1 - i; j < len(s); j += k {
        freq[int(s[j]-'a')]++
      }
    }
    sum, max := 0, 0
    for _, c := range freq {
      sum += c
      if c > max {
        max = c
      }
    }
    res += sum - max
  }
  printf("%d\n", res)
}

func main() {
  defer flush()

  var t int
  scanf("%d\n", &t)
  for i := 1; i <= t; i++ {
    var n, k int
    scanf("%d %d\n", &n, &k)
    var s string
    scanf("%s\n", &s)
    solve(s, k)
  }
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
    // adjust the following cap as needed
    // 2 << 17 is good enough to scan strings of len 2*10^5
    // cap could go as high as 2 << 26 before cf judge breaks
    maxCap := 2 << 20
    buf := make([]byte, maxCap)
    s.Buffer(buf, maxCap)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%d\n", sol(k, s))
	}
}

func sol(k int64, s string) int64 {
	chunks := []string{}
	for i := k; i <= int64(len(s)); i += k {
		chunks = append(chunks, s[i-k:i])
	}
	var l, r int64
	if k%2 == 1 {
		l, r = k/2, k/2
	} else {
		l, r = k/2-1, k/2
	}

	ret := int64(0)

	// middle element
	if k%2 == 1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
		}
		ret += int64(len(chunks)) - max(chars)
		l--
		r++
	}

	// remaining elements
	for l >= 0 && r <= k-1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
			chars[chunk[r]]++
		}
		ret += int64(len(chunks))*2 - max(chars)
		l--
		r++
	}

	return ret
}

func max(m map[byte]int64) int64 {
	maxSoFar := int64(0)
	for _, v := range m {
		if v > maxSoFar {
			maxSoFar = v
		}
	}
	return maxSoFar
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	maxCap := 2 << 20
	buf := make([]byte, maxCap)
	s.Buffer(buf, maxCap)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%d\n", sol(k, s))
	}
}

func sol(k int64, s string) int64 {
	chunks := []string{}
	for i := k; i <= int64(len(s)); i += k {
		chunks = append(chunks, s[i-k:i])
	}
	var l, r int64
	if k%2 == 1 {
		l, r = k/2, k/2
	} else {
		l, r = k/2-1, k/2
	}

	ret := int64(0)

	// middle element
	if k%2 == 1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
		}
		ret += int64(len(chunks)) - max(chars)
		l--
		r++
	}

	// remaining elements
	for l >= 0 && r <= k-1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
			chars[chunk[r]]++
		}
		ret += int64(len(chunks))*2 - max(chars)
		l--
		r++
	}

	return ret
}

func max(m map[byte]int64) int64 {
	maxSoFar := int64(0)
	for _, v := range m {
		if v > maxSoFar {
			maxSoFar = v
		}
	}
	return maxSoFar
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	maxCap := 2 << 17
	buf := make([]byte, maxCap)
	s.Buffer(buf, maxCap)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%d\n", sol(k, s))
	}
}

func sol(k int64, s string) int64 {
	chunks := []string{}
	for i := k; i <= int64(len(s)); i += k {
		chunks = append(chunks, s[i-k:i])
	}
	var l, r int64
	if k%2 == 1 {
		l, r = k/2, k/2
	} else {
		l, r = k/2-1, k/2
	}

	ret := int64(0)

	// middle element
	if k%2 == 1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
		}
		ret += int64(len(chunks)) - max(chars)
		l--
		r++
	}

	// remaining elements
	for l >= 0 && r <= k-1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
			chars[chunk[r]]++
		}
		ret += int64(len(chunks))*2 - max(chars)
		l--
		r++
	}

	return ret
}

func max(m map[byte]int64) int64 {
	maxSoFar := int64(0)
	for _, v := range m {
		if v > maxSoFar {
			maxSoFar = v
		}
	}
	return maxSoFar
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

const MAX_CAPACITY = 2 << 26

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	buf := make([]byte, MAX_CAPACITY)
	s.Buffer(buf, MAX_CAPACITY)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%d\n", sol(k, s))
	}
}

func sol(k int64, s string) int64 {
	chunks := []string{}
	for i := k; i <= int64(len(s)); i += k {
		chunks = append(chunks, s[i-k:i])
	}
	var l, r int64
	if k%2 == 1 {
		l, r = k/2, k/2
	} else {
		l, r = k/2-1, k/2
	}

	ret := int64(0)

	// middle element
	if k%2 == 1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
		}
		ret += int64(len(chunks)) - max(chars)
		l--
		r++
	}

	// remaining elements
	for l >= 0 && r <= k-1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
			chars[chunk[r]]++
		}
		ret += int64(len(chunks))*2 - max(chars)
		l--
		r++
	}

	return ret
}

func max(m map[byte]int64) int64 {
	maxSoFar := int64(0)
	for _, v := range m {
		if v > maxSoFar {
			maxSoFar = v
		}
	}
	return maxSoFar
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func ReadInts() []int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.Atoi(i)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func IsRuneSetPalindrome(a []rune, len int) (isPalindrome bool, incorrectIndexes []int) {
	if len == 0 {
		return
	}
	isPalindrome = true
	if len == 1 {
		return
	}
	middle := len / 2
	for i := 0; i < middle; i++ {
		lastPos := len - 1 - i
		if a[i] != a[lastPos] {
			isPalindrome = false
			incorrectIndexes = append(incorrectIndexes, lastPos)
		}
	}

	return
}

func IsKPeriodicRuneSet(w []rune, len , k int) (isKPeriodic bool, incorrectIndexes []int) {
	if !(len % k == 0) {
		return
	}
	middle := len / 2
	if (len % 2 != 0) {
		middle += 1
	}
	isKPeriodic = true
	for i := 0; i < middle; i++ {
		period := i + k
		if !(w[i] == w[period]) {
			isKPeriodic = false
			incorrectIndexes = append(incorrectIndexes, period)
		}
	}

	return
}

func RuneSetFrequencyArray(w []rune, len int, lowerLimit int, upperLimit int) []int {
	n := upperLimit - lowerLimit
	frequencyArray := make([]int, n)
	if len == 0 {
		return frequencyArray
	}
	for i := 0; i < len; i++ {
		index := int(w[i]) - lowerLimit
		frequencyArray[index] += 1
	}

	return frequencyArray
}

func GetMaxInt(a []int, len int) int {
	if len == 0 {
		return 0
	}
	if len == 1 {
		return a[0]
	}
	max := a[0]
	for i := 1; i < len; i++ {
		if a[i] > max {
			max = a[i]
		}
	}

	return max
}

func main() {
	nTestCases := ReadInt()
	fmt.Printf("nTestCases: %#v", nTestCases)
	for nTestCases != 0 {
		input := ReadInts()
		fmt.Printf("input: %#v", input)
		str := ReadString()
		fmt.Printf("str: %#v", str)
		n := input[0]
		fmt.Printf("n: %#v", n)
		k := input[1]
		fmt.Printf("k: %#v", k)
		r := []rune(str)
		isPalindrome, pIncorrectPos := IsRuneSetPalindrome(r, n)
		isKPeriodicRuneSet, kIncorrectPos := IsKPeriodicRuneSet(r, n, k)
		if isPalindrome && isKPeriodicRuneSet {
			fmt.Println(0)
		} else if isPalindrome && !isKPeriodicRuneSet {
			fmt.Println(len(kIncorrectPos))
		} else {
			runeSetFrequencyArray := RuneSetFrequencyArray(r, n, 97, 122)
			lenFA := len(runeSetFrequencyArray)
			mostFrequentRunePos := GetMaxInt(runeSetFrequencyArray, lenFA)
			min := n - mostFrequentRunePos
			nP := len(pIncorrectPos)
			if nP % 2 != 0 {
				min += 1
			}
			fmt.Println(min)
		}
		nTestCases -= 1
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

// func ReadInts() []int {
//     str, _ := reader.ReadString(lineDelim)
//     str = str[:len(str)-1]
//     numbersRaw := strings.Split(str, " ")
//     var numbers []int
//     for _, i := range numbersRaw {
//         n, _ := strconv.Atoi(i)
//         numbers = append(numbers, int(n))
//     }

//     return numbers
// }
func ReadIntsAndTrim() []int {
	str, _ := reader.ReadString(lineDelim)
	str = strings.TrimSpace(str)
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.ParseInt(i, 10, 0)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

// func ReadString() string {
//     str, _ := reader.ReadString(lineDelim)
//     str = str[:len(str)-1]

//     return str
// }
func ReadStringAndTrim() string {
	str, _ := reader.ReadString(lineDelim)
	str = strings.TrimSpace(str)

	return str
}

func IsRuneSetPalindrome(a []rune, len int) (isPalindrome bool, incorrectIndexes []int) {
	if len == 0 {
		return
	}
	isPalindrome = true
	if len == 1 {
		return
	}
	middle := len / 2
	for i := 0; i < middle; i++ {
		lastPos := len - 1 - i
		if a[i] != a[lastPos] {
			isPalindrome = false
			incorrectIndexes = append(incorrectIndexes, lastPos)
		}
	}

	return
}

func IsKPeriodicRuneSet(w []rune, len , k int) (isKPeriodic bool, incorrectIndexes []int) {
	if !(len % k == 0) {
		return
	}
	middle := len / 2
	if (len % 2 != 0) {
		middle += 1
	}
	isKPeriodic = true
	for i := 0; i < middle; i++ {
		period := i + k
		if !(w[i] == w[period]) {
			isKPeriodic = false
			incorrectIndexes = append(incorrectIndexes, period)
		}
	}

	return
}

func RuneSetFrequencyArray(w []rune, len int, lowerLimit int, upperLimit int) []int {
	n := upperLimit - lowerLimit
	frequencyArray := make([]int, n)
	if len == 0 {
		return frequencyArray
	}
	for i := 0; i < len; i++ {
		index := int(w[i]) - lowerLimit
		frequencyArray[index] += 1
	}

	return frequencyArray
}

func GetMaxInt(a []int, len int) int {
	if len == 0 {
		return 0
	}
	if len == 1 {
		return a[0]
	}
	max := a[0]
	for i := 1; i < len; i++ {
		if a[i] > max {
			max = a[i]
		}
	}

	return max
}

func main() {
	nTestCases := ReadInt()
	fmt.Printf("nTestCases: %#v\n", nTestCases)
	for nTestCases != 0 {
		input := ReadIntsAndTrim()
		fmt.Printf("input: %#v\n", input)
		str := ReadStringAndTrim()
		fmt.Printf("str: %#v\n", str)
		n := input[0]
		fmt.Printf("n: %#v\n", n)
		k := input[1]
		fmt.Printf("k: %#v\n", k)
		r := []rune(str)
		isPalindrome, pIncorrectPos := IsRuneSetPalindrome(r, n)
		isKPeriodicRuneSet, kIncorrectPos := IsKPeriodicRuneSet(r, n, k)
		if isPalindrome && isKPeriodicRuneSet {
			fmt.Println(0)
		} else if isPalindrome && !isKPeriodicRuneSet {
			fmt.Println(len(kIncorrectPos))
		} else {
			runeSetFrequencyArray := RuneSetFrequencyArray(r, n, 97, 122)
			lenFA := len(runeSetFrequencyArray)
			mostFrequentRunePos := GetMaxInt(runeSetFrequencyArray, lenFA)
			min := n - mostFrequentRunePos
			nP := len(pIncorrectPos)
			if nP % 2 != 0 {
				min += 1
			}
			fmt.Println(min)
		}
		nTestCases -= 1
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func ReadInts() []int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.Atoi(i)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func IsRuneSetPalindrome(a []rune, len int) (isPalindrome bool, incorrectIndexes []int) {
	if len == 0 {
		return
	}
	isPalindrome = true
	if len == 1 {
		return
	}
	middle := len / 2
	for i := 0; i < middle; i++ {
		lastPos := len - 1 - i
		if a[i] != a[lastPos] {
			isPalindrome = false
			incorrectIndexes = append(incorrectIndexes, lastPos)
		}
	}

	return
}

func IsKPeriodicRuneSet(w []rune, len , k int) (isKPeriodic bool, incorrectIndexes []int) {
	if !(len % k == 0) {
		return
	}
	middle := len / 2
	if (len % 2 != 0) {
		middle += 1
	}
	isKPeriodic = true
	for i := 0; i < middle; i++ {
		period := i + k
		if !(w[i] == w[period]) {
			isKPeriodic = false
			incorrectIndexes = append(incorrectIndexes, period)
		}
	}

	return
}

func RuneSetFrequencyArray(w []rune, len int, lowerLimit int, upperLimit int) []int {
	n := upperLimit - lowerLimit
	frequencyArray := make([]int, n)
	if len == 0 {
		return frequencyArray
	}
	for i := 0; i < len; i++ {
		index := int(w[i]) - lowerLimit
		frequencyArray[index] += 1
	}

	return frequencyArray
}

func GetMaxInt(a []int, len int) int {
	if len == 0 {
		return 0
	}
	if len == 1 {
		return a[0]
	}
	max := a[0]
	for i := 1; i < len; i++ {
		if a[i] > max {
			max = a[i]
		}
	}

	return max
}

func main() {
	nTestCases := ReadInt()
	for nTestCases != 0 {
		input := ReadInts()
		n := input[0]
		k := input[1]
		str := ReadString()
		r := []rune(str)
		isPalindrome, pIncorrectPos := IsRuneSetPalindrome(r, n)
		isKPeriodicRuneSet, kIncorrectPos := IsKPeriodicRuneSet(r, n, k)
		if isPalindrome && isKPeriodicRuneSet {
			fmt.Println(0)
		} else if isPalindrome && !isKPeriodicRuneSet {
			fmt.Println(len(kIncorrectPos))
		} else if !isPalindrome && !isKPeriodicRuneSet {
			runeSetFrequencyArray := RuneSetFrequencyArray(r, n, 97, 122)
			lenFA := len(runeSetFrequencyArray)
			mostFrequentRunePos := GetMaxInt(runeSetFrequencyArray, lenFA)
			var min int
			nP := len(pIncorrectPos)
			if nP % 2 == 0 {
				min = n - mostFrequentRunePos
			} else {
				min = n - mostFrequentRunePos + 1
			}
			fmt.Println(min)
		}
		nTestCases -= 1
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func ReadInts() []int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.Atoi(i)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func IsRuneSetPalindrome(a []rune, len int) (isPalindrome bool, incorrectIndexes []int) {
	if len == 0 {
		return
	}
	isPalindrome = true
	if len == 1 {
		return
	}
	middle := len / 2
	for i := 0; i < middle; i++ {
		lastPos := len - 1 - i
		if a[i] != a[lastPos] {
			isPalindrome = false
			incorrectIndexes = append(incorrectIndexes, lastPos)
		}
	}

	return
}

func IsKPeriodicRuneSet(w []rune, len , k int) (isKPeriodic bool, incorrectIndexes []int) {
	if !(len % k == 0) {
		return
	}
	middle := len / 2
	if (len % 2 != 0) {
		middle += 1
	}
	isKPeriodic = true
	for i := 0; i < middle; i++ {
		period := i + k
		if !(w[i] == w[period]) {
			isKPeriodic = false
			incorrectIndexes = append(incorrectIndexes, period)
		}
	}

	return
}

func RuneSetFrequencyArray(w []rune, len int, lowerLimit int, upperLimit int) []int {
	n := upperLimit - lowerLimit
	frequencyArray := make([]int, n)
	if len == 0 {
		return frequencyArray
	}
	for i := 0; i < len; i++ {
		index := int(w[i]) - lowerLimit
		frequencyArray[index] += 1
	}

	return frequencyArray
}

func GetMaxInt(a []int, len int) int {
	if len == 0 {
		return 0
	}
	if len == 1 {
		return a[0]
	}
	max := a[0]
	for i := 1; i < len; i++ {
		if a[i] > max {
			max = a[i]
		}
	}

	return max
}

func main() {
	nTestCases := ReadInt()
	for nTestCases != 0 {
		input := ReadInts()
		n := input[0]
		k := input[1]
		str := ReadString()
		r := []rune(str)
		isPalindrome, pIncorrectPos := IsRuneSetPalindrome(r, n)
		isKPeriodicRuneSet, kIncorrectPos := IsKPeriodicRuneSet(r, n, k)
		if isPalindrome && isKPeriodicRuneSet {
			fmt.Println(0)
		} else if isPalindrome && !isKPeriodicRuneSet {
			fmt.Println(len(kIncorrectPos))
		} else {
			runeSetFrequencyArray := RuneSetFrequencyArray(r, n, 97, 122)
			lenFA := len(runeSetFrequencyArray)
			mostFrequentRunePos := GetMaxInt(runeSetFrequencyArray, lenFA)
			var min int
			nP := len(pIncorrectPos)
			if nP % 2 == 0 {
				min = n - mostFrequentRunePos
			} else {
				min = n - mostFrequentRunePos + 1
			}
			fmt.Println(min)
		}
		nTestCases -= 1
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func ReadIntsAndTrim() []int {
	str, _ := reader.ReadString(lineDelim)
	str = strings.TrimSpace(str)
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.ParseInt(i, 10, 0)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

func ReadStringAndTrim() string {
	str, _ := reader.ReadString(lineDelim)
	str = strings.TrimSpace(str)

	return str
}

func IsRuneSetPalindrome(a []rune, len int) (isPalindrome bool, incorrectIndexes []int) {
	if len == 0 {
		return
	}
	isPalindrome = true
	if len == 1 {
		return
	}
	middle := len / 2
	for i := 0; i < middle; i++ {
		lastPos := len - 1 - i
		if a[i] != a[lastPos] {
			isPalindrome = false
			incorrectIndexes = append(incorrectIndexes, lastPos)
		}
	}

	return
}

func IsKPeriodicRuneSet(w []rune, len , k int) (isKPeriodic bool, incorrectIndexes []int) {
	if !(len % k == 0) {
		return
	}
	middle := len / 2
	if (len % 2 != 0) {
		middle += 1
	}
	isKPeriodic = true
	for i := 0; i < middle; i++ {
		period := i + k
		if !(w[i] == w[period]) {
			isKPeriodic = false
			incorrectIndexes = append(incorrectIndexes, period)
		}
	}

	return
}

func RuneSetFrequencyArray(w []rune, len int, lowerLimit int, upperLimit int) []int {
	n := upperLimit - lowerLimit
	frequencyArray := make([]int, n)
	if len == 0 {
		return frequencyArray
	}
	for i := 0; i < len; i++ {
		index := int(w[i]) - lowerLimit
		frequencyArray[index] += 1
	}

	return frequencyArray
}

func GetMaxInt(a []int, len int) int {
	if len == 0 {
		return 0
	}
	if len == 1 {
		return a[0]
	}
	max := a[0]
	for i := 1; i < len; i++ {
		if a[i] > max {
			max = a[i]
		}
	}

	return max
}

func main() {
	nTestCases := ReadInt()
	for nTestCases != 0 {
		input := ReadIntsAndTrim()
		str := ReadStringAndTrim()
		n := input[0]
		k := input[1]
		r := []rune(str)
		isPalindrome, pIncorrectPos := IsRuneSetPalindrome(r, n)
		isKPeriodicRuneSet, kIncorrectPos := IsKPeriodicRuneSet(r, n, k)
		if isPalindrome && isKPeriodicRuneSet {
			fmt.Println(0)
		} else if isPalindrome && !isKPeriodicRuneSet {
			fmt.Println(len(kIncorrectPos))
		} else {
			nP := len(pIncorrectPos)
			for i := 0; i < nP; i++ {
				pos := pIncorrectPos[i]
				r[pos] = r[n - pos - 1]
			}
			runeSetFrequencyArray := RuneSetFrequencyArray(r, n, 97, 122)
			lenFA := len(runeSetFrequencyArray)
			mostFrequentRuneCount := GetMaxInt(runeSetFrequencyArray, lenFA)
			min := n - mostFrequentRuneCount
			if n % 2 != 0 {
				min += 1
			}
			fmt.Println(min)
		}
		nTestCases -= 1
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func ReadInts() []int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.Atoi(i)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func IsRuneSetPalindrome(a []rune, len int) (isPalindrome bool, incorrectIndexes []int) {
	if len == 0 {
		return
	}
	isPalindrome = true
	if len == 1 {
		return
	}
	middle := len / 2
	for i := 0; i < middle; i++ {
		lastPos := len - 1 - i
		if a[i] != a[lastPos] {
			isPalindrome = false
			incorrectIndexes = append(incorrectIndexes, lastPos)
		}
	}

	return
}

func IsKPeriodicRuneSet(w []rune, len , k int) (isKPeriodic bool, incorrectIndexes []int) {
	if !(len % k == 0) {
		return
	}
	middle := len / 2
	if (len % 2 != 0) {
		middle += 1
	}
	isKPeriodic = true
	for i := 0; i < middle; i++ {
		period := i + k
		if !(w[i] == w[period]) {
			isKPeriodic = false
			incorrectIndexes = append(incorrectIndexes, period)
		}
	}

	return
}

func RuneSetFrequencyArray(w []rune, len int, lowerLimit int, upperLimit int) []int {
	n := upperLimit - lowerLimit
	frequencyArray := make([]int, n)
	if len == 0 {
		return frequencyArray
	}
	for i := 0; i < len; i++ {
		index := int(w[i]) - lowerLimit
		frequencyArray[index] += 1
	}

	return frequencyArray
}

func GetMaxInt(a []int, len int) int {
	if len == 0 {
		return 0
	}
	if len == 1 {
		return a[0]
	}
	max := a[0]
	for i := 1; i < len; i++ {
		if a[i] > max {
			max = a[i]
		}
	}

	return max
}

func main() {
	nTestCases := ReadInt()
	for nTestCases != 0 {
		input := ReadInts()
		str := ReadString()
		n := input[0]
		k := input[1]
		r := []rune(str)
		isPalindrome, pIncorrectPos := IsRuneSetPalindrome(r, n)
		isKPeriodicRuneSet, kIncorrectPos := IsKPeriodicRuneSet(r, n, k)
		if isPalindrome && isKPeriodicRuneSet {
			fmt.Println(0)
		} else if isPalindrome && !isKPeriodicRuneSet {
			fmt.Println(len(kIncorrectPos))
		} else {
			runeSetFrequencyArray := RuneSetFrequencyArray(r, n, 97, 122)
			lenFA := len(runeSetFrequencyArray)
			mostFrequentRunePos := GetMaxInt(runeSetFrequencyArray, lenFA)
			var min int
			nP := len(pIncorrectPos)
			if nP % 2 == 0 {
				min = n - mostFrequentRunePos
			} else {
				min = n - mostFrequentRunePos + 1
			}
			fmt.Println(min)
		}
		nTestCases -= 1
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func ReadInts() []int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    numbersRaw := strings.Split(str, " ")
    var numbers []int
    for _, i := range numbersRaw {
        n, _ := strconv.Atoi(i)
        numbers = append(numbers, int(n))
    }

    return numbers
}

func ReadInt() int {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func IsRuneSetPalindrome(a []rune, len int) (isPalindrome bool, incorrectIndexes []int) {
	if len == 0 {
		return
	}
	isPalindrome = true
	if len == 1 {
		return
	}
	middle := len / 2
	for i := 0; i < middle; i++ {
		lastPos := len - 1 - i
		if a[i] != a[lastPos] {
			isPalindrome = false
			incorrectIndexes = append(incorrectIndexes, lastPos)
		}
	}

	return
}

func IsKPeriodicRuneSet(w []rune, len , k int) (isKPeriodic bool, incorrectIndexes []int) {
	if !(len % k == 0) {
		return
	}
	middle := len / 2
	if (len % 2 != 0) {
		middle += 1
	}
	isKPeriodic = true
	for i := 0; i < middle; i++ {
		period := i + k
		if !(w[i] == w[period]) {
			isKPeriodic = false
			incorrectIndexes = append(incorrectIndexes, period)
		}
	}

	return
}

func RuneSetFrequencyArray(w []rune, len int, lowerLimit int, upperLimit int) []int {
	n := upperLimit - lowerLimit
	frequencyArray := make([]int, n)
	if len == 0 {
		return frequencyArray
	}
	for i := 0; i < len; i++ {
		index := int(w[i]) - lowerLimit
		frequencyArray[index] += 1
	}

	return frequencyArray
}

func GetMaxInt(a []int, len int) int {
	if len == 0 {
		return 0
	}
	if len == 1 {
		return a[0]
	}
	max := a[0]
	for i := 1; i < len; i++ {
		if a[i] > max {
			max = a[i]
		}
	}

	return max
}

func main() {
	nTestCases := ReadInt()
	fmt.Printf("nTestCases: %#v\n", nTestCases)
	for nTestCases != 0 {
		input := ReadInts()
		fmt.Printf("input: %#v\n", input)
		str := ReadString()
		fmt.Printf("str: %#v\n", str)
		n := input[0]
		fmt.Printf("n: %#v\n", n)
		k := input[1]
		fmt.Printf("k: %#v\n", k)
		r := []rune(str)
		isPalindrome, pIncorrectPos := IsRuneSetPalindrome(r, n)
		isKPeriodicRuneSet, kIncorrectPos := IsKPeriodicRuneSet(r, n, k)
		if isPalindrome && isKPeriodicRuneSet {
			fmt.Println(0)
		} else if isPalindrome && !isKPeriodicRuneSet {
			fmt.Println(len(kIncorrectPos))
		} else {
			runeSetFrequencyArray := RuneSetFrequencyArray(r, n, 97, 122)
			lenFA := len(runeSetFrequencyArray)
			mostFrequentRunePos := GetMaxInt(runeSetFrequencyArray, lenFA)
			min := n - mostFrequentRunePos
			nP := len(pIncorrectPos)
			if nP % 2 != 0 {
				min += 1
			}
			fmt.Println(min)
		}
		nTestCases -= 1
	}
}

package main

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

type BufferedWriter interface {
    Printf(format string, a ...interface{})
    Flush()
}

type writerImpl struct {
    *bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
    return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

type WordScanner interface {
    NextInt() int
    NextInt64() int64
    NextString() string
}

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
    impl.Scan()
    bb := impl.Bytes()
    i := 0
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    if bb[0] == '-' {
        for _, b := range bb[1:] {
            i *= 10
            i -= int64(b - '0')
        }
        return i
    }
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        _, k := reader.NextInt64(), reader.NextInt64()
        s := reader.NextString()
        writer.Printf("%d\n", sol(k, s))
    }
}

func sol(k int64, s string) int64 {
    chunks := []string{}
    for i := k; i <= int64(len(s)); i += k {
        chunks = append(chunks, s[i-k:i])
    }
    var l, r int64
    if k % 2 == 1 {
        l, r = k/2, k/2
    } else {
        l, r = k/2 -1, k/2
    }

    ret := int64(0)

    // middle element
    if k % 2 == 1 {
        chars := map[byte]int64{}
        for _, chunk := range chunks {
            chars[chunk[l]]++
        }
        ret += int64(len(chunks)) - max(chars)
        l--
        r++
    }

    // remaining elements
    for l >= 0 && r <= k-1 {
        chars := map[byte]int64{}
        for _, chunk := range chunks {
            chars[chunk[l]]++
            chars[chunk[r]]++
        }
        ret += int64(len(chunks))*2 - max(chars)
        l--
        r++
    }

    return ret
}

func max(m map[byte]int64) int64 {
    maxSoFar := int64(0)
    for _, v := range m {
        if v > maxSoFar {
            maxSoFar = v
        }
    }
    return maxSoFar
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	maxCap := 2 << 15
	buf := make([]byte, maxCap)
	s.Buffer(buf, maxCap)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%d\n", sol(k, s))
	}
}

func sol(k int64, s string) int64 {
	chunks := []string{}
	for i := k; i <= int64(len(s)); i += k {
		chunks = append(chunks, s[i-k:i])
	}
	var l, r int64
	if k%2 == 1 {
		l, r = k/2, k/2
	} else {
		l, r = k/2-1, k/2
	}

	ret := int64(0)

	// middle element
	if k%2 == 1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
		}
		ret += int64(len(chunks)) - max(chars)
		l--
		r++
	}

	// remaining elements
	for l >= 0 && r <= k-1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
			chars[chunk[r]]++
		}
		ret += int64(len(chunks))*2 - max(chars)
		l--
		r++
	}

	return ret
}

func max(m map[byte]int64) int64 {
	maxSoFar := int64(0)
	for _, v := range m {
		if v > maxSoFar {
			maxSoFar = v
		}
	}
	return maxSoFar
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	maxCap := 2 << 16
	buf := make([]byte, maxCap)
	s.Buffer(buf, maxCap)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%d\n", sol(k, s))
	}
}

func sol(k int64, s string) int64 {
	chunks := []string{}
	for i := k; i <= int64(len(s)); i += k {
		chunks = append(chunks, s[i-k:i])
	}
	var l, r int64
	if k%2 == 1 {
		l, r = k/2, k/2
	} else {
		l, r = k/2-1, k/2
	}

	ret := int64(0)

	// middle element
	if k%2 == 1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
		}
		ret += int64(len(chunks)) - max(chars)
		l--
		r++
	}

	// remaining elements
	for l >= 0 && r <= k-1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
			chars[chunk[r]]++
		}
		ret += int64(len(chunks))*2 - max(chars)
		l--
		r++
	}

	return ret
}

func max(m map[byte]int64) int64 {
	maxSoFar := int64(0)
	for _, v := range m {
		if v > maxSoFar {
			maxSoFar = v
		}
	}
	return maxSoFar
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	maxCap := 2 << 10
	buf := make([]byte, maxCap)
	s.Buffer(buf, maxCap)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%d\n", sol(k, s))
	}
}

func sol(k int64, s string) int64 {
	chunks := []string{}
	for i := k; i <= int64(len(s)); i += k {
		chunks = append(chunks, s[i-k:i])
	}
	var l, r int64
	if k%2 == 1 {
		l, r = k/2, k/2
	} else {
		l, r = k/2-1, k/2
	}

	ret := int64(0)

	// middle element
	if k%2 == 1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
		}
		ret += int64(len(chunks)) - max(chars)
		l--
		r++
	}

	// remaining elements
	for l >= 0 && r <= k-1 {
		chars := map[byte]int64{}
		for _, chunk := range chunks {
			chars[chunk[l]]++
			chars[chunk[r]]++
		}
		ret += int64(len(chunks))*2 - max(chars)
		l--
		r++
	}

	return ret
}

func max(m map[byte]int64) int64 {
	maxSoFar := int64(0)
	for _, v := range m {
		if v > maxSoFar {
			maxSoFar = v
		}
	}
	return maxSoFar
}


Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on.The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex v sad if there is a vertex u in subtree of vertex v such that dist(v, u) > au, where au is the number written on vertex u, dist(v, u) is the sum of the numbers written on the edges on the path from v to u.Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root.Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove?

In the first line of the input integer n (1 ≤ n ≤ 105) is given — the number of vertices in the tree. In the second line the sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 109) is given, where ai is the number written on vertex i. The next n - 1 lines describe tree edges: ith of them consists of two integers pi and ci (1 ≤ pi ≤ n,  - 109 ≤ ci ≤ 109), meaning that there is an edge connecting vertices i + 1 and pi with number ci written on it.

Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree.

NoteThe following image represents possible process of removing leaves from the tree:

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Vertex struct {
  Id int
  Limit int64
  Edges []*Edge
  Seen bool
}

type Edge struct {
  V *Vertex
  Cost int64
}

var (
  vertices []*Vertex
  deleted int
)

func visit(u *Vertex, pathCost int64) {
  u.Seen = true
  if pathCost > u.Limit {
    return
  }
  deleted--
  for _, edge := range u.Edges {
    v := edge.V
    if v.Seen {
      continue
    }
    nextPathCost := pathCost + edge.Cost
    if nextPathCost < 0 {
      nextPathCost = 0
    }
    visit(v, nextPathCost)
  }
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  vertices = make([]*Vertex, n + 1)
  for i := 1; i <= n; i++ {
    vertices[i] = &Vertex{ i, getI64(), []*Edge{}, false }
  }
  for u := 2; u <= n; u++ {
    v, cost := getI(), getI64()
    uPtr, vPtr := vertices[u], vertices[v]
    uPtr.Edges = append(uPtr.Edges, &Edge{ vPtr, cost })
    vPtr.Edges = append(vPtr.Edges, &Edge{ uPtr, cost })
  }

  deleted = n
  visit(vertices[1], 0)
  writer.WriteString(fmt.Sprintf("%d\n", deleted))
}

package main

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

var n int
var weight []int64
var head [][]*Edge

type Edge struct{
	Value int64
	to int
}
func dfs(u int, mx int64, par int) int{
	if  mx > weight[u] {
		return 0
	}
	if mx < 0 {
		mx = 0
	}
	ret := 1
	for _, edge := range head[u] {
		if edge.to != par {
			ret += dfs(edge.to, mx + edge.Value, u)
		}
	}
	return ret
}
func main() {
	fmt.Scanf("%d\n", &n)
	weight = make([]int64, n)
	head = make([][]*Edge, n)
	reader := bufio.NewReaderSize(os.Stdin, 10000000)
	byte, _, _ := reader.ReadLine()
	strs := strings.Split(string(byte), " ")
	for i:=0; i < n; i++ {
		weight[i], _ = strconv.ParseInt(strs[i], 10, 64)
	}

	for i:=1; i < n; i++ {
		byte, _, _ = reader.ReadLine()
		strs = strings.Split(string(byte), " ")
		to, _ := strconv.Atoi(strs[0])
		value, _ := strconv.ParseInt(strs[1], 10, 64)
		e := &Edge{Value: value, to: to-1}
		ve := &Edge{Value: value, to: i}
		head[i] = append(head[i], e)
		head[to - 1] = append(head[to - 1], ve)
	}
	fmt.Println(n - dfs(0, 0, 0))
}

package main

import (
	"fmt"
	"container/list"
	"bufio"
	"os"
	"strings"
	"strconv"
)

var n int
var weight []int64
var head []*list.List

type Edge struct{
	Value int64
	to int
}
func dfs(u int, mx int64, par int) int{
	if  mx > weight[u] {
		return 0
	}
	if mx < 0 {
		mx = 0
	}
	ret := 1
	for e := head[u].Front(); e != nil; e= e.Next() {
		edge, _ := e.Value.(*Edge)
		if edge.to != par {
			ret += dfs(edge.to, mx + edge.Value, u)
		}
	}
	return ret
}
func main() {
	fmt.Scanf("%d\n", &n)
	weight = make([]int64, n)
	head = make([]*list.List, n)
	reader := bufio.NewReaderSize(os.Stdin, 10000000)
	byte, _, _ := reader.ReadLine()
	strs := strings.Split(string(byte), " ")
	for i:=0; i < n; i++ {
		weight[i], _ = strconv.ParseInt(strs[i], 10, 64)
		head[i] = &list.List{}
	}

	for i:=1; i < n; i++ {
		byte, _, _ = reader.ReadLine()
		strs = strings.Split(string(byte), " ")
		to, _ := strconv.Atoi(strs[0])
		value, _ := strconv.ParseInt(strs[1], 10, 64)
		e := &Edge{Value: value, to: to-1}
		ve := &Edge{Value: value, to: i}
		head[i].PushBack(e)
		head[to - 1].PushBack(ve)
	}
	fmt.Println(n - dfs(0, 0, 0))
}

package main

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

func main() {
	n := getInt()
	A := getNint(n)

	C := make([]int, n+1)
	G := make([][]int, n+1)
	for i := 2; i <= n; i++ {
		p, c := getInt(), getInt()
		C[i] = c
		G[i] = append(G[i], p)
		G[p] = append(G[p], i)
	}

	V := make([]bool, n+1) // vis?
	P := make([]bool, n+1) // pruned?
	q := make([]int, 1, n)
	D := make([]int64, n+1) // dist
	q[0] = 1
	var ans int
	for i := 0; i < len(q); i++ {
		v := q[i]
		V[v] = true
		for _, u := range G[v] {
			if V[u] {
				continue
			}
			V[u] = true
			q = append(q, u)
			D[u] = D[v] + int64(C[u])
			remax64(&D[u], 0)
			P[u] = P[v] || D[u] > int64(A[u-1])
			if P[u] {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

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

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

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

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

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

package main

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

func main() {
	n := getInt()
	A := getNint(n)

	C := make([]int, n+1)
	G := make([][]int, n+1)
	for i := 2; i <= n; i++ {
		p, c := getInt(), getInt()
		C[i] = c
		G[i] = append(G[i], p)
		G[p] = append(G[p], i)
	}

	V := make([]bool, n+1) // vis?
	P := make([]bool, n+1) // pruned?
	q := make([]int, 1, n)
	D := make([]int64, n+1) // dist
	q[0] = 1
	var ans int
	for i := 0; i < len(q); i++ {
		v := q[i]
		V[v] = true
		for _, u := range G[v] {
			if V[u] {
				continue
			}
			V[u] = true
			q = append(q, u)
			D[u] = D[v] + int64(C[u])
			P[u] = P[v] || D[u] > int64(A[u-1])
			if P[u] {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

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

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

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

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

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


Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how hard he tries, he will not be able to remove a simple subsequence!We say that a string formed by $$$n$$$ characters '(' or ')' is simple if its length $$$n$$$ is even and positive, its first $$$\frac{n}{2}$$$ characters are '(', and its last $$$\frac{n}{2}$$$ characters are ')'. For example, the strings () and (()) are simple, while the strings )( and ()() are not simple.Kuroni will be given a string formed by characters '(' and ')' (the given string is not necessarily simple). An operation consists of choosing a subsequence of the characters of the string that forms a simple string and removing all the characters of this subsequence from the string. Note that this subsequence doesn't have to be continuous. For example, he can apply the operation to the string ')()(()))', to choose a subsequence of bold characters, as it forms a simple string '(())', delete these bold characters from the string and to get '))()'. Kuroni has to perform the minimum possible number of operations on the string, in such a way that no more operations can be performed on the remaining string. The resulting string does not have to be empty.Since the given string is too large, Kuroni is unable to figure out how to minimize the number of operations. Can you help him do it instead?A sequence of characters $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The only line of input contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$) formed by characters '(' and ')', where $$$|s|$$$ is the length of $$$s$$$.

In the first line, print an integer $$$k$$$  — the minimum number of operations you have to apply. Then, print $$$2k$$$ lines describing the operations in the following format: For each operation, print a line containing an integer $$$m$$$  — the number of characters in the subsequence you will remove. Then, print a line containing $$$m$$$ integers $$$1 \le a_1 < a_2 < \dots < a_m$$$  — the indices of the characters you will remove. All integers must be less than or equal to the length of the current string, and the corresponding subsequence must form a simple string. If there are multiple valid sequences of operations with the smallest $$$k$$$, you may print any of them.

NoteIn the first sample, the string is '(()(('. The operation described corresponds to deleting the bolded subsequence. The resulting string is '(((', and no more operations can be performed on it. Another valid answer is choosing indices $$$2$$$ and $$$3$$$, which results in the same final string.In the second sample, it is already impossible to perform any operations.

package main

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

var reader io.Reader
var scanner *bufio.Scanner

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

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

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

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

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

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	s := NextBytes()
	n := len(s)
	var l, r int
	left := make([]int, 0, n)
	right := make([]int, 0, n)
	result := make([][]int, 0)
	for {
		for l, r = 0, n-1; l < r; {
			for l < r && s[l] != '(' {
				l++
			}
			for l < r && s[r] != ')' {
				r--
			}
			if l < r && s[l] == '(' && s[r] == ')' {
				left = append(left, l)
				right = append(right, r)
				l++
				r--
			} else {
				break
			}
		}
		if len(left) > 0 {
			// stderr("part", string(s), "left", left, "right", right)
			t := make([]int, len(left)+len(right))
			for i, pos := range left {
				t[i] = pos
			}
			for i := len(right) - 1; i >= 0; i-- {
				t[len(left)+len(right)-i-1] = right[i]
			}
			result = append(result, t)

			nl := 0
			for i, l, r := 0, 0, len(right)-1; i < n; i++ {
				for l < len(left) && left[l] < i {
					l++
				}
				for l == len(left) && r >= 0 && right[r] < i {
					r--
				}
				if l < len(left) && left[l] == i || l == len(left) && r >= 0 && right[r] == i {
					continue
				}
				s[nl] = s[i]
				nl++
			}
			s = s[:nl]
			n = nl
			// stderr(string(s))
			left = left[:0]
			right = right[:0]
		} else {
			break
		}
	}

	fmt.Fprintln(out, len(result))
	for _, ar := range result {
		fmt.Fprintln(out, len(ar))
		for _, pos := range ar {
			fmt.Fprint(out, pos+1, " ")
		}
		fmt.Fprintln(out)
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line := readLine(reader)
	i, j := 0, len(line)-1
	ops := 0
	result := make([]int, 0)
	for i < j && i < len(line) && j >= 0 {
		for i <= len(line)-1 && line[i] == ')'  {
			i++
		}
		for j >= 0 && line[j] == '(' {
			j--
		}
		if i < j && i < len(line) && j >= 0 {
			ops += 2
			result = append(result, i+1, j+1)
			i++
			j--
		}
	}
	if ops == 0 {
		fmt.Println(0)
		return
	}
	fmt.Println(1)
	fmt.Println(ops)
	sort.Ints(result)
	for _, i := range result {
		fmt.Printf("%d ", i)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/problemset/problem/1305/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	S []rune
	n int
)

func main() {
	S = ReadRuneSlice()
	n = len(S)

	A := []int{}
	l, r := 0, n-1
	for l < r {
		for l < n && S[l] != '(' {
			l++
		}

		for r >= 0 && S[r] != ')' {
			r--
		}

		if l < r {
			A = append(A, l+1, r+1)
			l++
			r--
		} else {
			break
		}
	}

	sort.Sort(sort.IntSlice(A))

	if len(A) == 0 {
		fmt.Println(0)
		return
	}

	fmt.Println(1)
	fmt.Println(len(A))
	fmt.Println(PrintIntsLine(A...))
}

func solve() {
}

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

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

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

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

	var s []byte
	Fscan(in, &s)

	ans := [][]int{}
	for {
		n := len(s)
		used := make([]bool, n)
a := []int{}
		i := 0
		j:=n-1
		for {
			for ; i < n; i++ {
				if s[i] == '(' {
					break
				}
			}
			for ;j>=0;j-- {
				if s[j] ==')' {
					break
				}
			}
			if i<j {
				used[i]=true
				used[j]=true
				a = append(a, i,j)
				i++
				j--
			} else {
				break
			}
		}
		if len(a) == 0 {
			break
		}
		sort.Ints(a)
		ans = append(ans, a)
		newS := []byte{}
		for i, b := range used {
			if !b {
				newS = append(newS, s[i])
			}
		}
s=newS
//println(string(s))
		//cl := make([]int, n)
		//cr := make([]int, n)
		//for i, b := range s {
		//	if i == 0 {
		//		if b == '(' {
		//			cl[0]=1
		//		}
		//	} else {
		//		cl[i] =cl[i-1]
		//		if b == '(' {
		//			cl[i]++
		//		}
		//	}
		//}
		//for i := n - 1; i >= 0; i-- {
		//	b := s[i]
		//	if i == n-1 {
		//		if b == ')' {
		//			cr[n-1]=1
		//		}
		//	} else {
		//		cr[i] =cr[i+1]
		//		if b == ')' {
		//			cr[i]++
		//		}
		//	}
		//}
		//ans := 0
		//for i := range s {
		//	if cl[i]<cr[i] {
		//		ans=cl[i]
		//	} else {
		//		break
		//	}
		//}
		//for i, b := range s {
		//	if b=='(' {
		//
		//	}
		//}
	}

	Fprintln(out, len(ans))
	for _, a := range ans {
		Fprintln(out, len(a))
		for i, v := range a {
			if i > 0 {
				Fprint(out, " ")
			}
			Fprint(out, v+1)
		}
		Fprintln(out)
	}

}

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

package main

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

func main() {
	s := ScanWord()
	i := getSimpleIndex(s)
	sort.Ints(i)
	if len(i) == 0 {
		P(0)
	} else {
		P(1)
		P(len(i))
		P(SArr(i))
	}

	close(O)
	oWg.Wait()
}

func getSimpleIndex(s string) []int {
	openP := make([]int, 0, len(s))
	closeP := make([]int, 0, len(s))

	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			openP = append(openP, i)
		} else if s[i] == ')' {
			closeP = append(closeP, i)
		}
	}

	left, right := 0, len(closeP)-1
	openIndex := []int{}
	closeIndex := []int{}

	for left < len(openP) && right >= 0 && openP[left] < closeP[right] {
		openIndex = append(openIndex, openP[left]+1)
		closeIndex = append(closeIndex, closeP[right]+1)
		left++
		right--
	}
	r := append(openIndex, closeIndex...)
	return r
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {

    inputString := scanString()
    start, end := 0, len(inputString) - 1
    firstArray := []int{}
	secondArray := []int{}

	for start < end{
		for start < end && inputString[start] != '('{
			start++
		}
		for start < end && inputString[end] != ')'{
			end--
		}
		if start >= end{
			break
		}
		firstArray = append(firstArray, start+1)
		secondArray = append(secondArray, end+1)
		start++
		end--
	}

	sort.Ints(firstArray)
	sort.Ints(secondArray)

	if len(firstArray) == 0{
		printFmt(0)
	}else{
		printFmt(1)
		printFmt(len(firstArray)+len(secondArray))
		fmt.Print(spaceSeperatedStringFromArray(firstArray), spaceSeperatedStringFromArray(secondArray))
	}

	close(channelType)
	oWg.Wait()
}

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

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if (a == 0) {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}

package main
import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	a := make([]int, 0, len(s))
	b := make([]int, 0, len(s))
	for i, e := range s {
		if e == '(' {
			a = append(a, i)
		}
		if s[len(s)-i-1] == ')' {
			b = append(b, len(s)-i-1)
		}
	}
	c := make([]int, 0, len(s))
	for i , j := 0, 0; i < len(a) && j < len(b) && a[i] < b[j];i, j = i + 1, j + 1 {
		c = append(c, a[i]+1, b[j]+1)
	}
	if len(c) == 0 {
		fmt.Fprintln(w, "0")
		return
	}
	sort.Ints(c)
	fmt.Fprintln(w, 1)
	fmt.Fprintln(w, len(c))
	for i, e := range c {
		if i == 0 {
			fmt.Fprint(w, e)
		} else {
			fmt.Fprint(w," ", e)
		}
	}
	fmt.Fprintln(w)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line := readLine(reader)
	i,j := 0, len(line)-1
	ops := 0
	result := make([]int, 0)
	for i<j {
		for line[i] == ')' && i <= len(line)-1{
			i++
		}
		for line[j] == '(' && j >= 0{
			j--
		}
		if i < j && i < len(line) && j >=0 {
			ops += 2
			result = append(result, i+1, j+1)
			i++
			j--
		}
	}
	fmt.Println(ops)
	sort.Ints(result)
	for _, i := range result {
		fmt.Printf("%d ", i)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

package main

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

func main() {
	s := ScanWord()
	i := getSimpleIndex(s)
	if len(i) == 0 {
		P(0)
	} else {
		P(1)
		P(len(i))
		P(SArr(i))
	}

	close(O)
	oWg.Wait()
}

func getSimpleIndex(s string) []int {
	openP := make([]int, 0, len(s))
	closeP := make([]int, 0, len(s))

	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			openP = append(openP, i)
		} else if s[i] == ')' {
			closeP = append(closeP, i)
		}
	}

	left, right := 0, len(closeP)-1
	openIndex := []int{}
	closeIndex := []int{}

	for left < len(openP) && right >= 0 {
		openIndex = append(openIndex, openP[left]+1)
		closeIndex = append(closeIndex, closeP[right]+1)
		left++
		right--
	}
	r := append(openIndex, closeIndex...)
	return r
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	s := ScanWord()
	i := getSimpleIndex(s)
	if len(i) == 0 {
		P(0)
	} else {
		P(1)
		P(len(i))
		P(SArr(i))
	}

	close(O)
	oWg.Wait()
}

func getSimpleIndex(s string) []int {
	openP := make([]int, 0, len(s))
	closeP := make([]int, 0, len(s))

	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			openP = append(openP, i)
		} else if s[i] == ')' {
			closeP = append(closeP, i)
		}
	}

	left, right := 0, len(closeP)-1
	openIndex := []int{}
	closeIndex := []int{}

	for left < len(openP) && right >= 0 && openP[left] < closeP[right] {
		openIndex = append(openIndex, openP[left]+1)
		closeIndex = append(closeIndex, closeP[right]+1)
		left++
		right--
	}
	r := append(openIndex, closeIndex...)
	return r
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {

    inputString := scanString()
    start, end := 0, len(inputString) - 1
    firstArray := []int{}
	secondArray := []int{}

	for start < end{
		for start < end && inputString[start] != '('{
			start++
		}
		for start < end && inputString[end] != ')'{
			end--
		}
		if start >= end{
			break
		}
		firstArray = append(firstArray, start+1)
		secondArray = append(secondArray, end+1)
		start++
		end--
	}

	if len(firstArray) == 0{
		printFmt(0)
	}else{
		printFmt(1)
		printFmt(len(firstArray)+len(secondArray))
		fmt.Print(spaceSeperatedStringFromArray(firstArray), spaceSeperatedStringFromArray(secondArray))
	}

	close(channelType)
	oWg.Wait()
}

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

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string {in.Scan(); return in.Text() }
func scanInt() int {i, _ := strconv.Atoi(scanString()); return i}
func scanInt64() int64 {i, _ := strconv.ParseInt(scanString(), 10, 64); return i}
func scanStringSlice(n int) []string {s := make([]string, n); for i := 0; i < n; i++ {s[i] = scanString()}; return s}
func scanIntSlice(n int) []int {arr := make([]int, n); for i := 0; i < n; i++ {arr[i] = scanInt()}; return arr}
func scanInt64Slice(n int) []int64 {arr := make([]int64, n); for i := 0; i < n; i++ {arr[i] = scanInt64()}; return arr}

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string {return fmt.Sprintf("%v", v)}
func spaceSeperatedStringFromArray(a []int) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.Itoa(a[i]) + " ")}; return sb.String()}
func spaceSeperatedStringFromArray64(a []int64) string {sb := strings.Builder{}; sb.Grow(len(a) * 9); for i := range a {sb.WriteString(strconv.FormatInt(a[i], 10) + " ")}; return sb.String()}
func minMaxFromArray(args ...int64) (int64, int64) {minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64); for _, v := range args {if v < minVal {minVal = v}; if v > maxVal {maxVal = v}}; return minVal, maxVal}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64 {return a / gcdCalculation(a, b) * b}
func gcdCalculation(a, b int64) int64 {if (a == 0) {return b}; return gcdCalculation(b%a, a)}
func sortInt64Slice(a []int64) {sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })}
func absoluteValue(x int64) int64 {if x < 0 {return -x}; return x}

package main
import (
	"bufio"
	"fmt"
	"os"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	a := make([]int, 0, len(s))
	b := make([]int, 0, len(s))
	for i, e := range s {
		if e == '(' {
			a = append(a, i)
		}
		if s[len(s)-i-1] == ')' {
			b = append(b, len(s)-i-1)
		}
	}
	c := make([]int, 0, len(s))
	for i , j := 0, 0; i < len(a) && j < len(b) && a[i] < b[j];i, j = i + 1, j + 1 {
		c = append(c, a[i]+1, b[j]+1)
	}
	if len(c) == 0 {
		fmt.Fprintln(w, "0")
		return
	}
	fmt.Fprintln(w, len(c)/2)
	fmt.Fprintln(w, len(c))
	for i, e := range c {
		if i == 0 {
			fmt.Fprint(w, e)
		} else {
			fmt.Fprint(w," ", e)
		}
	}
	fmt.Fprintln(w)
}

package main
import (
	"bufio"
	"fmt"
	"os"
)
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var s string
	fmt.Fscan(r, &s)
	a := make([]int, 0, len(s))
	b := make([]int, 0, len(s))
	for i, e := range s {
		if e == '(' {
			a = append(a, i)
		}
		if s[len(s)-i-1] == ')' {
			b = append(b, len(s)-i-1)
		}
	}
	c := make([]int, 0, len(s))
	for i , j := 0,len(b) - 1; i < len(a) && j >= 0 && a[i] < b[j];i, j = i + 1, j - 1 {
		c = append(c, a[i]+1, b[j]+1)
	}
	if len(c) == 0 {
		fmt.Fprintln(w, "0")
		return
	}
	fmt.Fprintln(w, len(c)/2)
	fmt.Fprintln(w, len(c))
	for i, e := range c {
		if i == 0 {
			fmt.Fprint(w, e)
		} else {
			fmt.Fprint(w," ", e)
		}
	}
	fmt.Fprintln(w)
}