You are given a string $$$a$$$, consisting of $$$n$$$ characters, $$$n$$$ is even. For each $$$i$$$ from $$$1$$$ to $$$n$$$ $$$a_i$$$ is one of 'A', 'B' or 'C'.A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.You want to find a string $$$b$$$ that consists of $$$n$$$ characters such that:   $$$b$$$ is a regular bracket sequence;  if for some $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) $$$a_i=a_j$$$, then $$$b_i=b_j$$$. In other words, you want to replace all occurrences of 'A' with the same type of bracket, then all occurrences of 'B' with the same type of bracket and all occurrences of 'C' with the same type of bracket.Your task is to determine if such a string $$$b$$$ exists.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The only line of each testcase contains a string $$$a$$$. $$$a$$$ consists only of uppercase letters 'A', 'B' and 'C'. Let $$$n$$$ be the length of $$$a$$$. It is guaranteed that $$$n$$$ is even and $$$2 \le n \le 50$$$.

For each testcase print "YES" if there exists such a string $$$b$$$ that:    $$$b$$$ is a regular bracket sequence;  if for some $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) $$$a_i=a_j$$$, then $$$b_i=b_j$$$.  Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first testcase one of the possible strings $$$b$$$ is "(())()".In the second testcase one of the possible strings $$$b$$$ is "()()".

package main

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

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

func print(a ...interface{}) { fmt.Fprint(writer, a...) }
func scan(a ...interface{})  { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()
	////////////////////
	var count int
	scan(&count)
	for count != 0 {
		solve()
		count--
	}

}

func solve() {
	s := ""
	scan(&s)
	b := false
	if check(s, 'A', 'B', 'C') {
		b = true
	} else if check(s, 'A', 'C', 'B') {
		b = true
	} else if check(s, 'B', 'A', 'C') {
		b = true
	} else if check(s, 'B', 'C', 'A') {
		b = true
	} else if check(s, 'C', 'A', 'B') {
		b = true
	} else if check(s, 'C', 'B', 'A') {
		b = true
	} else {
		print("No", "\n")
	}
	if b {
		print("Yes", "\n")
	}
}

func check(s string, plus rune, minus rune, temp rune) bool {
	count := 0
	count2 := 0
	for _, v := range s {
		if v == plus {
			count++
			count2++
		}
		if v == minus {
			count--
			count2--
		}
		if v == temp {
			count++
			count2--
		}
		if count < 0 {
			count = -1000
		}
		if count2 < 0 {
			count2 = -1000
		}
	}
	if count == 0 || count2 == 0 {
		return true
	}
	return false
}

package main

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

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

	var T int
	var s []byte
O:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &s)
	o:
		for i := 0; i < 8; i++ {
			c := 0
			for _, b := range s {
				c += i>>(b-'A')&1*2 - 1
				if c < 0 {
					continue o
				}
			}
			if c == 0 {
				Fprintln(out, "YES")
				continue O
			}
		}
		Fprintln(out, "NO")
	}
}
func main() { CF1494A(os.Stdin, os.Stdout) }

package main
import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var t int
	var s []byte
T:
	for Scan(&t); t > 0; t-- {
		Scan(&s)
	o:
		for i := 0; i < 8; i++ {
			c := 0
			for _, b := range s {
				c += i>>(b-'A')&1*2 - 1
				if c < 0 {
					continue o
				}
			}
			if c == 0 {
				Println("YES")
				continue T
			}
		}
		Println("NO")
	}
}

// 1494A. ABC String
package main

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

func valid_sequence(s string) bool {
	stack := make([]byte, 0)
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack = append(stack, s[i])
		} else {
			if len(stack) == 0 {
				return false
			}
			stack = stack[:len(stack)-1]
		}
	}
	return len(stack) == 0
}
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)
		A := "()"
		B := "()"
		C := "()"
		ok := false
		for i := 0; i < 2; i++ {
			for j := 0; j < 2; j++ {
				for k := 0; k < 2; k++ {
					res := []byte(s)
					m := make(map[byte]byte)
					m['A'] = A[i]
					m['B'] = B[j]
					m['C'] = C[k]
					for l := 0; l < len(s); l++ {
						res[l] = m[s[l]]
					}
					if valid_sequence(string(res)) {
						ok = true
					}
				}
			}
		}
		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	a      string
)

func check(x []byte, y byte) bool {
	z := make([]byte, len(x))
	copy(z, x)
	for i := range z {
		if z[i] != '(' && z[i] != ')' {
			z[i] = y
		}
	}
	temp := 0
	for i := range z {
		if z[i] == '(' {
			temp++
		} else {
			temp--
		}
		if temp < 0 {
			return false
		}
	}
	return temp == 0
}

func solve(s string) string {
	l := len(s)
	if s[0] == s[l-1] {
		return "NO"
	}
	x := []byte(s)
	for i := range x {
		if s[i] == s[0] {
			x[i] = '('
		}
		if s[i] == s[l-1] {
			x[i] = ')'
		}
	}
	if check(x, '(') || check(x, ')') {
		return "YES"
	}
	return "NO"
}

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

package main

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

var bytes []byte

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

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

	b := nextByte()

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

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

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

func ScanInt() int {
	return int(ScanInt64())
}

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

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

	return builder.String()
}

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

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

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		s := ScanString()
		n := len(s)

		if s[0] == s[n-1] {
			fmt.Println("NO")
			continue
		}

		c := 'A' + 'B' + 'C' - s[0] - s[n-1]
		s = strings.ReplaceAll(s, s[0:1], "(")
		s = strings.ReplaceAll(s, s[n-1:n], ")")

		if len(strings.ReplaceAll(s, "(", "")) > len(strings.ReplaceAll(s, ")", "")) {
			s = strings.ReplaceAll(s, string(c), "(")
		} else {
			s = strings.ReplaceAll(s, string(c), ")")
		}

		open := 0

		for _, c := range s {
			if c == '(' {
				open++
			} else {
				open--
				if open < 0 {
					break
				}
			}
		}

		if open == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import . "fmt"

