You have three piles of candies: red, green and blue candies:  the first pile contains only red candies and there are $$$r$$$ candies in it,  the second pile contains only green candies and there are $$$g$$$ candies in it,  the third pile contains only blue candies and there are $$$b$$$ candies in it. Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.

The first line contains integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a separate line of the input. It contains three integers $$$r$$$, $$$g$$$ and $$$b$$$ ($$$1 \le r, g, b \le 10^8$$$) — the number of red, green and blue candies, respectively.

Print $$$t$$$ integers: the $$$i$$$-th printed integer is the answer on the $$$i$$$-th test case in the input.

NoteIn the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.

package main

import (
    "fmt"
)

func min3(a, b, c int) int {
	if a <= b && a <= c {
		return a;
	}
	if b <= a && b <= c {
		return b;
	}
	return c
}

func max3(a, b, c int) int {
	if a >= b && a >= c {
		return a;
	}
	if b >= a && b >= c {
		return b;
	}
	return c;
}

func min2(a, b int) int {
	if a <= b {
		return a;
	}
	return b;
}

func main() {

    var a, b, c, t int

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

	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d %d\n", &a, &b, &c);
		if a > b {
			f := a;
			a = b;
			b = f;
		}
		if a > c {
			f := a;
			a = c;
			c = f;
		}
		if b > c {
			f := b;
			b = c;
			c = f;
		}
		ans := a;
		if c - b >= a {
			c -= a;
		} else {
			a -= c - b;
			half := a / 2;
			c -= half;
			b -= a - half;
		}
		ans += min2(b, c);
		fmt.Println(ans);
	}
}

// @problemURL https://codeforces.com/problemset/problem/1263/A
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 main() {
	// defer cleanup()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		s := make([]int, 3)
		scanf("%d %d %d\n", &s[0], &s[1], &s[2])
		sort.Slice(s, func(i, j int) bool {
			if s[i] < s[j] {
				return true
			}
			return false
		})
		if s[2] > s[1]+s[0] {
			fmt.Println(s[1] + s[0])
		} else {
			fmt.Println((s[0] + s[1] + s[2]) / 2)
		}
	}
}

func min(i1 int, i2 int) int {
	if i1 > i2 {
		return i2
	}
	return i1
}

// TODO Try without cleanup => Try on codeforces

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 t int
var r, g, b int

func main() {
	t = ReadInt()

	PrintDebug("%d %s %f\n", 100, "test", 199.111)
	PrintDebug("デバッグテスト")

	for tc := 0; tc < t; tc++ {
		r, g, b = ReadInt3()

		solve()
	}
}

func solve() {
	A := []int{r, g, b}
	// 降順ソート
	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	sum := A[1] + A[2]
	if sum <= A[0] {
		fmt.Println(sum)
	} else {
		if A[0] > A[1] {
			// fmt.Println(A[0])
			ans := 0

			diff := A[0] - A[1]
			A[0] -= diff
			ans += diff
			A[2] -= diff
			tmp := (A[2] + (2 - 1)) / 2
			ans += A[2] + A[0] - tmp
			fmt.Println(ans)
		} else {
			// 一番大きいものと2番めが同じ
			tmp := (A[2] + (2 - 1)) / 2
			ans := A[2] + A[0] - tmp
			fmt.Println(ans)
		}
	}
}

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

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

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 t int
var r, g, b int

func main() {
	t = ReadInt()

	for i := 0; i < 10000; i++ {
		PrintDebug("%d %s %f\n", 100, "test", 199.111)
		PrintDebug("デバッグテスト")
	}

	for tc := 0; tc < t; tc++ {
		r, g, b = ReadInt3()

		solve()
	}
}

func solve() {
	A := []int{r, g, b}
	// 降順ソート
	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	sum := A[1] + A[2]
	if sum <= A[0] {
		fmt.Println(sum)
	} else {
		if A[0] > A[1] {
			// fmt.Println(A[0])
			ans := 0

			diff := A[0] - A[1]
			A[0] -= diff
			ans += diff
			A[2] -= diff
			tmp := (A[2] + (2 - 1)) / 2
			ans += A[2] + A[0] - tmp
			fmt.Println(ans)
		} else {
			// 一番大きいものと2番めが同じ
			tmp := (A[2] + (2 - 1)) / 2
			ans := A[2] + A[0] - tmp
			fmt.Println(ans)
		}
	}
}

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

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

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
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 t int
var r, g, b int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		r, g, b = ReadInt3()

		solve()
	}
}

func solve() {
	A := []int{r, g, b}
	// 降順ソート
	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	sum := A[1] + A[2]
	if sum <= A[0] {
		fmt.Println(sum)
	} else {
		if A[0] > A[1] {
			// fmt.Println(A[0])
			ans := 0

			diff := A[0] - A[1]
			A[0] -= diff
			ans += diff
			A[2] -= diff
			tmp := (A[2] + (2 - 1)) / 2
			ans += A[2] + A[0] - tmp
			fmt.Println(ans)
		} else {
			// 一番大きいものと2番めが同じ
			tmp := (A[2] + (2 - 1)) / 2
			ans := A[2] + A[0] - tmp
			fmt.Println(ans)
		}
	}
}

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

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

package main

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

func main() {
	var n int
	s := []int{0, 0, 0}
	fmt.Fscanln(os.Stdin, &n)
	for i := 0; i < n; i++ {
		fmt.Fscanln(os.Stdin, &s[0], &s[1], &s[2])
		sort.Ints(s)
		if s[2] >= s[0]+s[1] {
			fmt.Println(s[0] + s[1])
		} else {
			fmt.Println((s[0] + s[1] + s[2]) / 2)
		}
	}
}

package main

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

func main() {
	var n int
	s := []int{0,0,0}
	fmt.Fscanln(os.Stdin,&n)
	for i:=0;i<n;i++{
		fmt.Fscanln(os.Stdin,&s[0],&s[1],&s[2])
		sort.Ints(s)
		if (s[2]>s[0]+s[1]){
			fmt.Fprintln(os.Stdout,s[0]+s[1])
		}else{
			fmt.Fprintln(os.Stdout,(s[1]+s[0]+s[2])/2)
		}

	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	for case_ := 0; case_ < t; case_++ {
		Fprintln(out, solveCase(in, out))
	}
}

func solveCase(in io.Reader, out io.Writer) int {
	sort3 := func(a ...int) (int, int, int) {
		sort.Ints(a)
		return a[0], a[1], a[2]
	}

	var a, b, c int
	Fscan(in, &a, &b, &c)
	a, b, c = sort3(a, b, c)
	if a+b <= c {
		return a + b
	}
	same := a + b - c
	ans := c - same + same/2*3
	if same%2 == 1 {
		ans++
	}
	return ans
}

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}

package main

import (
	"fmt"
	"os"
)

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

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

func main() {
	var nt, r, b, g int

	fmt.Fscanln(os.Stdin, &nt)

	for t := 0; t < nt; t++ {
		fmt.Fscanln(os.Stdin, &r, &b, &g)

		if r > b {
			b, r = r, b
		}
		if b > g {
			g, b = b, g
		}

		if r > b {
			b, r = r, b
		}

		var res = b + min(r, g - b)

		res += (r - min(r, g - b)) / 2

		fmt.Println(res)
	}

}

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 gcd(a,b int)int{
	if b==0{
		return a
	}
	return gcd(b,a%b)
}

var a[10] int

