package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		p := io.nextInts(2 * n)

		p = append(p, 2*n+1)
		dp := big.NewInt(1)
		last, cnt := 0, uint(0)
		for _, x := range p {
			if x > last {
				dp.Or(dp, new(big.Int).Lsh(dp, cnt))
				last, cnt = x, 0
			}
			cnt++
		}

		if dp.Bit(n) == 1 {
			io.println("YES")
		} else {
			io.println("NO")
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

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

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		p := make([]int64, n*2)
		for i := range p {
			p[i] = sint64()
		}
		printf("%s\n", sol(p))
	}
}

func sol(p []int64) string {
	s := make([]bool, len(p))
	target := int64(len(p))
	lastIdx := int64(len(p))
	groupLens := []int64{}
	for i := int64(len(p) - 1); i >= 0; i-- {
		val := p[i]
		s[val-1] = true
		if val == target {
			groupLens = append(groupLens, lastIdx-i)
			lastIdx = i
			for target > 0 && s[target-1] {
				target--
			}
			// if target == 0 {
			// }
		}
	}
	// printf("%v\n", groupLens)
	dp := make([]bool, len(p)/2+1)
	dp[0] = true
	for _, v := range groupLens {
		tmp := make([]bool, len(dp))
		for j := range tmp {
			if dp[j] {
				tmp[j] = true
			}
			if v == int64(j) {
				tmp[j] = true
			}
			if int64(j) >= v && dp[int64(j)-v] {
				tmp[j] = true
			}
		}
		dp = tmp
		// printf("after: v=%d %v\n", v, dp)
	}
	// printf("%v\n", dp)
	if dp[len(dp)-1] {
		return "YES"
	}
	return "NO"
}

package main

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

/*
6
OEYCDK
EYOKCD
KDCEOY
CKHOYE
YOEDKC
DCKYEO
3
IWL
GIW
WLI
*/

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i][1] > pq[j][1]
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.([2]int))
}

func (pq *priorityQueue) Pop() (res interface{}) {
	res = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	return res
}

var err error

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

var (
	names map[string]int
	words []string
	withs [][]string
	res   []string
	has   []bool
)

func dfs(ind int) {
	if has[ind] {
		return
	}
	has[ind] = true
	for i := len(withs[ind]) - 1; i >= 0; i-- {
		dfs(names[withs[ind][i]])
	}
	res = append(res, words[ind])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		// file2, err := os.Create(name + ".out")
		// if err != nil {
		// 	log.Fatal(err)
		// }
		in = bufio.NewReaderSize(file1, 8192)
		// out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	for cases := nextInt(); cases > 0; cases-- {
		n := nextInt()
		arr := make([]int, 2*n)
		for i := range arr {
			arr[i] = nextInt()
		}
		inds := []int{0}
		for i := 1; i < 2*n; i++ {
			if arr[i] > arr[inds[len(inds)-1]] {
				inds = append(inds, i)
			}
		}
		dp := make([][]bool, len(inds)+1)
		for i := range dp {
			dp[i] = make([]bool, 2*n+1)
		}
		dp[len(inds)][n] = true
		inds = append(inds, 2*n)
		for i := len(inds) - 2; i >= 0; i-- {
			num := inds[i+1] - inds[i]
			for diff := range dp[i] {
				if diff-num >= 0 && dp[i+1][diff-num] {
					dp[i][diff] = true
				}
				if diff+num <= 2*n && dp[i+1][diff+num] {
					dp[i][diff] = true
				}
			}
		}
		if dp[0][n] {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		p := io.nextInts(2 * n)

		mx := make([]int, 2*n+1)
		for i := 0; i < 2*n; i++ {
			mx[i+1] = mx[i]
			if p[i] > p[mx[i]] {
				mx[i+1] = i
			}
		}

		dp := make([][]int, n+1)
		for i := 0; i <= n; i++ {
			dp[i] = make([]int, n+1)
		}

		var solve func(i, j int) int
		solve = func(i, j int) int {
			if i < 0 || j < 0 {
				return -1
			}
			if i == 0 && j == 0 {
				return 1
			}
			if dp[i][j] == 0 {
				k := i + j
				d := k - mx[k]
				dp[i][j] = -1
				if solve(i-d, j) == 1 || solve(i, j-d) == 1 {
					dp[i][j] = 1
				}
			}
			return dp[i][j]
		}

		if solve(n, n) == 1 {
			io.println("YES")
		} else {
			io.println("NO")
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		n := io.nextInt()
		p := io.nextInts(2 * n)

		p = append(p, 2*n+1)
		dp := make([]bool, 2*n+1)
		dp[0] = true
		last, cnt := 0, 0
		for _, x := range p {
			if x > last {
				for i := 2 * n; i >= cnt; i-- {
					dp[i] = dp[i] || dp[i-cnt]
				}
				last, cnt = x, 0
			}
			cnt++
		}

		if dp[n] {
			io.println("YES")
		} else {
			io.println("NO")
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 1024*1024*10)
	sc.Split(bufio.ScanWords)

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

	for t := in(); t > 0; t-- {
		n := in()
		a := make([]int, 2*n)

		b := make([]int, 0, n)

		for i := range a {
			a[i] = in()
		}

		for i := 1; i < 2*n; i++ {
			if a[i] < a[i-1] {
				a[i] = a[i-1]
			}
		}

		c := 0
		p := a[0]

		for i := range a {
			if a[i] == p {
				c++
			} else {
				b = append(b, c)
				c = 1
				p = a[i]
			}
		}

		dp := make([][]bool, len(b)+1)

		for i := range dp {
			dp[i] = make([]bool, n+1)
		}

		m := len(b)

		for i := 0; i <= m; i++ {
			dp[i][0] = true
		}

		for i := 1; i <= n; i++ {
			dp[0][i] = false
		}

		for i := 1; i <= m; i++ {
			for j := 1; j <= n; j++ {
				if j < b[i-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i-1][j] || dp[i-1][j-b[i-1]]
				}
			}
		}

		if dp[m][n] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, 2*n)
		pos := []int{0}
		for i := range a {
			Fscan(in, &a[i])
			if a[i] > a[pos[len(pos)-1]] {
				pos = append(pos, i)
			}
		}
		pos = append(pos, 2*n)
		a = nil
		for i := 1; i < len(pos); i++ {
			a = append(a, pos[i]-pos[i-1])
		}
		dp := make([]bool, n+1)
		dp[0] = true
		for _, v := range a {
			for s := n; s >= v; s-- {
				dp[s] = dp[s] || dp[s-v]
			}
		}
		if dp[n] {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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


package main

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

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

func MAX(x, y 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 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)

		ARRAY := make([]int64, n+1)
		BARRAY := make([]int, 0)

		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		sort.Slice(ARRAY, func(i, j int) bool {
			return ARRAY[i] > ARRAY[j]
		})
		count := 1

		for i := 0; i < n; i++ {
			if ARRAY[i] == ARRAY[i+1] {
				count = count + 1
			} else {
				BARRAY = append(BARRAY, count)
				count = 1
			}
		}

		sort.Ints(BARRAY)
		k := int64(len(BARRAY))

		var max int64
		for i := 0; int64(i) < k; i++ {
			if (k-int64(i))*int64(BARRAY[i]) > max {
				max = (k - int64(i)) * int64(BARRAY[i])
			}
		}
		fmt.Println(int64(n) - max)
	}
}

package main

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

var in *bufio.Reader

func solve() {
	var n int
	fmt.Fscan(in, &n)

	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(in, &ai)

		cnt[ai]++
	}

	freqs := make([]int, 0)
	for _, v := range cnt {
		freqs = append(freqs, v)
	}

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

	last := freqs[0]
	minCost, curCost := n, n
	for i, v := range freqs {
		curCost -= v
		curCost += (last - v) * i
		if minCost > curCost {
			minCost = curCost
		}
		last = v
	}
	fmt.Println(minCost)
}

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

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

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