func main() {
	var t int
	var a []byte

	for Scan(&t); t > 0; t-- {
		Scan(&a)
		if solve(a) {
			Println("YES")
		} else {
			Println("NO")
		}
	}
}

func solve(a []byte) bool {
	for m := 1; m < (1<<3)-1; m++ {
		bal := 0
		for _, c := range a {
			bal += (m>>((c-'A'))&1)*2 - 1
			if bal < 0 {
				break
			}
		}
		if bal == 0 {
			return true
		}
	}
	return false
}

package main

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

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

	for tc := 0; tc < tcs; tc++ {
		var s string
		_, _ = fmt.Fscan(in, &s)

		ans := false
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", "("), "B", "("), "C", "("))
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", "("), "B", "("), "C", ")"))
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", "("), "B", ")"), "C", "("))
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", "("), "B", ")"), "C", ")"))
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", ")"), "B", "("), "C", "("))
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", ")"), "B", "("), "C", ")"))
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", ")"), "B", ")"), "C", "("))
		ans = ans || isPossible(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, "A", ")"), "B", ")"), "C", ")"))

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

func isPossible(s string) bool {
	var stack = make(Stack, 0)

	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack.Push(string('('))
		} else {
			if stack.IsEmpty() {
				return false
			}
			stack.Pop()
		}
	}
	return stack.IsEmpty()
}

type Stack []string

// IsEmpty: check if stack is empty
func (s *Stack) IsEmpty() bool {
	return len(*s) == 0
}

// Push a new value onto the stack
func (s *Stack) Push(str string) {
	*s = append(*s, str) // Simply append the new value to the end of the stack
}

// Remove and return top element of stack. Return false if stack is empty.
func (s *Stack) Pop() (string, bool) {
	if s.IsEmpty() {
		return "", false
	} else {
		index := len(*s) - 1   // Get the index of the top most element.
		element := (*s)[index] // Index into the slice and obtain the element.
		*s = (*s)[:index]      // Remove it from the stack by slicing it off.
		return element, true
	}
}

package main

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int

		fmt.Fscan(input, &n)

		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		intiNum := 0
		EndNumb := 0
		MiddleNum := 0
		if string(STRING[0]) == string(STRING[len(STRING)-1]) {
			fmt.Println("NO")
		} else {
			init := string(STRING[0])
			end := string(STRING[len(STRING)-1])
			for i := 0; i < len(STRING); i++ {
				if string(STRING[i]) == init {
					intiNum++
				} else {
					if string(STRING[i]) == end {
						EndNumb++
					} else {
						MiddleNum++
					}
				}
			}
			if intiNum+MiddleNum != EndNumb && EndNumb+MiddleNum != intiNum {
				fmt.Println("NO")
			} else {
				if intiNum > EndNumb {
					open := 0
					close := 0
					q := 0
					for j := 0; j < len(STRING); j++ {
						if string(STRING[j]) == init {
							open++
						} else {
							close++
						}
						if close > open {
							fmt.Println("NO")
							q = 1
							break
						}
					}
					if q == 0 {
						for m := len(STRING) - 1; m > -1; m-- {
							if string(STRING[m]) != init {
								close++
							} else {
								open++
							}
							if open > close {
								fmt.Println("NO")
								q = 1
								break
							}
						}
					}
					if q == 0 {
						fmt.Println("YES")
					}

				} else {
					open := 0
					close := 0
					q := 0
					for j := 0; j < len(STRING); j++ {
						if string(STRING[j]) != end {
							open++
						} else {
							close++
						}
						if close > open {
							fmt.Println("NO")
							q = 1
							break
						}
					}
					if q == 0 {
						for m := len(STRING) - 1; m > -1; m-- {
							if string(STRING[m]) == end {
								close++
							} else {
								open++
							}
							if open > close {
								fmt.Println("NO")
								q = 1
								break
							}
						}
					}
					if q == 0 {
						fmt.Println("YES")
					}

				}
			}

		}
	}
}

package main

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

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

	var t int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &s)
		a := 0
		b := 0
		c := 0
		ac := 0
		ab := 0
		bc := 0
		for i := range s {
			if s[i] == 'A' {
				if a >= 0 {
					a++
				}
				if ac >= 0 {
					ac++
				}
				if ab >= 0 {
					ab++
				}
				b--
				c--
				bc--
			}
			if s[i] == 'B' {
				if b >= 0 {
					b++
				}
				if ab >= 0 {
					ab++
				}
				if bc >= 0 {
					bc++
				}
				a--
				c--
				ac--
			}
			if s[i] == 'C' {
				if c >= 0 {
					c++
				}
				if ac >= 0 {
					ac++
				}
				if bc >= 0 {
					bc++
				}
				a--
				b--
				ab--
			}
		}

		if a == 0 || b == 0 || c == 0 || ab == 0 || ac == 0 || bc == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func print(a ...interface{}) { fmt.Fprint(writer, a...) }
func scan(a ...interface{})  { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()
	////////////////////
	var count int
	scan(&count)
	for count != 0 {
		solve()
		count--
	}

}

func solve() {
	s := ""
	scan(&s)
	b := false
	if check(s, 'A', 'B', false) {
		b = true
	} else if check(s, 'B', 'A', true) {
		b = true
	} else if check(s, 'A', 'B', true) {
		b = true
	} else if check(s, 'B', 'A', false) {
		b = true
	} else {
		print("No", "\n")
	}
	if b {
		print("Yes", "\n")
	}
}