func main(){
	defer writer.Flush()
	var T int
	scanf("%d\n",&T)
	for cas:=1;cas<=T;cas++{
		for i:=0; i<3;i++{
			scanf("%d",&a[i])
		}
		scanf("\n")
		sort.Ints(a[:3])
		/*
		for _,ai:=range a[:3]{
			printf("%d ",ai)
		}
		printf("\n")
		 */
		if a[2]>a[1]+a[0] {
			printf("%d\n",a[1]+a[0])
		}else{
			printf("%d\n",(a[2]+a[1]+a[0])/2)
		}
	}
}

package main

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

func main() {
	var rows int

	fmt.Fscanln(os.Stdin, &rows)

	s := make([]int, 3)
	for i := 0; i < rows; i++ {
		fmt.Fscanln(os.Stdin, &s[0], &s[1], &s[2])

		i := 0
		for {
			sort.Slice(s, func(i, j int) bool {
				return s[i] > s[j]
			})

			if s[0] == 0 || s[1] == 0 {
				break
			}

			d := s[1] - s[2]

			if d == 0 {
				d = s[1]/2
			}

			if d == 0 {
				d = 1
			}

			i += d
			s[0] -= d
			s[1] -= d
		}

		fmt.Fprintln(os.Stdout, i)
	}
}

// @problemURL https://codeforces.com/problemset/problem/1263/A
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 main() {
	// defer cleanup()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		s := make([]int, 3)
		scanf("%d %d %d\n", &s[0], &s[1], &s[2])
		sort.Slice(s, func(i, j int) bool {
			if s[i] < s[j] {return true}
			return false
		})
		ans := s[0]
		s[2] -= s[0]
		if s[2] > 0 {
			ans += min(s[1], s[2])
		}
		fmt.Println(ans)
	}
}

func min(i1 int, i2 int) int {
	if i1 > i2 {
		return i2
	}
	return i1
}

// TODO Try without cleanup => Try on codeforces

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
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 t int
var r, g, b int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		r, g, b = ReadInt3()

		solve()
	}
}

func solve() {
	A := []int{r, g, b}
	// 降順ソート
	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	sum := A[1] + A[2]
	if sum <= A[0] {
		fmt.Println(sum)
	} else {
		if A[0] > A[1] {
			fmt.Println(A[0])
		} else {
			// 一番大きいものと2番めが同じ
			tmp := (A[2] + (2 - 1)) / 2
			ans := A[2] + A[0] - tmp
			fmt.Println(ans)
		}
	}
}

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

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

package main

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

type IntSlice []int

func main() {
	var n int
	s := []int{0, 0, 0}
	fmt.Fscanf(os.Stdin, "%d", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(os.Stdin, "%d %d %d", &s[0], &s[1], &s[2])
		sort.Ints(s)
		if s[2] >= s[0]+s[1] {
			fmt.Println(s[0] + s[1])
		} else {
			fmt.Println((s[0] + s[1] + s[2]) / 2)
		}
	}
}

package main

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

func main() {
	var n int
	s := []int{0, 0, 0}
	fmt.Fscanf(os.Stdin, "%d", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(os.Stdin, "%d %d %d", &s[0], &s[1], &s[2])
		sort.Ints(s)
		if s[2] >= s[0]+s[1] {
			fmt.Println(s[0] + s[1])
		} else {
			fmt.Println((s[0] + s[1] + s[2]) / 2)
		}
	}
}

package main

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

func main() {
	var n int
	s := []int{0,0,0}
	fmt.Fscanln(os.Stdin,&n)
	for i:=0;i<n;i++{
		fmt.Fscanln(os.Stdin,&s[0],&s[1],&s[2])
		sort.Ints(s)
		if (s[2]>s[0]+s[1]){
			fmt.Fprintln(os.Stdout,s[0]+s[1])
		}else{
			fmt.Fprintln(os.Stdout,s[2])
		}

	}
}

package main

import (
	"fmt"
)

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

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

func main() {
	var nt, r, b, g int
	fmt.Scanf("%d", &nt)
	for t := 0; t < nt; t++ {
		fmt.Scanf("%d%d%d", &r, &b, &g)

		if r > b {
			b, r = r, b
		}
		if b > g {
			g, b = b, g
		}

		if r > b {
			b, r = r, b
		}

		var res = b + min(r, g - b)

		res += (r - min(r, g - b)) / 2

		fmt.Println(res)
	}

}

package main

import (
	"fmt"
)

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

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

func main() {
	var nt, r, b, g int
	fmt.Scanf("%d", &nt)
	for t := 0; t < nt; t++ {
		fmt.Scanf("%d%d%d", &r, &b, &g)

		if r > b {
			b, r = r, b
		}
		if b > g {
			g, b = b, g
		}

		if r > b {
			b, r = r, b
		}

		var res = b + min(r, g - b)

		res += (r - min(r, g - b)) / 2

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

}

package main

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

func main() {
	var rows int

	fmt.Fscanln(os.Stdin, &rows)

	s := make([]int, 3)
	for i := 0; i < rows; i++ {
		fmt.Fscanln(os.Stdin, &s[0], &s[1], &s[2])

		i := 0
		for {
			sort.Slice(s, func(i, j int) bool {
				return s[i] > s[j]
			})

			if s[0] == 0 || s[1] == 0 {
				break
			}

			d := s[1]

			if d > 1 {
				d -= 1
			}

			i += d
			s[0] -= d
			s[1] -= d
		}
		fmt.Fprintln(os.Stdout, i)
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var rows int
	fmt.Scanln(&rows)

	s := make([]int, 3)
	for i := 0; i < rows; i++ {
		fmt.Scanf("%d %d %d", &s[0], &s[1], &s[2])

		i := 0
		for {
			sort.Slice(s, func(i, j int) bool {
				return s[i] > s[j]
			})

			if s[0] == 0 || s[1] == 0 {
				break
			}

			s[0]--
			s[1]--
			i++
		}
		fmt.Println(i)
	}
}


It is given a positive integer $$$n$$$. In $$$1$$$ move, one can select any single digit and remove it (i.e. one selects some position in the number and removes the digit located at this position). The operation cannot be performed if only one digit remains. If the resulting number contains leading zeroes, they are automatically removed.E.g. if one removes from the number $$$32925$$$ the $$$3$$$-rd digit, the resulting number will be $$$3225$$$. If one removes from the number $$$20099050$$$ the first digit, the resulting number will be $$$99050$$$ (the $$$2$$$ zeroes going next to the first digit are automatically removed).What is the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive? It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$n$$$ ($$$25 \le n \le 10^{18}$$$). It is guaranteed that, for each $$$n$$$ occurring in the input, the answer exists. It is guaranteed that the number $$$n$$$ has no leading zeros.

For each test case output on a separate line an integer $$$k$$$ ($$$k \ge 0$$$) — the minimum number of steps to get a number such that it is divisible by $$$25$$$ and positive.

NoteIn the first test case, it is already given a number divisible by $$$25$$$.In the second test case, we can remove the digits $$$1$$$, $$$3$$$, and $$$4$$$ to get the number $$$75$$$.In the third test case, it's enough to remove the last digit to get the number $$$325$$$.In the fourth test case, we can remove the three last digits to get the number $$$50$$$.In the fifth test case, it's enough to remove the digits $$$4$$$ and $$$7$$$.

package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var s string
		ans := 100000000
		fmt.Scan(&s)
		for j := 0; j+1 < len(s); j++ {
			for k := j + 1; k < len(s); k++ {
				now := int(s[j]-'0')*10 + int(s[k]-'0')
				if now%25 == 0 {
					ans = min(ans, len(s)-j-2)
				}
			}
		}
		fmt.Println(ans)
	}

}

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

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

package main

import "fmt"

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

	for t > 0 {
		t --
		fmt.Scan(&s)
		fmt.Println(divisible(s))
	}
}

