Three friends are going to meet each other. Initially, the first friend stays at the position $$$x = a$$$, the second friend stays at the position $$$x = b$$$ and the third friend stays at the position $$$x = c$$$ on the coordinate axis $$$Ox$$$.In one minute each friend independently from other friends can change the position $$$x$$$ by $$$1$$$ to the left or by $$$1$$$ to the right (i.e. set $$$x := x - 1$$$ or $$$x := x + 1$$$) or even don't change it.Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let $$$a'$$$, $$$b'$$$ and $$$c'$$$ be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is $$$|a' - b'| + |a' - c'| + |b' - c'|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of test cases. The next $$$q$$$ lines describe test cases. The $$$i$$$-th test case is given as three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.

For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after one minute.

/*
*In The Name of God
*
* +===============================================
* | Author:        Mohammad Fatemi <mr.smf8@gmail.com>
* |
* | Creation Date: 29-02-2020
* |
* | File Name:     p7.go
* +===============================================
 */

// https://codeforces.com/contest/1272/problem/A
package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

func main() {
	var q int
	scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		var a, b, c float64
		scanf("%f %f %f\n", &a, &b, &c)
		ans := math.Inf(1)
		for i := -1; i <= 1; i++ {
			for j := -1; j <= 1; j++ {
				for k := -1; k <= 1; k++ {
					ta, tb, tc := (a + float64(i)), (b + float64(j)), (c + float64(k))
					sum := math.Abs(ta-tb) + math.Abs(ta-tc) + math.Abs(tc-tb)
					ans = math.Min(ans, sum)
				}
			}
		}
		fmt.Println(int(ans))
	}
}

package main

import (
	"fmt"
	"math"
	"sort"
)

var q, a, b, c int

func main() {
	_, _ = fmt.Scan(&q)
	for q > 0 {
		_, _ = fmt.Scan(&a)
		_, _ = fmt.Scan(&b)
		_, _ = fmt.Scan(&c)
		q--
		fmt.Printf("%0.f\n", f(a, b, c))
	}
}

func f(a, b, c int) float64 {
	ar := []int{a, b, c}
	sort.Ints(ar)
	a = ar[0]
	b = ar[1]
	c = ar[2]
	if math.Abs(float64(a-b)) <= 1 && math.Abs(float64(b-c)) <= 1 {
		return 0
	}
	if a < b && b < c {
		a++
		c--
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	if b == c && b != a {
		a++
		b--
		c--
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	if a == b && b != c {
		c--
		a++
		b++
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	return 0
}

// @problemURL url.com
package main

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

// var inFile, _ = os.Open("in.txt")
// var outFile, _ = os.OpenFile("out.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
// var in = bufio.NewReader(inFile)
// var out = bufio.NewWriter(outFile)

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

func printf(f string, a ...interface{}) { _, _ = fmt.Fprintf(out, f, a...) }
func scanf(f string, a ...interface{})  { _, _ = fmt.Fscanf(in, f, a...) }

func cleanup() {
	_ = out.Flush()
}

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

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

func main() {
	defer cleanup()
	var q int
	scanf("%d\n", &q)
	for qq := 0; qq < q; qq++ {
		s := make([]int, 3)
		scanf("%d %d %d\n", &s[0], &s[1], &s[2])
		sort.Slice(s, func(i, j int) bool { return s[i] < s[j] })

		// fmt.Println(s)
		ans := 2 * min(min(s[2]-s[0], abs(s[2]-s[0]-1)), abs(s[2]-s[0]-2))

		printf("%d\n", ans)
	}
}

// TODO Try without cleanup => Try on codeforces
// TODO ReadString without delim at the end

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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)
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var q int
var a, b, c int64

func main() {
	q = ReadInt()

	for tc := 0; tc < q; tc++ {
		a, b, c = ReadInt64_3()

		solve()
	}
}

func solve() {
	A := LongInt{a, b, c}
	sort.Sort(A)

	// aa, bb, cc := A[0], A[1], A[2]
	// if aa < bb {
	// 	aa++
	// }
	// if bb < cc {
	// 	cc--
	// }

	// ans := int64(0)
	// ans += AbsInt(bb - aa)
	// ans += AbsInt(cc - bb)
	// ans += AbsInt(cc - aa)

	aa, _, cc := A[0], A[1], A[2]
	if aa < cc {
		aa++
	}
	if aa < cc {
		cc--
	}
	ans := 2 * (cc - aa)

	fmt.Println(ans)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

type LongInt []int64

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

// S := LongInt{'a', 'b', 'c'}
// sort.Sort(S) or sort.Sort(sort.Reverse(S))

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

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

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

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

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

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

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	q := readi()
	for i := 0; i < q; i++ {
		a := readi()
		b := readi()
		c := readi()
		println(solve(a, b, c))
	}
}

func solve(a, b, c int) int {
	x := max(a, max(b, c))
	i := min(a, min(b, c))
	return max((x-i-2)*2, 0)
}

package main

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

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

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

	var n, min, a, b, c, dist, i int64
	fmt.Fscanf(reader, "%d\n", &n)
	for i = 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d %d %d\n", &a, &b, &c)
		min = math.MaxInt64
		p := []int64{a - 1, a, a + 1}
		q := []int64{b - 1, b, b + 1}
		r := []int64{c - 1, c, c + 1}
		for _, a1 := range p {
			for _, b1 := range q {
				for _, c1 := range r {
					dist = abs(a1-b1) + abs(a1-c1) + abs(b1-c1)
					if min > dist {
						min = dist
					}
					//fmt.Println(abs(a1-b1), abs(a1-c1), abs(b1-c1), dist, min)
				}
			}
		}
		fmt.Fprintf(writer, "%d\n", min)
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1272/problem/A

package main

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

func Solve(a, b, c int) int {
	arr := []int{a, b, c}
	sort.Ints(arr)
	if arr[0] == arr[2] || arr[0]+1 == arr[2] {
		return 0
	}
	return 2 * (arr[2] - arr[0] - 2)
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var a, b, c int
		fmt.Fscanf(reader, "%d %d %d\n", &a, &b, &c)
		fmt.Fprintf(writer, "%d\n", Solve(a, b, c))
	}
}

/*
*In The Name of God
*
* +===============================================
* | Author:        Mohammad Fatemi <mr.smf8@gmail.com>
* |
* | Creation Date: 29-02-2020
* |
* | File Name:     p7.go
* +===============================================
 */

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

func main() {
	var q int
	scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		var a, b, c int
		scanf("%d %d %d\n", &a, &b, &c)
		a, b, c = sort(a, b, c)
		var ab, bc, ac int
		ab = 0
		bc = 0
		if a-b > 0 {
			ab = a - b - 1
			a--
		}
		if b-c > 0 {
			bc = b - c - 1
			c++
		}
		ac = (a - c)
		fmt.Println((ab + ac + bc))
	}
}