func check(s string, plus rune, minus rune, c bool) bool {
	count := 0
	for _, v := range s {
		if v == plus {
			count++
		}
		if v == minus {
			count--
		}
		if v == 'C' {
			if c {
				count++
			} else {
				count--
			}
		}
		if count < 0 {
			return false
		}
	}
	if count == 0 {
		return true
	}
	return false
}

package main

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

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

func print(a ...interface{}) { fmt.Fprint(writer, a...) }
func scan(a ...interface{})  { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()
	////////////////////
	var count int
	scan(&count)
	for count != 0 {
		solve()
		count--
	}

}

func solve() {
	s := ""
	scan(&s)
	if check(s, 'A', 'B', false) {
		print("Yes", "\n")
		return
	}
	if check(s, 'B', 'A', true) {
		print("Yes", "\n")
		return
	}
	if check(s, 'A', 'B', true) {
		print("Yes", "\n")
		return
	}
	if check(s, 'B', 'A', false) {
		print("Yes", "\n")
		return
	}
	print("No", "\n")
}

func check(s string, plus rune, minus rune, c bool) bool {
	count := 0
	for _, v := range s {
		if v == plus {
			count++
		}
		if v == minus {
			count--
		}
		if v == 'C' {
			if c {
				count++
			} else {
				count--
			}
		}
		if count < 0 {
			return false
		}
	}
	if count == 0 {
		return true
	}
	return false
}

package main

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

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

func print(a ...interface{}) { fmt.Fprint(writer, a...) }
func scan(a ...interface{})  { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()
	////////////////////
	var count int
	scan(&count)
	for count != 0 {
		solve()
		count--
	}

}

func solve() {
	s := ""
	scan(&s)
	if check(s, 'A', 'B', 'C') {
		print("Yes", "\n")
		return
	}
	if check(s, 'B', 'A', 'C') {
		print("Yes", "\n")
		return
	}
	print("No", "\n")
}

func check(s string, plus rune, minus rune, c rune) bool {
	count := 0
	count2 := 0
	for _, v := range s {
		if v == plus {
			count++
			count2++
		}
		if v == minus {
			count--
			count2--
		}
		if v == c {
			count++
			count2--
		}
		if count < 0 {
			count = 1000
		}
		if count2 < 0 {
			count2 = 1000
		}
	}
	if count == 0 || count2 == 0 {
		return true
	}
	return false
}

package main

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

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

func print(a ...interface{}) { fmt.Fprint(writer, a...) }
func scan(a ...interface{})  { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()
	////////////////////
	var count int
	scan(&count)
	for count != 0 {
		solve()
		count--
	}

}

func solve() {
	s := ""
	aca, bcb, acb, bca := 0, 0, 0, 0
	scan(&s)
	for _, v := range s {
		if v == 'A' {
			aca++
			acb++
			bca--
			bcb--
		}
		if v == 'B' {
			aca--
			acb--
			bca++
			bcb++
		}
		if v == 'C' {
			aca++
			acb--
			bca--
			bcb++
		}
		if aca < 0 {
			aca = -100
		}
		if acb < 0 {
			acb = -100
		}
		if bca < 0 {
			bca = -100
		}
		if bcb < 0 {
			bcb = -100
		}
	}
	if aca == 0 || acb == 0 || bca == 0 || bcb == 0 {
		print("YES", "\n")
	} else {
		print("NO", "\n")
	}
}


Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.You have to find the minimum number of digits in which these two numbers can differ.

The first line contains integer k (1 ≤ k ≤ 109). The second line contains integer n (1 ≤ n < 10100000). There are no leading zeros in n. It's guaranteed that this situation is possible.

Print the minimum number of digits in which the initial number and n can differ.

NoteIn the first example, the initial number could be 12.In the second example the sum of the digits of n is not less than k. The initial number could be equal to n.

package main

import (
	"fmt"
)

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

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

	digitCount := make(map[int]int)
	sum := 0
	for _, c := range num {
		sum += int(c - '0')
		digitCount[int(c-'0')]++
	}

	if sum >= k {
		fmt.Println(0)
		return
	}

	need := k - sum
	digits := 0

	for digit := 0; digit < 9; digit++ {
		valueAdded := 9 - digit

		// fmt.Println(need)
		if need > digitCount[digit]*valueAdded {
			need -= digitCount[digit] * valueAdded
			digits += digitCount[digit]
			continue
		}

		digits += need / valueAdded
		if need%valueAdded != 0 {
			digits++
		}
		break
	}

	fmt.Println(digits)
}

//
package main

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

func solve(k int, n string) int {
	sum := 0
	arr := []byte(n)
	res := 0

	for i := range arr {
		sum += int(arr[i] - '0')
		if int(sum) > k {
			return 0
		}
	}

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

	for i := 0; sum < k; i++ {
		if arr[i] != '9' {
			sum += int('9' - arr[i])
			res++
		}
	}

	return res
}

func min(n1 int, n2 int) int {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k int
	var n string
	fmt.Fscanf(r, "%d\n", &k)
	fmt.Fscanf(r, "%s\n", &n)
	fmt.Fprintf(os.Stdout, "%d\n", solve(k, n))
}

//
package main

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

func solve(k int, n string) int {
	sum, count, i := 0, 0, 0
	arr := []byte(n)

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

	for i := range arr {
		sum += int(arr[i] - '0')
	}

	needed := k - sum
	for needed > 0 {
		needed -= 9 - int(arr[i]-'0')
		count++
		i++
	}

	return count
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k int
	var n string
	fmt.Fscanf(r, "%d\n", &k)
	fmt.Fscanf(r, "%s\n", &n)
	fmt.Fprintf(os.Stdout, "%d\n", solve(k, n))
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	K := io.NextInt()
	N := io.NextString()

	sum := 0
	freq := make([]int, 10)
	for _, c := range N {
		d := c - '0'
		freq[d]++
		sum += int(d)
	}
	wantChange := K - sum

	L := 0
	R := len(N)
	good := R
	for L <= R {
		M := (L + R) >> 1
		if GetMaxChange(freq, M) >= wantChange {
			R = M - 1
			good = M
		} else {
			L = M + 1
		}
	}
	io.Println(good)
}