func divisible(s string) int {
	l := len(s)
	if l < 3 || checkDiv(s[l-2 : l]) {
		return 0
	}

	//var k = 0
	for i := l - 2; i >= 0; i -- {
		for j := i + 1; j < l; j ++ {
			if checkDiv(string(s[i]) + string(s[j])) {
				return (l - 1 - j) + (j - i - 1)// asb(l - j + i - j)
			}
		}
	}

	return -1
}

func checkDiv(s string) bool {
	return s == "00" || s == "25" || s == "50" || s == "75"
}

package main

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

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

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

func solve() {
	var s string
	scan(&s)
	n := len(s)
	// printf("%s\n", s)
	zero, five := -1, -1
	ans := n
	for i := n - 1; i >= 0; i-- {
		if s[i] == '0' {
			// printf("%d\n", i)
			if zero == -1 {
				zero = i
			} else {
				if ans > n-i-2 {
					ans = n - i - 2
				}
			}
		} else if s[i] == '5' {
			if zero != -1 {
				if ans > n-i-2 {
					ans = n - i - 2
				}
			}
			if five == -1 {
				five = i
			}
		} else if s[i] == '2' || s[i] == '7' {
			if five != -1 {
				if ans > n-i-2 {
					ans = n - i - 2
				}
			}
		}
	}
	printf("%d\n", ans)
}

func main() {
	defer out.Flush()
	n := 1
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

// 00
package main

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

func min(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		zeros := 0
		ans := len(s)
		n := len(s)
		for i := n - 1; i >= 0; i-- {
			if s[i] == '0' {
				zeros++
			}
			if zeros == 2 {
				ans = min(ans, n-i-2)
				break
			}
			if zeros == 1 && s[i] == '5' {
				ans = min(ans, n-i-2)
				break
			}
		}
		found_five := false
		for i := n - 1; i >= 0; i-- {
			if s[i] == '5' {
				found_five = true
			}
			if found_five && (s[i] == '2' || s[i] == '7') {
				ans = min(ans, n-i-2)
				break
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

  var t int
  fmt.Fscan(reader, &t)
  for ; t > 0; t-- {
    var n int64
    fmt.Fscan(reader, &n)
    ans := 99
    for u := 0; u < 10; u += 5 {
      steps := 0
      m := n
      for m > 0 {
        if int(m%10) != u {
          steps++
          m /= 10
        } else {
          break
        }
      }
      for m > int64(u) {
        if m%25 != 0 {
          m = 10*(m/100) + int64(u)
          steps++
        } else {
          break
        }
      }
      if m != 0 {
        if ans > steps {
          ans = steps
        }
      }
    }
    fmt.Fprint(writer, ans, "\n")
  }
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"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)

		min := math.MaxInt
		k := 0
		for i := len(s) - 1; i >= 0; i-- {
			for j := i - 1; j >= 0; j-- {
				if s[i] == '0' && (s[j] == '0' || s[j] == '5') {
					//
					if i-j-1+k < min {
						// fmt.Println("here: ", i, j, k)
						min = i - j - 1 + k
					}
				}

				if s[i] == '5' && (s[j] == '2' || s[j] == '7') {
					//
					// 2-1-1
					if i-j-1+k < min {
						min = i - j - 1 + k
					}
				}
			}
			k++
		}
		fmt.Fprintln(out, min)
	}
}

package main

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

/*
3
25
125
1251
---
0
0
1
=====
1
50555
---
3
*/

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

	bld := strings.Builder{}

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

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

		minCnt := maxInt

		{
			cnt := 0

			i := len(s) - 1
			for ; i >= 0; i-- {
				if s[i] == '0' {
					break
				} else {
					cnt++
				}
			}

			for j := i - 1; j >= 0; j-- {
				if s[j] == '5' || s[j] == '0' {
					break
				} else {
					cnt++
				}
			}

			minCnt = min(minCnt, cnt)
		}

		{
			cnt := 0

			i := len(s) - 1
			for ; i >= 0; i-- {
				if s[i] == '5' {
					break
				} else {
					cnt++
				}
			}

			for j := i - 1; j >= 0; j-- {
				if s[j] == '2' || s[j] == '7' {
					break
				} else {
					cnt++
				}
			}

			minCnt = min(minCnt, cnt)
		}

		fmt.Fprintln(&bld, minCnt)
	}

	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 {
	x int64
	y int64
}

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 {
	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 "fmt"

func main() {
	var s int

	fmt.Scan(&s)

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

func solve() {
	var s string
	fmt.Scan(&s)
	q := five(s)
	e := zero(s)

	if q > e {
		fmt.Println(e)
	} else {
		fmt.Println(q)
	}
}

func five(s string) int {
	k := 0
	q := 0
	for len(s) > 0 && s[len(s)-1] != '5' {
		s = s[:len(s)-1]
		k++
	}

	if len(s) > 0 && q == 0 {
		q++
	} else {
		return k + 30
	}

	s = s[:len(s)-1]

	for len(s) > 0 && (s[len(s)-1] != '2' && s[len(s)-1] != '7') {
		s = s[:len(s)-1]
		k++
	}

	if len(s) > 0 && q == 1 {
		return k
	}

	return k + 30
}

func zero(s string) int {
	k := 0
	q := 0
	for len(s) > 0 && s[len(s)-1] != '0' {
		s = s[:len(s)-1]
		k++
	}

	if len(s) > 0 && q == 0 {
		q++
	} else {
		return k + 30
	}

	s = s[:len(s)-1]

	for len(s) > 0 && (s[len(s)-1] != '0' && s[len(s)-1] != '5') {
		s = s[:len(s)-1]
		k++
	}

	if len(s) > 0 && q == 1 {
		return k
	}

	return k + 30
}

package main

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

//problem B

type problem struct {
	n string
}

//end with: 00 25 50 75
func (p *problem) endWith(end string) (int, bool) {
	i := len(p.n) - 1
	step := 0
	for ; i >= 0; step++ {
		if p.n[i] == end[1] {
			i--
			break
		}
		i--
	}

	for ; i >= 0; step++ {
		if p.n[i] == end[0] {
			return step, true
		}
		i--
	}
	return step, false
}

func (p *problem) MinSteps() int {
	minSteps := 20

	for _, end := range []string{"00", "25", "50", "75"} {
		needSteps, ok := p.endWith(end)
		if ok && needSteps < minSteps {
			minSteps = needSteps
		}
	}

	return minSteps
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t int
	var p problem

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%s\n", &p.n)
		fmt.Printf("%d\n", p.MinSteps())
	}
}

package main

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

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

	return b
}

func min(nums ...int) int {
	result := nums[0]
	for _, num := range nums {
		result = min2(result, num)
	}

	return result
}

func solve(s, pattern string) int {
	matchIdx := 1
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == pattern[matchIdx] {
			matchIdx--
			if matchIdx < 0 {
				return len(s) - i - 2
			}
		}
	}

	return 1000000
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	var s string

	_, _ = fmt.Fscan(r, &t)

	for ; t > 0; t-- {
		_, _ = fmt.Fscan(r, &s)
		fmt.Printf("%d\n", min(solve(s, "00"), solve(s, "25"), solve(s, "50"), solve(s, "75")))
	}
}

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 ; t > 0; t-- {
		var a int64
		_, _ = fmt.Fscan(r, &a)
		fmt.Println(min(solve(a, 0, 0), solve(a, 2, 5), solve(a, 5, 0), solve(a, 7, 5)))
	}
}

func solve(a, d1, d2 int64) int {
	ans := 0
	for a > 0 && a%10 != d2 {
		a /= 10
		ans++
	}
	a /= 10
	for a > 0 && a%10 != d1 {
		a /= 10
		ans++
	}
	return ans
}