package main

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

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

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

	// single test case

	var tt int
	Fscan(in, &tt)

	for tt > 0 {
		tt--

		var n int
		Fscan(in, &n)

		t := 0
		occur := map[int]int{}

		for i := 0; i < n; i++ {
			Fscan(in, &t)
			occur[t]++
		}

		cntOccur := make([]int, n+1)

		for _, v := range occur {
			cntOccur[v]++
		}

		save, s := 0, 0
		for i, c := range cntOccur {
			if i*(len(occur)-s) > save {
				save = i * (len(occur) - s)
			}
			s += c
		}
		Fprint(out, n-save, "\n")
	}

	// 입력 에러 방지
	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("읽지않은 데이터 발견：\n" + _s)
	}
}

// LETYLETYLETY
func main() { CF702f(os.Stdin, os.Stdout) }

// YTELYTELYTEL

package main

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

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

func main(){
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for (t > 0){
		t--
		fmt.Fscan(in, &n)
		m := make(map[int]int)
		cnt := make([]int, n+1)
		d := make([]int, n+1)

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

		for k := range m {
			cnt[m[k]]++
		}

		d[n] = cnt[n]
		for i := n-1; i>=1; i--{
			d[i] = d[i+1] + cnt[i]
		}

		result := n
		for i := 1; i<=n; i++{
			result = min(result, n-i*d[i])
		}

		fmt.Println(result)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		hash := make(map[int64]int64, 0)
		for j := 1; j <= n; j++ {
			var x int64
			fmt.Fscan(in, &x)
			hash[x]++
		}
		var arr []int64
		for _, val := range hash {
			arr = append(arr, val)
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] <= arr[j]
		})
		k := len(arr)
		// convert to hash array of counts
		suffixSum := make([]int64, k+1)
		suffixSum[k] = 0
		suffixSum[k-1] = arr[k-1]
		for i := k - 2; i >= 0; i-- {
			suffixSum[i] = suffixSum[i+1] + arr[i]
		}
		preSum := int64(0)
		ans := int64(n + 5)
		for i := 0; i < k; i++ {
			curAns := preSum + suffixSum[i+1] - int64(k-i-1)*arr[i]
			if curAns < ans {
				ans = curAns
			}
			preSum += arr[i]
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func solve(r io.Reader) int {
	var n int
	fmt.Fscan(r, &n)
	cnt := map[int]int{}
	set := make(map[int]int)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(r, &x)
		cnt[x]++
	}
	for _, value := range cnt {
		set[value] = value
	}

	result := n
	for _, value := range set {
		curr := 0
		for _, v := range cnt {
			if v < value {
				curr += v
			} else {
				curr += (v - value)
			}
		}
		result = min(result, curr)
	}
	return result
}
func x(r io.Reader) {
	buf := bufio.NewReader(r)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	fmt.Fscan(buf, &t)
	for i := 0; i < t; i++ {
		re := solve(buf)
		writer.WriteString(strconv.Itoa(re) + "\n")
	}
}

func main() { x(os.Stdin) }

package main

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

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

func MAX(x, y 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 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)

		ARRAY := make([]int64, n+1)
		BARRAY := make([]int, 0)

		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		sort.Slice(ARRAY, func(i, j int) bool {
			return ARRAY[i] > ARRAY[j]
		})
		countt := 1

		for i := 0; i < n; i++ {
			if ARRAY[i] == ARRAY[i+1] {
				countt = countt + 1
			} else {
				BARRAY = append(BARRAY, countt)
				countt = 1
			}
		}

		sort.Ints(BARRAY)
		k := int64(len(BARRAY))

		var maxx int64
		for i := 0; int64(i) < k; i++ {
			if (k-int64(i))*int64(BARRAY[i]) > maxx {
				maxx = (k - int64(i)) * int64(BARRAY[i])
			}
		}
		fmt.Println(int64(n) - maxx)
	}
}

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		cnt := map[int]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			cnt[v]++
		}
		cc := make([]int, n+1)
		for _, c := range cnt {
			cc[c]++
		}
		save, s := 0, 0
		for i, c := range cc {
			if i*(len(cnt)-s) > save {
				save = i * (len(cnt) - s)
			}
			s += c
		}
		Fprintln(out, n-save)
	}
}
func main() { CF1490F(os.Stdin, os.Stdout) }

package main

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func solve(r io.Reader) int {
	var n int
	fmt.Fscan(r, &n)
	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(r, &x)
		cnt[x]++
	}
	result := n
	for _, value := range cnt {
		curr := 0
		for _, v := range cnt {
			if v < value {
				curr += v
			} else {
				curr += (v - value)
			}
		}
		result = min(result, curr)
	}
	return result
}
func x(r io.Reader) {
	buf := bufio.NewReader(r)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	fmt.Fscan(buf, &t)
	for i := 0; i < t; i++ {
		re := solve(buf)
		writer.WriteString(strconv.Itoa(re))
	}
}

func main() { x(os.Stdin) }


package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	for tt := rw.NextInt(); tt > 0; tt-- {
		n, x := rw.NextInt(), rw.NextInt()
		a := rw.NextInts(n)
		var sum int
		all := true
		any := false
		for _, e := range a {
			all = all && e == x
			any = any || e == x
			sum += e
		}
		if n*x == sum {
			if all {
				rw.Println(0)
			} else {
				rw.Println(1)
			}
		} else {
			if any {
				rw.Println(1)
			} else {
				rw.Println(2)
			}
		}
	}
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

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

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