func GetMaxChange(freq []int, digits int) int {
	change := 0
	for d, f := range freq {
		use := Min(f, digits)
		change += use * (9 - d)
		digits -= use
	}
	return change
}

func Min(args ...int) int {
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

import (
	"fmt"
)

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

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

	digitCount := make(map[int]int)
	sum := 0
	for _, c := range num {
		sum += int(c - '0')
		digitCount[int(c-'0')]++
	}

	if sum >= k {
		fmt.Println(0)
		return
	}

	need := k - sum
	digits := 0

	for digit := 1; digit < 9; digit++ {
		valueAdded := 9 - digit

		// fmt.Println(need)
		if need > digitCount[digit]*valueAdded {
			need -= digitCount[digit] * valueAdded
			digits += digitCount[digit]
			continue
		}

		digits += need / valueAdded
		if need%valueAdded != 0 {
			digits++
		}
		break
	}

	fmt.Println(digits)
}

//
package main

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

func solve(k int, n string) int {
	sum := byte(0)
	arr := []byte(n)
	res := 0

	for i := range arr {
		sum += arr[i] - '0'
		if int(sum) > k {
			return 0
		}
	}

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

	diff := byte(k) - sum
	for i := range arr {
		m := 9 - (arr[i] - '0')
		diff -= min(m, diff)
		res++
		if diff == 0 {
			break
		}
	}

	return res
}

func min(n1 byte, n2 byte) byte {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k int
	var n string
	fmt.Fscanf(r, "%d\n", &k)
	fmt.Fscanf(r, "%s\n", &n)
	fmt.Fprintf(os.Stdout, "%d\n", solve(k, n))
}

//
package main

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

func solve(k int, n int) int {
	sum := 0
	arr := []int{}
	res := 0

	for n > 0 {
		mod := n % 10
		n /= 10
		sum += mod
		if sum > k {
			return 0
		}
		arr = append(arr, mod)
	}

	sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
	diff := k - sum
	for i := range arr {
		m := 9 - arr[i]
		diff -= min(m, diff)
		res++
		if diff == 0 {
			break
		}
	}

	return res
}

func min(n1 int, n2 int) int {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k, n int
	fmt.Fscanf(r, "%d\n", &k)
	fmt.Fscanf(r, "%d\n", &n)
	fmt.Fprintf(os.Stdout, "%d\n", solve(k, n))
}

//
package main

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

func solve(k int, n string) int {
	sum := byte(0)
	arr := []byte(n)
	res := 0

	sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
	for i := range arr {
		sum += arr[i] - '0'
	}

	diff := byte(k) - sum
	for i := range arr {
		m := 9 - (arr[i] - '0')
		diff -= min(m, diff)
		res++
		if diff == 0 {
			break
		}
	}

	return res
}

func min(n1 byte, n2 byte) byte {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k int
	var n string
	fmt.Fscanf(r, "%d\n", &k)
	fmt.Fscanf(r, "%s\n", &n)
	fmt.Fprintf(os.Stdout, "%d\n", solve(k, n))
}

//
package main

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

func solve(k int, n int) int {
	sum := 0
	arr := []int{}
	res := 0

	for n > 0 {
		mod := n % 10
		n /= 10
		sum += mod
		if sum > k {
			return 0
		}
		arr = append(arr, mod)
	}

	sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
	diff := k - sum
	for i := range arr {
		m := 9 - arr[i]
		diff -= min(m, diff)
		res++
		if diff == 0 {
			break
		}
	}

	return res
}

func min(n1 int, n2 int) int {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k, n int
	fmt.Fscanf(r, "%d\n", &k)
	fmt.Fscanf(r, "%s\n", &n)
	fmt.Fprintf(os.Stdout, "%d\n", solve(k, n))
}

//
package main

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

func solve(k byte, n string) int {
	sum := byte(0)
	arr := []byte(n)
	res := 0

	for i := range arr {
		sum += arr[i] - '0'
		if sum > k {
			return 0
		}
	}

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

	diff := byte(k) - sum
	for i := range arr {
		m := 9 - (arr[i] - '0')
		diff -= min(m, diff)
		res++
		if diff == 0 {
			break
		}
	}

	return res
}

func min(n1 byte, n2 byte) byte {
	if n1 < n2 {
		return n1
	}

	return n2
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k byte
	var n string
	fmt.Fscanf(r, "%d\n", &k)
	fmt.Fscanf(r, "%s\n", &n)
	fmt.Fprintf(os.Stdout, "%d\n", solve(k, n))
}


Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading s1 and text s2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text.

The first line contains a newspaper heading s1. The second line contains the letter text s2. s1 и s2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading.

If Vasya can write the given anonymous letter, print YES, otherwise print NO

Instead of dogging Your footsteps it disappears but you dont notice anything
where is your dog

Instead of dogging Your footsteps it disappears but you dont notice anything
Your dog is upstears

Instead of dogging your footsteps it disappears but you dont notice anything
Your dog is upstears

// 43B
package main

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

func main() {
	var i int
	a := make([]int, 150)
	var s, l string
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanLines)
	in.Scan()
	s = in.Text()
	in.Scan()
	l = in.Text()
	for i = 0; i < len(s); i++ {
		a[s[i]]++
	}
	for i = 0; i < len(l); i++ {
		if a[l[i]] < 1 && l[i] != ' ' {
			fmt.Print("NO")
			return
		}
		a[l[i]]--
	}
	fmt.Print("YES")
	return
}

package main