func min(a int, args ...int) int {
	for _, b := range args {
		if a > b {
			a = b
		}
	}
	return a
}

package main

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

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

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

func Solve(s, p string) (ans int) {
	ans = 0
	for i, j := len(s)-1, 1; i >= 0; i-- {
		if s[i] == p[j] {
			j--
			if j < 0 {
				return
			}
		} else {
			ans += 1
		}
	}
	return
}

func main() {
	var ntc int
	var s string
	fmt.Fscanf(in, "%d\n", &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fscanf(in, "%s\n", &s)
		ans := Min(Solve(s, "00"), Solve(s, "25"))
		ans = Min(ans, Solve(s, "50"))
		ans = Min(ans, Solve(s, "75"))
		fmt.Fprintf(out, "%d\n", ans)
	}
	out.Flush()
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

var t int

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

	for o := 0; o < t; o++ {
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		var first, second int
		var indf, inds int
		q := len(STRING)
		for i := q - 1; i >= 0; i-- {
			if string(STRING[i]) == "0" {
				indf = i - 1
				break
			} else {
				first++
			}
		}
		for i := q - 1; i >= 0; i-- {
			if string(STRING[i]) == "5" {
				inds = i - 1
				break
			} else {
				second++
			}
		}

		for j := indf; j >= 0; j-- {
			if string(STRING[j]) == "5" || string(STRING[j]) == "0" {
				break
			} else {
				first++
			}
		}

		for j := inds; j >= 0; j-- {
			if string(STRING[j]) == "2" || string(STRING[j]) == "7" {
				break
			} else {
				second++
			}
		}

		fmt.Println(MINN(first, second))
	}

}

package main

import (
	"fmt"
)

func max(a []int) int {
	x := a[0]
	for _, k := range a {
		if x < k {
			x = k
		}
	}
	return x
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var s string
		fmt.Scanf("%s\n", &s)
		k := len(s)
		for i := len(s) - 1; i >= 0; i-- {
			if s[i] != '0' && s[i] != '5' {
				continue
			}
			var v byte
			if s[i] == '0' {
				v = '0'
			}
			if s[i] == '5' {
				v = '2'
			}
			for j := i - 1; j >= 0; j-- {
				if (s[j] == v || s[j] == v+5) && (len(s)-j-2 < k) {
					k = len(s) - j - 2
					break
				}
			}
		}
		fmt.Printf("%d\n", k)
	}
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	fmt.Fscan(reader, &t)
	for i := 0; i < t; i++ {
		var s string
		fmt.Fscan(reader, &s)
		n := len(s)
		pos := strings.LastIndexByte(s, '5')
		result := 10000
		if pos >= 0 {
			idx1 := strings.LastIndexByte(s[0:pos], '2')
			idx2 := strings.LastIndexByte(s[0:pos], '7')
			result = n - max(idx1, idx2) - 2
		}
		pos = strings.LastIndexByte(s, '0')
		if pos >= 0 {
			idx1 := strings.LastIndexByte(s[0:pos], '0')
			idx2 := strings.LastIndexByte(s[0:pos], '5')
			result = min(n-max(idx1, idx2)-2, result)
		}
		fmt.Fprintln(writer, result)
	}
}

package main

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

const Inf = 1000

var (
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

	T int
)

func latest(s []byte, c byte) ([]byte, int) {
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == c {
			return s[:i], len(s) - i - 1
		}
	}
	return s, Inf
}

func latests(s []byte, c []byte) ([]byte, int) {
	var ans int
	for i := len(c) - 1; i >= 0; i-- {
		var res int
		s, res = latest(s, c[i])
		ans += res
	}
	return s, ans
}

func main() {
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var s string
		fmt.Fscan(r, &s)

		var a [4]int

		_, a[0] = latests([]byte(s), []byte("00"))
		_, a[1] = latests([]byte(s), []byte("25"))
		_, a[2] = latests([]byte(s), []byte("50"))
		_, a[3] = latests([]byte(s), []byte("75"))

		min := a[0]
		for _, i := range a {
			if min > i {
				min = i
			}
		}
		fmt.Fprintln(w, min)
	}
	_ = w.Flush()
}

package main

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

var N string

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

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

		ans := solve()
		fmt.Println(ans)
	}
}

func solve() int {
	var minCount int = 1e9
	var count int
	for j := len(N) - 1; j >= 0; j-- {

		if N[j] == '5' {

			var add int

			found := false
			for k := j - 1; k >= 0; k-- {
				if N[k] == '2' || N[k] == '7' {
					found = true
					break
				}
				add++
			}

			if found {
				minCount = min(minCount, count + add)
			}

			count++

		} else if N[j] == '0' {

			var add int

			found := false
			for k := j - 1; k >= 0; k-- {
				if N[k] == '0' || N[k] == '5' {
					found = true
					break
				}
				add++
			}

			if found {
				minCount = min(minCount, count + add)
			}

			count++

		} else {
			count++
		}
	}

	return minCount
}

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

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int
	fmt.Fscanf(r, "%d\n", &T)
	for t := 0; t < T; t++ {
		var num string
		fmt.Fscanf(r, "%s\n", &num)

		suf := []string{"00", "25", "50", "75"}

		res := len(num)

		for _, s := range suf {
			for i := 0; i < len(num); i++ {
				for j := i + 1; j < len(num); j++ {
					if num[i] == s[0] && num[j] == s[1] {
						k := len(num) - j - 1 + j - i - 1
						if k < res {
							res = k
						}
					}
				}
			}
		}

		fmt.Println(res)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var s string
		ans := 100000000
		fmt.Scan(&s)
		for j := 0; j+1 < len(s); j++ {
			for k := i + 1; k < len(s); k++ {
				now := int(s[j]-'0')*10 + int(s[k]-'0')
				if now%25 == 0 {
					ans = min(ans, len(s)-j-2)
				}
			}
		}
		fmt.Println(ans)
	}

}

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

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

package main

import "fmt"

func main() {
	var n int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var s string
		ans := 1000000009
		fmt.Scan(&s)
		for j := 0; j+1 < len(s); j++ {
			for k := i + 1; k < len(s); k++ {
				now := int(s[i]-'0')*10 + int(s[j]-'0')
				if now%25 == 0 {
					ans = min(ans, len(s)-i-2)
				}
			}
		}
		fmt.Println(ans)
	}

}

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

package main

import "fmt"

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

	for t > 0 {
		t --
		fmt.Scan(&s)
		fmt.Println(divisible(s))
	}
}

func divisible(s string) int {
	l := len(s)
	if l < 3 || checkDiv(s[l-2 : l]) {
		return 0
	}

	//var c byte = ' '
	//var k = 0
	for i := l - 2; i >= 0; i -- {
		for j := i + 1; j < l; j ++ {

			if checkDiv(string(s[i]) + string(s[j])) {
				//fmt.Printf("%d %d\n", i, j)
				return asb(l - j + i - j)
			}
		}
	}

	return -1
}

func checkDiv(s string) bool {
	return s == "00" || s == "25" || s == "50" || s == "75"
}

func asb(x int) int {
	if x < 0 {
		x = -x
	}

	return x
}


