//nolint
package main

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

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

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

func main() {
	defer writer.Flush()

	Main()
}

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

//}

func Solve() {
	var st string
	scan(&st)
	if len(st) == 1 {
		println(0)
		return
	}
	c1 := 0
	for _, c := range st {
		if c == '1' {
			c1++
		}
	}
	if c1*2 > len(st) {
		println(len(st) - c1)
	} else if c1*2 < len(st) {
		println(c1)
	} else {
		println(c1 - 1)
	}
}

package main

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

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

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

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

	round := 0
	Fscan(in, &round)

	onesNum := 0
	zerosNum := 0
	res := 0
	targetStr := ""

	for i := 1; i <= round; i++ {

		onesNum = 0
		zerosNum = 0
		res = 0

		Fscan(in, &targetStr)

		for j := range targetStr {
			if string(targetStr[j]) == "0" {
				zerosNum++
			} else {
				onesNum++
			}
			if zerosNum != onesNum {
				res = max(res, min(zerosNum, onesNum))
			}

		}

		Fprintln(out, res)
	}
}

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

package main

import (
	"fmt"
	"strings"
)

func getStringCount(a []string) int{

	sum:=0
	sm2:=0
	if  len(a)<2{

		return 0
	}else{

		for _,value:=range a{
			if value==string('0'){
			sum++
		}else{
			sm2++
		}
		}

	}
	if sum<sm2 && (sum!=0||sm2!=0){
		return sum
	} else if sum>sm2  &&(sum!=0||sm2!=0){
		return sm2
	} else{
		return 0
	}

}

func main() {

	var size int

	fmt.Scanf("%d\n",&size)

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

		s:=""
		fmt.Scanf("%s\n",&s)

		sum,sum2:=strings.Count(s,"0"),strings.Count(s,"1")
		if sum<sum2{

	fmt.Printf("%d\n",sum)
		} else  if sum2<sum{
	fmt.Printf("%d\n",sum2)
	} else{
	fmt.Printf("%d\n",sum2-1)
	}

	}

}

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var binary string
		fmt.Fscan(in,&binary)
		zeros:= strings.Count(binary,"1")
		ones:= strings.Count(binary,"0")
		if len(binary) == 2 || len(binary) == 1 {
			fmt.Fprintln(out,0)
		} else if zeros == ones {
			fmt.Fprintln(out,zeros-1)
		} else if zeros > ones {
			fmt.Fprintln(out,ones)
		} else {
			fmt.Fprintln(out,zeros)
		}
	}
}

package main

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

const (
    bufferSize = 1000000
)

var (
    cin *Scanner
)

type Scanner struct {
    scanner *bufio.Scanner
}

func (s *Scanner)nextInt() int {
    s.scanner.Scan()
    t := s.scanner.Text()
    i, _ := strconv.Atoi(t)
    return i
}

func (s *Scanner)nextWord() string {
    s.scanner.Scan()
    return s.scanner.Text()
}

func init() {
    cin = &Scanner{scanner: bufio.NewScanner(os.Stdin)}
    buffer := make([]byte, 0, bufferSize)
    cin.scanner.Buffer(buffer, bufferSize)
    cin.scanner.Split(bufio.ScanWords)
}

func main() {
    t := cin.nextInt()
    for t > 0 {
        s := cin.nextWord()
        zeros, ones := 0, 0
        for _, c := range s {
            if c == '0' {
                zeros++
            } else {
                ones++
            }
        }
        if zeros < ones {
            fmt.Println(zeros)
        } else if zeros > ones {
            fmt.Println(ones)
        } else {
            fmt.Println(zeros - 1)
        }
        t--
    }
}

package main

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

)

/*

b) https://codeforces.com/contest/1633

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

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n int

		fmt.Fscan(in , &n)

		arr  := make([]string,n)

		for i := 0 ; i < n ; i++{
			fmt.Fscan(in , &arr[i])

			num  :=  Minority(arr[i])

			fmt.Fprintln(out ,num)

		}

		//count := 0

	}

	T := 1

	//fmt.Fscan(in ,&T)

	for o := 0 ; o < T ; o++{
		solve()
	}
}

func Minority(str string)int{

	countZero := 0

	count :=0

	numerical_runes := []rune(str)

	for _ , num := range(numerical_runes){

		if(string(num) == "0"){
			countZero++

		}

	}

	countOne := len(str)-countZero

	//fmt.Println("Count One",countOne)
	//fmt.Println("Count zero",countZero)

	if countOne != countZero{

			count = min(countOne , countZero)
	}else{
		return countZero-1
	}

	return count
}

func min(n1, n2 int)int{

if  n1 < n2{
	return n1
}
return n2
}

/*
func DivisionOfSeven(num int)int{

	//n := len(arr)

if num % 7 == 0{

	num =  num
}else{

	for j := 0 ; j < 10 ; j++{

		if (num -  num % 10 + j) % 7 == 0{
			num =  num  - num % 10 + j
		}

	}
}

return num

}

func DivisionOfSeven(arr []int)[]int{

	n := len(arr)

	var status int =  0
	//fmt.Fprintln(arr)
for i := 0 ; i < n ; i++{

	if arr[i] % 7 == 0{

		status = 1
	}else if arr[i] > 7  && status == 0{

		arr[i] = arr[i] + ((7 - (arr[i] % 7)) % 7)
	}

		}

	return arr

}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

*/

func main(){

	run(os.Stdin , os.Stdout)
}

package main

import "fmt"

func process(in string) int {
    if len(in) < 3 {
        return 0
    }
    o, z := 0, 0

    for _, c := range in {
        if c == '1' {
            o++
        } else {
            z++
        }
    }

    if o == z {
        return o-1
    } else if o < z {
        return o
    }
    return z
}

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

    for n > 0 {
        var input string
        fmt.Scanln(&input)
        fmt.Println(process(input))
        n--
    }
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1633B
Date: 8/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1633/B
Problem: CF1633B
**/
func (in *CF1633B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		ones := 0
		for i := 0; i < len(str); i++ {
			if str[i] == '1' {
				ones++
			}
		}
		zeros := len(str) - ones
		if ones == zeros {
			fmt.Println(ones - 1)
		} else {
			fmt.Println(int(math.Min(float64(zeros), float64(ones))))
		}
	}
}

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

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

package main

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

func main() {

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

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

	for t > 0 {
		s := ""
		fmt.Fscan(reader, &s)
		fmt.Fprintln(writter, solve(s))

		t--
	}

	// s := "1"
	// fmt.Println(solve(s))

}

func solve(s string) int {

	zero := 0
	one := 0
	result := 0

	for i := range s {
		if s[i] == '0' {
			zero++
		}

		if s[i] == '1' {
			one++
		}

		if zero > one {
			result = max(result, one)
		}

		if one > zero {
			result = max(result, zero)
		}

	}

	return result
}

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

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

	return sum
}

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

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

	return sum
}

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

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

	return b
}

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

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

	return result
}

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

	return gcd(b%a, a)
}

func printMatrix(matrix [][]int) {

	for i := range matrix {

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

		fmt.Println()

	}

}

func checkPrime(num int) bool {

	if num < 2 {
		return false
	}

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

	return true
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var s string
	scan(&s)
	cnt := [2]int{}
	for _, i := range s {
		cnt[i-'0']++
	}
	if cnt[0] == cnt[1] {
		printf("%v\n", cnt[0]-1)
	} else if cnt[0] < cnt[1] {
		printf("%v\n", cnt[0])
	} else {
		printf("%v\n", cnt[1])
	}
}

package main

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