func sort(a, b, c int) (int, int, int) {
	r1 := math.Max(float64(a), math.Max(float64(b), float64(c)))
	r3 := math.Min(float64(a), math.Max(float64(b), float64(c)))
	r2 := float64(a+b+c) - r1 - r3
	return int(r1), int(r2), int(r3)
}

package main

import (
	"fmt"
	"math"
	"sort"
)

var q, a, b, c int

func main() {
	_, _ = fmt.Scan(&q)
	for q > 0 {
		_, _ = fmt.Scan(&a)
		_, _ = fmt.Scan(&b)
		_, _ = fmt.Scan(&c)
		q--
		fmt.Printf("%0.f\n", f(a, b, c))
	}
}

func f(a, b, c int) float64 {
	ar := []int{a, b, c}
	sort.Ints(ar)
	a = ar[0]
	b = ar[1]
	c = ar[2]
	if math.Abs(float64(a-b)) <= 1 && math.Abs(float64(b-c)) <= 1 {
		return 0
	}
	if a < b && b < c {
		a++
		c--
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	if b == c && b != a {
		a++
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	if a == b && b != c {
		c--
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	return 0
}

package main

import (
	"fmt"
	"math"
	"sort"
)

var q, a, b, c int

func main() {
	_, _ = fmt.Scan(&q)
	for q > 0 {
		_, _ = fmt.Scan(&a)
		_, _ = fmt.Scan(&b)
		_, _ = fmt.Scan(&c)
		q--
		fmt.Printf("%v\n", f(a, b, c))
	}
}

func f(a, b, c int) float64 {
	ar := []int{a, b, c}
	sort.Ints(ar)
	a = ar[0]
	b = ar[1]
	c = ar[2]
	if math.Abs(float64(a-b)) <= 1 && math.Abs(float64(b-c)) <= 1 {
		return 0
	}
	if a < b && b < c {
		a++
		c--
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	if b == c && b != a {
		a++
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	if a == b && b != c {
		c--
		return math.Abs(float64(a-b)) + math.Abs(float64(a-c)) + math.Abs(float64(b-c))
	}
	return 0
}

package main

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

func main() {
	var x int
	fmt.Fscan(os.Stdin, &x)
	var v = []int{0, 0, 0}
	for i := 0; i < x; i++ {
		fmt.Fscan(os.Stdin, &v[0], &v[1], &v[2])
		sort.Ints(v)
		if v[0] < v[1] {
			v[0]++
		}
		if v[2] > v[1] {
			v[2]--
		}
		rez := v[2] - v[1] + v[2] - v[0] + v[1] - v[0]
		fmt.Println(rez)
	}
}


You are given a string $$$s$$$ of length $$$n$$$, which consists only of the first $$$k$$$ letters of the Latin alphabet. All letters in string $$$s$$$ are uppercase.A subsequence of string $$$s$$$ is a string that can be derived from $$$s$$$ by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.A subsequence of $$$s$$$ called good if the number of occurences of each of the first $$$k$$$ letters of the alphabet is the same.Find the length of the longest good subsequence of $$$s$$$.

The first line of the input contains integers $$$n$$$ ($$$1\le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le 26$$$). The second line of the input contains the string $$$s$$$ of length $$$n$$$. String $$$s$$$ only contains uppercase letters from 'A' to the $$$k$$$-th letter of Latin alphabet.

Print the only integer — the length of the longest good subsequence of string $$$s$$$.

NoteIn the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.In the second example, none of the subsequences can have 'D', hence the answer is $$$0$$$.

package main

import "fmt"

func main() {
	var n, k int
	var s string
	fmt.Scan(&n, &k, &s)
	a := make([]int, k)
	for _, ch := range s {
		a[ch-'A'] += 1
	}
	min := a[0]
	for i := 1; i < k; i++ {
		if a[i] < min {
			min = a[i]
		}
	}
	fmt.Print(k * min)
}

package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	var s string
	fmt.Scan(&s)
	cnt := make([]int, 26)
	for i := 0; i < N; i++ {
		c := s[i] - 'A'
		cnt[c]++
	}
	ans := N + N
	for i := 0; i < K; i++ {
		if cnt[i] < ans {
			ans = cnt[i]
		}
	}
	fmt.Println(ans * K)
}

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 min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

type Pair struct {
	first  int64
	second int
}

func main() {
	defer writer.Flush()
	var n, k int64
	scanf("%d %d\n", &n, &k)
	var s string
	scanf("%s", &s)

	count := [26]int64{}

	for i := 0; i < int(n); i++ {
		count[s[i]-'A']++
	}
	sofar := int64(9999999999)
	// pairs := make([]Pair, 26)
	for i := 0; i < int(k); i++ {
		sofar = min(sofar, count[i])
	}

	// sort.Slice(pairs, func(i, j int) bool {
	// 	if pairs[i].first > pairs[j].first {
	// 		return true
	// 	}
	// 	return false
	// })

	// for i := int64(0); i < 26; i++ {
	// 	if (i+1)*pairs[i].first > sofar {
	// 		sofar = (i + 1) * pairs[i].first
	// 	}
	// }
	printf("%d", sofar*k)

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, k int

	fmt.Fscan(reader, &n, &k)
	var str string

	letters := make(map[string]int)
	fmt.Fscan(reader, &str)
	for _, key := range str {
		letters[string(key)]++
	}

	if len(letters) < k {
		fmt.Println(0)
		return
	}

	var mn int = math.MaxInt32
	for _, vl := range letters {
		if mn > vl {
			mn = vl
		}
	}

	fmt.Println(mn * k)

}

package main

import (
	"fmt"
)

func main() {
	n, k, s, aCode := 0, 0, "", "A"[0]
	fmt.Scan(&n, &k, &s)

	codeCount := make([]int, k)
	for i := 0; i < n; i++ {
		codeCount[s[i]-aCode]++
	}

	min := 100000
	for i := 0; i < k; i++ {
		if codeCount[i] < min {
			min = codeCount[i]
		}
	}

	fmt.Println(min * k)
}


Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table).At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other.After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss". Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.

The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other. The second line contains integer m (1 ≤ m ≤ n) — the number of Bob's moves. The third line contains m distinct integers x1, x2, ..., xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.

Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in the order the were made. If the sought move doesn't exist, then print "-1".

package main

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

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

	var n, k, sz, m int
	Fscan(in, &n, &k, &sz, &m)
	sz++
	x := make([]int, m)
	for i := range x {
		Fscan(in, &x[i])
	}

	ans := sort.Search(m+1, func(end int) bool {
		if end == 0 {
			return false
		}
		y := make([]int, end, end+1)
		copy(y, x)
		sort.Ints(y)
		y = append(y, n+1)
		cnt := y[0] / sz
		for i := 1; i <= end; i++ {
			cnt += (y[i] - y[i-1]) / sz
		}
		return cnt < k
	})
	if ans == m+1 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n, k, sz, m int
	Fscan(in, &n, &k, &sz, &m)
	sz++
	x := make([]int, m)
	for i := range x {
		Fscan(in, &x[i])
	}

	ans := sort.Search(m+1, func(end int) bool {
		if end == 0 {
			return false
		}
		y := make([]int, end)
		copy(y, x)
		sort.Ints(y)
		y = append(y, n+1)
		cnt := y[0] / sz
		for i := 1; i <= end; i++ {
			cnt += (y[i] - y[i-1]) / sz
			if cnt >= k {
				return false
			}
		}
		return true
	})
	if ans == m+1 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n, k, sz, m int
	Fscan(in, &n, &k, &sz, &m)
	sz++
	x := make([]int, m)
	for i := range x {
		Fscan(in, &x[i])
	}

	ans := sort.Search(m+1, func(end int) bool {
		if end == 0 {
			return false
		}
		y := make([]int, end, end+1)
		copy(y, x)
		sort.Ints(y)
		y = append(y, n+1)
		cnt := y[0] / sz
		for i := 1; i <= end; i++ {
			cnt += (y[i] - y[i-1]) / sz
			if cnt >= k {
				return false
			}
		}
		return true
	})
	if ans == m+1 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n, k, sz, m int
	Fscan(in, &n, &k, &sz, &m)
	x := make([]int, m)
	for i := range x {
		Fscan(in, &x[i])
	}

	ans := sort.Search(m+1, func(end int) bool {
		if end == 0 {
			return false
		}
		y := make([]int, end)
		copy(y, x)
		sort.Ints(y)
		y = append(y, n)
		cnt := (y[0] - 1) / sz
		for i := 1; i <= end; i++ {
			cnt += (y[i] - y[i-1]) / sz
			if cnt >= k {
				return false
			}
		}
		return true
	})
	if ans == m+1 {
		ans = -1
	}
	Fprint(out, ans)
}

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


You are given a positive integer $$$n$$$. Since $$$n$$$ may be very large, you are given its binary representation.You should compute the number of triples $$$(a,b,c)$$$ with $$$0 \leq a,b,c \leq n$$$ such that $$$a \oplus b$$$, $$$b \oplus c$$$, and $$$a \oplus c$$$ are the sides of a non-degenerate triangle. Here, $$$\oplus$$$ denotes the bitwise XOR operation.You should output the answer modulo $$$998\,244\,353$$$.Three positive values $$$x$$$, $$$y$$$, and $$$z$$$ are the sides of a non-degenerate triangle if and only if $$$x+y>z$$$, $$$x+z>y$$$, and $$$y+z>x$$$.

The first and only line contains the binary representation of an integer $$$n$$$ ($$$0 < n < 2^{200\,000}$$$) without leading zeros. For example, the string 10 is the binary representation of the number $$$2$$$, while the string 1010 represents the number $$$10$$$.

Print one integer — the number of triples $$$(a,b,c)$$$ satisfying the conditions described in the statement modulo $$$998\,244\,353$$$.

NoteIn the first test case, $$$101_2=5$$$.  The triple $$$(a, b, c) = (0, 3, 5)$$$ is valid because $$$(a\oplus b, b\oplus c, c\oplus a) = (3, 6, 5)$$$ are the sides of a non-degenerate triangle.  The triple $$$(a, b, c) = (1, 2, 4)$$$ is valid because $$$(a\oplus b, b\oplus c, c\oplus a) = (3, 6, 5)$$$ are the sides of a non-degenerate triangle. The $$$6$$$ permutations of each of these two triples are all the valid triples, thus the answer is $$$12$$$.In the third test case, $$$11\,011\,111\,101\,010\,010_2=114\,514$$$. The full answer (before taking the modulo) is $$$1\,466\,408\,118\,808\,164$$$.

package main

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

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

	s := readString(reader)

	res := solve(s)

	fmt.Println(res)
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MOD = 998244353

func modAdd(a, b int) int {
	a += b
	if a >= MOD {
		a -= MOD
	}
	return a
}

func solve(s string) int {
	dp := make([][][]int, 2)
	for i := 0; i < 2; i++ {
		dp[i] = make([][]int, 8)
		for j := 0; j < 8; j++ {
			dp[i][j] = make([]int, 8)
		}
	}
	dp[0][0][0] = 1

	n := len(s)

	for i := 1; i <= n; i++ {
		clear(dp[i&1])
		for mask1 := 0; mask1 < 8; mask1++ {
			for mask2 := 0; mask2 < 8; mask2++ {
				for m := 0; m < 8; m++ {
					var flag bool
					for j := 0; j < 3; j++ {
						if s[i-1] == '0' && (mask2>>j)&1 == 0 && (m>>j)&1 == 1 {
							flag = true
							break
						}
					}
					if flag {
						continue
					}
					tmp1 := mask1
					tmp2 := mask2

					for j := 0; j < 3; j++ {
						if int(s[i-1]-'0') != (m>>j)&1 {
							tmp2 |= 1 << j
						}
					}
					for j := 0; j < 3; j++ {
						if m == (1<<j) || m == 7-(1<<j) {
							tmp1 |= 1 << j
						}
					}
					dp[i&1][tmp1][tmp2] = modAdd(dp[i&1][tmp1][tmp2], dp[(i-1)&1][mask1][mask2])
				}
			}
		}
	}

	var ans int

	for i := 0; i < 8; i++ {
		ans = modAdd(ans, dp[n&1][7][i])
	}

	return ans
}

func clear(mat [][]int) {
	for i := 0; i < len(mat); i++ {
		for j := 0; j < len(mat[i]); j++ {
			mat[i][j] = 0
		}
	}
}

package main

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

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

	s := readString(reader)

	res := solve(s)

	fmt.Println(res)
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MOD = 998244353

func modAdd(a, b int) int {
	a += b
	if a >= MOD {
		a -= MOD
	}
	return a
}

func solve(s string) int {
	dp := make([][][]int, len(s)+1)
	for i := 0; i <= len(s); i++ {
		dp[i] = make([][]int, 8)
		for j := 0; j < 8; j++ {
			dp[i][j] = make([]int, 8)
		}
	}
	dp[0][0][0] = 1

	n := len(s)

	for i := 1; i <= n; i++ {
		for mask1 := 0; mask1 < 8; mask1++ {
			for mask2 := 0; mask2 < 8; mask2++ {
				for m := 0; m < 8; m++ {

					var flag bool
					for j := 0; j < 3; j++ {
						if s[i-1] == '0' && (mask2>>j)&1 == 0 && (m>>j)&1 == 1 {
							flag = true
							break
						}
					}
					if flag {
						continue
					}
					tmp1 := mask1
					tmp2 := mask2

					for j := 0; j < 3; j++ {
						if int(s[i-1]-'0') != (m>>j)&1 {
							tmp2 |= 1 << j
						}
					}
					for j := 0; j < 3; j++ {
						if m == (1<<j) || m == 7-(1<<j) {
							tmp1 |= 1 << j
						}
					}
					dp[i][tmp1][tmp2] = modAdd(dp[i][tmp1][tmp2], dp[i-1][mask1][mask2])
				}
			}
		}
	}

	var ans int

	for i := 0; i < 8; i++ {
		ans = modAdd(ans, dp[n][7][i])
	}

	return ans
}


Nezzar has $$$n$$$ balls, numbered with integers $$$1, 2, \ldots, n$$$. Numbers $$$a_1, a_2, \ldots, a_n$$$ are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that $$$a_i \leq a_{i+1}$$$ for all $$$1 \leq i < n$$$.Nezzar wants to color the balls using the minimum number of colors, such that the following holds.  For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.  Note that a sequence with the length at most $$$1$$$ is considered as a strictly increasing sequence.Please help Nezzar determine the minimum number of colors.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases.  The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that $$$a_1 \leq a_2 \leq \ldots \leq a_n$$$.

For each test case, output the minimum number of colors Nezzar can use.

NoteLet's match each color with some numbers. Then:In the first test case, one optimal color assignment is $$$[1,2,3,3,2,1]$$$.In the second test case, one optimal color assignment is $$$[1,2,1,2,1]$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n, a, la int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &la)
		count := 0
		ans := 0
		for j := 1; j < n; j++ {
			fmt.Fscan(in, &a)
			if a == la {
				count++
			} else {
				if count > ans {
					ans = count
				}
				la = a
				count = 0
			}
		}
		if count > ans {
			ans = count
		}

		fmt.Println(ans + 1)
	}
}