Programming teacher Dmitry Olegovich is going to propose the following task for one of his tests for students:You are given a tree T with n vertices, specified by its adjacency matrix a[1... n, 1... n]. What is the output of the following pseudocode?used[1 ... n] = {0, ..., 0};procedure dfs(v):    print v;    used[v] = 1;    for i = 1, 2, ..., n:        if (a[v][i] == 1 and used[i] == 0):            dfs(i);dfs(1);In order to simplify the test results checking procedure, Dmitry Olegovich decided to create a tree T such that the result is his favorite sequence b. On the other hand, Dmitry Olegovich doesn't want to provide students with same trees as input, otherwise they might cheat. That's why Dmitry Olegovich is trying to find out the number of different trees T such that the result of running the above pseudocode with T as input is exactly the sequence b. Can you help him?Two trees with n vertices are called different if their adjacency matrices a1 and a2 are different, i. e. there exists a pair (i, j), such that 1 ≤ i, j ≤ n and a1[i][j] ≠ a2[i][j].

The first line contains the positive integer n (1 ≤ n ≤ 500) — the length of sequence b.  The second line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ n). It is guaranteed that b is a permutation, or in other words, each of the numbers 1, 2, ..., n appears exactly once in the sequence b. Also it is guaranteed that b1 = 1.

Output the number of trees satisfying the conditions above modulo 109 + 7.

package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Split(bufio.ScanWords)
	if !sc.Scan() {
		panic("could not scan a word from the reader")
	}
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

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

var (
	bb [501]int
	dp [501][501]uint64
)

func main() {
	n := nextInt()
	if n == 1 {
		fmt.Println(1)
		return
	}
	for i := 0; i < n; i++ {
		bb[i] = nextInt()
	}
	for i := n; i > 0; i-- {
		dp[i][i] = 1
		for j := i + 1; j <= n; j++ {
			dp[i][j] = dp[i+1][j]
			for k := i + 1; k < j; k++ {
				if bb[k] > bb[i] {
					dp[i][j] = (dp[i][j] + dp[i+1][k]*dp[k][j]) % 1000000007
				}
			}
		}
	}
	fmt.Println(dp[1][n] % 1000000007)
}


Gerald found a table consisting of n rows and m columns. As a prominent expert on rectangular tables, he immediately counted the table's properties, that is, the minimum of the numbers in the corners of the table (minimum of four numbers). However, he did not like the final value — it seemed to be too small. And to make this value larger, he decided to crop the table a little: delete some columns on the left and some on the right, as well as some rows from the top and some from the bottom. Find what the maximum property of the table can be after such cropping. Note that the table should have at least two rows and at least two columns left in the end. The number of cropped rows or columns from each of the four sides can be zero.

The first line contains two space-separated integers n and m (2 ≤ n, m ≤ 1000). The following n lines describe the table. The i-th of these lines lists the space-separated integers ai, 1, ai, 2, ..., ai, m (0 ≤ ai, j ≤ 109) — the m numbers standing in the i-th row of the table.

NoteIn the first test case Gerald cannot crop the table — table contains only two rows and only two columns.In the second test case if we'll crop the table, the table will contain zero in some corner cell. Also initially it contains two zeros in the corner cells, so the answer is 0.

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }
func nc() byte     { sc.Scan(); return sc.Text()[0] }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i ...int) {
  for _, ii := range i {
    w.WriteString(strconv.Itoa(ii))
    sp()
  }
}
func pri64(i ...int64) {
  for _, ii := range i {
    w.WriteString(strconv.FormatInt(ii, 10))
    sp()
  }
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

var mat [][]int

func check(value int) bool {
  n := len(mat)
  m := len(mat[0])
  was := make([][]bool, m)
  for i := 0; i < m; i++ {
    was[i] = make([]bool, m)
  }
  good := make([]int, m)
  for i := 0; i < n; i++ {
    tl := 0
    for j := 0; j < m; j++ {
      if mat[i][j] >= value {
        good[tl] = j
        tl++
        for t := 0; t < tl-1; t++ {
          if was[good[t]][good[tl-1]] {
            return true
          } else {
            was[good[t]][good[tl-1]] = true
          }
        }
      }
    }
  }
  return false
}

func main() {
  n, m := ni32(), ni32()
  mat = make([][]int, n)
  for i := 0; i < n; i++ {
    mat[i] = make([]int, m)
  }
  for i := 0; i < n; i++ {
    for j := 0; j < m; j++ {
      mat[i][j] = ni32()
    }
  }

  left, right := -1, 1000000009
  for left < right-1 {
    mid := (left + right) >> 1
    if check(mid) {
      left = mid
    } else {
      right = mid
    }
  }
  pri32(left)
  w.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }
func nc() byte     { sc.Scan(); return sc.Text()[0] }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i ...int) {
  for _, ii := range i {
    w.WriteString(strconv.Itoa(ii))
    sp()
  }
}
func pri64(i ...int64) {
  for _, ii := range i {
    w.WriteString(strconv.FormatInt(ii, 10))
    sp()
  }
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

func check(mat [][]int, value int) bool {
  n := len(mat)
  m := len(mat[0])
  was := make([][]bool, m)
  for i := 0; i < m; i++ {
    was[i] = make([]bool, m)
  }
  good := make([]int, m)
  for i := 0; i < n; i++ {
    tl := 0
    for j := 0; j < m; j++ {
      if mat[i][j] >= value {
        good[tl] = j
        tl++
        for t := 0; t < tl-1; t++ {
          if was[good[t]][good[tl-1]] {
            return true
          } else {
            was[good[t]][good[tl-1]] = true
          }
        }
      }
    }
  }
  return false
}

func main() {
  mat := make([][]int, 1010)
  for i := 0; i < 1010; i++ {
    mat[i] = make([]int, 1010)
  }
  n, m := ni32(), ni32()
  for i := 0; i < n; i++ {
    for j := 0; j < m; j++ {
      mat[i][j] = ni32()
    }
  }

  left, right := -1, 1000000009
  for left < right-1 {
    mid := (left + right) >> 1
    if check(mat, mid) {
      left = mid
    } else {
      right = mid
    }
  }
  pri32(left)
  w.Flush()
}


This is the easy version of the problem. The only difference between the two versions is the constraint on $$$n$$$. You can make hacks only if all versions of the problem are solved.A forest is an undirected graph without cycles (not necessarily connected).Mocha and Diana are friends in Zhijiang, both of them have a forest with nodes numbered from $$$1$$$ to $$$n$$$, and they would like to add edges to their forests such that:   After adding edges, both of their graphs are still forests.  They add the same edges. That is, if an edge $$$(u, v)$$$ is added to Mocha's forest, then an edge $$$(u, v)$$$ is added to Diana's forest, and vice versa. Mocha and Diana want to know the maximum number of edges they can add, and which edges to add.

The first line contains three integers $$$n$$$, $$$m_1$$$ and $$$m_2$$$ ($$$1 \le n \le 1000$$$, $$$0 \le m_1, m_2 < n$$$) — the number of nodes and the number of initial edges in Mocha's forest and Diana's forest. Each of the next $$$m_1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the edges in Mocha's forest. Each of the next $$$m_2$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the edges in Diana's forest.

The first line contains only one integer $$$h$$$, the maximum number of edges Mocha and Diana can add (in each forest). Each of the next $$$h$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) — the edge you add each time. If there are multiple correct answers, you can print any one of them.

NoteIn the first example, we cannot add any edge.In the second example, the initial forests are as follows.We can add an edge $$$(2, 4)$$$.

package main

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

var _, _, _ = main, rw, do

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

type edge struct {
	a, b int
}

func rw(r io.Reader, w io.Writer) {
	var n, m1, m2 int
	fmt.Fscan(r, &n, &m1, &m2)
	e1 := make([]edge, m1)
	for i := 0; i < m1; i++ {
		fmt.Fscan(r, &e1[i].a, &e1[i].b)
	}
	e2 := make([]edge, m2)
	for i := 0; i < m2; i++ {
		fmt.Fscan(r, &e2[i].a, &e2[i].b)
	}
	w1 := do(n, e1[:m1], e2[:m2])
	fmt.Fprintln(w, len(w1))
	for _, v := range w1 {
		fmt.Fprintln(w, v.a, v.b)
	}
}