func solve(n int, x int, A []int) int {
	sort.Ints(A)

	if A[0] == x && A[n-1] == x {
		return 0
	}

	i := sort.SearchInts(A, x)
	if i < n && A[i] == x {
		return 1
	}
	var sum int64

	for i := 0; i < n; i++ {
		sum += int64(A[i]) - int64(x)
	}

	if sum == 0 {
		return 1
	}

	return 2
}

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

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

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

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

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

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

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

	return i
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

const _B = 1024 * 1024

// Buffer is the IO middleware
type Buffer struct {
	i   int
	b   []byte
	in  io.Reader
	out io.Writer
}

// NewBuffer provides the io utils references for Solution
func NewBuffer(in io.Reader, out io.Writer) *Buffer {
	return &Buffer{
		b:   make([]byte, _B),
		in:  in,
		out: out,
	}
}

type test struct {
	n, x    int
	ratings []int
}

func readInt(b []byte, i, n int) (int, int) {
	for ; b[i] != '-' && !(b[i] >= '0' && b[i] <= '9'); i++ {
	}

	neg := b[i] == '-'
	if neg {
		i++
	}

	var x int
	for ; i < n && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	if neg {
		x = -x
	}

	return x, i
}

func (o *Buffer) processInput() (int, []test) {
	b, _ := ioutil.ReadAll(o.in)
	n := len(b)

	var t int
	var i int

	t, i = readInt(b, i, n)
	tests := make([]test, t)

	for j := 0; j < t; j++ {
		test := &tests[j]

		test.n, i = readInt(b, i, n)
		test.x, i = readInt(b, i, n)

		test.ratings = make([]int, test.n)
		for k := 0; k < test.n; k++ {
			test.ratings[k], i = readInt(b, i, n)
		}
	}

	return t, tests
}

func (o *Buffer) println(x int) {
	o.b[o.i] = byte(x) + '0'
	o.i++
	o.b[o.i] = '\n'
	o.i++

	if o.i >= len(o.b)-(1<<4) {
		o.flush()
	}
}

func (o *Buffer) flush() {
	if o.i > 0 {
		o.out.Write(o.b[:o.i])
		o.i = 0
	}
}

// Solution solves cf 1419 C
func Solution(_io *Buffer) {

	t, tests := _io.processInput()
	// fmt.Println(t, tests)

	for i := 0; i < t; i++ {
		test := &tests[i]

		// 2 <= n <= 1e3
		// -4e3 <= x <= 4e3

		someEqual := false
		allEqual := true

		for j := 0; j < test.n; j++ {
			if test.ratings[j] == test.x {
				someEqual = true
			} else {
				allEqual = false
			}
		}

		if allEqual {
			_io.println(0)
			continue
		}

		if someEqual {
			_io.println(1)
			continue
		}

		sum := 0
		for j := 0; j < test.n; j++ {
			sum += test.x - test.ratings[j]
		}

		if sum == 0 {
			_io.println(1)
		} else {
			_io.println(2)
		}
	}

	_io.flush()
}

func main() {
	_io := NewBuffer(os.Stdin, os.Stdout)
	Solution(_io)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

const _B = 1024 * 1024

// Buffer is the IO middleware
type Buffer struct {
	i   int
	b   []byte
	in  io.Reader
	out io.Writer
}

// NewBuffer provides the io utils references for Solution
func NewBuffer(in io.Reader, out io.Writer) *Buffer {
	return &Buffer{
		b:   make([]byte, _B),
		in:  in,
		out: out,
	}
}

type test struct {
	n, x    int
	ratings []int
}

func readInt(b []byte, i, n int) (int, int) {
	for ; b[i] != '-' && !(b[i] >= '0' && b[i] <= '9'); i++ {
	}

	neg := b[i] == '-'
	if neg {
		i++
	}

	var x int
	for ; i < n && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	if neg {
		x = -x
	}

	return x, i
}

func (o *Buffer) processInput() (int, []test) {
	b, _ := ioutil.ReadAll(o.in)
	n := len(b)

	var t int
	var i int

	t, i = readInt(b, i, n)
	tests := make([]test, t)

	for j := 0; j < t; j++ {
		test := &tests[j]

		test.n, i = readInt(b, i, n)
		test.x, i = readInt(b, i, n)

		test.ratings = make([]int, test.n)
		for k := 0; k < test.n; k++ {
			test.ratings[k], i = readInt(b, i, n)
		}
	}

	return t, tests
}

func (o *Buffer) println(x int) {
	o.b[o.i] = byte(x) + '0'
	o.i++
	o.b[o.i] = '\n'
	o.i++

	if o.i >= len(o.b)-(1<<4) {
		o.flush()
	}
}

func (o *Buffer) flush() {
	if o.i > 0 {
		o.out.Write(o.b[:o.i])
		o.i = 0
	}
}

// Solution solves cf 1419 C
func Solution(_io *Buffer) {

	t, tests := _io.processInput()
	// fmt.Println(t, tests)

	for i := 0; i < t; i++ {
		test := &tests[i]

		// 2 <= n <= 1e3
		// -4e3 <= x <= 4e3

		allEqual := true
		for j := 0; j < test.n; j++ {
			if test.ratings[j] != test.x {
				allEqual = false
				break
			}
		}

		if allEqual {
			_io.println(0)
			continue
		}

		sum := 0
		for j := 0; j < test.n; j++ {
			sum += test.x - test.ratings[j]
		}

		if sum == 0 {
			_io.println(1)
		} else {
			_io.println(2)
		}
	}

	_io.flush()
}

func main() {
	_io := NewBuffer(os.Stdin, os.Stdout)
	Solution(_io)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

const _B = 1024 * 1024

// Buffer is the IO middleware
type Buffer struct {
	i   int
	b   []byte
	in  io.Reader
	out io.Writer
}

// NewBuffer provides the io utils references for Solution
func NewBuffer(in io.Reader, out io.Writer) *Buffer {
	return &Buffer{
		b:   make([]byte, _B),
		in:  in,
		out: out,
	}
}

type test struct {
	n, x    int
	ratings []int
}

func readInt(b []byte, i, n int) (int, int) {
	for ; b[i] != '-' && !(b[i] >= '0' && b[i] <= '9'); i++ {
	}

	neg := b[i] == '-'
	if neg {
		i++
	}

	var x int
	for ; i < n && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	if neg {
		x = -x
	}

	return x, i
}

func (o *Buffer) processInput() (int, []test) {
	b, _ := ioutil.ReadAll(o.in)
	n := len(b)

	var t int
	var i int

	t, i = readInt(b, i, n)
	tests := make([]test, t)

	for j := 0; j < t; j++ {
		test := &tests[j]

		test.n, i = readInt(b, i, n)
		test.x, i = readInt(b, i, n)

		test.ratings = make([]int, test.n)
		for k := 0; k < test.n; k++ {
			test.ratings[k], i = readInt(b, i, n)
		}
	}

	return t, tests
}

func (o *Buffer) println(x int) {
	o.b[o.i] = byte(x) + '0'
	o.i++
	o.b[o.i] = '\n'
	o.i++

	if o.i >= len(o.b)-(1<<4) {
		o.flush()
	}
}

func (o *Buffer) flush() {
	if o.i > 0 {
		o.out.Write(o.b[:o.i])
		o.i = 0
	}
}

// Solution solves cf 1419 C
func Solution(_io *Buffer) {

	t, tests := _io.processInput()
	// fmt.Println(t, tests)

	for i := 0; i < t; i++ {
		test := &tests[i]

		// 2 <= n <= 1e3
		// -4e3 <= x <= 4e3

		ans := 0
		sum := 0

		for j := 0; j < test.n-1; j++ {
			sum += test.x - test.ratings[j]
		}

		if sum != 0 {
			ans++
		}

		if test.n > 0 {
			if test.x-test.ratings[test.n-1] != -sum {
				ans++
			}
		}

		_io.println(ans)
	}

	_io.flush()
}

func main() {
	_io := NewBuffer(os.Stdin, os.Stdout)
	Solution(_io)
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	for tt := rw.NextInt(); tt > 0; tt-- {
		n, x := rw.NextInt(), rw.NextInt()
		a := rw.NextInts(n)
		var sum int
		all := true
		for _, e := range a {
			all = all && e == x
			sum += e
		}
		if n*x == sum {
			if all {
				rw.Println(0)
			} else {
				rw.Println(1)
			}
		} else {
			rw.Println(2)
		}
	}
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}


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 main() {
	var ntc, a, b int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fscan(in, &a, &b)
		ans := Min((a+b)/4, Min(a, b))
		fmt.Fprintf(out, "%d\n", ans)
		out.Flush()
	}
	out.Flush()
}

package main

import (
	"fmt"
)
func main() {
	var n, cs, ma, max, min int;
	var list []int;
	fmt.Scan(&n);
	for i:=0;i<n;i++{
		fmt.Scan(&cs, &ma);
		max = int((cs + ma) / 4);
		min = mins(cs, ma);
		list = append(list, mins(max, min));
	}
	for _, ival := range list{
		fmt.Println(ival);
	}
	return;
}
func mins (a int, b int) int {
	if b < a {
		return b;
	}
	return a;
}

package main

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

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

	var T, A, B int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &A, &B)
		result := min((A+B)/4, min(A, B))
		fmt.Fprintln(out, result)
	}
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

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