// func main() {
// 	in := bufio.NewReader(os.Stdin)
// 	var t, n, a int
// 	fmt.Fscan(in, &t)
// 	for i := 0; i < t; i++ {
// 		fmt.Fscan(in, &n)
// 		bucket := make([]int, n)
// 		for j := 0; j < n; j++ {
// 			fmt.Fscan(in, &a)
// 			bucket[a-1]++
// 		}
// 		ans := 0
// 		for j := 0; j < n; j++ {
// 			if ans < bucket[j] {
// 				ans = bucket[j]
// 			}
// 		}

// 		fmt.Println(ans)
// 	}
// }

package main

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

// func main() {
// 	in := bufio.NewReader(os.Stdin)
// 	var t, n, a, la int
// 	fmt.Fscan(in, &t)
// 	for i := 0; i < t; i++ {
// 		fmt.Fscan(in, &n)
// 		count := 0
// 		ans := 0
// 		for j := 0; j < n; j++ {
// 			fmt.Fscan(in, &a)
// 			if a == la {
// 				count++
// 			} else {
// 				if count > ans {
// 					ans = count
// 				}
// 				la = a
// 				count = 0
// 			}
// 		}
// 		if count > ans {
// 			ans = count
// 		}

// 		fmt.Println(ans + 1)
// 	}
// }

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n, a int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		bucket := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			bucket[a-1]++
		}
		ans := 0
		for j := 0; j < n; j++ {
			if ans < bucket[j] {
				ans = bucket[j]
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var arr [100]int
	var t int
	fmt.Scanf("%v\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%v\n", &n)

		for i := 0; i < n-1; i++ {
			fmt.Scanf("%v", &arr[i])
		}
		fmt.Scanf("%v\n", &arr[n-1])

		ans, count, curr := 0, 0, 0
		for i := 0; i < n; i++ {
			if arr[i] != curr {
				curr = arr[i]

				if count > ans {
					ans = count
				}
				count = 0
			}

			count++
		}

		if count > ans {
			ans = count
		}

		fmt.Println(ans)
	}
}