func getF(f []int, x int) int {
	if f[x] != x {
		f[x] = getF(f, f[x])
	}
	return f[x]
}

func newF(n int) []int {
	f := make([]int, n+1)
	for i := 1; i <= n; i++ {
		f[i] = i
	}
	return f
}

func newInitF(n int, e []edge) []int {
	f := newF(n)
	for _, v := range e {
		union(f, v.a, v.b)
	}
	return f
}

func union(f []int, i, j int) {
	fi, fj := getF(f, i), getF(f, j)
	f[fi] = fj
}

func same(f []int, i, j int) bool {
	return getF(f, i) == getF(f, j)
}

func do(n int, e1, e2 []edge) []edge {
	f1 := newInitF(n, e1)
	f2 := newInitF(n, e2)
	var r []edge
	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			if !same(f1, i, j) && !same(f2, i, j) {
				r = append(r, edge{i, j})
				union(f1, i, j)
				union(f2, i, j)
			}
		}
	}
	return r
}

package main

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

var _, _, _ = main, rw, do

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

type edge struct {
	a, b int
}

func rw(r io.Reader, w io.Writer) {
	var n, m1, m2 int
	fmt.Fscan(r, &n, &m1, &m2)
	e1 := make([]edge, m1)
	for i := 0; i < m1; i++ {
		fmt.Fscan(r, &e1[i].a, &e1[i].b)
	}
	e2 := make([]edge, m2)
	for i := 0; i < m2; i++ {
		fmt.Fscan(r, &e2[i].a, &e2[i].b)
	}
	w1 := do(n, e1[:m1], e2[:m2])
	fmt.Fprintln(w, len(w1))
	for _, v := range w1 {
		fmt.Fprintln(w, v.a, v.b)
	}
}

func getF(f []int, x int) int {
	if f[x] != x {
		f[x] = getF(f, f[x])
	}
	return f[x]
}

func newF(n int) []int {
	f := make([]int, n+1)
	for i := 1; i <= n; i++ {
		f[i] = i
	}
	return f
}

func newInitF(n int, e []edge) []int {
	f := newF(n)
	for _, v := range e {
		union(f, v.a, v.b)
	}
	return f
}

func union(f []int, i, j int) {
	fi, fj := getF(f, i), getF(f, j)
	f[fi] = fj
}

func same(f []int, i, j int) bool {
	return getF(f, i) == getF(f, j)
}

func do(n int, e1, e2 []edge) []edge {
	if len(e1) > len(e2) {
		e1, e2 = e2, e1
	}
	f1 := newInitF(n, e1)
	f2 := newInitF(n, e2)
	var r []edge
	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			if !same(f1, i, j) && !same(f2, i, j) {
				r = append(r, edge{i, j})
				union(f1, i, j)
				union(f2, i, j)
			}
		}
	}
	return r
}

package main

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

type dsu struct {
	p []int
	d []int
	c []int
}

func newdsu(n int) *dsu {
	res := &dsu{
		make([]int, n+1),
		make([]int, n+1),
		make([]int, n+1),
	}
	for i := 0; i <= n; i++ {
		res.p[i] = i
		res.c[i] = 1
	}
	return res
}

func (d *dsu) add(i, j int) {
	pi := d.get(i)
	pj := d.get(j)

	if d.d[pi] > d.d[pj] {
		d.p[pj] = pi
		d.c[pj] += d.c[pj]
	} else {
		d.p[pi] = pj
		d.c[pi] += d.c[pj]
		if d.d[pj] < d.d[pi]+1 {
			d.d[pj] = d.d[pi] + 1
		}
	}
}

func (d *dsu) get(i int) int {
	j := i
	for i != d.p[i] {
		i = d.p[i]
	}

	for j != d.p[j] {
		j = d.p[j]
		d.p[j] = i
	}

	return i
}

type edge struct {
	u, v int
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var n, m1, m2 int

	e1 := make([]edge, 0)
	e2 := make([]edge, 0)
	fmt.Fscanf(r, "%d %d %d\n", &n, &m1, &m2)

	for i := 0; i < m1+m2; i++ {
		var u, v int
		fmt.Fscanf(r, "%d %d\n", &u, &v)

		if i < m1 {
			e1 = append(e1, edge{u, v})
		} else {
			e2 = append(e2, edge{u, v})
		}
	}

	d1 := newdsu(n * 2)
	d2 := newdsu(n * 2)

	for _, e := range e1 {
		d1.add(e.u, e.v)
	}
	for _, e := range e2 {
		d2.add(e.u, e.v)
	}

	root := make(map[int]bool)

	for i := 1; i <= n; i++ {
		if d2.get(i) == i {
			root[i] = true
		}
	}

	s := []edge{}
	for i := 1; i <= n; i++ {
		if d1.get(i) == i {
			s = append(s, edge{i, d1.c[i]})
		}
	}
	sort.Slice(s, func(i, j int) bool {
		return s[i].v < s[j].v
	})

	res := []edge{}
	for _, x := range s {
		j := x.u
		if d1.get(j) == j {
			for i, _ := range root {
				if d1.get(i) != d1.get(j) && d2.get(i) != d2.get(j) {
					d1.add(j, i)
					d2.add(j, i)
					if d2.get(i) != i {
						delete(root, i)
					}
					if d2.get(j) != j {
						delete(root, j)
					}
					res = append(res, edge{j, i})
				}
			}
		}
	}

	w := bufio.NewWriterSize(os.Stdout, 1024*1024)

	fmt.Fprintln(w, len(res))
	for _, e := range res {
		fmt.Fprintln(w, e.u, e.v)
	}
	w.Flush()
}

package main

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

type dsu struct {
	p []int
	d []int
}

func newdsu(n int) *dsu {
	res := &dsu{
		make([]int, n+1),
		make([]int, n+1),
	}
	for i := 0; i <= n; i++ {
		res.p[i] = i
	}
	return res
}

func (d *dsu) add(i, j int) {
	pi := d.get(i)
	pj := d.get(j)

	if d.d[pi] > d.d[pj] {
		d.p[pj] = pi
	} else {
		d.p[pi] = pj
		if d.d[pj] < d.d[pi]+1 {
			d.d[pj] = d.d[pi] + 1
		}
	}
}

func (d *dsu) get(i int) int {
	j := i
	for i != d.p[i] {
		i = d.p[i]
	}

	for j != d.p[j] {
		j = d.p[j]
		d.p[j] = i
	}

	return i
}

type edge struct {
	u, v int
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var n, m1, m2 int

	e1 := make([]edge, 0)
	e2 := make([]edge, 0)
	fmt.Fscanf(r, "%d %d %d\n", &n, &m1, &m2)

	for i := 0; i < m1+m2; i++ {
		var u, v int
		fmt.Fscanf(r, "%d %d\n", &u, &v)

		if i < m1 {
			e1 = append(e1, edge{u, v})
		} else {
			e2 = append(e2, edge{u, v})
		}
	}

	d1 := newdsu(n * 2)
	d2 := newdsu(n * 2)

	for _, e := range e1 {
		d1.add(e.u, e.v)
	}
	for _, e := range e2 {
		d2.add(e.u, e.v)
	}

	res := []edge{}
	for j := 1; j <= n; j++ {
		for i := j + 1; i <= n; i++ {
			if d1.get(i) != d1.get(j) && d2.get(i) != d2.get(j) {
				d1.add(j, i)
				d2.add(j, i)
				res = append(res, edge{j, i})
			}
		}
	}

	fmt.Println(len(res))
	for _, e := range res {
		fmt.Println(e.u, e.v)
	}
}