import (
    "fmt"
    "bufio"
    "os"
)
func main(){
    reader := bufio.NewReader(os.Stdin)
    w, _ := reader.ReadString('\n')
    l, _ := reader.ReadString('\n')
    counter_w := make(map[byte]int)
    counter_l := make(map[byte]int)
    for i:=0; i<len(w); i++{
        if w[i] == ' '{
            continue
        }
        counter_w[w[i]] += 1
    }
    for i:=0; i<len(l); i++{
        if l[i] == ' '{
            continue
        }
        counter_l[l[i]] += 1
    }
    result := "YES"
    for letter, count := range counter_l{
        value, ok := counter_w[letter]
        if ok==false || value < count{
            result = "NO"
            break
        }
    }
    fmt.Println(result)
}


Petya organized a strange birthday party. He invited $$$n$$$ friends and assigned an integer $$$k_i$$$ to the $$$i$$$-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are $$$m$$$ unique presents available, the $$$j$$$-th present costs $$$c_j$$$ dollars ($$$1 \le c_1 \le c_2 \le \ldots \le c_m$$$). It's not allowed to buy a single present more than once.For the $$$i$$$-th friend Petya can either buy them a present $$$j \le k_i$$$, which costs $$$c_j$$$ dollars, or just give them $$$c_{k_i}$$$ dollars directly.Help Petya determine the minimum total cost of hosting his party.

The first input line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^5$$$) — the number of friends, and the number of unique presents available. The following line contains $$$n$$$ integers $$$k_1, k_2, \ldots, k_n$$$ ($$$1 \leq k_i \leq m$$$), assigned by Petya to his friends.  The next line contains $$$m$$$ integers $$$c_1, c_2, \ldots, c_m$$$ ($$$1 \le c_1 \le c_2 \le \ldots \le c_m \le 10^9$$$) — the prices of the presents. It is guaranteed that sum of values $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$, and the sum of values $$$m$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case output a single integer — the minimum cost of the party.

NoteIn the first example, there are two test cases. In the first one, Petya has $$$5$$$ friends and $$$4$$$ available presents. Petya can spend only $$$30$$$ dollars if he gives  $$$5$$$ dollars to the first friend.  A present that costs $$$12$$$ dollars to the second friend.  A present that costs $$$5$$$ dollars to the third friend.  A present that costs $$$3$$$ dollars to the fourth friend.  $$$5$$$ dollars to the fifth friend. In the second one, Petya has $$$5$$$ and $$$5$$$ available presents. Petya can spend only $$$190$$$ dollars if he gives  A present that costs $$$10$$$ dollars to the first friend.  A present that costs $$$40$$$ dollars to the second friend.  $$$90$$$ dollars to the third friend.  $$$40$$$ dollars to the fourth friend.  $$$10$$$ dollars to the fifth friend.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1470A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var T, n, m int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		id := make([]int, n)
		for i := range id {
			Fscan(in, &id[i])
		}
		sort.Ints(id)
		c := make([]int, m)
		for i := range c {
			Fscan(in, &c[i])
		}
		ans := int64(0)
		for i, k := range id {
			ans += int64(c[min(n-1-i, k-1)])
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1470A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var T, n, m int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		id := make([]int, n)
		for i := range id {
			Fscan(in, &id[i])
		}
		sort.Ints(id)
		c := make([]int, m)
		for i := range c {
			Fscan(in, &c[i])
		}
		ans := int64(0)
		for i := n - 1; i >= 0; i-- {
			ans += int64(c[min(id[i]-1, n-1-i)])
		}
		Fprintln(out, ans)
	}
}

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

package main

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