func readInt(x *int) {
	if _, err := fmt.Scan(x); err != nil {
		panic(err)
	}
}
func read(x *string) {
	if _, err := fmt.Scan(x); err != nil {
		panic(err)
	}
}
func readLine() string {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	return text
}
func readArray(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		readInt(&arr[i])
	}
	return arr
}
func min(vars ...int) int {
	m := vars[0]
	for _, val := range vars {
		if val < m {
			m = val
		}
	}
	return m
}
func main() {
	var t int
	readInt(&t)
	for ; t > 0; t-- {
		var s string
		read(&s)
		z := strings.Count(s, "0")
		o := len(s) - z
		// fmt.Println(z, o)
		if z != o {
			fmt.Println(min(z, o))
		} else {
			fmt.Println(z - 1)
		}
	}

}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var testCases int
	fmt.Scanln(&testCases)
	for testCase := 0; testCase < testCases; testCase++ {
		var n string
		fmt.Scanln(&n)
		ones := strings.Count(n, "1")
		zeroes := strings.Count(n, "0")
		if ones == zeroes {
			fmt.Println(ones - 1)
		} else if ones < zeroes {
			fmt.Println(ones)
		} else {
			fmt.Println(zeroes)
		}
	}
}

package main

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

var s string

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &s)

		ans := solve()

		fmt.Println(ans)
	}
}

type pair struct {
	v, id int
}

type ByV []*pair

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

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6

func solve() int {
	var z int
	var o int
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			z++
		} else {
			o++
		}
	}

	if o != z {
		return min(o, z)
	}

	if s[0] == '0' {
		return o - 1
	} else {
		return z - 1
	}

}

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

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

package main

import (
	"fmt"
)

// B. Minority

func solve() {

	var s string

	fmt.Scanf("%s\n", &s)

	if len(s) > 2 {
		num0 := 0
		num1 := 0

		max := 0

		for _, c := range s {
			ch := string(c)

			if ch == "0" {
				num0++
			} else if ch == "1" {
				num1++
			}

			if num1 > num0 {
				max = num0
			} else if num1 < num0 {
				max = num1
			}
		}

		fmt.Println(max)
	} else {
		fmt.Println("0")
	}
}

func main() {

	var t int

	fmt.Scanf("%d\n", &t)

	for t > 0 {
		solve()
		t--
	}
}

// Data structures

type Pair struct {
	First, Second int
}

type Pairs []Pair

func (p Pairs) Len() int           { return len(p) }
func (p Pairs) Less(i, j int) bool { return p[i].First < p[j].First }
func (p Pairs) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

package main

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

func f(x int) (res [10]int) {
	j := 0
	for i := x; i < 10; i++ {
		res[j] = i
	}
	for i := 0; i < x; i++ {
		res[j] = i
	}
	return
}

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

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

		ones := 0
		zeroes := 0
		for i := range n {
			if n[i] == '0' {
				zeroes++
			} else {
				ones++
			}
		}

		res := 0
		if ones == zeroes {
			res = ones - 1
		} else if ones < zeroes {
			res = ones
		} else {
			res = zeroes
		}

		if res < 0 {
			res = 0
		}

		fmt.Fprintln(out, res)
	}
}

package main

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

/*
4
101010
111000
011010
001110
---
2
2
2
2
======
6
0
1
00
11
01
10
---
0
0
0
0
0
0
=======
4
101
010
000
111
---
1
1
0
0
*/

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

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

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

		oneCnt := 0
		for _, r := range s {
			if r == '1' {
				oneCnt++
			}
		}

		zeroCnt := len(s) - oneCnt

		rmvCnt := 0

		if zeroCnt < oneCnt {
			rmvCnt = zeroCnt
		} else if oneCnt < zeroCnt {
			rmvCnt = oneCnt
		} else {
			rmvCnt = oneCnt - 1
		}

		fmt.Fprintln(writer, rmvCnt)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

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

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

// generated by 1e9y at 31-01-2022
// template version: 2022-01-11

package main

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

// 0000.A
func solve(input string) int {
	n := len(input)
	if n == 1 || n == 2 {
		return 0
	}

	ones, zeros := 0, 0
	for _, s := range input {
		if s == '0' {
			zeros++
		} else {
			ones++
		}
	}

	if ones == 0 || zeros == 0 {
		return 0
	}

	if ones == zeros {
		return ones - 1
	}

	if ones < zeros {
		return ones
	}

	return zeros
}

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

	t := ReadInt(in)
	for i := 0; i < t; i++ {
		s := ReadLine(in)
		Output(solve(s))
	}
}

// helpers for convenient input reading

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

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

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

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

// helper for convenient answer output

func Output(v interface{}) {
	switch v.(type) {
	case bool:
		if v == true {
			Println("YES")
		} else {
			Println("NO")
		}
	default:
		Println(v)
	}
}