package main

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

func solve() {
	a := get64()
	b := get64()
	if a > b {
		a, b = b, a
	}

	f := func(g int64) int64 {
		a0 := a - 2*g
		b0 := b - 2*g
		rest := min64(a0, b0/3)
		return g + rest
	}

	l, r := L(0), a/2
	fl, fr := f(l), f(r)
	for r-l > 2 {
		n, m := (2*l+r)/3, (l+2*r)/3
		fn, fm := f(n), f(m)
		if fn <= fm {
			l = n
			fl = fn
			continue
		}
		r = m
		fr = fm
	}
	put64ln(max64(max64(fl, fr), f(l+1)))
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

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

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

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

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

func absf(x float64) float64 {
	return math.Abs(x)
}

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

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

func maxf(x float64, y float64) float64 {
	return math.Max(x, y)
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func min64(x int64, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func minf(x float64, y float64) float64 {
	return math.Min(x, y)
}

func L(i int) int64 {
	return int64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1611B
Date: 26/01/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1611/B
Problem: CF1611B
**/
func (in *CF1611B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		a, b := in.NextInt(), in.NextInt()
		teams := int(math.Floor(float64(a+b) / 4.0))
		ans := 0
		if a >= teams && b >= teams {
			ans = teams
		} else {
			ans = int(math.Min(float64(a), float64(b)))
		}
		fmt.Println(ans)
	}
}

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

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

package main

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

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

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

	for t := 0; t < T; t++ {
		var m, p int64
		fmt.Fscan(in, &m, &p)

		fmt.Fprintln(out, min((m+p)/4, m, p))
	}
}

package main

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

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)
)

var (
	T int
)

func solve(a, b int) int {
	d := b - a
	if d < 2 {
		return a / 2
	}
	d /= 2
	if d >= a {
		return a
	}
	return d + (a-d)/2
}

func main() {
	_, _ = fmt.Fscan(rr, &T)
	for iCase := 0; iCase < T; iCase++ {
		var a, b int
		_, _ = fmt.Fscan(rr, &a, &b)
		if a > b {
			a, b = b, a
		}
		_, _ = fmt.Fprintln(ww, solve(a, b))
	}
	_ = ww.Flush()
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	a, b   int64
)