/*
1
5 4
2 2 3 3 4
3 5 12 20
---
30   4 -> 3, 3 -> 5, 3 -> 12, 2 -> 5, 2 -> 5
======
2
1 1
1
1
1 2
1
1 2
---
1
1
======
1
2 2
1 2
1 2
---
2
======
1
2 2
2 2
1 2
---
3
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int
	scanf("%d %d\n", &n, &m)

	k := make([]int, n)

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

	c := make([]int, m)

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

	sort.Ints(k)

	sum := int64(0)

	j := 0

	for i := n - 1; i >= 0; i-- {
		if c[j] < c[k[i]-1] {
			sum += int64(c[j])
			j++
		} else {
			sum += int64(c[k[i]-1])
		}
	}

	fmt.Fprintln(writer, sum)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return nums[idx]
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n, &m)
		k := make([]int, n)
		c := make([]int, m)

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

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

		fmt.Fprintln(out, solve(k, c))

	}

}

func solve(k []int, c []int) int64 {

	sum := int64(0)

	reverseSort(k)

	for i := range k {

		if i >= len(c) {
			sum += int64(c[k[i]-1])
		} else if c[i] > c[k[i]-1] {
			sum += int64(c[k[i]-1])
		} else {
			sum += int64(c[i])
		}

	}

	return sum

}

//印出數字陣列
func printIntArr(array []int) {

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

	fmt.Println()

}

//排降序
func reverseSort(a []int) {

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

}

package main

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

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

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		fmt.Fprintln(out, solve())
	}
}

func solve() int64 {
	var x, n, m int
	fmt.Fscan(in, &n, &m)
	cnt := make([]int, m)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		cnt[x-1]++
	}
	c := make([]int64, m)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &c[i])
	}
	ptr := 0
	res := int64(0)

	for i := m - 1; i >= 0; i-- {
		for cnt[i] > 0 && ptr < i {
			res += c[ptr]
			ptr++
			cnt[i]--
		}
		if cnt[i] > 0 {
			res += c[i] * int64(cnt[i])
		}
	}
	return res
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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

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

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

// [2 2 3 3 4]
//  G G G B B
//
// [4 4 4 4 4]
//  B B B B G
func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n, m := sint64(), sint64()
		k := make([]int64, n)
		for i := range k {
			k[i] = sint64()
		}
		c := make([]int64, m)
		for i := range c {
			c[i] = sint64()
		}
		printf("%d\n", sol(n, m, k, c))
	}
}

func sol(n, m int64, k, c []int64) int64 {
	sort.Slice(k, func(il, ir int) bool {
		return k[il] > k[ir]
	})
	ret := int64(0)
	buyN := int64(0)
	for i := range k {
		if k[i]-1 >= buyN {
			buyN++
		}
	}
	nxt := 0
	for i := range k {
		if buyN > 0 {
			ret += c[nxt]
			nxt++
			buyN--
			continue
		}
		ret += c[k[i]-1]
	}
	return ret
}

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

package main

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

var t int

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

	fmt.Fscan(input, &t)

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

		KArr := make([]int, n+1)
		CArr := make([]int, m+1)
		IndexArr := make([]int, m+1)
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &KArr[i])
			IndexArr[KArr[i]] = IndexArr[KArr[i]] + 1
		}
		for j := 1; j < m+1; j++ {
			fmt.Fscan(input, &CArr[j])
		}

		Remainder := n
		INDEX := 0

		for s := 1; Remainder > -1; s++ {
			Remainder = Remainder - IndexArr[s] - 1
			INDEX = INDEX + 1
			if Remainder <= 0 {
				break
			}

		}
		var SUM int64
		if Remainder == 0 {
			for h := 1; h < INDEX+1; h++ {
				SUM = SUM + int64(CArr[h])*int64(IndexArr[h]+1)
			}
			fmt.Println(SUM)
		} else {
			qu := Remainder + IndexArr[INDEX] + 1
			if INDEX > 1 {
				for h := 1; h < INDEX; h++ {
					SUM = SUM + int64(CArr[h])*int64(IndexArr[h]+1)
				}
			}
			SUM = SUM + int64(CArr[INDEX])*int64(qu)
			fmt.Println(SUM)

		}

	}
}

package main

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

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

func solve() {
    var n, m int64
    fmt.Fscan(input, &n, &m)
    k := make([]int64, n)
    for i := 0; i < len(k); i++ {
        fmt.Fscan(input, &k[i])
    }
    c, cc := make([]int64, m), make([]int64, m)
    for i := 0; i < len(c); i++ {
        fmt.Fscan(input, &c[i])
        cc[i] = c[i]
    }
    sort.Slice(k, func(i, j int) bool { return c[k[i] - 1] > c[k[j] - 1]})
    sort.Slice(cc, func(i, j int) bool {return cc[i] < cc[j]})
    sum := int64(0)
    for i := 0; i < len(k); i++ {
        if cc[0] < c[k[i] - 1] {
            sum += cc[0]
            cc = cc[1:]
        } else {
            sum += c[k[i] - 1]
        }
    }

    fmt.Fprintln(output, sum)
}

package main

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m)
		k := make([]int, n)
		c := make([]int64, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &k[i])
			k[i]--
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &c[i])
		}

		sum := int64(0)
		available := 0
		sort.Sort(sort.Reverse(sort.IntSlice(k)))
		for i := range k {
			if available <= k[i] {
				sum += c[available]
				available++
			} else {
				sum += c[k[i]]
			}
		}

		fmt.Println(sum)
	}
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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

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

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

// [2 3 4 3 2]
// [2 2 3 3 4] (sort)
//  G G G B B
// #G > #B
// G => add relevant elements
// B => add first few elements
// [3 5 12 20]
// G => 5+5+12
// B => 3+5
func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n, m := sint64(), sint64()
		k := make([]int64, n)
		for i := range k {
			k[i] = sint64()
		}
		c := make([]int64, m)
		for i := range c {
			c[i] = sint64()
		}
		printf("%d\n", sol(n, m, k, c))
	}
}

func sol(n, m int64, k, c []int64) int64 {
	sort.Slice(k, func(il, ir int) bool {
		return k[il] < k[ir]
	})
	nb := min(m, n/2)
	ng := n - nb
	ret := int64(0)
	for i := int64(0); i < ng; i++ {
		ret += c[k[i]-1]
	}
	for i := int64(0); i < nb; i++ {
		ret += c[i]
	}
	return ret
}

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

package main

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

var t int

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

	fmt.Fscan(input, &t)

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

		KArr := make([]int, n+1)
		CArr := make([]int, m+1)
		IndexArr := make([]int, m+1)
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &KArr[i])
			IndexArr[KArr[i]] = IndexArr[KArr[i]] + 1
		}
		for j := 1; j < m+1; j++ {
			fmt.Fscan(input, &CArr[j])
		}

		Remainder := n
		INDEX := 0

		for s := 1; Remainder > -1; s++ {
			Remainder = Remainder - IndexArr[s] - 1
			INDEX = INDEX + 1
			if Remainder <= 0 {
				break
			}

		}
		var SUM int64
		if Remainder == 0 {
			for h := 1; h < INDEX+1; h++ {
				SUM = SUM + int64(CArr[h]*(IndexArr[h]+1))
			}
			fmt.Println(SUM)
		} else {
			qu := Remainder + IndexArr[INDEX] + 1
			if INDEX > 1 {
				for h := 1; h < INDEX; h++ {
					SUM = SUM + int64(CArr[h]*(IndexArr[h]+1))
				}
			}
			SUM = SUM + int64(CArr[INDEX]*qu)
			fmt.Println(SUM)

		}

	}
}

package main

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

var t int

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

	fmt.Fscan(input, &t)

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

		KArr := make([]int, n+1)
		CArr := make([]int, m+1)
		IndexArr := make([]int, m+1)
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &KArr[i])
			IndexArr[KArr[i]] = IndexArr[KArr[i]] + 1
		}
		for j := 1; j < m+1; j++ {
			fmt.Fscan(input, &CArr[j])
		}

		Remainder := n
		INDEX := 0

		for s := 1; Remainder > -1; s++ {
			Remainder = Remainder - IndexArr[s] - 1
			INDEX = INDEX + 1
			if Remainder <= 0 {
				break
			}

		}
		var SUM int64
		if Remainder == 0 {
			for h := 1; h < INDEX+1; h++ {
				SUM = SUM + int64(CArr[h]*(IndexArr[h]+1))
			}
			fmt.Println(SUM)
		} else {
			qu := Remainder + IndexArr[INDEX] + 1
			for h := 1; h < INDEX; h++ {
				SUM = SUM + int64(CArr[h]*(IndexArr[h]+1))
			}
			SUM = SUM + int64(CArr[INDEX]*qu)
			fmt.Println(SUM)

		}

	}
}


This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.Paul and Mary have a favorite string $$$s$$$ which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of chalk of two colors: red and green. Let's call a coloring of a string wonderful if the following conditions are met:  each letter of the string is either painted in exactly one color (red or green) or isn't painted;  each two letters which are painted in the same color are different;  the number of letters painted in red is equal to the number of letters painted in green;  the number of painted letters of this coloring is maximum among all colorings of the string which meet the first three conditions. E. g. consider a string $$$s$$$ equal to "kzaaa". One of the wonderful colorings of the string is shown in the figure.    The example of a wonderful coloring of the string "kzaaa". Paul and Mary want to learn by themselves how to find a wonderful coloring of the string. But they are very young, so they need a hint. Help them find $$$k$$$ — the number of red (or green, these numbers are equal) letters in a wonderful coloring.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one non-empty string $$$s$$$ which consists of lowercase letters of the Latin alphabet. The number of characters in the string doesn't exceed $$$50$$$.

For each test case, output a separate line containing one non-negative integer $$$k$$$ — the number of letters which will be painted in red in a wonderful coloring.

NoteThe first test case contains the string from the statement. One of the wonderful colorings is shown in the figure. There's no wonderful coloring containing $$$3$$$ or more red letters because the total number of painted symbols will exceed the string's length.The string from the second test case can be painted as follows. Let's paint the first occurrence of each of the letters "c", "o", "e" in red and the second ones in green. Let's paint the letters "d", "f" in red and "r", "s" in green. So every letter will be painted in red or green, hence the answer better than $$$5$$$ doesn't exist.The third test case contains the string of distinct letters, so you can paint any set of characters in red, as long as the size of this set doesn't exceed half of the size of the string and is the maximum possible.The fourth test case contains a single letter which cannot be painted in red because there will be no letter able to be painted in green.The fifth test case contains a string of identical letters, so there's no way to paint more than one letter in red.

package main
import(
    "fmt"
    "sort"
    "strings"
)
func main() {
	var x int
	fmt.Scan(&x)
	for i:=0;i<x;i++{
		var word string
		fmt.Scan(&word)
		list:= strings.Split(word,"")
		sort.Strings(list)
		red:=1
		for j:=1;j<len(list);j++{
			if list[j] != list[j-1] {
				red++
			}
		}
		for j:=0;j<len(list);j++{ // keep singles & doubles
			counter:=1
			for k:=j+1;k<len(list);k++{
				if list[j] == list[k] {
					counter++
				}
				if counter >= 3 {
					counter--
					list = append(list[:k],list[k+1:]...)
					k--
				}
			}
		}
		fmt.Println(len(list)/2)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, s := 0, ""
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &s)
		o, tot, ones := map[string]int{}, 0, 0
		for j := 0; j < len(s); j++ {
			o[string(s[j])]++
		}
		for _, v := range o {
			if v == 1 {
				ones++
			} else {
				tot++
			}
		}
		fmt.Fprintln(w, tot+(ones/2))
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

		chars := make([]int, 26)
		var d int
		for _, ch := range s {
			chars[ch-'a']++
			if chars[ch-'a'] == 2 {
				d++
			}
		}

		var t int
		for _, v := range chars {
			if v == 1 {
				t++
			}
		}

		fmt.Fprintln(out, (t/2)+d)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1551B1
Date: 26/10/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1551/B1
Problem: CF1551B1
**/
func (in *CF1551B1) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		str := in.NextString()
		letters := make([]int, 32)
		colors := ""
		color := "R"
		r, g := 0, 0
		for i := 0; i < len(str); i++ {
			l := str[i]-'a'
			if letters[l] ==0 {
				colors+=color
				if color == "R" {
					r++
					color = "G"
				} else {
					g++
					color = "R"
				}
			} else if letters[l] == 1 {
				colors+=color
				if color == "R" {
					r++
					color = "G"
				} else {
					g++
					color = "R"
				}
			} else {
				colors+="W"
			}
			letters[l]++
		}

		ans := int(math.Min(float64(r), float64(g)))

		fmt.Println(ans)
	}

}

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

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

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	s      string
)