package main

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

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

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

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

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

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var s []byte
		scan(&s)
		cnt0 := 0
		cnt1 := 0
		for _, b := range s {
			if b == '1' {
				cnt1++
			} else {
				cnt0++
			}
		}
		if cnt0 == cnt1 {
			printf("%d\n", cnt0-1)
		} else {
			printf("%d\n", min(cnt0, cnt1))
		}
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			fmt.Fprintln(w, o-1)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

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

		var c0, c1 int
		for _, ch := range s {
			if ch == '0' {
				c0++
			} else {
				c1++
			}
		}

		if c0 == c1 {
			fmt.Fprintln(out, c0-1)
		} else if c0 > c1 {
			fmt.Fprintln(out, c1)
		} else {
			fmt.Fprintln(out, c0)
		}
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			p, oc, zc, mxo, mxz := "", 0, 0, math.MinInt32, math.MinInt32
			for j := 0; j < len(s); j++ {
				if oc > mxo {
					mxo = oc
				}
				if zc > mxz {
					mxz = zc
				}
				if p == "1" && string(s[j]) == "1" {
					oc++
				} else if p == "0" && string(s[j]) == "0" {
					zc++
				} else {
					if string(s[j]) == "1" {
						oc, zc = 1, 0
					} else {
						zc, oc = 1, 0
					}
				}
				p = string(s[j])
			}
			if mxo == 0 || mxz == 0 {
				fmt.Fprintln(w, 0)
			} else {
				if mxo > mxz {
					fmt.Fprintln(w, mxo)
				} else {
					fmt.Fprintln(w, mxz)
				}
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			p, oc, zc, mxo, mxz := "", 0, 0, math.MinInt32, math.MinInt32
			for j := 0; j < len(s); j++ {
				if p == "1" && string(s[j]) == "1" {
					oc++
				} else if p == "0" && string(s[j]) == "0" {
					zc++
				} else {
					if oc > mxo {
						mxo = oc
					}
					if zc > mxz {
						mxz = zc
					}
					if string(s[j]) == "1" {
						oc, zc = 1, 0
					} else {
						zc, oc = 1, 0
					}
				}
				// fmt.Fprintln(w, oc, zc, mxo, mxz)
				p = string(s[j])
			}
			if oc > mxo {
				mxo = oc
			}
			if zc > mxz {
				mxz = zc
			}
			if mxo == mxz {
				fmt.Fprintln(w, 0)
			} else {
				if mxo > mxz {
					fmt.Fprintln(w, mxo)
				} else {
					fmt.Fprintln(w, mxz)
				}
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			p, oc, zc, mxo, mxz := "", 0, 0, math.MinInt32, math.MinInt32
			for j := 0; j < len(s); j++ {
				if p == "1" && string(s[j]) == "1" {
					oc++
				} else if p == "0" && string(s[j]) == "0" {
					zc++
				} else {
					if string(s[j]) == "1" {
						oc, zc = 1, 0
					} else {
						zc, oc = 1, 0
					}
					if oc > mxo {
						mxo = oc
					}
					if zc > mxz {
						mxz = zc
					}
				}
				p = string(s[j])
			}
			if mxo == mxz {
				fmt.Fprintln(w, 0)
			} else {
				if mxo > mxz {
					fmt.Fprintln(w, mxo)
				} else {
					fmt.Fprintln(w, mxz)
				}
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			p, oc, zc, mxo, mxz := "", 0, 0, math.MinInt32, math.MinInt32
			for j := 0; j < len(s); j++ {
				if p == "1" && string(s[j]) == "1" {
					oc++
				} else if p == "0" && string(s[j]) == "0" {
					zc++
				} else {
					if string(s[j]) == "1" {
						oc = 1
					} else {
						zc = 1
					}
					if oc > mxo {
						mxo = oc
					}
					if zc > mxz {
						mxz = zc
					}
				}
				p = string(s[j])
			}
			if mxo == mxz {
				fmt.Fprintln(w, 0)
			} else {
				if mxo > mxz {
					fmt.Fprintln(w, mxo)
				} else {
					fmt.Fprintln(w, mxz)
				}
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			p, oc, zc, mxo, mxz := "", 0, 0, math.MinInt32, math.MinInt32
			for j := 0; j < len(s); j++ {
				if p == "1" && string(s[j]) == "1" {
					oc++
				} else if p == "0" && string(s[j]) == "0" {
					zc++
				} else {
					if oc > mxo {
						mxo = oc
					}
					if zc > mxz {
						mxz = zc
					}
					if string(s[j]) == "1" {
						oc, zc = 1, 0
					} else {
						oc, zc = 0, 1
					}
				}
				p = string(s[j])
			}
			if mxo == mxz {
				fmt.Fprintln(w, 0)
			} else {
				if mxo > mxz {
					fmt.Fprintln(w, mxo)
				} else {
					fmt.Fprintln(w, mxz)
				}
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			p, oc, zc, mxo, mxz := "", 0, 0, math.MinInt32, math.MinInt32
			for j := 0; j < len(s); j++ {
				if p == "1" && string(s[j]) == "1" {
					oc++
				} else if p == "0" && string(s[j]) == "0" {
					zc++
				} else {
					if oc > mxo {
						mxo = oc
					}
					if zc > mxz {
						mxz = zc
					}
					oc, zc = 1, 1
				}
				p = string(s[j])
			}
			if mxo == mxz {
				fmt.Fprintln(w, 0)
			} else {
				if mxo > mxz {
					fmt.Fprintln(w, mxo)
				} else {
					fmt.Fprintln(w, mxz)
				}
			}
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s := ""
		fmt.Fscan(f, &s)
		o, z := strings.Count(s, "1"), strings.Count(s, "0")
		if o < z {
			fmt.Fprintln(w, o)
		} else if z < o {
			fmt.Fprintln(w, z)
		} else {
			fmt.Fprintln(w, 0)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

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

		var c int64
		for win := len(s) - 1; win > 2; win-- {
			for i := 0; win+i <= len(s); i++ {
				s2 := s[i : win+i]

				var c0, c1 int64
				for _, ch := range s2 {
					if ch == '0' {
						c0++
					} else {
						c1++
					}
				}

				if c0 > c1 && c1 > c {
					c = c1
				} else if c1 > c0 && c0 > c {
					c = c0
				}
			}

		}
		fmt.Fprintln(out, c)
	}
}

package main

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

func max(a int, rest ...int) int {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

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

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

		var c int64
		for win := len(s) - 1; win > 2; win-- {
			for i := 0; win+i <= len(s); i++ {
				s2 := s[i : win+i]

				var c0, c1 int64
				for _, ch := range s2 {
					if ch == '0' {
						c0++
					} else {
						c1++
					}
				}

				if c0 > c1 && c1 > c {
					c = c1
				} else if c1 > c0 && c0 > c {
					c = c0
				}
			}

			if c > 0 {
				break
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

func max(a int, rest ...int) int {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

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

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

		var c int

		for win := len(s) - 1; win > 2; win-- {
			for i := 0; win+i <= len(s); i++ {
				s2 := s[i : win+i]

				// fmt.Println("Sub:", s2)
				var c0, c1 int
				for _, ch := range s2 {
					if ch == '0' {
						c0++
					} else {
						c1++
					}
				}

				if c0 > c1 && c1 > c {
					c = c1
				} else if c1 > c0 && c0 > c {
					c = c0
				}
			}

			if c > 0 {
				break
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

func max(a int, rest ...int) int {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

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

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

		var c0, c1 int
		for _, ch := range s {
			if ch == '0' {
				c0++
			} else {
				c1++
			}
		}

		// check the front
		var c int
		if s[0] == '0' && c0-1 != c1 {
			if c0-1 > c1 {
				c = max(c, c1)
			} else {
				c = max(c, c0-1)
			}
		} else if s[0] == '1' && c1-1 != 0 {
			if c1-1 > c0 {
				c = max(c, c0)
			} else {
				c = max(c, c1-1)
			}
		}

		if s[len(s)-1] == '0' && c0-1 != c1 {
			if c0-1 > c1 {
				c = max(c, c1)
			} else {
				c = max(c, c0-1)
			}
		} else if s[len(s)-1] == '1' && c1-1 != c0 {
			if c1-1 > c0 {
				c = max(c, c0)
			} else {
				c = max(c, c1-1)
			}
		}

		fmt.Fprintln(out, c)
	}
}

package main

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

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

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

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

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

		var c0, c1 int
		for _, ch := range s {
			if ch == '0' {
				c0++
			} else {
				c1++
			}
		}

		// check the front
		var c int
		if s[0] == '0' && c0-1 > c1 {
			c = max(c, c1)
		} else if s[0] == '1' && c1-1 > c0 {
			c = max(c, c0)
		}

		if s[len(s)-1] == '0' && c0-1 > c1 {
			c = max(c, c1)
		} else if s[len(s)-1] == '1' && c1-1 > c0 {
			c = max(c, c0)
		}

		fmt.Fprintln(out, c)
	}
}

package main

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

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

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

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

	round := 0
	Fscan(in, &round)

	onesNum := 0
	zerosNum := 0
	res := 0
	targetStr := ""

	for i := 1; i <= round; i++ {

		onesNum = 0
		zerosNum = 0

		Fscan(in, &targetStr)

		for j := range targetStr {
			if string(targetStr[j]) == "0" {
				zerosNum++
			} else {
				onesNum++
			}
			if zerosNum != onesNum {
				res = max(res, min(zerosNum, onesNum))
			}

		}

		if zerosNum < onesNum {
			Fprintln(out, zerosNum)
		} else if zerosNum == onesNum {
			Fprintln(out, 0)
		} else {
			Fprintln(out, onesNum)
		}
	}
}

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

package main

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

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

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

	round := 0
	Fscan(in, &round)

	onesNum := 0
	zerosNum := 0
	res := 0
	targetStr := ""

	for i := 1; i <= round; i++ {

		onesNum = 0
		zerosNum = 0

		Fscan(in, &targetStr)

		for j := range targetStr {
			if string(targetStr[j]) == "0" {
				zerosNum++
			} else {
				onesNum++
			}
			if zerosNum != onesNum {
				res = max(res, max(zerosNum, onesNum))
			}

		}

		if zerosNum < onesNum {
			Fprintln(out, zerosNum)
		} else if zerosNum == onesNum {
			Fprintln(out, 0)
		} else {
			Fprintln(out, onesNum)
		}
	}
}

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

package main

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

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

	round := 0
	Fscan(in, &round)

	onesNum := 0
	zerosNum := 0
	targetStr := ""

	for i := 1; i <= round; i++ {

		onesNum = 0
		zerosNum = 0

		Fscan(in, &targetStr)

		for _, j := range targetStr {
			if string(j) == "0" {
				zerosNum++
			} else {
				onesNum++
			}
		}

		if zerosNum < onesNum {
			Fprintln(out, zerosNum)
		} else if zerosNum == onesNum {
			Fprintln(out, 0)
		} else {
			Fprintln(out, onesNum)
		}
	}
}

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

package main

import (
	"fmt"
	"strings"
)

func getStringCount(a []string) int{

	sum:=0
	sm2:=0
	if  len(a)<2{

		return 0
	}else{

		for _,value:=range a{
			if value==string('0'){
			sum++
		}else{
			sm2++
		}
		}

	}
	if sum<sm2 && (sum!=0||sm2!=0){
		return sum
	} else if sum>sm2  &&(sum!=0||sm2!=0){
		return sm2
	} else{
		return 0
	}

}

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]string ,size)

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

		fmt.Scanf("%s\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{

	outputs[i]=getStringCount(strings.Split(inputs[i],""))

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
	"strings"
)

func getStringCount(a []string) int{

	sum:=0
	sm2:=0
	if len(a)%2==0||len(a)<2{

		return 0
	}else{

		for _,value:=range a{
			if value==string('0'){
			sum++
		}else{
			sm2++
		}
		}

	}
	if sum<sm2 && (sum!=0||sm2!=0){
		return sum
	} else if sum>sm2  &&(sum!=0||sm2!=0){
		return sm2
	} else{
		return 0
	}

}

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]string ,size)

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

		fmt.Scanf("%s\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{

	outputs[i]=getStringCount(strings.Split(inputs[i],""))

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

package main

import (
	"fmt"
	"strings"
)

func getStringCount(a []string) int{

	sum:=0
	sm2:=0
	if len(a)%2==0||len(a)<2{

		return 0
	}else{

		for _,value:=range a{
			if value==string('0'){
			sum++
		}else{
			sm2++
		}
		}

	}
	if sum<sm2{
		return sum
	} else{
		return sm2
	}

}

func main() {

	var size int

	fmt.Scanf("%d\n",&size)
	outputs:=make([]int ,size)

	inputs:=make([]string ,size)

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

		fmt.Scanf("%s\n",&inputs[i])

	}

		fmt.Scanf("\n")
	for i:=0;i<size;i++{

	outputs[i]=getStringCount(strings.Split(inputs[i],""))

}
for _,value :=range outputs{
	fmt.Printf("%d\n",value)
}
}

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