package main

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

func main() {
	scan := bufio.NewScanner(os.Stdin)
	scan.Scan()
	t, _ := strconv.Atoi(scan.Text())
	var arr []int

	for i := 0; i < t; i++ {
		scan.Scan()
		n, _ := strconv.Atoi(scan.Text())
		scan.Scan()
		data := regexp.MustCompile(" ").Split(scan.Text(), -1)
		sort.Strings(data)
		max, count, placeHolder := 0, 0, ""

		if n > 1 {
			for j := 0; j < n; j++ {
				if placeHolder == data[j] {
					count++
				} else {
					placeHolder = data[j]
					count = 1
				}
				if count > max {
					max = count
				}

			}
		}
		if max > 0 {
			arr = append(arr, max)
		} else {
			arr = append(arr, 1)
		}
	}

	for _, min := range arr {
		fmt.Println(min)
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.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 main() {
	defer writer.Flush()

	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		n := 0
		scan(&n)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			scan(&a[i])
		}

		solve(a)
	}
}

func solve(a []int) {
	ans := 1
	cnt := make(map[int]int)
	for _, x := range a {
		cnt[x]++
		ans = IntMax(cnt[x], ans)
	}
	printf("%d\n", ans)
}

// IntMax returns maximum of received int numbers
func IntMax(nums ...int) int {
	cand := nums[0]
	for _, num := range nums {
		if cand < num {
			cand = num
		}
	}
	return cand
}