func solve(a, b int64) int64 {
	if a < b/3 {
		return a
	}
	if b < a/3 {
		return b
	}
	return (a + b) / 4
}

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt64() int64 {
	i, err := strconv.ParseInt(scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

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

func isEven(c byte) bool {
	return c == '2' || c == '4' || c == '6' || c == '8'
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		a, b := scanInt64(), scanInt64()
		if a > b {
			a, b = b, a
		}
		if b >= a * 3 {
			fmt.Println(a)
			continue
		}
		fmt.Println((a+b)/4)
	}
}

package main
import "fmt"

func countways(a, b int) int{
	if a > b{
		return countways(b, a)
	} else if a!=0 && b / a >= 3{
		return a
	} else if a==0 {
		return 0
	} else{
		d := b - a
		count := int(d / 2)
		b -= 3*count
		a -= count
		count += int((a+b)/4)
		return count
	}
}

func main(){
	var N_INPS, a, b ,i int
	fmt.Scanf("%d\n",&N_INPS)
	var inps [][2]int
	for i=0; i<N_INPS;i++{
		fmt.Scanf("%d %d\n", &a, &b)
		inps = append(inps,[2]int{a,b})
	}
	for _, inp := range inps{
		fmt.Println(countways(inp[0], inp[1]))
	}
}

package main
import "fmt"

func countways(a, b int64) int64{
	if a > b{
		return countways(b, a)
	} else if b > 3*a {
		return a
	} else if a == b {
		return int64(a/2)
	} else{
		d := b - a
		count := int64(d / 2)
		b -= 3*count
		a -= count
		count += int64((a+b)/4)
		return count
	}
}

func main(){
	var N_INPS, a, b ,i int64
	fmt.Scanf("%d\n",&N_INPS)
	var inps [][2]int64
	for i=0; i<N_INPS;i++{
		fmt.Scanf("%d %d\n", &a, &b)
		inps = append(inps,[2]int64{a,b})
	}
	for _, inp := range inps{
		fmt.Println(countways(inp[0], inp[1]))
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		fmt.Fprintln(out,min((a+b)/4,min(a,b)))
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}

package main

import (
	"fmt"
)

func solve(){
	var a,b int64
	fmt.Scan(&a,&b)
	if a < b{
		a,b = b,a
	}
	if a > 3 * b{
		fmt.Println(b)
	}else{
		fmt.Println((a + b) / 4)
	}
}

func main(){
	n := 0
	fmt.Scan(&n)
	for i := 0;i < n;i++{
		solve()
	}
}

package main

import (
	"fmt"
)

func solve(){
	var a,b int64
	fmt.Scan(&a,&b)
	if a < b{
		a,b = b,a
	}
	if a >= 3 * b{
		fmt.Println(b)
	}else{
		fmt.Println((a + b) / 4)
	}
}

func main(){
	n := 0
	fmt.Scan(&n)
	for i := 0;i < n;i++{
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt64() int64 {
	i, err := strconv.ParseInt(scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func solve(){

}

func main(){
	sc.Split(bufio.ScanWords)
	n := scanInt()
	for i := 0;i < n;i++{
		a := scanInt64()
		b := scanInt64()
		if a < b{
			a,b = b,a
		}
		if a >= 3 * b{
			fmt.Println(b)
		}else{
			fmt.Println((a + b) / 4)
		}
	}
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var a, b int
		fmt.Fscan(in, &a, &b)
		fmt.Fprintln(out, sort.Search((a+b)/4, func(x int) bool {
			return min(a, b) <= x
		}))
	}
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

func upperBoundSearch(a int, b int) int {
	l, r := 0, (a+b)/4
	for l < r {
		x := l + (r-l)/2
		if min(a, b) > x {
			l = x + 1
		} else {
			r = x
		}
	}

	return l
}

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var a, b int
		fmt.Fscan(in, &a, &b)
		fmt.Fprintln(out, sort.Search((a+b)/4, func(x int) bool {
			return min(a, b) <= x
		}))
	}
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

func upperBoundSearch(a int, b int) int {
	l, r := 0, (a+b)/4
	for l < r {
		x := l + (r-l)/2
		if min(a, b) > x {
			l = x + 1
		} else {
			r = x
		}
	}

	return l
}

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var a, b int
		fmt.Fscan(in, &a, &b)
		fmt.Fprintln(out, upperBoundSearch(a, b))
	}
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func FprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

func upperBoundSearch(a int, b int) int {
	l, r := 0, (a+b)/4
	for l < r {
		x := l + (r-l)/2
		if x >= 0 && min(a, b) > x {
			l = x + 1
		} else {
			r = x
		}
	}

	return l
}

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var a, b int
		fmt.Fscan(in, &a, &b)
		fmt.Fprintln(out, upperBoundSearch(a, b))
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

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

func solve() {
    var a,b, ans int
    scanf("%d %d\n", &a, &b)

    if a > b {
        b, a = a,b
    }

    k := (b-a)/2
    k = min(min(k, a), b/3)
    ans = k+min(a-k,(b-3*k))/2
    printf("%d\n", ans)

}

func main() {

    defer writer.Flush()

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

package main
import "fmt"

func countways(a, b int) int{
	if a > b{
		return countways(b, a)
	} else if a!=0 && b / a >= 3{
		return a
	} else{
		d := b - a
		count := int(d / 2)
		b -= 3*count
		a -= count
		count += int((a+b)/4)
		return count
	}
}

func main(){
	var N_INPS, a, b ,i int
	fmt.Scanf("%d\n",&N_INPS)
	var inps [][2]int
	for i=0; i<N_INPS;i++{
		fmt.Scanf("%d %d\n", &a, &b)
		inps = append(inps,[2]int{a,b})
	}
	for _, inp := range inps{
		fmt.Println(countways(inp[0], inp[1]))
	}
}

package main
import "fmt"

func countways(a, b int64) int64{
	if a > b{
		return countways(b, a)
	} else if b > 3*a {
		return a
	} else if a == b {
		return int64(a/2)
	} else{
	    fmt.Println("ok")
		d := b - a
		count := int64(d / 2)
		b -= 3*count
		a -= count
		count += int64((a+b)/4)
		return count
	}
}

func main(){
	var N_INPS, a, b ,i int64
	fmt.Scanf("%d\n",&N_INPS)
	var inps [][2]int64
	for i=0; i<N_INPS;i++{
		fmt.Scanf("%d %d\n", &a, &b)
		inps = append(inps,[2]int64{a,b})
	}
	for _, inp := range inps{
		fmt.Println(countways(inp[0], inp[1]))
	}
}

package main
import "fmt"

func countways(a, b int) int{
	if a > b{
		return countways(b, a)
	} else if b > 3*a{
		return a
	} else if a == b {
		return int(a/2)
	} else{
		d := b - a
		count := int(d / 2)
		b -= 3*count
		a -= count
		count += int((a+b)/4)
		return count
	}
}

func main(){
	var N_INPS, a, b int
	fmt.Scanf("%d\n",&N_INPS)
	var inps [][2]int
	for i:=0; i<N_INPS;i++{
		fmt.Scanf("%d %d\n", &a, &b)
		inps = append(inps,[2]int{a,b})
	}
	for _, inp := range inps{
		fmt.Println(countways(inp[0], inp[1]))
	}
}

package main
import "fmt"

func countways(a, b int) int{
	if a > b{
		return countways(b, a)
	} else if b > 3*a{
		return a
	} else{
		d := b - a
		count := int(d / 2)
		b -= 3*count
		a -= count
		count += int((a+b)/4)
		return count
	}
}

func main(){
	var N_INPS, a, b int
	fmt.Scanf("%d\n",&N_INPS)
	var inps [][2]int
	for i:=0; i<N_INPS;i++{
		fmt.Scanf("%d %d\n", &a, &b)
		inps = append(inps,[2]int{a,b})
	}
	for _, inp := range inps{
		fmt.Println(countways(inp[0], inp[1]))
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if max(max(a,b)/3,min(a,b)/2) == max(a,b)/3 {
			if max(a,b)/3 >= min(a,b) {
				fmt.Fprintln(out,min(a,b))
			} else {
				if max(a,b)%3 == 2 {
					if min(a,b) - max(a,b)/3 >= 2 {
						//return max(a,b)/3+1
						fmt.Fprintln(out,max(a,b)/3+1)
					} else {
						// return max(a,b)/3
						fmt.Fprintln(out,max(a,b)/3)
					}
				} else if max(a,b)%3 == 1 {
					if min(a,b) - max(a,b)/3 >= 3 {
						// return max(a,b)/3+1
						fmt.Fprintln(out,max(a,b)/3+1)
					} else {
						// return max(a,b)/3
						fmt.Fprintln(out,max(a,b)/3)
					}
				} else {
					fmt.Fprintln(out,max(a,b)/3)
					// return max(a,b)/3
				}
			}
		} else {
			if min(a,b)%2 == 0 {
				fmt.Fprintln(out,min(a,b)/2)
				// return min(a,b)/2
			} else {
				if max(a,b) - min(a,b) >= 3 {
					// return min(a,b)/2+1
					fmt.Fprintln(out,min(a,b)/2+1)
				} else {
					// return min(a,b)/2
					fmt.Fprintln(out,min(a,b)/2)
				}
			}
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if a == b {
			fmt.Fprintln(out,a/2)
		} else if max(a,b) >= 3*min(a,b) {
			fmt.Fprintln(out,min(a,b))
		} else {
			if max(a,b)/3 >= min(a,b)/2 {
				if max(a,b)%3 == 0 {
					fmt.Fprintln(out,max(a,b)/3)
				} else if max(a,b)%3 == 1 {
					if min(a,b) >= max(a,b)/3+3 {
						fmt.Fprintln(out,max(a,b)/3+1)
					} else {
						fmt.Fprintln(out,max(a,b)/3)
					}
				} else if max(a,b)%3 == 2 {
					if max(a,b)/3 <= min(a,b)-2 {
						fmt.Fprintln(out,max(a,b)/3+1)
					} else {
						fmt.Fprintln(out,max(a,b)/3)
					}
				}
			} else {
				if min(a,b)%2 == 1 {
					if max(a,b) >= ((min(a,b)/2)*2)+3 {
						fmt.Fprintln(out,min(a,b)/2+1)
					} else {
						fmt.Fprintln(out,min(a,b)/2)
					}
				} else {
					fmt.Fprintln(out,min(a,b)/2)
				}
			}
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if a == b {
			fmt.Fprintln(out,a/2)
		} else if max(a,b) >= 3*min(a,b) {
			fmt.Fprintln(out,min(a,b))
		} else {
			if max(a,b)/3 >= min(a,b)/2 {
				if max(a,b)%3 == 0 {
					fmt.Fprintln(out,max(a,b)/3)
				} else if max(a,b)%3 == 1 {
					if min(a,b) >= max(a,b)/3+3 {
						fmt.Fprintln(out,max(a,b)/3+1)
					} else {
						fmt.Fprintln(out,max(a,b)/3)
					}
				} else if max(a,b)%3 == 2 {
					if max(a,b)/3 <= min(a,b)-2 {
						fmt.Fprintln(out,max(a,b)/3+1)
					} else {
						fmt.Fprintln(out,max(a,b)/3)
					}
				}
			} else {
				fmt.Fprintln(out,min(a,b)/2)
			}
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if a == b {
			fmt.Fprintln(out,a/2)
		} else if max(a,b) >= 3*min(a,b) {
			fmt.Fprintln(out,min(a,b))
		} else {
			if max(a,b)/3 >= min(a,b)/2 {
				if max(a,b)%3 == 2 {
					fmt.Fprintln(out,max(a,b)/3+1)
				} else {
					fmt.Fprintln(out,max(a,b)/3)
				}
			} else {
				if min(a,b)%2 == 1 {
					if max(a,b)-min(a,b) >= 3 {
						fmt.Fprintln(out,min(a,b)/2+1)
					} else {
						fmt.Fprintln(out,min(a,b)/2)
					}
				}
			}
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if a == b {
			fmt.Fprintln(out,a/2)
			continue
		}
		if max(a,b) >= min(a,b)*3 {
			fmt.Fprintln(out,min(a,b))
			continue
		}
		if max(a,b)%3 == 2 {
			if min(a,b) - max(a,b)/3 >= 2 {
				fmt.Fprintln(out,max(a,b)/3+1)
			} else {
				fmt.Fprintln(out,max(a,b)/3)
			}
		} else {
			fmt.Fprintln(out,max(a,b)/3)
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if max(a,b) - min(a,b) <= min(a,b) {
			fmt.Fprintln(out,min(a,b)/2)
		} else {

			if max(a,b)/3 < min(a,b) && min(a,b) - max(a,b)/3 == 2 {
				fmt.Fprintln(out,(max(a,b)/3)+1)
			} else {
				fmt.Fprintln(out,min(max(a,b)/3,min(a,b)))
			}
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if max(a,b) - min(a,b) <= min(a,b) {
			fmt.Fprintln(out,min(a,b)/2)
		} else {

			if max(a,b)/3 < min(a,b) && max(a,b)/3 - min(a,b) == 2 {
				fmt.Fprintln(out,(max(a,b)/3)+1)
			} else {
				fmt.Fprintln(out,min(max(a,b)/3,min(a,b)))
			}
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		if max(a,b) - min(a,b) <= min(a,b) {
			fmt.Fprintln(out,min(a,b)/2)
		} else {
			fmt.Fprintln(out,min(max(a,b)/3,min(a,b)))
		}
	}
}
func min (x,y int) int {
	if x>y{
		return y
	} else {
		return x
	}
}
func max (x,y int) int {
	if x>y{
		return x
	} else {
		return y
	}
}

package main

import (
	"fmt"
)

func solve(){
	var a,b int
	fmt.Scan(&a,&b)
	if a < b{
		a,b = b,a
	}
	if a >= 3 * b{
		fmt.Println(b)
	}else{
		fmt.Println((a + b) / 4)
	}
}

func main(){
	n := 0
	fmt.Scan(&n)
	for i := 0;i < n;i++{
		solve()
	}
}

package main

import (
	"fmt"
)

func solve(){
	var a,b int
	fmt.Scan(&a,&b)
	if a < b{
		a,b = b,a
	}
	if a > 3 * b{
		fmt.Println(b)
	}else{
		fmt.Println((a + b) / 4)
	}
}

func main(){
	n := 0
	fmt.Scan(&n)
	for i := 0;i < n;i++{
		solve()
	}
}


package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	grid := make([]string, n)
	var rng [11][][]uint32
	for i := 0; i < 11; i++ {
		rng[i] = makeGrid(n, m)
	}
	for i := 0; i < n; i++ {
		grid[i] = getNextString(scanner)
		for j := 0; j < m; j++ {
			rng[0][i][j] = 1 << uint(grid[i][j]-'a')
		}
	}
	for i := 1; i < 11; i++ {
		x := 1 << uint(i-1)
		for j := 0; j+x < n; j++ {
			for k := 0; k+x < m; k++ {
				if j-x < 0 {
					continue
				}
				if k-x < 0 {
					continue
				}
				if i == 1 {
					rng[i][j][k] = rng[0][j][k] | rng[i-1][j-x][k] | rng[i-1][j+x][k] | rng[i-1][j][k-x] | rng[i-1][j][k+x]
					continue
				}
				rng[i][j][k] = rng[0][j][k] | rng[i-1][j-x>>1][k] | rng[i-1][j+x>>1][k] | rng[i-1][j][k-x>>1] | rng[i-1][j][k+x>>1]
			}
		}
	}
	var ans int
	for j := 0; j < n; j++ {
		for k := 0; k < m; k++ {
			low := 0
			high := 2000
			for low+1 < high {
				mid := (low + high) >> 1
				if j-mid < 0 || j+mid >= n {
					high = mid
					continue
				}
				if k-mid < 0 || k+mid >= m {
					high = mid
					continue
				}
				i := 32 - bits.LeadingZeros32(uint32(mid))
				x := 1 << uint(i-1)
				c := bits.OnesCount32(rng[i][j][k] | rng[i][j+mid-x][k] | rng[i][j-mid+x][k] | rng[i][j][k+mid-x] | rng[i][j][k-mid+x])
				if c > 1 {
					high = mid
					continue
				}
				low = mid
			}
			ans += high
		}
	}
	fmt.Fprintln(writer, ans)
}
func makeGrid(h, w int) [][]uint32 {
	index := make([][]uint32, h, h)
	data := make([]uint32, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i][1] > pq[j][1]
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.([2]int))
}

func (pq *priorityQueue) Pop() (res interface{}) {
	res = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	return res
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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
}

var (
	dx [4]int = [4]int{-1, 0, 1, 0}
	dy [4]int = [4]int{0, 1, 0, -1}
)

func solve() {
	n, m := nextInt(), nextInt()
	arr := make([][]rune, n)
	for i := range arr {
		arr[i] = []rune(next())
	}
	dist := make([][]int64, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int64, m)
	}

	buff := make([][2]int, 2*n*m)

	res := int64(0)
	for c := 'a'; c <= 'z'; c++ {
		q := buff[0:0]

		for i := range dist {
			for j := range dist[i] {
				if arr[i][j] == c {
					has := false
					for k := 0; k < 4; k++ {
						x, y := i+dx[k], j+dy[k]
						if x < 0 || y < 0 || x >= n || y >= m || arr[x][y] != c {
							has = true
							break
						}
					}
					if has {
						res++
						dist[i][j] = 1
						q = append(q, [2]int{i, j})
					} else {
						dist[i][j] = -1
					}
				}
			}
		}

		for len(q) > 0 {
			x, y := q[0][0], q[0][1]
			d := dist[x][y]
			q = q[1:]
			for i := 0; i < 4; i++ {
				nx, ny := x+dx[i], y+dy[i]
				if nx < 0 || ny < 0 || nx >= n || ny >= m || arr[nx][ny] != c {
					continue
				}
				if dist[nx][ny] == -1 {
					res += d + 1
					dist[nx][ny] = d + 1
					q = append(q, [2]int{nx, ny})
				}
			}
		}
	}
	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		// file2, err := os.Create(name + ".out")
		// if err != nil {
		// 	log.Fatal(err)
		// }
		in = bufio.NewReaderSize(file1, 8192)
		// out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []string) int {
	ans := 0
	rows, cols := len(a), len(a[0])
	var diags [2][][]int
	var lengths [][]int
	for i := range diags {
		diags[i] = make([][]int, rows)
		for r := range diags[i] {
			diags[i][r] = make([]int, cols)
			for c := range diags[i][r] {
				diags[i][r][c] = 1
			}
		}
	}
	lengths = make([][]int, rows)
	for i := range lengths {
		lengths[i] = make([]int, cols)
		for j := range lengths[i] {
			lengths[i][j] = 1
		}
	}

	for r := rows-1; r >= 0; r-- {
		for c := cols-1; c >= 0; c-- {
			color := a[r][c]
			leftColor, rightColor := safeGetByte(a, r+1, c-1), safeGetByte(a, r+1, c+1)
			if leftColor == color {
				diags[0][r][c] = diags[0][r+1][c-1] + 1
			}
			if rightColor == color {
				diags[1][r][c] = diags[1][r+1][c+1] + 1
			}

			if safeGetByte(a, r+1, c) == color {
				lengths[r][c] = getMin(diags[0][r][c], diags[1][r][c], lengths[r+1][c])
				l := lengths[r][c]
				if l == lengths[r+1][c] &&
					safeGetByte(a, r+l, c-l) == color &&
					safeGetByte(a, r+l, c+l) == color &&
					diags[1][r+l][c-l] >= l+1 &&
					diags[0][r+l][c+l] >= l+1 {
					lengths[r][c]++
				}
			}
			l := lengths[r][c]
			ans += l
		}
	}

	return ans
}

func safeGetByte(a []string, r, c int) byte {
	if r < 0 || r >= len(a) || c < 0 || c >= len(a[r]) {
		return ' '
	}
	return a[r][c]
}

func safeGetInt(a [][]int, r, c int) int {
	if r < 0 || r >= len(a) || c < 0 || c >= len(a[r]) {
		return 0
	}
	return a[r][c]
}

func getMin(arr ...int) int {
	if len(arr) == 0 { panic("length arr == 0") }

	var ans = arr[0]
	for _, v := range arr {
		if v < ans { ans = v }
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if debug != 0 && len(os.Args) > 1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024*1024)

	arr := readInts()
	a := make([]string, arr[0])
	for i := range a {
		a[i] = readLine()
	}
	ans := solve(a)
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = v
	}
	return res
}

func readInt() int64 {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 32)
	return int64(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

	m, n := readTwoNums(reader)

	G := make([]string, m)

	for i := 0; i < m; i++ {
		G[i], _ = reader.ReadString('\n')
	}

	fmt.Println(solve(m, n, G))
}

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

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

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

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

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

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

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

	return i
}

func solve(m, n int, G []string) int {
	up := make([][]int, m)
	down := make([][]int, m)

	for i := 0; i < m; i++ {
		up[i] = make([]int, n)
		down[i] = make([]int, n)
	}
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if i > 0 && G[i-1][j] == G[i][j] {
				up[i][j] = up[i-1][j] + 1
			}
		}
	}
	for i := m - 1; i >= 0; i-- {
		for j := 0; j < n; j++ {
			if i < m-1 && G[i+1][j] == G[i][j] {
				down[i][j] = down[i+1][j] + 1
			}
		}
	}

	L := make([]int, n)
	R := make([]int, n)

	var ans int
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			jj := j
			for j < n && G[i][j] == G[i][jj] {
				j++
			}
			j--
			L[jj] = jj
			for k := jj + 1; k <= j; k++ {
				L[k] = max(L[k-1], k-min(up[i][k], down[i][k]))
			}
			R[j] = j

			for k := j - 1; k >= jj; k-- {
				R[k] = min(R[k+1], k+min(up[i][k], down[i][k]))
			}

			for k := jj; k <= j; k++ {
				ans += min(k-L[k]+1, R[k]-k+1)
			}
		}
	}

	return 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 (
	"bufio"
	"fmt"
	"log"
	"os"
)

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i][1] > pq[j][1]
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.([2]int))
}

func (pq *priorityQueue) Pop() (res interface{}) {
	res = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	return res
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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
}

var (
	dx [4]int = [4]int{-1, 0, 1, 0}
	dy [4]int = [4]int{0, 1, 0, -1}
)

func solve() {
	n, m := nextInt(), nextInt()
	arr := make([][]rune, n)
	for i := range arr {
		arr[i] = []rune(next())
	}

	res := 0
	for c := 'a'; c <= 'z'; c++ {
		dist := make([][]int, n)
		q := []int{}

		for i := range dist {
			dist[i] = make([]int, m)
			for j := range dist[i] {
				if arr[i][j] != c {
					dist[i][j] = 0
					q = append(q, i)
					q = append(q, j)
				} else if i == 0 || i == n-1 || j == 0 || j == m-1 {
					dist[i][j] = 1
					q = append(q, i)
					q = append(q, j)
					res++
				} else {
					dist[i][j] = -1
				}
			}
		}

		for len(q) > 0 {
			x, y := q[0], q[1]
			q = q[2:]
			for i := 0; i < 4; i++ {
				nx, ny := x+dx[i], y+dy[i]
				if nx < 0 || ny < 0 || nx >= n || ny >= m {
					continue
				}
				if dist[nx][ny] == -1 {
					res += dist[x][y] + 1
					dist[nx][ny] = dist[x][y] + 1
					q = append(q, nx)
					q = append(q, ny)
				}
			}
		}
	}
	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		// file2, err := os.Create(name + ".out")
		// if err != nil {
		// 	log.Fatal(err)
		// }
		in = bufio.NewReaderSize(file1, 8192)
		// out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

func (pq priorityQueue) Len() int {
	return len(pq)
}

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i][1] > pq[j][1]
}