package main
import(
    "fmt"
    "bufio"
    "os"
    "strings"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var binary string
		fmt.Fscan(in,&binary)
		zeros:= strings.Count(binary,"1")
		ones:= strings.Count(binary,"0")
		if zeros == ones {
			fmt.Fprintln(out,0)
		} else if zeros > ones {
			fmt.Fprintln(out,ones)
		} else {
			fmt.Fprintln(out,zeros)
		}
	}
}

package main

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

var (
    cin *Scanner
)

type Scanner struct {
    scanner *bufio.Scanner
}

func (s *Scanner)nextInt() int {
    s.scanner.Scan()
    t := s.scanner.Text()
    i, _ := strconv.Atoi(t)
    return i
}

func (s *Scanner)nextWord() string {
    if !s.scanner.Scan() {
        fmt.Println("cannot scan")
    }
    return s.scanner.Text()
}

func init() {
    cin = &Scanner{scanner: bufio.NewScanner(os.Stdin)}
    cin.scanner.Split(bufio.ScanWords)
}

func main() {
    t := cin.nextInt()
    for t > 0 {
        s := cin.nextWord()
        zeros, ones := 0, 0
        for _, c := range s {
            if c == '0' {
                zeros++
            } else {
                ones++
            }
        }
        if zeros < ones {
            fmt.Println(zeros)
        } else if zeros > ones {
            fmt.Println(ones)
        } else {
            fmt.Println(zeros - 1)
        }
        t--
    }
}

package main

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

var (
    cin *Scanner
)

type Scanner struct {
    scanner *bufio.Scanner
}

func (s *Scanner)nextInt() int {
    s.scanner.Scan()
    t := s.scanner.Text()
    i, _ := strconv.Atoi(t)
    return i
}

func (s *Scanner)nextWord() string {
    s.scanner.Scan()
    return s.scanner.Text()
}

func init() {
    cin = &Scanner{scanner: bufio.NewScanner(os.Stdin)}
    cin.scanner.Split(bufio.ScanWords)
}

func main() {
    t := cin.nextInt()
    for t > 0 {
        s := cin.nextWord()
        zeros, ones := 0, 0
        for _, c := range s {
            if c == '0' {
                zeros++
            } else {
                ones++
            }
        }
        if zeros < ones {
            fmt.Println(zeros)
        } else if zeros > ones {
            fmt.Println(ones)
        } else {
            fmt.Println(zeros - 1)
        }
        t--
    }
}

package main

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

)

/*

b) https://codeforces.com/contest/1633

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

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n int

		fmt.Fscan(in , &n)

		arr  := make([]string,n)

		for i := 0 ; i < n ; i++{
			fmt.Fscan(in , &arr[i])

			num  :=  Minority(arr[i])

			fmt.Fprintln(out ,num)

		}

		//count := 0

	}

	T := 1

	//fmt.Fscan(in ,&T)

	for o := 0 ; o < T ; o++{
		solve()
	}
}

func Minority(str string)int{

	countZero := 0
	countOne := 0
	count :=0

	numerical_runes := []rune(str)

	for _ , num := range(numerical_runes){

		if(string(num) == "0"){
			countZero++

		}else{
			countOne++
		}

	}

	//fmt.Println("Count One",countOne)
	//fmt.Println("Count zero",countZero)

	if countOne != countZero{

			count = min(countOne , countZero)
	}else{
		return count
	}

	return count
}

func min(n1, n2 int)int{

if  n1 < n2{
	return n1
}
return n2
}

/*
func DivisionOfSeven(num int)int{

	//n := len(arr)

if num % 7 == 0{

	num =  num
}else{

	for j := 0 ; j < 10 ; j++{

		if (num -  num % 10 + j) % 7 == 0{
			num =  num  - num % 10 + j
		}

	}
}

return num

}

func DivisionOfSeven(arr []int)[]int{

	n := len(arr)

	var status int =  0
	//fmt.Fprintln(arr)
for i := 0 ; i < n ; i++{

	if arr[i] % 7 == 0{

		status = 1
	}else if arr[i] > 7  && status == 0{

		arr[i] = arr[i] + ((7 - (arr[i] % 7)) % 7)
	}

		}

	return arr

}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

*/

func main(){

	run(os.Stdin , os.Stdout)
}

package main

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

)

/*

b) https://codeforces.com/contest/1633

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

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n int

		fmt.Fscan(in , &n)

		arr  := make([]string,n)

		for i := 0 ; i < n ; i++{
			fmt.Fscan(in , &arr[i])

			num  :=  Minority(arr[i])

			fmt.Fprintln(out ,num)

		}

		//count := 0

	}

	T := 1

	//fmt.Fscan(in ,&T)

	for o := 0 ; o < T ; o++{
		solve()
	}
}

func Minority(str string)int{

	countZero := 0
	countOne := 0
	count :=0

	numerical_runes := []rune(str)

	for _ , num := range(numerical_runes){

		if(string(num) == "0"){
			countZero++

		}else{
			countOne++
		}

	}

	//fmt.Println("Count One",countOne)
	//fmt.Println("Count zero",countZero)

	if countOne != countZero{

			count = min(countOne , countZero)
	}

	return count
}

func min(n1, n2 int)int{

if  n1 < n2{
	return n1
}
return n2
}

/*
func DivisionOfSeven(num int)int{

	//n := len(arr)

if num % 7 == 0{

	num =  num
}else{

	for j := 0 ; j < 10 ; j++{

		if (num -  num % 10 + j) % 7 == 0{
			num =  num  - num % 10 + j
		}

	}
}

return num

}

func DivisionOfSeven(arr []int)[]int{

	n := len(arr)

	var status int =  0
	//fmt.Fprintln(arr)
for i := 0 ; i < n ; i++{

	if arr[i] % 7 == 0{

		status = 1
	}else if arr[i] > 7  && status == 0{

		arr[i] = arr[i] + ((7 - (arr[i] % 7)) % 7)
	}

		}

	return arr

}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

*/