package main

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

func main() {
	a:=bufio.NewReader(os.Stdin)
	l, _ :=a.ReadString('\n')
	l=strings.Trim(strings.Trim(l,"\n"),"\r")
	ln, _ :=strconv.Atoi(l)
	for i:=0; i<ln;i++{
		s,_:=a.ReadString('\n')
		las, _ := strconv.Atoi(strings.Trim(strings.Trim(s, "\n"), "\r"))
		str,_:=a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]int, las)
		mstra := strings.Split(str," ")
		for j:=0; j<las; j++{
			mstr[j], _ = strconv.Atoi(mstra[j])
		}
		fmt.Printf("%d\n",fn(mstr))
	}
}

func fn(a []int) (res int){
	if len(a) == 1{
		return 1
	}

	m:=make(map[int]int)
	max := 1
	for i:=0; i<len(a); i++{
		_, ok := m[a[i]]
		if ok{
			m[a[i]]++
			if m[a[i]] > max{
				max = m[a[i]]
			}
		}else{
			m[a[i]] = 1
		}
	}
	return max
}

package main

import (
	"fmt"
)

/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: kyicy
 * Time: 2021-01-28 22:37:17
**/

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

	nums := make([]int, 100)

	for t > 0 {
		t--

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

		var max, cur int
		for i := 0; i < n; i++ {
			if i != n-1 {
				fmt.Scanf("%d", &nums[i])

			} else {
				fmt.Scanf("%d\n", &nums[i])

			}
			if i == 0 {
				max = 1
				cur = 1
				continue
			}

			if nums[i] == nums[i-1] {
				cur += 1
			}

			if nums[i] != nums[i-1] || i == n-1 {
				if cur > max {
					max = cur
				}
				cur = 1
				continue
			}
		}

		fmt.Println(max)

	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		counter:=0
		mode:=0
		recent:=0
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if j == 0 {
				recent=x
				counter++
			} else {
				if x == recent {
					counter++
				} else {
					if counter > mode {
						mode = counter
					}
					counter=1
					recent= x
				}
			}
		}
		fmt.Fprintln(out,max(mode,counter))
	}
}
func max(a,b int) int {
	if a >= b {
		return a
	}
	return b
}