package main

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

type UF struct {
	parents []int
	size    []int
}

func (u *UF) init(n int) {
	u.parents = make([]int, n)
	u.size = make([]int, n)
	for i := range u.parents {
		u.parents[i] = i
		u.size[i] = 1
	}
}

func (u *UF) find(x int) int {
	for u.parents[x] != x {
		u.parents[x] = u.parents[u.parents[x]]
		x = u.parents[x]
	}
	return x
}

func (u *UF) union(a, b int) {
	pa := u.find(a)
	pb := u.find(b)
	if pa == pb {
		return
	}
	if u.size[pa] < u.size[pb] {
		pa, pb = pb, pa
	}
	u.parents[pb] = pa
	u.size[pa] += u.size[pb]
}

func (u *UF) connected(a, b int) bool {
	return u.find(a) == u.find(b)
}

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

	var n, m1, m2 int
	v := make([]int, 2)
	Fscan(in, &n, &m1, &m2)
	u1 := &UF{}
	u1.init(n + 1)
	u2 := &UF{}
	u2.init(n + 1)

	for i := 0; i < m1; i++ {
		Fscan(in, &v[0], &v[1])
		u1.union(v[0], v[1])
	}
	for i := 0; i < m2; i++ {
		Fscan(in, &v[0], &v[1])
		u2.union(v[0], v[1])
	}
	ans := make([][2]int, 0, 1000)
	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			if u1.connected(i, j) || u2.connected(i, j) {
				continue
			}
			u1.union(i, j)
			u2.union(i, j)
			ans = append(ans, [2]int{i, j})
		}
	}
	Fprintln(out, len(ans))
	for _, v := range ans {
		Fprintf(out, "%d %d\n", v[0], v[1])
	}
}

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

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	// tests()
	solve()
}

/* --- Solution D --- */
func solve() {
	n := in.nextInt()
	m1 := in.nextInt()
	m2 := in.nextInt()

	uf1 := NewUF(n)
	uf2 := NewUF(n)

	for i := 0; i < m1+m2; i++ {
		v := in.nextInt() - 1
		w := in.nextInt() - 1
		if i < m1 {
			uf1.union(v, w)
		} else {
			uf2.union(v, w)
		}
	}

	type edge struct{ v, w int }

	answer := []edge{}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if !uf1.connected(i, j) && !uf2.connected(i, j) {
				answer = append(answer, edge{i + 1, j + 1})
				uf1.union(i, j)
				uf2.union(i, j)
			}
		}
	}

	out.println(len(answer))
	for _, e := range answer {
		out.printf("%d %d\n", e.v, e.w)
	}
}

type UF struct {
	id []int
	sz []int
}

func NewUF(N int) *UF {
	uf := UF{}
	uf.id = make([]int, N)
	for i := range uf.id {
		uf.id[i] = i
	}
	uf.sz = make([]int, N)
	for i := range uf.sz {
		uf.sz[i] = 1
	}
	return &uf
}

func (uf *UF) find(p int) int {
	for uf.id[p] != p {
		p = uf.id[p]
	}
	return p
}

func (uf *UF) union(p, q int) {
	pRoot := uf.find(p)
	qRoot := uf.find(q)
	if pRoot == qRoot {
		return
	}
	if uf.sz[pRoot] > uf.sz[qRoot] {
		uf.id[qRoot] = pRoot
		uf.sz[pRoot] += uf.sz[qRoot]
	} else {
		uf.id[pRoot] = qRoot
		uf.sz[qRoot] += uf.sz[pRoot]
	}
}

func (uf *UF) connected(p, q int) bool {
	return uf.find(p) == uf.find(q)
}

func tests() {
	tt := in.nextInt()
	for ; tt > 0; tt-- {
		solve()
	}
}