func main(){

	run(os.Stdin , os.Stdout)
}

//nolint
package main

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

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

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

func main() {
	defer writer.Flush()

	Main()
}

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

//}

func Solve() {
	var st string
	scan(&st)
	c1 := 0
	for _, c := range st {
		if c == '1' {
			c1++
		}
	}
	if c1*2 > len(st) {
		println(len(st) - c1)
	} else if c1*2 < len(st) {
		println(c1)
	} else {
		println(0)
	}
}

package main

import "fmt"

func process(in string) int {
    if len(in) < 3 {
        return 0
    }
    o, z := 0, 0

    for _, c := range in {
        if c == '1' {
            o++
        } else {
            z++
        }
    }

    if o == z {
        return o-1
    } else if o < z {
        return o
    }
    return z
}

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

    for n > 0 {
        var input string
        fmt.Scanln(&input)
        fmt.Println(process(input))
        n--
    }
}


package main

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

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

func CF1635B(_r io.Reader, _w io.Writer) {
	max := func(i, j int) int {
		if i > j {
			return i
		}
		return j
	}
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		bigger := make([]bool, n)
		for i := 1; i < n-1; i++ {
			if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
				bigger[i] = true
			}
		}
		ans := 0 //计次
		//先处理可以一箭双雕的
		for i := 1; i < n-1; i++ {
			if bigger[i-1] && bigger[i+1] {
				arr[i] = max(arr[i-1], arr[i+1])
				ans++
				bigger[i-1] = false
				bigger[i+1] = false
			}
		}
		//处理剩余的单个
		for i := 1; i < n-1; i++ {
			if bigger[i] {
				arr[i] = max(arr[i-1], arr[i+1])
				ans++
			}
		}
		fmt.Fprintln(out, ans)
		for pos, v := range arr {
			if pos == n-1 {
				fmt.Fprintln(out, v)
			} else {
				fmt.Fprint(out, v, " ")
			}
		}
	}
}

package main

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

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

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

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

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

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		var c int
		for i := 1; i < n-1; i++ {
			if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
				if i < n-2 {
					arr[i+1] = max(arr[i], arr[i+2])
				} else {
					arr[i] = max(arr[i-1], arr[i+1])
				}
				c++
			}
		}

		fmt.Fprintln(out, c)
		for _, v := range arr {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1635B
Date: 5/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1635/B
Problem: CF1635B
**/
func (in *CF1635B) Run() {
	var sol strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}
		ans := 0
		for i := 1; i < n-1; i++ {
			if arr[i] > arr[i+1] && arr[i] > arr[i-1] {
				if i+2 < n {
					arr[i+1] = int(math.Max(float64(arr[i]), float64(arr[i+2])))
				} else {
					arr[i+1] = arr[i]
				}
				ans++
			}
		}

		sol.WriteString(fmt.Sprintf("%d\n", ans))
		for i := 0; i < n; i++ {
			sol.WriteString(fmt.Sprintf("%d ", arr[i]))
		}
		sol.WriteString("\n")
	}
	fmt.Println(sol.String())
}

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

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

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, 0, n)
		for j := 0; j < n; j++ {
			var num int
			fmt.Fscan(in, &num)
			arr = append(arr, num)
		}
		// solve
		diff := 0
		for i := 1; i < n-1; i ++ {
			if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
				if i + 2 < n {
					arr[i+1] = max(arr[i], arr[i+2])
				} else {
					arr[i+1] = arr[i]
				}
				diff ++
			}
		}
		fmt.Fprintln(out, diff)
		for k, v := range arr {
			fmt.Fprint(out, v)
			if k != n-1 {
				fmt.Fprint(out, " ")
			} else {
				fmt.Fprintln(out)
			}
		}
	}
}

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

package main

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

/*
4
6
2 4 4 5 5 4
5
1 3 2 3 3
3
1 3 1
5
1 2 3 4 1
---
0
2 4 4 2 5 4
1
1 3 3 3 3
1
1 3 3
4
1 2 4 4 1

*/

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

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

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

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		cnt := 0

		prevMaxIdx := -1

		for i := range a {
			if i == 0 || i == n-1 {
				continue
			}

			if i == prevMaxIdx+1 {
				a[i], _ = max(a[i-1], a[i+1])
				cnt++
			}

			if a[i] > a[i-1] && a[i] > a[i+1] {
				prevMaxIdx = i
			}
		}

		if prevMaxIdx == n-2 {
			a[n-1] = a[n-2]
			cnt++
		}

		fmt.Fprintln(writer, cnt)

		for _, num := range a {
			fmt.Fprintf(writer, "%d ", num)
		}
		fmt.Fprintln(writer)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

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

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

//goland:noinspection GoUnusedFunction
func max(nums ...int) (max, idx int) {
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx], idx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

	var t int
	Fscan(in, &t)
	var solve func()
	solve = func() {

		var n int
		Fscan(in, &n)
		a := make([]int, n)

		for j := 0; j < n; j++ {
			Fscan(in, &a[j])

		}
		cnt := 0
		for i := 1; i < n-1; i++ {
			if a[i-1] < a[i] && a[i] > a[i+1] {
				cnt++
				if i+2 < n {
					if a[i+2] >= a[i] {
						a[i+1] = a[i+2]
					} else {
						a[i+1] = a[i]
					}
				} else {
					a[i+1] = a[i]
				}
			}
		}
		Fprintln(out, cnt)
		for i := 0; i < n; i++ {
			Fprint(out, a[i], " ")
		}
		Fprintln(out)
	}
	for i := 0; i < t; i++ {
		solve()
	}

}

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

package main

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

func main() {
	inputReader := bufio.NewReader(os.Stdin)
	c := ReadLine(inputReader)
	numCases, _ := strconv.Atoi(c)

	cases := make([][]int, numCases)
	for i := 0; i < numCases; i++ {
		s := ReadLine(inputReader)
		size, _ := strconv.Atoi(s)
		arr := make([]int, size)

		els := strings.Split(ReadLine(inputReader), " ")

		for j := 0; j < len(els); j++ {
			n, _ := strconv.Atoi(els[j])
			arr[j] = n
		}
		cases[i] = arr
	}

	for _, a := range cases {
		processCase(a)
	}
}

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}

	return strings.TrimSpace(string(line))
}

func processCase(arr []int) {
	var count = 0
	for i := 1; i < len(arr)-1; i++ {
		if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
			if i == len(arr)-2 {
				arr[i+1] = arr[i]
				count++
				continue
			}
			if arr[i+2] >= arr[i] {
				arr[i+1] = arr[i+2]
			} else {
				arr[i+1] = arr[i]
			}
			count++
		}
	}
	fmt.Println(count)
	s := strings.Trim(strings.Join(strings.Fields(fmt.Sprint(arr)), " "), "[]")
	fmt.Println(s)
}

//nolint
package main

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

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

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

func main() {
	defer writer.Flush()

	Main()
}

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

//}