package main

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

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

func (in *CF1478A) 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 *CF1478A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1478A
 Date: 13/04/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1478/A
 Problem: CF1478A
**/
func (in *CF1478A) Run() {
	T := in.NextInt()
	for ; T > 0; T-- {
		N := in.NextInt()
		m := make(map[int]int)
		max := 0
		for ; N > 0; N-- {
			val := in.NextInt()
			d, ok := m[val]
			if !ok {
				m[val] = 1
			} else {
				m[val] = d + 1
			}
			d = m[val]
			max = int(math.Max(float64(d), float64(max)))
		}

		fmt.Println(max)
	}
}

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

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

package main

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		a := make([]int, n)
		min := 1
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			cur := 1
			for j := 0; j < i; j++ {
				if a[j] == a[i] {
					cur++
				}
			}
			if cur > min {
				min = cur
			}
		}
		fmt.Println(min)
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func scanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

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

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

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()

		prev, prevCount := 0, 0
		maxCount := 0

		for i := 0; i < n; i++ {
			a := scanInt()

			if a == prev {
				prevCount++
			} else {
				prev, prevCount = a, 1
			}

			if prevCount > maxCount {
				maxCount = prevCount
			}
		}

		if prevCount > maxCount {
			maxCount = prevCount
		}

		fmt.Println(maxCount)
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

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

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(A []int) int {
	n := len(A)
	var res int
	for i := 0; i < n; {
		j := i
		for i < n && A[i] == A[j] {
			i++
		}
		res = max(res, i-j)
	}
	return res
}

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

package main

import "fmt"

func main(){
  var tt int
  fmt.Scan(&tt)
  for t:=0;t<tt;t++ {
    var n int
    ans:=0
    fmt.Scan(&n)
    m:=make(map[int]int)
    for i:=0;i<n;i++{
      var j int
      fmt.Scan(&j)
      m[j]++
      if m[j]>ans{
        ans=m[j]
      }
    }
    fmt.Println(ans)
  }
}

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		var n, a int
		fmt.Scan(&n)
		fmt.Scan(&a)
		currentLength := 1
		maxLength := 1
		currentLengthElem := a
		for j := 1; j < n; j++ {
			fmt.Scan(&a)
			if a == currentLengthElem {
				currentLength++
			} else {
				if currentLength > maxLength {
					maxLength = currentLength
				}
				currentLengthElem = a
				currentLength = 1
			}
		}

		if currentLength > maxLength {
			maxLength = currentLength
		}
		fmt.Println(maxLength)
	}
}

package main

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

func main() {
	problemA()
	//problemB()

}

func problemA()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	cases := 0
	Fscan(in, &cases)
	max:= func(x int, y int) int {
		if x>y{
			return x
		}else {
			return y
		}
	}
	for ; cases > 0; cases-- {
		var length int
		Fscan(in,&length)
		var prev int
		Fscan(in,&prev)
		count:=1
		lcount := 1
		for i := 1; i < length; i++ {
			var element int
			Fscan(in,&element)
			if prev == element {
				lcount++
			}else {
				count = max(lcount,count);
				lcount = 1
			}
			prev = element
		}
		count = max(lcount,count);
		Fprintln(out,count)
	}

}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n+1)
		for j := 0; j < n; j++ {
			var t int
			fmt.Fscan(r, &t)
			a[t]++
		}
		var max int
		for _, x := range a {
			if x > max {
				max = x
			}
		}
		fmt.Fprintln(w, max)
	}
}

package main

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

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

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

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

		for i := range a {
			fmt.Fscan(in, &a[i])
		}

		fmt.Fprintln(out, solve(a))

	}

}

func solve(a []int) int {

	count := 1
	max := 1

	for i := 1; i < len(a); i++ {

		if a[i] == a[i-1] {
			count++

			if i == len(a)-1 {
				if count > max {
					max = count
				}
			}

		} else {
			if count > max {
				max = count
			}
			count = 1
		}

	}

	return max

}

package main

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

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

func scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		log.Fatal(err)
	}
}

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

func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		log.Fatal(err)
	}
}

func solve() {
	var n int
	scan(&n)
	last, cnt := -1, 0
	ans := 1
	for i := 0; i < n; i++ {
		var x int
		scan(&x)
		if x == last {
			cnt += 1
		} else {
			last = x
			cnt = 1
		}
		if cnt > ans {
			ans = cnt
		}
	}
	printf("%d\n", ans)
	//writer.Flush()
}

func main() {
	defer writer.Flush()

	testCases := 0
	scan(&testCases)
	for i := 0; i < testCases; i++ {
		solve()
	}
}

package main

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

func main() {

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

	for tc := 0; tc < tcs; tc++ {
		var n int
		var a [200]int

		_, _ = fmt.Fscan(in, &n)
		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)
			a[temp]++
		}

		ans := 1
		for i := 0; i < 200; i++ {
			if a[i] > ans {
				ans = a[i]
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		mx := 0
		for i := 0; i < n; {
			st := i
			for ; i < n && a[i] == a[st]; i++ {
			}
			if i-st > mx {
				mx = i - st
			}
		}
		Fprintln(out, mx)
	}
}

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