func (pq priorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.([2]int))
}

func (pq *priorityQueue) Pop() (res interface{}) {
	res = (*pq)[len(*pq)-1]
	*pq = (*pq)[:len(*pq)-1]
	return res
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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
}

var (
	dx [4]int = [4]int{-1, 0, 1, 0}
	dy [4]int = [4]int{0, 1, 0, -1}
)

func solve() {
	n, m := nextInt(), nextInt()
	arr := make([][]rune, n)
	for i := range arr {
		arr[i] = []rune(next())
	}

	res := int64(0)
	for c := 'a'; c <= 'z'; c++ {
		dist := make([][]int64, n)
		q := []int{}

		for i := range dist {
			dist[i] = make([]int64, m)
			for j := range dist[i] {
				if arr[i][j] != c {
					dist[i][j] = 0
					q = append(q, i)
					q = append(q, j)
				} else if i == 0 || i == n-1 || j == 0 || j == m-1 {
					dist[i][j] = 1
					q = append(q, i)
					q = append(q, j)
					res++
				} else {
					dist[i][j] = -1
				}
			}
		}

		for len(q) > 0 {
			x, y := q[0], q[1]
			q = q[2:]
			for i := 0; i < 4; i++ {
				nx, ny := x+dx[i], y+dy[i]
				if nx < 0 || ny < 0 || nx >= n || ny >= m {
					continue
				}
				if dist[nx][ny] == -1 {
					res += dist[x][y] + 1
					dist[nx][ny] = dist[x][y] + 1
					q = append(q, nx)
					q = append(q, ny)
				}
			}
		}
	}
	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		// file2, err := os.Create(name + ".out")
		// if err != nil {
		// 	log.Fatal(err)
		// }
		in = bufio.NewReaderSize(file1, 8192)
		// out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	grid := make([]string, n)
	var rng [11][][]uint32
	for i := 0; i < 11; i++ {
		rng[i] = makeGrid(n, m)
	}
	for i := 0; i < n; i++ {
		grid[i] = getNextString(scanner)
		for j := 0; j < m; j++ {
			rng[0][i][j] = 1 << uint(grid[i][j]-'a')
		}
	}
	for i := 1; i < 11; i++ {
		x := 1 << uint(i-1)
		for j := 0; j+x < n; j++ {
			for k := 0; k+x < m; k++ {
				if j-x < 0 {
					continue
				}
				if k-x < 0 {
					continue
				}
				rng[i][j][k] = rng[0][j][k] | rng[i-1][j-x][k] | rng[i-1][j+x][k] | rng[i-1][j][k-x] | rng[i-1][j][k+x]
			}
		}
	}
	var ans int
	for j := 0; j < n; j++ {
		for k := 0; k < m; k++ {
			low := 0
			high := 2000
			for low+1 < high {
				mid := (low + high) >> 1
				if j-mid < 0 || j+mid >= n {
					high = mid
					continue
				}
				if k-mid < 0 || k+mid >= m {
					high = mid
					continue
				}
				i := 32 - bits.LeadingZeros32(uint32(mid))
				x := 1 << uint(i-1)
				c := bits.OnesCount32(rng[i][j][k] | rng[i][j+mid-x][k] | rng[i][j-mid+x][k] | rng[i][j][k+mid-x] | rng[i][j][k-mid+x])
				if c > 1 {
					high = mid
					continue
				}
				low = mid
			}
			ans += high
		}
	}
	fmt.Fprintln(writer, ans)
}
func makeGrid(h, w int) [][]uint32 {
	index := make([][]uint32, h, h)
	data := make([]uint32, h*w, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}