var a = make([]int, 200_005)

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	result := 0
	for i := 1; i+1 < n; i++ {
		if isLocalMax(i) {
			result++
			a[i+1] = a[i]
			change(i + 1)
		}
	}
	println(result)
	for i := 0; i < n; i++ {
		print(a[i], " ")
	}
	println()
}

func isLocalMax(i int) bool {
	return a[i] > a[i-1] && a[i] > a[i+1]
}

func change(i int) {
	if a[i-1] > a[i+1] {
		a[i] = a[i-1]
	} else {
		a[i] = a[i+1]
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

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

func solve() {
	n := readInt(in)
	a := readArrInt(in)
	res := 0
	for i := 1; i < n-1; i++ {
		if a[i] > a[i-1] && a[i] > a[i+1] {
			res++
			a[i+1] = a[i]
			if i+2 != n {
				a[i+1] = max(a[i], a[i+2])
			}
		}
	}
	fmt.Println(res)
	for _, x := range a {
		fmt.Print(x, " ")
	}
	fmt.Println()
}

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

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

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

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

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

package main

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

func isLocMax(a []int, j int) bool {
	return j > 0 && j < len(a)-1 && a[j] > a[j-1] && a[j] > a[j+1]
}

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		ch := 0
		for j := 1; j < n-1; j++ {
			if isLocMax(a, j) && isLocMax(a, j+2) {
				ch++
				a[j+1] = max(a[j], a[j+2])
				j += 2
			} else if isLocMax(a, j) {
				ch++
				a[j+1] = a[j]
				j++
			}
		}
		fmt.Println(ch)
		for j := 0; j < n; j++ {
			fmt.Print(a[j], " ")
		}
		fmt.Println()
	}
}

package main

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

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

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

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

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

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		var c int
		for i := 1; i < n-1; i++ {
			if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
				if i < n-2 && arr[i+2] > arr[i+1] {
					arr[i+1] = max(arr[i], arr[i+2])
				} else {
					arr[i] = arr[i-1]
				}
				c++
			}
		}

		fmt.Fprintln(out, c)
		for _, v := range arr {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		var c int
		for i := 1; i < n-1; i++ {
			if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
				if i < n-2 && arr[i+2] > arr[i+1] {
					arr[i+1] = max(arr[i], arr[i+2])
				} else {
					arr[i] = arr[i-1]
				}
				c++
			}
		}

		fmt.Fprintln(out, c)
		for _, v := range arr {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		var c int
		for i := 1; i < n-1; i++ {

			if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
				if i < n-2 && arr[i+2] > arr[i+1] {
					arr[i+1] = arr[i+2]
				} else {
					arr[i] = arr[i-1]
				}
				c++
			}
		}

		fmt.Fprintln(out, c)
		for _, v := range arr {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		var c int
		var max int
		for i := 1; i < n-1; i++ {
			if arr[i] > max {
				max = arr[i]
			}

			if arr[i] > arr[i-1] && arr[i] > arr[i+1] {
				if i < n-2 && arr[i+2] > max {
					max = arr[i+2]
				}

				arr[i+1] = max
				c++
			}
		}

		fmt.Fprintln(out, c)
		for _, v := range arr {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1635B
Date: 5/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1635/B
Problem: CF1635B
**/
func (in *CF1635B) Run() {
	var sol strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		max := -1
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			max = int(math.Max(float64(max), float64(arr[i])))
		}
		ans := 0
		for i := 1; i < n-1; i++ {
			if arr[i] > arr[i+1] && arr[i] > arr[i-1] {
				ans++
				arr[i+1] = max
			}
		}

		sol.WriteString(fmt.Sprintf("%d\n", ans))
		for i := 0; i < n; i++ {
			sol.WriteString(fmt.Sprintf("%d ", arr[i]))
		}
		sol.WriteString("\n")
	}
	fmt.Println(sol.String())
}

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

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

package main

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

/*
4
6
2 4 4 5 5 4
5
1 3 2 3 3
3
1 3 1
5
1 2 3 4 1
---
0
2 4 4 2 5 4
1
1 3 3 3 3
1
1 3 3
4
1 2 4 4 1

*/

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

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

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

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		cnt := 0

		prevMaxIdx := -1

		for i := range a {
			if i == 0 || i == n-1 {
				continue
			}

			if i == prevMaxIdx+1 {
				a[i], _ = max(a[i-1], a[i+1])
				cnt++
			}

			if a[i] > a[i-1] && a[i] > a[i+1] {
				prevMaxIdx = i
			}
		}

		if prevMaxIdx == n-2 {
			a[n-1] = a[n-2]
		}

		fmt.Fprintln(writer, cnt)

		for _, num := range a {
			fmt.Fprintf(writer, "%d ", num)
		}
		fmt.Fprintln(writer)
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

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

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

//goland:noinspection GoUnusedFunction
func max(nums ...int) (max, idx int) {
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx], idx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

	var t int
	Fscan(in, &t)
	var solve func()
	solve = func() {

		var n int
		Fscan(in, &n)
		a := make([]int, n)

		for j := 0; j < n; j++ {
			Fscan(in, &a[j])

		}
		cnt := 0
		for i := 1; i < n-1; i++ {
			if a[i-1] < a[i] && a[i] > a[i+1] {
				cnt++
				if i+2 < n {
					a[i+1] = a[i+2]
				} else {
					a[i+1] = a[i]
				}
			}
		}
		Fprintln(out, cnt)
		for i := 0; i < n; i++ {
			Fprint(out, a[i], " ")
		}
		Fprintln(out)
	}
	for i := 0; i < t; i++ {
		solve()
	}

}

func main() { CF772(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 main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n, maxEmotion, maxSeqLen, fMax, sMax int
	var answer uint64
	scanf("%d %d %d\n", &n, &maxEmotion, &maxSeqLen)
	hap := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &hap[i])
		if hap[i] >= fMax {
			sMax = fMax
			fMax = hap[i]
		} else if hap[i] > sMax {
			sMax = hap[i]
		}
	}
	/* find first and second max of hap, use first max maxSeqLen, then use second,
	then again max maxSeqLen and repeat until maxEmotion counter is done */
	// loop obviously don't make threw time restriction
	// emotionCounter := 0
	// for {
	// 	// if emotionCounter >= maxEmotion {
	// 	// 	break
	// 	// }
	// 	i = maxEmotion - emotionCounter // i > 0 always
	// 	printf("i: %d\n", i)
	// 	if i >= maxSeqLen {
	// 		emotionCounter += maxSeqLen + 1
	// 		answer += uint64(fMax)*uint64(maxSeqLen) + uint64(sMax)
	// 	} else {
	// 		// this case could happend only at the end of sequence
	// 		emotionCounter += i
	// 		answer += uint64(fMax) * uint64(i)
	// 		break
	// 	}
	// }
	cycles := maxEmotion / (maxSeqLen + 1)
	answer += (uint64(fMax)*uint64(maxSeqLen) + uint64(sMax)) * uint64(cycles)
	remains := maxEmotion % (maxSeqLen + 1)
	answer += uint64(fMax) * uint64(remains)
	printf("%d\n", answer)
}

package main

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

func main() {
	var n, m, k, last, slast, res int64
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanf(scr, "%d %d %d\n", &n, &m, &k)
	a := make([]int64, n)

	for i := int64(0); i < n; i++ {
		fmt.Fscanf(scr, "%d", &a[i])
		if i == 0 {
			last = a[i]
		} else {
			if a[i] >= last {
				slast = last
				last = a[i]
			} else if a[i] >= slast {
				slast = a[i]
			}
		}
	}

	x := m / (k + 1)
	y := m % (k + 1)

	res = (last * x * k) + (slast * x) + (last * y)

	fmt.Fprintln(ocr, res)
	ocr.Flush()
}

package main

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