package main

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

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

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

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

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

		}
		return initial
	}
}

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

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

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

		fmt.Fscan(input, &n)

		ArrayOfAIIII := make([]int, n)

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

		}

		ArrayOfAIIII = append(ArrayOfAIIII, 10000)
		ARRAY := make([]int, 0)
		ini := 0
		for i := 1; i < n+1; i++ {

			if ArrayOfAIIII[i] > ArrayOfAIIII[i-1] {
				ARRAY = append(ARRAY, i-ini)
				ini = i
			}
		}

		sort.Ints(ARRAY)
		fmt.Println(ARRAY[len(ARRAY)-1])

	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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

func solve() {
    var (
        n int
    )
    fmt.Fscan(input, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(input, &a[i])
    }

    sort.Ints(a)
    cnt := 1;
    ma := 0
    for i := 1; i < n; i++ {
        if a[i] == a[i - 1] {
            cnt++
        } else {
            ma = max(ma, cnt)
            cnt = 1
        }
    }
    ma = max(ma, cnt)
    fmt.Fprintln(output, ma)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n, a, la int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		count := 0
		ans := 0
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			if a == la {
				count++
			} else {
				if count > ans {
					ans = count
				}
				la = a
				count = 0
			}
		}
		if count > ans {
			ans = count
		}

		fmt.Println(ans + 1)
	}
}

package main

import (
	"fmt"
)

func main() {
	var arr [100]int
	var t int
	fmt.Scanf("%v\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%v\n", &n)

		for i := 0; i < n-1; i++ {
			fmt.Scanf("%v ", &arr[i])
		}
		fmt.Scanf("%v\n", &arr[n-1])

		ans, count, curr := 0, 0, 0
		for i := 0; i < n; i++ {
			if arr[i] != curr {
				curr = arr[i]

				if count > ans {
					ans = count
				}
				count = 0
			}

			count++
		}

		if count > ans {
			ans = count
		}

		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var arr [100]int
	var t int
	fmt.Scanf("%v\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%v\n", &n)

		for i := 0; i < n; i++ {
			fmt.Scanf("%v", &arr[i])
		}

		ans, count, curr := 0, 0, 0
		for i := 0; i < n; i++ {
			if arr[i] != curr {
				curr = arr[i]

				if count > ans {
					ans = count
				}
				count = 0
			}

			count++
		}

		if count > ans {
			ans = count
		}

		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var arr [100]int
	var t int
	fmt.Scanf("%v", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Scanf("%v", &n)

		for i := 0; i < n; i++ {
			fmt.Scanf("%v", &arr[i])
		}

		ans, count, curr := 0, 0, 0
		for i := 0; i < n; i++ {
			if arr[i] != curr {
				curr = arr[i]

				if count > ans {
					ans = count
				}
				count = 0
			}

			count++
		}

		if count > ans {
			ans = count
		}

		fmt.Println(ans)
	}
}

package main

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

func divisible(w int) (b bool) {
	b = false

	for i := 2; i <= 100; i += 2 {
		for j := 2; j <= 100; j += 2 {
			if (i + j) == w {
				b = true
				break
			}
		}
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	w, _ := strconv.Atoi(scanner.Text())

	if divisible(w) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	a:=bufio.NewReader(os.Stdin)
	l, _ :=a.ReadString('\n')
	l=strings.Trim(strings.Trim(l,"\n"),"\r")
	ln, _ :=strconv.Atoi(l)
	for i:=0; i<ln;i++{
		s,_:=a.ReadString('\n')
		las, _ := strconv.Atoi(strings.Trim(strings.Trim(s, "\n"), "\r"))
		str,_:=a.ReadString('\n')
		str = strings.Trim(strings.Trim(str, "\n"), "\r")
		mstr := make([]int, las)
		mstra := strings.Split(str," ")
		for j:=0; j<las; j++{
			mstr[j], _ = strconv.Atoi(mstra[j])
		}
		fmt.Printf("%s\n",fn(mstr))
	}
}

func fn(a []int) (res int){
	if len(a) == 1{
		return 1
	}

	m:=make(map[int]int)
	max := 1
	for i:=0; i<len(a); i++{
		_, ok := m[a[i]]
		if ok{
			m[a[i]]++
			if m[a[i]] > max{
				max = m[a[i]]
			}
		}else{
			m[a[i]] = 1
		}
	}
	return max
}

package main

import (
	"fmt"
)

/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: kyicy
 * Time: 2021-01-28 22:37:17
**/

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

	nums := make([]int,100)

	for t > 0 {
		t--

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

		var max, cur int
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &nums[i])
			if (i == 0) {
				max = 1
				cur = 1
				continue
			}

			if nums[i] == nums[i-1] {
				cur+=1
			}

			if nums[i] != nums[i-1] || i == n-1{
				if cur > max {
					max = cur
				}
				cur = 1
				continue
			}
		}

		fmt.Println(max)

	}
}


You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment $$$[0, n]$$$ on $$$OX$$$ axis. The road can have several crossroads, but for simplicity, we'll denote each crossroad as an interval $$$(x, x + 1)$$$ with integer $$$x$$$. So we can represent the road as a binary string consisting of $$$n$$$ characters, where character 0 means that current interval doesn't contain a crossroad, and 1 means that there is a crossroad.Usually, we can install the pipeline along the road on height of $$$1$$$ unit with supporting pillars in each integer point (so, if we are responsible for $$$[0, n]$$$ road, we must install $$$n + 1$$$ pillars). But on crossroads we should lift the pipeline up to the height $$$2$$$, so the pipeline won't obstruct the way for cars.We can do so inserting several zig-zag-like lines. Each zig-zag can be represented as a segment $$$[x, x + 1]$$$ with integer $$$x$$$ consisting of three parts: $$$0.5$$$ units of horizontal pipe + $$$1$$$ unit of vertical pipe + $$$0.5$$$ of horizontal. Note that if pipeline is currently on height $$$2$$$, the pillars that support it should also have length equal to $$$2$$$ units.  Each unit of gas pipeline costs us $$$a$$$ bourles, and each unit of pillar — $$$b$$$ bourles. So, it's not always optimal to make the whole pipeline on the height $$$2$$$. Find the shape of the pipeline with minimum possible cost and calculate that cost.Note that you must start and finish the pipeline on height $$$1$$$ and, also, it's guaranteed that the first and last characters of the input string are equal to 0.