/* --- I/O --- */
type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	in := In{bufio.NewScanner(os.Stdin)}
	in.scanner.Split(bufio.ScanWords)
	return &in
}

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

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var f1 [3005]int
var f2 [3005]int
func findf1(x int)int{
	if x!=f1[x]{
		f1[x]=findf1(f1[x])
	}
	return f1[x]
}
func findf2(x int)int{
	if x!=f2[x]{
		f2[x]=findf2(f2[x])
	}
	return f2[x]
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var n,m1,m2 int
	fmt.Fscan(in,&n,&m1,&m2)
	var e1 [3005][3005]int
	var e2 [3005][3005]int
	for i:=1;i<=n;i++{
		f1[i]=i
		f2[i]=i
	}
	for i:=1;i<=m1;i++{
		var u,v int
		fmt.Fscan(in,&u,&v)
		e1[u][v]=1
		e1[v][u]=1
		f1u := findf1(u)
		f1v := findf1(v)
		if f1u!=f1v{
			f1[f1u]=f1v
		}
	}
	for i:=1;i<=m2;i++{
		var u,v int
		fmt.Fscan(in,&u,&v)
		e2[u][v]=1
		e2[v][u]=1
		f2u := findf2(u)
		f2v := findf2(v)
		if f2u!=f2v{
			f2[f2u]=f2v
		}
	}
	ans:=0
	cool := [][]int{}
	for i:=1;i<=n;i++{
		for j:=1;j<=n;j++{
			if e1[i][j]!=0||e2[i][j]!=0{
				continue
			}
			if findf1(i)!=findf1(j)&&findf2(j)!=findf2(i){
				f1i := findf1(i)
				f1j := findf1(j)
				f1[f1i]=f1j
				f2i := findf2(i)
				f2j := findf2(j)
				f2[f2i]=f2j
				ans++
				e1[i][j]=1
				e2[i][j]=1
				e1[j][i]=1
				e2[j][i]=1
				cool = append(cool,[]int{i,j})
			}
		}
	}
	fmt.Fprintln(out,ans)
	for i:=1;i<=ans;i++{
		fmt.Fprintln(out,cool[i-1][0],cool[i-1][1])
	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type disjointSet struct {
	parent []int
}

func newDisjointSet(size int) *disjointSet {
	parent := make([]int, size)
	for i := range parent {
		parent[i] = -1
	}

	return &disjointSet{
		parent: parent,
	}
}

func (d *disjointSet) root(node int) int {
	if d.parent[node] == -1 {
		return node
	}

	d.parent[node] = d.root(d.parent[node])
	return d.parent[node]
}

func (d *disjointSet) join(a, b int) {
	ra := d.root(a)
	rb := d.root(b)
	if ra != rb {
		d.parent[rb] = ra
	}
}

func (d *disjointSet) connected(a, b int) bool {
	return d.root(a) == d.root(b)
}

type graph struct {
	set   *disjointSet
	nodes int
}

func newGraph(nodes int) *graph {
	return &graph{
		set:   newDisjointSet(nodes),
		nodes: nodes,
	}
}

func (g *graph) addEdge(a, b int) {
	g.set.join(a, b)
}

func (g *graph) canConnect(a, b int) bool {
	return !g.set.connected(a, b)
}

func solve(g1, g2 *graph) [][]int {
	res := [][]int{}
	for i := 0; i < g1.nodes; i += 1 {
		for j := i + 1; j < g1.nodes; j += 1 {
			if g1.canConnect(i, j) && g2.canConnect(i, j) {
				g1.addEdge(i, j)
				g2.addEdge(i, j)
				res = append(res, []int{i, j})
			}
		}
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	nodes, e1, e2 := stdin.Int(), stdin.Int(), stdin.Int()

	g1 := newGraph(nodes)
	for i := 0; i < e1; i += 1 {
		a, b := stdin.Int()-1, stdin.Int()-1
		g1.addEdge(a, b)
	}

	g2 := newGraph(nodes)
	for i := 0; i < e2; i += 1 {
		a, b := stdin.Int()-1, stdin.Int()-1
		g2.addEdge(a, b)
	}

	res := solve(g1, g2)
	fmt.Println(len(res))
	for _, p := range res {
		fmt.Println(p[0]+1, p[1]+1)
	}
}

package main

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

func main() {
	defer wr.Flush()
	n, m1, m2 := scanInt(), scanInt(), scanInt()
	mocha, diana := newUnionFind(n+1), newUnionFind(n+1)
	for i := 0; i < m1; i++ {
		u, v := scanInt(), scanInt()
		mocha.Union(u, v)
	}
	for i := 0; i < m2; i++ {
		u, v := scanInt(), scanInt()
		diana.Union(u, v)
	}

	addIfCan := func() (bool, int, int) {
		for i := 1; i <= n; i++ {
			x := mocha.Find(i)
			for j := i + 1; j <= n; j++ {
				y := mocha.Find(j)
				if x == y {
					continue
				}
				p, q := diana.Find(i), diana.Find(j)
				if p == q {
					continue
				}
				mocha.Union(x, y)
				diana.Union(p, q)
				return true, i, j
			}
		}
		return false, 0, 0
	}

	ret := make([][2]int, 0)
	for {
		added, i, j := addIfCan()
		if !added {
			break
		}
		ret = append(ret, [2]int{i, j})
	}

	fmt.Fprintln(wr, len(ret))
	for _, p := range ret {
		fmt.Fprintf(wr, "%d %d\n", p[0], p[1])
	}
}

type UnionFind []int

func newUnionFind(n int) UnionFind {
	s := make([]int, n)
	for i := range s {
		s[i] = i
	}
	return s
}

func (uf UnionFind) Union(x, y int) {
	x, y = uf.Find(x), uf.Find(y)
	if x == y {
		return
	} else if y < x {
		x, y = y, x
	}
	// always, x < y
	uf[x] = y
}

func (uf UnionFind) Find(x int) int {
	p := uf[x]
	if x == p {
		return x
	}
	uf[x] = uf.Find(p)
	return uf[x]
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type uf struct {
	fa []int
}

func newUnionFind(n int) uf {
	fa := make([]int, n)
	for i := range fa {
		fa[i] = i
	}
	return uf{fa}
}

func (u uf) find(x int) int {
	if u.fa[x] != x {
		u.fa[x] = u.find(u.fa[x])
	}
	return u.fa[x]
}

func (u uf) merge(from, to int) (isNewMerge bool) {
	x, y := u.find(from), u.find(to)
	if x == y {
		return false
	}
	u.fa[x] = y
	return true
}

func (u uf) same(x, y int) bool { return u.find(x) == u.find(y) }

func (u uf) countRoots(l, r int) (cnt int) {
	for i := l; i <= r; i++ {
		if u.find(i) == i {
			cnt++
		}
	}
	return
}

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

	var n, m1, m2, v, w int
	Fscan(in, &n, &m1, &m2)
	u1, u2 := newUnionFind(n+1), newUnionFind(n+1)
	for i := 0; i < m1; i++ {
		Fscan(in, &v, &w)
		u1.merge(v, w)
	}
	for i := 0; i < m2; i++ {
		Fscan(in, &v, &w)
		u2.merge(v, w)
	}
	ans := [][2]int{}
	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			if !u1.same(i, j) && !u2.same(i, j) {
				ans = append(ans, [2]int{i, j})
				u1.merge(i, j)
				u2.merge(i, j)

			}
		}
	}
	Fprintln(out, len(ans))
	for _, p := range ans {
		Fprintln(out, p[0], p[1])
	}

}

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

package main

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

var _, _, _ = main, rw, do

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

type edge struct {
	a, b int
}

func rw(r io.Reader, w io.Writer) {
	var n, m1, m2 int
	fmt.Fscan(r, &n, &m1, &m2)
	e1 := make([]edge, m1)
	for i := 0; i < m1; i++ {
		fmt.Fscan(r, &e1[i].a, &e1[i].b)
	}
	e2 := make([]edge, m2)
	for i := 0; i < m2; i++ {
		fmt.Fscan(r, &e2[i].a, &e2[i].b)
	}
	w1 := do(n, e1[:m1], e2[:m2])
	fmt.Fprintln(w, len(w1))
	for _, v := range w1 {
		fmt.Fprintln(w, v.a, v.b)
	}
}

func getF(f []int, x int) int {
	if f[x] == x {
		return x
	}
	f[x] = getF(f, f[x])
	return f[x]
}

func newF(n int) []int {
	f := make([]int, n+1)
	for i := 1; i <= n; i++ {
		f[i] = i
	}
	return f
}

func newInitF(n int, e []edge) []int {
	f := newF(n)
	for _, v := range e {
		f[v.a] = getF(f, v.b)
	}
	return f
}

func do(n int, e1, e2 []edge) []edge {
	var r []edge
	if len(e1) > len(e2) {
		e1, e2 = e2, e1
	}
	f1 := newInitF(n, e1)
	f2 := newInitF(n, e2)
	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			f1i, f1j := getF(f1, i), getF(f1, j)
			f2i, f2j := getF(f2, i), getF(f2, j)
			if f1i != f1j && f2i != f2j {
				r = append(r, edge{i, j})
				f1[f1i] = f1j
				f2[f2i] = f2j
			}
		}
	}
	return r
}

package main

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

type dsu struct {
	p []int
	d []int
}

func newdsu(n int) *dsu {
	res := &dsu{
		make([]int, n+1),
		make([]int, n+1),
	}
	for i := 0; i <= n; i++ {
		res.p[i] = i
	}
	return res
}

func (d *dsu) add(i, j int) {
	pi := d.get(i)
	pj := d.get(j)

	if d.d[pi] > d.d[pj] {
		d.p[pj] = pi
	} else {
		d.p[pi] = pj
		if d.d[pj] < d.d[pi]+1 {
			d.d[pj] = d.d[pi] + 1
		}
	}
}

func (d *dsu) get(i int) int {
	j := i
	for i != d.p[i] {
		i = d.p[i]
	}

	for j != d.p[j] {
		j = d.p[j]
		d.p[j] = i
	}

	return i
}

type edge struct {
	u, v int
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var n, m1, m2 int

	e1 := make([]edge, 0)
	e2 := make([]edge, 0)
	fmt.Fscanf(r, "%d %d %d\n", &n, &m1, &m2)

	for i := 0; i < m1+m2; i++ {
		var u, v int
		fmt.Fscanf(r, "%d %d\n", &u, &v)

		if u > v {
			u, v = v, u
		}

		if i < m1 {
			e1 = append(e1, edge{u, v})
		} else {
			e2 = append(e2, edge{u, v})
		}
	}

	sort.Slice(e1, func(i, j int) bool {
		return e1[i].u < e1[j].u
	})
	sort.Slice(e2, func(i, j int) bool {
		return e2[i].u < e2[j].u
	})

	d1 := newdsu(n * 2)
	d2 := newdsu(n * 2)

	for _, e := range e1 {
		d1.add(e.u, e.v)
	}
	for _, e := range e2 {
		d2.add(e.u, e.v)
	}

	res := []edge{}
	for j := 1; j <= n; j++ {
		for i := 2; i <= n; i++ {
			if d1.get(i) != d1.get(j) && d2.get(i) != d2.get(j) {
				d1.add(j, j)
				d2.add(j, i)
				res = append(res, edge{j, i})
			}
		}
	}

	fmt.Println(len(res))
	for _, e := range res {
		fmt.Println(e.u, e.v)
	}
}