func main() {
	  in := bufio.NewReader(os.Stdin)
		n,m,k := 0,0,0;
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k);
		k++;
		var slice = make([]int, 213456);
		for i := 0; i < n; i++ {
			x := 0;
			fmt.Fscanf(in, "%d", &x);
			slice[i] = x;
		}
		sort.Slice(slice, func(i, j int) bool { return slice[i] > slice[j]});
		var a int64 =  int64(slice[0]) * int64(m - m/k) + int64(m/k) * int64(slice[1]);
		fmt.Println(a)
}

package main

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

func main() {
	io := newIo()
	n := io.nextInt()
	m := io.nextInt()
	k := io.nextInt()

	a := make([]int64, n)
	for i := range a {
		a[i] = io.nextInt()
	}
	sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })

	div := m / (k + 1)
	mod := m % (k + 1)
	ans := (a[0]*k+a[1])*div + a[0]*mod
	fmt.Println(ans)
}

type _io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *_io {
	return &_io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (_io *_io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := _io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (_io *_io) next() string {
	for _io.nextToken >= len(_io.tokens) {
		line := _io.nextLine()
		_io.tokens = strings.Fields(line)
		_io.nextToken = 0
	}
	r := _io.tokens[_io.nextToken]
	_io.nextToken++
	return r
}

func (_io *_io) nextInt() int64 {
	i, _ := strconv.ParseInt(_io.next(), 10, 64)
	return i
}

package main

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

func solveB(mat, sum, even []int, n, index int) bool {
	if (sum[n-1]-mat[index])%2 != 0 {
		return false
	}
	p := (sum[n-1] - mat[index]) / 2
	esum := even[index]
	if index%2 == 0 {
		esum -= mat[index]
	}

	esum += sum[n-1]-sum[index]-(even[n-1]-even[index])

	if p == esum {
		return true
	}
	return false
}
func main() {
	buf := bufio.NewReader(os.Stdin)

	var n,m int
	var k int64
	var v int64
	var first,second int64
	first=-1
	second=-1
	fmt.Fscanf(buf, "%d %d %d\n", &n,&m,&k)

	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &v)
		 if v > first{
			second=first
			first=v
		}else if v > second{
			second=v
		}
	}
	//fmt.Printf("f=%d s=%d\n",first,second)
	var cnt int64=int64(m)/(k+1)
	var ans int64=cnt*(second+k*first)
	ans += first*(int64(m)%(k+1))

	fmt.Printf("%d\n", ans)
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var n, m, k, t1, t2 int64

	scanf("%d %d %d\n", &n, &m, &k)

	arr := []int{}

	for i := 0; i < int(n); i++ {
		scanf("%d", &t1)
		arr = append(arr, int(t1))
	}

	sort.Ints(arr)

	t1 = int64(arr[n-1])
	t2 = int64(arr[n-2])

	lo, hi, mid := int64(0), int64(m), int64(n)

	ans := int64(0)

	for lo <= hi {
		mid = lo + (hi-lo)/2

		if mid+(mid+1)*k >= int64(m) {
			hi = mid - 1
		} else {
			lo = mid + 1
		}

	}

	// fmt.Println(hi + 1)

	ans = (hi+1)*t2 + (m-hi-1)*t1

	printf("%d", ans)

}

package main

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

func main() {
	sc := NewScanner()
	N, M, K := sc.NextInt64(), sc.NextInt64(), sc.NextInt64()
	a := sc.NextInt64Array()

	V := SortInterFace(a)
	sort.Sort(V)

	T := M / (K + 1)

	sum := a[N-1]*K*T + a[N-2]*T
	sum += a[N-1] * (M - T*(K+1))

	fmt.Println(sum)
}

type SortInterFace []int64

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i] < s[j]
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

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

func maxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = max(s, v)
	}
	return s
}

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	var n, m, k, last, slast, res int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanf(scr, "%d %d %d\n", &n, &m, &k)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(scr, "%d", &a[i])
		if i == 0 {
			last = a[i]
		} else {
			if a[i] >= last {
				slast = last
				last = a[i]
			} else if a[i] >= slast {
				slast = a[i]
			}
		}
	}

	x := m / (k + 1)
	y := m % (k + 1)

	res = (last * x * k) + (slast * x) + (last * y)

	fmt.Fprintln(ocr, res)
	ocr.Flush()
}

package main

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

func main() {
	var n, m, k, last, slast, res int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)

	fmt.Scanf("%d %d %d\n", &n, &m, &k)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(scr, "%d", &a[i])
		if i == 0 {
			last = a[i]
		} else {
			if a[i] >= last {
				slast = last
				last = a[i]
			} else if a[i] >= slast {
				slast = a[i]
			}
		}
	}
	y := k
oc:
	for m > 0 {
		for i := 0; i < y; i++ {
			if m > 0 {
				res += last
				m--
			} else {
				break oc
			}
		}
		res += slast
		m--
		fmt.Println(res)
	}
	fmt.Fprintln(ocr, res)
	ocr.Flush()

}

package main

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

func main() {
	  in := bufio.NewReader(os.Stdin)
		n,m,k := 0,0,0;
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k);
		k++;
		var slice = make([]int, 213456);
		for i := 0; i < n; i++ {
			x := 0;
			fmt.Fscanf(in, "%d", &x);
			slice[i] = x;
		}
		sort.Slice(slice, func(i, j int) bool { return slice[i] > slice[j]});
		var a int64 =  int64(slice[0] * (m - m/k) + (m/k) * slice[1]);
		fmt.Println(a)
}

package main

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

func main() {
	  in := bufio.NewReader(os.Stdin)
		n,m,k := 0,0,0;
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k);
		k++;
		var slice = make([]int, 213456);
		for i := 0; i < n; i++ {
			x := 0;
			fmt.Fscanf(in, "%d", &x);
			slice[i] = x;
		}
		sort.Slice(slice, func(i, j int) bool { return slice[i] > slice[j]});
		fmt.Println(slice[0] * (m - m/k) + (m/k) * slice[1]);
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var n, m, k, t1, t2 int64

	scanf("%d %d %d\n", &n, &m, &k)

	arr := []int{}

	for i := 0; i < int(n); i++ {
		scanf("%d", &t1)
		arr = append(arr, int(t1))
	}

	sort.Ints(arr)

	t1 = int64(arr[n-1])
	t2 = int64(arr[n-2])

	lo, hi, mid := int64(0), int64(n), int64(n)

	ans := int64(0)

	for lo <= hi {
		mid = lo + (hi-lo)/2

		if mid+(mid+1)*k >= int64(m) {
			hi = mid - 1
		} else {
			lo = mid + 1
		}

	}

	// fmt.Println(hi + 1)

	ans = (hi+1)*t2 + (m-hi-1)*t1

	printf("%d", ans)

}

package main

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

func main() {
	sc := NewScanner()
	N, M, K := sc.NextInt(), sc.NextInt(), sc.NextInt()
	a := sc.NextIntArray()

	sort.Ints(a)

	T := M / (K + 1)

	sum := a[N-1]*K*T + a[N-2]*T
	sum += a[N-1] * (M - T*(K+1))

	fmt.Println(sum)
}

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

func maxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = max(s, v)
	}
	return s
}

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

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

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

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

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

	return mp
}

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