The fist line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$2 \cdot T$$$ lines contain independent queries — one query per two lines. The first line contains three integers $$$n$$$, $$$a$$$, $$$b$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le a \le 10^8$$$, $$$1 \le b \le 10^8$$$) — the length of the road, the cost of one unit of the pipeline and the cost of one unit of the pillar, respectively. The second line contains binary string $$$s$$$ ($$$|s| = n$$$, $$$s_i \in \{0, 1\}$$$, $$$s_1 = s_n = 0$$$) — the description of the road. It's guaranteed that the total length of all strings $$$s$$$ doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$T$$$ integers — one per query. For each query print the minimum possible cost of the constructed pipeline.

NoteThe optimal pipeline for the first query is shown at the picture above.The optimal pipeline for the second query is pictured below:  The optimal (and the only possible) pipeline for the third query is shown below:  The optimal pipeline for the fourth query is shown below:

// To execute Go code, please declare a func main() in a package "main"

package main

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

func getNumsFromOneLine(ir *bufio.Reader) []int {
  stream, _ := ir.ReadString('\n')
  // Trims the stream and then splits
  trimmedStream := strings.TrimSpace(stream)
  splitArr := strings.Split(trimmedStream, " ")
  // convert strings to integers and store them in a slice
  nums := make([]int, len(splitArr))
  for index, val := range splitArr {
    nums[index], _ = strconv.Atoi(val)
  }
  return nums
}

func main() {
  ir := bufio.NewReader(os.Stdin)
  t := getNumsFromOneLine(ir)[0]

  //   dp[n][2] (0: 在中间 1:上面)

  //   dp[n][0] = min(dp[n-1][0] + 1个红色 + 1个黑色, dp[n - 1][1] + 2个红色 + 1个黑色)   --- 注意这种情况只针对字符串值为0的情况
  //   dp[n][1] = min(dp[n-1][1] + 1个红色 + 2个黑色，dp[n - 1][0] + 2个红色 + 2个黑色)
  for i := 0; i < t; i++ {
    nab := getNumsFromOneLine(ir)
    n, a, b := nab[0], int64(nab[1]), int64(nab[2])
    s, _ := ir.ReadString('\n')
    dp := make([][2]int64, n+1)
    dp[0][0] = b
    dp[0][1] = 1000000000000000000
    for j := 1; j <= n; j++ {
      if s[j-1] == '0' {
        dp[j][0] = dp[j-1][0] + a + b
        if dp[j-1][1] + 2 * a + b < dp[j][0] {
          dp[j][0] = dp[j-1][1] + 2 * a + b
        }

        dp[j][1] = dp[j-1][0] + 2*a + 2*b
        if dp[j-1][1] + a + 2 * b < dp[j][1] {
          dp[j][1] = dp[j-1][1] + a + 2 * b
        }
      } else {

        dp[j][1] = dp[j-1][1] + a + b * 2
        // if dp[j-1][0] + 2 * a + 2 * b < dp[j][1] {
        //   dp[j][1] = dp[j-1][0] + 2 * a + 2 * b
        // }

        dp[j][0] = 1000000000000000000
      }

    }
    fmt.Println(dp[n][0])
  }

}

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

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

func solveOne() {

	n, a, b := readInt64(), readInt64(), readInt64()
	s := read()

	var k int64
	for k = int64(2); 2*a > (k-1)*b; k++ {
	}

	arr := make([]int64, 0)
	cnt := int64(1)
	for i := int64(0); i < n-1; i++ {
		if s[i] != s[i+1] {
			arr = append(arr, cnt)
			cnt = 1
		} else {
			cnt++
		}
	}
	arr = append(arr, cnt)

	if len(arr) == 1 {
		printInt64(n*a + (n+1)*b)
		return
	}

	ans := n*a + (n+1)*2*b + 2*a - arr[0]*b - arr[len(arr)-1]*b

	for i := 2; i < len(arr)-2; i += 2 {
		if arr[i] >= k {
			ans += 2*a - (arr[i]-1)*b
		}
	}

	printInt64(ans)

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 2*100000 + 5
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

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

func solveOne() {

	n, a, b := readInt64(), readInt64(), readInt64()
	s := read()

	var k int64
	for k = int64(2); 2*a > (k-1)*b; k++ {
	}

	arr := make([]int64, 0)
	cnt := int64(1)
	for i := int64(0); i < n-1; i++ {
		if s[i] != s[i+1] {
			arr = append(arr, cnt)
			cnt = 1
		} else {
			cnt++
		}
	}
	arr = append(arr, cnt)

	if len(arr) == 1 {
		printInt64(n*a + (n+1)*b)
		return
	}

	ans := n*a + (n+1)*2*b + 2*a - arr[0]*b - arr[len(arr)-1]*b

	for i := 2; i < len(arr)-2; i++ {
		if arr[i] >= k {
			ans += 2*a - (arr[i]-1)*b
		}
	}

	printInt64(ans)

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 2*100000 + 5
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}