func solve(s string) int {
	var (
		m    = make(map[rune]int)
		v, w int
	)
	for _, x := range s {
		m[x]++
	}
	for i := 'a'; i <= 'z'; i++ {
		if m[i] > 1 {
			v++
		}
		if m[i] == 1 {
			w++
		}
	}
	return v + w/2
}

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

package main

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

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

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

		var buckets [26]int

		for _, c := range s {
			buckets[c - 'a']++
		}

		ans := 0
		for _, val := range buckets {
			if val > 2 {
				ans += val - 2
			}
		}
		if (len(s) - ans) & 0x1 != 0 {
			Fprintln(out, (len(s) - ans - 1) >> 1)
		} else {
			Fprintln(out, (len(s) - ans) >> 1)
		}
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var t int
	var s string
	for fmt.Scanln(&t); t > 0; t-- {
		x, y := 0, 0
		mp := make(map[byte]int)
		fmt.Scanln(&s)
		b := []byte(s)
		for _, c := range b {
			mp[c]++
		}
		for _, v := range mp {
			if v >= 2 {
				x++
			} else {
				y++
			}
		}
		fmt.Println(x + y>>1)
	}
}

package main

import (
    "fmt"
)

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

    for i := 0; i < testCases; i++ {
        var input string
        store := make(map[rune]int)
        fmt.Scan(&input)
        for _, v := range input {
            store[v] += 1
        }
        result := 0
        acc := 0
        for _, v := range store {
            if v == 1 {
                result += 1
            } else {
                acc += 1
            }
        }
        result = result / 2
        result += acc
        fmt.Println(result)
    }
}