package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		solve()
	}
}
func solve() {
	n := ReadInt()
	a := ReadInts(n)
	v := a[n-1]
	ans := 0
	for i := n - 2; i >= 0; i-- {
		if v < a[i] {
			ans++
			v = a[i]
		}
	}
	println(ans)
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func ReadString() (s string) { fmt.Fscan(_r, &s); return }
func ReadInt() (i int)       { fmt.Fscan(_r, &i); return }
func ReadInts(n int) (a []int) {
	for ; n > 0; n-- {
		a = append(a, ReadInt())
	}
	return
}
func print(a ...interface{})   { fmt.Fprint(_w, a...) }
func println(a ...interface{}) { fmt.Fprintln(_w, a...) }
func prints(s []int)           { v := fmt.Sprint(s); println(v[1 : len(v)-1]) }

package main

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

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

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

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

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

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

/**
Run solve the problem CF1591B
Date: 12/12/21
User: epradere
URL: https://codeforces.com/contest/1591/problem/B
Problem: CF1591B
**/
func (in *CF1591B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		indexMax := 0
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i] > arr[indexMax] {
				indexMax = i
			}
		}

		ant := -1
		count := 0
		max := arr[indexMax]
		for i := n-1; i >= 0; i-- {
			val := arr[i]
			if val == max {
				break
			}
			if val < max && val > ant {
				count++
				ant = val
			} else if val > ant {
				ant = val
			}
		}

		fmt.Println(count)
	}
}

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

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

package main

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

func main() {
	var n, nl int
	writer := bufio.NewWriter(os.Stdout)
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader,&nl)
		l := make([]int, nl)
		for j := 0; j < nl; j++ {
			fmt.Fscan(reader,&l[j])
		}

		cnt := 0
		max := l[nl-1]
		for k := nl-1; k >= 0; k-- {
			if max < l[k] {
				max = l[k]
				cnt++
			}
		}
		writer.WriteString(strconv.Itoa(cnt)+"\n")
	}

	writer.Flush()
}

package main

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

const MOD int64 = 1000000007

var n int

var a[]int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n)

		a = make([]int, n)

		for j := 0; j < n; j++ {
			fmt.Fscan(read, &a[j])
		}

		fmt.Println(solve())
	}
}

type pair struct {
	v int
	idx []int
}

func solve() int64 {

	if n == 1 {
		return 0
	}

	//1276453 -> 1237645 -> 1234576

	var k int64

	e := a[n - 1]

	for i := n - 2; i>= 0; i-- {
		if a[i] > e {
			e = a[i]
			k++
		}
	}

	return k
}

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

package main

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

/*
5
5
3 2 7 8 6
1
4
6
7 6 2 1 2 8
5
3 5 2 3 5
5
3 5 2 3 1
---
1
0
0
0
2
====
4
5
3 5 2 3 1
5
5 4 3 2 1
5
5 4 3 1 1
5
4 5 3 1 1
---
2
4
3
2
*/

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

	bld := strings.Builder{}

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

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

		a := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		x := make([]int, 0)
		x = append(x, a[n-1])

		for i := n - 2; i >= 0; i-- {
			if a[i] > x[len(x)-1] {
				x = append(x, a[i])
			}
		}

		fmt.Fprintln(&bld, len(x)-1)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

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

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

	return true
}

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

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

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

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

package main

import "fmt"

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

		var maxvals, minvals []int
		max := l[0]
		cnt := 0
		for l[len(l)-1] != max {
			for k := 0; k < len(l); k++ {
				if max < l[k] {
					max = l[k]
				}
				if l[k] > l[len(l)-1] {
					maxvals = append(maxvals, l[k])
				} else {
					minvals = append(minvals, l[k])
				}
			}

			l = append(make([]int, 0, len(maxvals)), maxvals...)
			if len(l) == 0 {
				break
			}
			maxvals = make([]int, 0, 0)
			cnt++
		}

		if len(l) == 0 {
			fmt.Println(0)
		} else {
			fmt.Println(cnt)
		}
		cnt = 0
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1591B
Date: 12/12/21
User: epradere
URL: https://codeforces.com/contest/1591/problem/B
Problem: CF1591B
**/
func (in *CF1591B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		indexMax := 0
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i] > arr[indexMax] {
				indexMax = i
			}
		}

		ini := n - 1
		count := 0
		for i := n - 1; i >= 0; i-- {
			if ini < 0 {
				break
			}
			if arr[indexMax] == arr[ini] {
				break
			} else if arr[i] > arr[ini] {
				ini--
				count++
			}
		}

		fmt.Println(count)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1591B
Date: 12/12/21
User: epradere
URL: https://codeforces.com/contest/1591/problem/B
Problem: CF1591B
**/
func (in *CF1591B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		indexMax := 0
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if arr[i] > arr[indexMax] {
				indexMax = i
			}
		}

		ini := n - 1
		count := 0
		for i := n - 2; i >= 0; i-- {
			if ini < 0 {
				break
			}
			if arr[indexMax] == arr[ini] {
				break
			} else if arr[i] > arr[ini] {
				ini--
				count++
			}
		}

		fmt.Println(count)
	}
}

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

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1279D(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	r := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b&15)
		}
		return
	}
	const mod int64 = 998244353
	pow := func(x, n int64) int64 {
		x %= mod
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int64) int64 { return pow(a, mod-2) }
	div := func(a, b int64) int64 { return a * inv(b) % mod }

	n := r()
	cnts := [1e6 + 1]int{}
	ps := make([][]int, n)
	for i := range ps {
		ps[i] = make([]int, r())
		for j := range ps[i] {
			ps[i][j] = r()
			cnts[ps[i][j]]++
		}
	}
	ans := int64(0)
	for _, p := range ps {
		s := 0
		for _, v := range p {
			s += cnts[v]
		}
		ans = (ans + div(int64(s), int64(len(p)))) % mod
	}
	Fprint(_w, div(ans, int64(n)*int64(n)))
}

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

package main

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

const (
	mod = 998244353
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([][]int, n)
	totalM := 0
	likeCnt := make(map[int]int)
	for i := 0; i < n; i++ {
		m := 0
		fmt.Fscanf(in, "%d", &m)
		totalM += m
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Fscanf(in, "%d", &a[i][j])
			likeCnt[a[i][j]]++
		}
		fmt.Fscanf(in, "\n")
	}
	qt := int64(1)
	for i := 0; i < n; i++ {
		qt *= int64(len(a[i]))
		qt %= mod
	}
	//fmt.Println(qt)
	q1 := make([]int64, n)
	for i := 0; i < n; i++ {
		t1 := len(a[i])
		x, y := int64(0), int64(0)
		exgcd(int64(t1), mod, &x, &y)
		for x < 0 {
			x += mod
		}
		//fmt.Println("debug1", x)
		q1[i] = int64(int64(qt)*int64(x)) % mod
	}
	//fmt.Println(a)
	//fmt.Println(q1)

	top := int64(0)
	for i := 0; i < n; i++ {
		for j := 0; j < len(a[i]); j++ {
			top += int64(likeCnt[a[i][j]]) * int64(q1[i])
			top %= mod
		}
	}
	btm := int64(1)
	x, y := int64(0), int64(0)
	exgcd(int64(n), mod, &x, &y)
	for x < 0 {
		x += mod
	}
	btm *= x
	btm %= mod
	//fmt.Println("debugbtm", btm)
	exgcd(int64(n), mod, &x, &y)
	for x < 0 {
		x += mod
	}
	btm *= x
	btm %= mod
	for i := 0; i < n; i++ {
		//fmt.Println("debugbtm", btm)

		exgcd(int64(len(a[i])), mod, &x, &y)
		for x < 0 {
			x += mod
		}
		btm *= x
		btm %= mod
	}
	//fmt.Println("debug", top, btm)
	ans := (top * btm) % mod
	fmt.Fprintf(out, "%d\n", ans)
	return
}

func exgcd(a, b int64, x, y *int64) int64 {
	if b == 0 {
		*x = 1
		*y = 0
		return a
	}
	r := exgcd(b, a%b, x, y)
	t := *x
	*x = *y
	*y = t - (a/b)*(*y)
	return r
}