package main

import "fmt"

func main() {
	var str string
	var sumOfCases int16
	fmt.Scan(&sumOfCases)
	for i := int16(0); i < sumOfCases; i++ {
		litterList := [26]int8{}
		var num int8
		fmt.Scan(&str)
		var length = int8(len(str))
		for _, litter := range str {
			index := litter - 'a'
			litterList[index]++
		}
		for _, n := range litterList {
			if n >= 2 {
				num++
				length=length-n
			}
		}
		fmt.Println(num+length/2)
	}
}

package main

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

func solve(s string)  {
	ma := make(map[string]int)

	for i := range s {
		cur := s[i:(i+1)]
		_, ok := ma[cur]
		if !ok {
			ma[cur] = 1
		} else {
			ma[cur]++
		}
	}
	cnt := 0
	ans := 0
	for _, value := range ma {
		if value == 1 {
			cnt++
		} else {
			ans++
		}
	}
	ans += cnt / 2
	fmt.Println(ans)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	i := 0

	for scanner.Scan() {
		s := scanner.Text()
		if i == 0 {
			i++
			continue
		}
		i++
		if len(s) == 0 {
			break
		}
		solve(s)
	}
}

package main

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

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

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)
		ARRAY := make([]int, 26)
		l := len(STRING)
		for i := 0; i < l; i++ {
			m := int(STRING[i]) - 97
			ARRAY[m]++
		}
		answer := 0
		b := 0
		for j := 0; j < 26; j++ {
			if ARRAY[j] > 1 {
				answer++
			}
			if ARRAY[j] == 1 {
				b++
			}
		}
		answer = answer + int(b/2)
		fmt.Println(answer)

	}

}

package main

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

func MIN(x, y int64) int64 {
	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 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 {
	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
	}

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

	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 countStr(s, a string) int {
	var ans int
	ans = 0
	for _, l := range s {
		if string(l) == a {
			ans = ans + 1
		}
	}
	return ans
}

func countArrOfStr(arr []string, s string) int {
	var ans int
	ans = 0
	for _, l := range arr {
		if l == s {
			ans = ans + 1
		}
	}
	return ans
}

func isInArray(arr []string, s string) bool {
	var ans bool = false
	for _, l := range arr {
		if l == s {
			ans = true
			break
		}
	}
	return ans
}

func setArrofStr(arr []string) []string {
	var ans []string
	for _, l := range arr {
		if isInArray(ans, l) == false {
			ans = append(ans, l)
		}
	}
	return ans

}

var t int

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

	for o := 0; o < t; o++ {
		var s string
		fmt.Fscan(input, &s)
		var bir []string
		var kop []string
		for _, letter := range s {
			var c int
			c = countStr(s, string(letter))
			if c == 1 {
				bir = append(bir, string(letter))
			} else {
				kop = append(kop, string(letter))
			}
		}
		fmt.Println(len(setArrofStr(bir))/2 + len(setArrofStr(kop)))

	}
}

package main

import (
	"fmt"
)

func main() {

	var (
		n   int
		str string
	)
	fmt.Scan(&n)
	for n > 0 {
		n--
		fmt.Scan(&str)
		var s [30]int
		ans := 0
		for i := 0; i < len(str); i++ {
			s[int(str[i])-97]++
		}
		for i := 0; i < 26; i++ {
			if s[i] > 2 {
				s[i] = 2
			}
			ans += s[i]
		}
		fmt.Println(ans/2)
	}

}

package main

import "fmt"

func main() {
	var (
		t int
		s string
	)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		red, green := make(map[rune]bool), make(map[rune]bool)
		for _, ch:= range s {
			if !red[ch] {
				red[ch] = true
			} else if red[ch] {
				green[ch] = true
			}
		}
		redSize, greenSize := len(red), len(green)
		fmt.Println(greenSize + (redSize - greenSize) / 2)
	}
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		printf("%d\n", sol(_string()))
	}
}

func sol(s string) int {
	cum := 0
	count := map[rune]int{}
	for _, r := range s {
		if count[r] >= 2 {
			continue
		}
		count[r]++
		cum++
	}
	return cum / 2
}

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

func solve(s string) int {
	count := make(map[byte]int)
	length := 0

	for _, ch := range []byte(s) {
		if count[ch] < 2 {
			length += 1
			count[ch] += 1
		}
	}
	return length / 2
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		s := stdin.Word()
		fmt.Println(solve(s))
	}
}

package main

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

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

	solve := func(Case int) {
		var s []byte
		Fscan(in, &s)
		ans := 0
		for b := byte('a'); b <= 'z'; b++ {
			c := bytes.Count(s, []byte{b})
			if c > 2 {
				 c = 2
			}
			ans+=c
		}
		if ans&1>0 {
			ans--
		}
		Fprintln(out, ans/2)
	}

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

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

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

package main
import(
    "fmt"
    "sort"
    "strings"
)
func main() {
	var x int
	fmt.Scan(&x)
	for i:=0;i<x;i++{
		var word string
		fmt.Scan(&word)
		list:= strings.Split(word,"")
		sort.Strings(list)
		red:=1
		for j:=1;j<len(list);j++{
			if list[j] != list[j-1] {
				red++
			}
		}
		if red > len(word)/2 {
			fmt.Println(len(word)/2)
		} else {
			fmt.Println(red)
		}
	}
}