package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)

	current := 0
	capacity := 0
	record := make(map[int]bool)

	for i := 0; i < n; i++ {
		if _in, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			log := strings.Split(re.ReplaceAllString(_in, ""), " ")
			if len(log) != 2 {
				return
			}

			action := log[0]
			id, err := strconv.Atoi(log[1])
			if err != nil {
				return
			}

			if action == "+" {
				current++
				record[id] = true
				if abs(current) > capacity {
					capacity = abs(current)
				}
			} else if action == "-" {
				if _, ok := record[id]; ok {
					current--
					record[id] = false
				} else {
					capacity++
				}
			}

		}
	}

	fmt.Println(capacity)
}

func abs(n int) int {
	if n >= 0 {
		return n
	} else {
		return -n
	}
}

package main

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

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

	in := make([]bool, 1000001, 1000001)
	cur := 0
	ans := 0

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		c := bs.Text()[0]
		bs.Scan()
		p, _ := strconv.Atoi(bs.Text())
		if c == '+' {
			in[p] = true
			cur++
			if ans < cur {
				ans = cur
			}
		} else {
			if in[p] == true {
				cur--
			} else {
				ans++
			}
			in[p] = false
		}
	}

	fmt.Println(ans)
}

package main
import (
	"fmt"
)
func main(){
	var n, register int
	var action string
	var peopleMap map[int] bool
	peopleMap = make(map[int]bool)
	var tmpList []int
	var peopleList []int
	res := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++{
		fmt.Scanf("%s%d\n", &action, &register)
		if action == "+"{
			peopleMap[register] = true
			tmpList = append(tmpList, register)
		}else{
			tmpList = append(tmpList, register * -1)
			_, ok := peopleMap[register]
			if ok{
				delete(peopleMap, register)
			}else{
				peopleList = append(peopleList, register)
			}
		}
	}
	peopleMap = make(map[int]bool)
	peopleList = append(peopleList, tmpList...)
	for i := 0; i < len(peopleList); i++{
		if peopleList[i] > 0{
			peopleMap[peopleList[i]] = true
		}else{
			now := peopleList[i] * -1
			delete(peopleMap, now)
		}
		res = Max(res, len(peopleMap))
	}
	fmt.Println(res)
}

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

package main

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

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

	num := 0
	fmt.Fscanf(r, "%d\n", &num)
	m := map[int]bool{}

	capacity := 0
	log := []int{}

	var id int
	var sign int
	for i := 0; i < num; i++ {
		fmt.Fscanf(r, "%c %d\n", &sign, &id)
		switch sign {
		case '-':
			log = append(log, -id)
			if _, ok := m[id]; !ok {
				capacity++
			}
		case '+':
			m[id] = true
			log = append(log, id)
		}
	}

	maxCap := capacity
	for _, id := range log {
		if id > 0 {
			capacity++
			if maxCap < capacity {
				maxCap = capacity
			}
		} else {
			capacity--
		}
	}

	fmt.Println(maxCap)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := map[int]bool{}
	people, maxPeople := 0, 0

	for i := 0; i < n; i++ {
		isPhus := next() == "+"
		a := nextInt()

		if isPhus {
			m[a] = true
			people++
			if people > maxPeople {
				maxPeople = people
			}
		} else {
			if _, ok := m[a]; ok {
				delete(m, a)
				people--
			} else {
				maxPeople++
			}
		}
	}

	println(maxPeople)
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main
import (
	"fmt"
)
func main(){
	var n, register int
	var action string
	var peopleMap map[int] bool
	peopleMap = make(map[int]bool)
	var tmpList []int
	var peopleList []int
	res := 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++{
		fmt.Scanf("%s%d", &action, &register)
		if action == "+"{
			peopleMap[register] = true
			tmpList = append(tmpList, register)
		}else{
			tmpList = append(tmpList, register * -1)
			_, ok := peopleMap[register]
			if ok{
				delete(peopleMap, register)
			}else{
				peopleList = append(peopleList, register)
			}
		}
	}
	peopleMap = make(map[int]bool)
	peopleList = append(peopleList, tmpList...)
	for i := 0; i < len(peopleList); i++{
		if peopleList[i] > 0{
			peopleMap[peopleList[i]] = true
		}else{
			now := peopleList[i] * -1
			delete(peopleMap, now)
		}
		res = Max(res, len(peopleMap))
	}
	fmt.Println(res)
}

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

package main

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

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

	in := make([]bool, 1000001, 1000001)
	cur := 0
	ans := 0

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		c := bs.Text()[0]
		bs.Scan()
		p, _ := strconv.Atoi(bs.Text())
		if c == '+' {
			//in[p] = true
			cur++
			//if ans < cur {
			//		ans = cur
			//	}
		} else {
			//	if in[p] {
			//		cur--
			//	} else {
			//		ans++
			//	}
			in[p] = false
		}
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
)

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

	in := make([]bool, 1000001, 1000001)
	cur := 0
	ans := 0

	var c byte
	var p int
	for i := 0; i < n; i++ {
		fmt.Scanf("%c %d", &c, &p)
		if c == '+' {
			in[p] = true
			cur++
			if ans < cur {
				ans = cur
			}
		} else {
			if in[p] {
				cur--
			} else {
				ans++
			}
			in[p] = false
		}
	}

	fmt.Println(ans)
}

package main

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

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

	//in := make([]bool, 1000001, 1000001)
	//cur := 0
	ans := 0

	bs := bufio.NewScanner(os.Stdin)
	bs.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		bs.Scan()
		//c := bs.Text()[0]
		bs.Scan()
		//p, _ := strconv.Atoi(bs.Text())
		//if c == '+' {
		//	in[p] = true
		//	cur++
		//	if ans < cur {
		//		ans = cur
		//	}
		//} else {
		//	if in[p] {
		//		cur--
		//	} else {
		//		ans++
		//	}
		//	in[p] = false
		//}
	}

	fmt.Println(ans)
}


package main

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

type Scanner struct{
	buf []byte
	len int
	index int
}

func readInt(scanner *Scanner) int{
	var ret = 0
	var valid = false
	for i := scanner.index; i < scanner.len; i++ {
		var ch = scanner.buf[i]
		if ch >= '0' && ch <= '9' {
			ret = ret * 10 + int(ch - '0')
			valid = true
		}else if valid{
			scanner.index = i + 1
			break
		}
	}
	return ret
}

var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {

	buffer, error := ioutil.ReadAll(os.Stdin)

	if error != nil {
		log.Fatal(error)
		return
	}

	var scanner = &Scanner{
		buf:buffer,
		len:len(buffer),
		index:0,
	}

	var n = readInt(scanner)
	var x = readInt(scanner)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		a[i] = readInt(scanner)
	}

	fmt.Println(run(a,n,x))
}

package main

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

const maxn = 120000
var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	//sort.Sort(sort.IntSlice(a))
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {

	var n, x = -1, -1
	a := []int{0}

	buf, error := ioutil.ReadAll(os.Stdin)

	var input = string(buf)
	if error != nil {
		log.Fatal(error)
		return
	}

	var t = 0
	var valid = false
	var k = 0
	for _,ch := range input {
		if ch >= '0' && ch <= '9' {
			t = t * 10 + int(ch - '0')
			valid = true
		}else {
			if valid {
				if n == -1 {
					n = t
					a = make([]int, n)
				} else if x == - 1{
					x = t
				} else {
					a[k] = t
					k++
				}
				valid = false
			}
			t = 0
		}
	}

	if valid {
		a[k] = t
		k++
	}

	fmt.Println(run(a,n,x))
}

package main

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

const maxn = 120000
var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	//sort.Sort(sort.IntSlice(a))
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {

	var n, x = -1, -1
	a := []int{0}

	buf, error := ioutil.ReadAll(os.Stdin)

	var input = string(buf)
	if error != nil {
		log.Fatal(error)
		return
	}

	var t = 0
	var valid = false
	var k = 0
	for _,ch := range input {
		if ch >= '0' && ch <= '9' {
			t = t * 10 + int(ch - '0')
			valid = true
		}else {
			if valid {
				if n == -1 {
					n = t
					a = make([]int, n)
				} else if x == - 1{
					x = t
				} else {
					a[k] = t
					k++
				}
				valid = false
			}
			t = 0
		}
	}

	if valid {
		a[k] = t
		k++
	}

	fmt.Println(run(a,n,x))
}

package main

import "fmt"

const maxn = 120000
var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)
var a = make([]int, maxn)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	//sort.Sort(sort.IntSlice(a))
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {

	var n, x int

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

	fmt.Printf("%d\n",run(a,n,x))
}

package main

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

type Scanner struct{
	buf []byte
	len int
	index int
}

func readInt(scannr *Scanner) int{
	var ret = 0
	for i := scannr.index; i < scannr.len; i++ {
		var ch = scannr.buf[i]
		if ch >= '0' && ch <= '9' {
			ret = ret * 10 + int(ch - '0')
		}else {
			scannr.index = i + 1
			break
		}
	}
	return ret
}

const maxn = 120000
var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	//sort.Sort(sort.IntSlice(a))
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {

	buffer, error := ioutil.ReadAll(os.Stdin)

	if error != nil {
		log.Fatal(error)
		return
	}

	var scanner = &Scanner{
		buf:buffer,
		len:len(buffer),
		index:0,
	}

	var n = readInt(scanner)
	var x = readInt(scanner)
	var a = make([]int,n)
	//fmt.Println(n,x)
	for i := 0; i < n; i++ {
		a[i] = readInt(scanner)
	}

	fmt.Println(run(a,n,x))
}

package main

import (
	"fmt"
	"sort"
)

const maxn = 12000

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	var keyMap = make(map[int]int)
	var bitwise = make(map[int]int)
	sort.Sort(sort.IntSlice(a))
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] == k {
			return 0
		}
		keyMap[k] = k
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if bitwise[t] == t {
			return 1
		}

		if bitwise[k] == t {
			return 2
		}
	}
	return -1
}

func main()  {
	var n, x = 0,0

	fmt.Scan(&n,&x)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(run(a,n,x))
}

package main

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

type Scanner struct{
	buf []byte
	len int
	index int
}

func readInt(scannr *Scanner) int{
	var ret = 0
	for i := scannr.index; i < scannr.len; i++ {
		var ch = scannr.buf[i]
		if ch >= '0' && ch <= '9' {
			ret = ret * 10 + int(ch - '0')
		}else {
			scannr.index = i + 1
			break
		}
	}
	return ret
}

var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {

	buffer, error := ioutil.ReadAll(os.Stdin)

	if error != nil {
		log.Fatal(error)
		return
	}

	var scanner = &Scanner{
		buf:buffer,
		len:len(buffer),
		index:0,
	}

	var n = readInt(scanner)
	var x = readInt(scanner)
	var a = make([]int,n)
	fmt.Println(n,x,a)
	for i := 0; i < n; i++ {
		a[i] = readInt(scanner)
	}

	fmt.Println(run(a,n,x))
}

package main

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

type Scanner struct{
	buf []byte
	len int
	index int
}

func readInt(scannr *Scanner) int{
	var ret = 0
	for i := scannr.index; i < scannr.len; i++ {
		var ch = scannr.buf[i]
		if ch >= '0' && ch <= '9' {
			ret = ret * 10 + int(ch - '0')
		}else {
			scannr.index = i + 1
			break
		}
	}
	return ret
}

var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {

	buffer, error := ioutil.ReadAll(os.Stdin)

	if error != nil {
		log.Fatal(error)
		return
	}

	var scanner = &Scanner{
		buf:buffer,
		len:len(buffer),
		index:0,
	}

	var n = readInt(scanner)
	var x = readInt(scanner)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		a[i] = readInt(scanner)
	}
	fmt.Println(n,x,a)

	fmt.Println(run(a,n,x))
}

package main

import (
	"fmt"
)

const maxn = 12000

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	var keyMap = make(map[int]bool)
	var bitwise = make(map[int]bool)
	for _,k := range a {
		if keyMap[k] {
			return 0
		}

		var t = k & x
		if keyMap[t] {
			return 1
		}
		keyMap[k] = true
	}

	for _, k:= range a {
		var t = k & x

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {
	var n, x = 0,0

	fmt.Scan(&n,&x)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(run(a,n,x))
}

package main

import (
	"fmt"
)

const maxn = 12000

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	var keyMap = make(map[int]bool)
	var bitwise = make(map[int]bool)
	//sort.Sort(sort.IntSlice(a))
	for _,k := range a {
		if keyMap[k] {
			return 0
		}
		keyMap[k] = true
	}

	for _,k := range a {
		var t = k & x
		if keyMap[t] {
			return 1
		}

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {
	var n, x = 0,0

	fmt.Scan(&n,&x)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(run(a,n,x))
}

package main

import (
	"fmt"
	"sort"
)

const maxn = 12000

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	var keyMap = make(map[int]int)
	var bitwise = make(map[int]int)
	sort.Sort(sort.IntSlice(a))
	for i,k := range a {
		if keyMap[k] != 0 {
			return 0
		}

		var t = k & x
		if keyMap[t] != 0 {
			return 1
		}
		keyMap[k] = t

		if bitwise[t] != 0 {
			return 2
		}

		bitwise[t] = i + 1
	}

	return -1
}

func main()  {
	var n, x = 0,0

	fmt.Scan(&n,&x)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(run(a,n,x))
}

package main

import (
	"fmt"
)

const maxn = 120000

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	var keyMap = make(map[int]bool)
	var bitwise = make(map[int]bool)
	//sort.Sort(sort.IntSlice(a))
	for _,k := range a {
		if keyMap[k] {
			return 0
		}
		keyMap[k] = true
	}

	for _,k := range a {
		var t = k & x
		if keyMap[t] {
			return 1
		}

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {
	var n, x = 0,0

	fmt.Scan(&n,&x)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(run(a,n,x))
}

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

const maxn = 120000
var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)
var a = make([]int, maxn)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	//sort.Sort(sort.IntSlice(a))
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {
	defer writer.Flush()

	var n, x int

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

	printf("%d\n",run(a,n,x))
}

package main

import (
	"fmt"
)

const maxn = 120000
var keyMap = make(map[int]int)
var bitwise = make(map[int]bool)
var a = make([]int, maxn)

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	//sort.Sort(sort.IntSlice(a))
	for i := 0; i < n; i++ {
		var k = a[i]
		if keyMap[k] != 0{
			return 0
		}
		keyMap[k] = i + 1
	}

	for i := 0; i < n; i++ {
		var k = a[i]
		var t = k & x
		if keyMap[t] != 0 && keyMap[t] != i + 1 {
			return 1
		}

		if bitwise[t]  {
			return 2
		}

		bitwise[t] = true
	}

	return -1
}

func main()  {
	var n, x = 0,0

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

	fmt.Println(run(a,n,x))
}

package main

import (
	"fmt"
	"sort"
)

const maxn = 12000

func run(a []int, n int, x int) int {
	if n == 1{
		return -1
	}
	var keyMap = make(map[int]int)
	var bitwise = make(map[int]int)
	sort.Sort(sort.IntSlice(a))
	for _,k := range a {
		if keyMap[k] == k {
			return 0
		}
		keyMap[k] = k
	}

	for _, k := range  a{
		var t = k & x
		if bitwise[t] == t {
			return 1
		}

		if bitwise[k] == t {
			return 2
		}

		bitwise[k] = t
	}
	return -1
}

func main()  {
	var n, x = 0,0

	fmt.Scan(&n,&x)
	var a = make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(run(a,n,x))
}


package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, a)
		fmt.Fprintln(w, w1)
	}
}

func do(n int, a []int) int {
	m := make(map[int]bool)

	for i := n - 2; i >= 0; i-- {
		if a[i] > a[i+1] {
			for j := 0; j <= i; j++ {
				m[a[j]] = true
			}
			break
		}
	}
	for i := n - 1; i >= 0; i-- {
		if m[a[i]] {
			for j := 0; j <= i; j++ {
				m[a[j]] = true
			}
			break
		}
	}
	return len(m)
}

package main

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

func A2() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int

		Fscan(in, &n)
		a := make([]int, n)
		far := make(map[int]int)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
			far[a[i]] = i
		}
		m := make(map[int]bool)

		var f bool
		var p = n
		for i := n - 2; i >= 0; i-- {
			if a[i] > a[i+1] {
				p = i
				f = true
				break
			}

		}
		if f {
			for i := 0; i <= p; i++ {
				m[a[i]] = true
				if far[a[i]] > p {
					p = far[a[i]]
				}
			}
			Fprintln(out, len(m))
		} else {
			Fprintln(out, 0)
		}

	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A2() }

package main

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

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

func main() {

	defer out.Flush()

	t := 0
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

	for ; t > 0; t-- {
		n, ans := 0, 0
		if _, err := fmt.Fscan(in, &n); err != nil {
			return
		}
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			if _, err := fmt.Fscan(in, &nums[i]); err != nil {
				return
			}
		}
		indices := make(map[int]int)
		zero := make(map[int]bool)
		for i := n - 1; i > 0; i-- {
			if _, ok := indices[nums[i]]; !ok {
				indices[nums[i]] = i
			}
			if nums[i-1] > nums[i] {
				k := 0
				if v, ok := indices[nums[i-1]]; ok {
					k = v
				} else {
					k = i - 1
				}
				for j := 0; j <= k; j++ {
					if _, ok := zero[nums[j]]; !ok {
						zero[nums[j]] = true
						ans++
					}
					if v, ok := indices[nums[j]]; ok && v > k {
						k = v
					}
				}
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		if n == 1 {
			Fprintln(out, 0)
			continue
		}
		a := make([]int, n)
		// 统计 a[i] 最早出现位置
		mp := map[int]int{}
		cnt := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			cnt[i] = len(mp)
			if _, ok := mp[a[i]]; !ok {
				mp[a[i]] = i
			}
		}
		j := n-1
		for ; j >= 0; j-- {
			if j >= 1 && a[j] == a[j-1] {
				continue
			}
			if i, ok := mp[a[j]]; ok && i < j {
				break
			}
			if j >= 1 && a[j] < a[j-1] {
				break
			}
		}
		if j >= 0 {
			Fprintln(out, cnt[j])
		} else {
			Fprintln(out, 0)
		}
	}
}

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

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	l, r := 0, n+1
	ans := n
	for l <= r {
		border := (l + r) / 2
		localAns := 0
		var s set[int]
		for i := 0; i < border; i++ {
			if !s.has(arr[i]) {
				localAns++
				s.add(arr[i])
			}
		}
		skip := false
		for i := border; i < n-1; i++ {
			num1, num2 := arr[i], arr[i+1]
			if s.has(num1) {
				num1 = 0
			}
			if s.has(num2) {
				num2 = 0
			}
			if num1 > num2 {
				skip = true
				break
			}
		}
		if skip {
			l = border + 1
		} else {
			r = border - 1
			ans = min(ans, localAns)
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

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

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}
func solve(A []int) int {
	n := len(A)
	first := make([]int, n+1)
	for i := 0; i <= n; i++ {
		first[i] = -1
	}
	last := make([]int, n+1)
	for i := 0; i < n; i++ {
		if first[A[i]] < 0 {
			first[A[i]] = i
		}
		last[A[i]] = i
	}

	type Pair struct {
		first  int
		second int
	}

	var events []Pair

	for i := 1; i <= n; i++ {
		if first[i] >= 0 {
			events = append(events, Pair{first[i], i})
			events = append(events, Pair{last[i], -i})
		}
	}

	sort.Slice(events, func(i, j int) bool {
		return events[i].first < events[j].first || events[i].first == events[j].first && events[i].second > events[j].second
	})

	sorted := make([]bool, n)
	sorted[n-1] = true
	for i := n - 2; i >= 0; i-- {
		sorted[i] = false
		if i+1 < n && sorted[i+1] && A[i] <= A[i+1] {
			sorted[i] = true
		}
	}

	if sorted[0] {
		return 0
	}

	res := n
	var open int
	nums := make(map[int]bool)
	for _, evt := range events {
		if evt.second > 0 {
			open++
		} else {
			open--
		}
		nums[abs(evt.second)] = true
		if open == 0 {
			x := evt.first
			if x+1 < n && sorted[x+1] {
				res = min(res, len(nums))
			}
		}
	}

	return min(res, len(nums))
}

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

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

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

package main

import (

	"fmt"
	"os"
	"bufio"
)

var (

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

func solve(n int) {

	var (

		a []int
		cnt = 0
		mp = map[int]int{}
	)
	for i := 0; i < n; i++ {

		var x int
		fmt.Fscan(in, &x)
		a = append(a, x)
		mp[x] = x
	}
	for j := n - 1; j > 0; j-- {

		if mp[a[j]] < mp[a[j-1]] {

			mp[a[j-1]] = 0
			cnt += 1
		}
	}
	for j := n - 1; j > 0; j-- {

		if mp[a[j]] < mp[a[j-1]] {

			mp[a[j-1]] = 0
			cnt += 1
		}
	}

	fmt.Fprintln(out, cnt)
}

func main() {

	defer out.Flush()
	var T int
	fmt.Fscan(in, &T)
	for i := 0; i < T; i++ {

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

package main

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

var bufferedStdin = bufio.NewReader(os.Stdin)
var bufferedStdout = bufio.NewWriter(os.Stdout)

func read(value ...interface{}) {
	_, _ = fmt.Fscan(bufferedStdin, value...)
}

func printf(format string, value ...interface{}) {
	_, _ = fmt.Fprintf(bufferedStdout, format, value...)
}

func printfErr(format string, value ...interface{}) {
	_, _ = fmt.Fprintf(os.Stderr, format, value...)
}

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

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

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

func findElementIds(array []int, f func(int) bool) []int {
	var result = make([]int, 0)
	for i := 0; i < len(array); i++ {
		if f(array[i]) {
			result = append(result, i)
		}
	}
	return result
}

func reduce(array []int, defaultValue int, f func(int, int) int) int {
	for i := 0; i < len(array); i++ {
		defaultValue = f(defaultValue, array[i])
	}
	return defaultValue
}

func solve(test int) {
	var n int
	read(&n)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		read(&a[i])
	}
	var m = make(map[int]int)
	var lastInd = -1
	for i := n - 2; i >= 0; i-- {
		m[a[i+1]] = max(m[a[i+1]], i+1)
		if a[i] > a[i+1] {
			lastInd = i + 1
			break
		}
	}
	for i := lastInd - 1; i >= 0; i-- {
		if m[a[i]] != 0 {
			lastInd = max(lastInd, m[a[i]]+1)
		}
	}
	var used = make(map[int]bool)
	var ans = 0
	for i := lastInd - 1; i >= 0; i-- {
		if !used[a[i]] {
			ans++
		}
		used[a[i]] = true
	}
	printf("%d\n", ans)
}

func main() {
	var t = 1
	_, _ = fmt.Fscan(bufferedStdin, &t)
	for i := 0; i < t; i++ {
		solve(i + 1)
	}
	_ = bufferedStdout.Flush()
}

package main

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

type void struct{}
var member void

var (
	reader bufio.Reader
	writer bufio.Writer
)

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

func solve() {
	var n int
	scan(&n)

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

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

	var mx int = -1
	for i := 1; i < n; i++ {
		if a[i - 1] > a[i] {
			mx = max(mx, pos[a[i - 1]])
		}
	}
	for i := 0; i <= mx; i++ {
		mx = max(mx, pos[a[i]])
	}

	q := make(map[int]void)
	for i := 0; i <= mx; i++ {
		q[a[i]] = member
	}

	printf("%v\n", len(q))
}

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	T = 1
	scan(&T)

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

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}

package main

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

func readLine() string {
	s, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return s
}

func readLines(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = readLine()
	}
	return res
}

func readInt() int {
	n, err := strconv.ParseInt(readLine(), 10, 32)
	if err != nil {
		panic(err)
	}
	return int(n)
}

func readInt2() (int, int) {
	as := readInts(2)
	return as[0], as[1]
}

func readInt3() (int, int, int) {
	as := readInts(3)
	return as[0], as[1], as[2]
}

func readUint() uint64 {
	n, err := strconv.ParseUint(readLine(), 10, 64)
	if err != nil {
		panic(err)
	}
	return n
}

func readInts(n int) []int {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	arr := make([]int, n)
	for k, a := range as {
		x, _ := strconv.ParseInt(a, 10, 64)
		arr[k] = int(x)
	}
	return arr
}

func readStrings(n int) []string {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	return as
}

func arr(n, m int) [][]int {
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	return a
}

const MAXN int = 1e5 + 7

var in = bufio.NewReader(os.Stdin)
var a []int = make([]int, MAXN)
var rcd []int = make([]int, MAXN)

func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, n, i int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		fmt.Fscan(in, &n)
		for i = 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
			rcd[i] = 0
		}
		if n == 1 {
			fmt.Fprintln(out, 0)
			continue
		}
		ans := 0
		for i = 1; i <= n; i++ {
			rcd[a[i]]++
			if rcd[a[i]] == 1 {
				ans++
			}
		}
		maxLen, pos, last := 0, n+1, n+1
		for pos > 1 {
			temp, val, l := pos-1, a[pos-1], 0
			if val > last {
				break
			}
			for a[temp] == val {
				temp--
				l++
			}
			if rcd[val] == l {
				maxLen += l
				last, pos = val, pos-l
				ans--
			} else {
				break
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

func main() {
	sortZeroRead()
}

func sortZeroRead() {
	in := bufio.NewReader(os.Stdin)
	var t int

	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		var n int

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

		// solve
		res := sortZero(arr, n)
		fmt.Println(res)
	}
}

func sortZero(arr []int, n int) int {
	invalid := make(map[int]bool)
	pos := make(map[int]int)
	foundInvalid := false
	start, end := -1, -1
	for i := len(arr) - 1; i > 0; i-- {
		if _, ok := pos[arr[i]]; !ok {
			pos[arr[i]] = i
		}
		if arr[i] < arr[i-1] || foundInvalid {
			invalid[arr[i-1]] = true
			posn := max(pos[arr[i-1]], i-1)
			end = max(end, posn)
			if !foundInvalid {
				start = i - 1
			}
			foundInvalid = true
		}
	}
	// check 0th element
	if foundInvalid && arr[0] != 0 {
		invalid[arr[0]] = true
		posn := max(pos[arr[0]], 0)
		end = max(end, posn)
	}

	for i := end; i > start; i-- {
		invalid[arr[i]] = true
	}

	return len(invalid)
}

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

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 t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

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

		mm := make([]bool, n+1)
		seen := []int{}
		var tot int
		for i := 0; i < n; i++ {
			if len(seen) > 0 && seen[len(seen)-1] == aa[i] {
				continue
			}

			idx := sort.SearchInts(seen, aa[i])
			if mm[aa[i]] && len(seen) > 0 || idx < len(seen) {
				for _, v := range seen {
					mm[v] = true
				}
				tot += len(seen)
				if mm[aa[i]] {
					seen = []int{}
				} else {
					seen = []int{aa[i]}
				}
			} else {
				if !mm[aa[i]] {
					seen = append(seen, aa[i])
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

// 00
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		m := make(map[int]int)
		ans := 0
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			m[a[i]] = a[i]
		}
		i := n - 2
		for i >= 0 {
			if a[i] > a[i+1] {
				break
			}
			i--
		}
		for i >= 0 {
			if m[a[i]] != 0 {
				m[a[i]] = 0
				ans++
			}
			i--
		}

		for i := 0; i < n; i++ {
			a[i] = m[a[i]]
		}

		i = n - 2
		for i >= 0 {
			if a[i] > a[i+1] {
				break
			}
			i--
		}
		for i >= 0 {
			if m[a[i]] != 0 {
				m[a[i]] = 0
				ans++
			}
			i--
		}

		fmt.Println(ans)

	}
}

package main

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

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

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

// func maxSquare(a int) int {
// 	tmp := int(math.Sqrt(float64(a)))
// 	if tmp*tmp == a {
// 		return tmp * tmp
// 	} else {
// 		return (tmp + 1) * (tmp + 1)
// 	}
// }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		slc := make([]int, n)
		count := make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &slc[i])
			count[slc[i]]++
		}
		// find rightmost non dec array; delete first part; check in map all before max
		index := 0
		for i := 1; i < n; i++ {
			if slc[i-1] > slc[i] {
				index = i
			}
		}
		//[index:len]
		m := make(map[int]int)
		for i := index; i < n; i++ {
			m[slc[i]]++
		}
		used := make(map[int]bool)
		max := 0
		res := 0
		for i := 0; i < index; i++ {
			//res += count[slc[i]]
			if !used[slc[i]] {
				res++
				used[slc[i]] = true
			}
			// slc[i]
			if m[slc[i]] > 0 {
				m[slc[i]] = 0
				if slc[i] > max {
					max = slc[i]
				}
			}
		}
		//fmt.Println("DEBUG: PREVRES", res, m)
		for k, v := range m {
			if k < max {
				res += min(v, 1)
			}
		}
		//fmt.Println("DEBUG:", index)
		fmt.Fprintln(out, res)
		// add remaining to res
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		fmt.Fprintln(out, solve())
	}
}

func solve() int {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	mp := make(map[int]bool)
	res := 0
	for {
		ok := true
		for i := n - 1; i > 0; i-- {
			if mp[a[i]] {
				a[i] = 0
			}
			if mp[a[i-1]] {
				a[i-1] = 0
			}
			// fmt.Println(a, mp)
			if a[i-1] > a[i] {
				res++
				mp[a[i-1]] = true
				a[i-1] = 0
				ok = false
			}
		}
		if ok {
			break
		}
	}
	return res
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(n, arr))
	}
}

func solve(n int, arr []int) int {
	value := [100002]int{}
	for i := 0; i <= n; i++ {
		value[i] = i
	}
	result := 0
	for {
		prev_result := result
		for i := n - 1; i > 0; i-- {
			if value[arr[i-1]] > value[arr[i]] {
				value[arr[i-1]] = 0
				result++
			}
		}
		if prev_result == result {
			return result
		}
	}
}

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

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

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

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

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

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

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

package main

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

func A2() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, ans int

		Fscan(in, &n)
		a := make([]int, n)
		cnt := make(map[int]bool)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
			cnt[a[i]] = true
		}
		m := make(map[int]bool)
		var max = a[n-1]
		var f bool
		var p = n - 1
		for i := n - 2; i >= 0; i-- {
			if a[i] > a[i+1] {
				f = true
			}
			if a[i] == max {
				p = i
			}
		}
		if f {
			Fprintln(out, len(cnt))
			return
		}
		for i := p - 1; i >= 0; i-- {
			if a[i] > max {
				if _, ok := m[a[i]]; !ok {
					ans++
					max = 0
					m[a[i]] = true
				}
			} else {
				max = a[i]
			}
		}
		Fprintln(out, ans)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A2() }

package main

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

func A2() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, ans int

		Fscan(in, &n)
		a := make([]int, n)
		cnt := make(map[int]bool)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
			cnt[a[i]] = true
		}
		m := make(map[int]bool)
		var max = a[n-1]
		var f bool
		var p = n - 1
		for i := n - 2; i >= 0; i-- {
			if a[i] > a[i+1] {
				f = true
			}
			if a[i] == max {
				p = i
			}
		}
		if p != n-1 && f {
			Fprintln(out, len(cnt))
			return
		}
		for i := p - 1; i >= 0; i-- {
			if a[i] > max {
				if _, ok := m[a[i]]; !ok {
					ans++
					max = 0
					m[a[i]] = true
				}
			}
		}
		Fprintln(out, ans)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A2() }

package main

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

func A2() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, ans int

		Fscan(in, &n)
		a := make([]int, n)
		cnt := make(map[int]bool)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
			cnt[a[i]] = true
		}
		m := make(map[int]bool)
		var max = a[n-1]
		var f bool
		var p = n - 1
		for i := n - 2; i >= 0; i-- {
			if a[i] > a[i+1] {
				f = true
			}
			if a[i] == max {
				p = i
				break
			}
		}
		if p != n-1 && f {
			Fprintln(out, len(cnt))
			return
		}
		for i := p - 1; i >= 0; i-- {
			if a[i] > max {
				if _, ok := m[a[i]]; !ok {
					ans++
					max = 0
					m[a[i]] = true
				}
			}
		}
		Fprintln(out, ans)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A2() }

package main

import "fmt"

func main() {

	t := 0
	if _, err := fmt.Scan(&t); err != nil {
		return
	}

	for ; t > 0; t-- {
		n, ans := 0, 0
		if _, err := fmt.Scan(&n); err != nil {
			return
		}
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			if _, err := fmt.Scan(&nums[i]); err != nil {
				return
			}
		}
		indices := make(map[int]int)
		zero := make(map[int]bool)
		for i := n - 1; i > 0; i-- {
			if _, ok := indices[nums[i]]; !ok {
				indices[nums[i]] = i
			}
			if nums[i-1] > nums[i] {
				k := 0
				if v, ok := indices[nums[i-1]]; ok {
					k = v
				} else {
					k = i - 1
				}
				for j := 0; j <= k; j++ {
					if _, ok := zero[nums[j]]; !ok {
						zero[nums[j]] = true
						ans++
					}
				}
				break
			}
		}
		fmt.Println(ans)
	}
}

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		if n == 1 {
			Fprintln(out, 0)
			continue
		}
		a := make([]int, n)
		// 统计 a[i] 最早出现位置
		mp := map[int]int{}
		cnt := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			cnt[i] = len(mp)
			if _, ok := mp[a[i]]; !ok {
				mp[a[i]] = i
			}
		}
		j := n-1
		for ; j >= 0; j-- {
			if i, ok := mp[a[j]]; ok && i < j-1 {
				break
			}
			if j >= 1 && a[j] < a[j-1] {
				break
			}
		}
		if j >= 0 {
			Fprintln(out, cnt[j])
		} else {
			Fprintln(out, 0)
		}
	}
}

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

package main

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

func Solve(_in io.Reader, _out io.Writer) {
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		if n == 1 {
			Fprintln(out, 0)
			continue
		}
		a := make([]int, n)
		// 统计 a[i] 最早出现位置
		mp := map[int]int{}
		cnt := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			cnt[i] = len(mp)
			if _, ok := mp[a[i]]; !ok {
				mp[a[i]] = i
			}
		}
		j := n-1
		for ; j >= 0; j-- {
			if i, ok := mp[a[j]]; ok && i < j {
				break
			}
			if j >= 1 && a[j] < a[j-1] {
				break
			}
		}
		if j >= 0 {
			Fprintln(out, cnt[j])
		} else {
			Fprintln(out, 0)
		}
	}
}

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

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	l, r := 0, n+1
	ans := n
	for l <= r {
		border := (l + r) / 2
		localAns := 0
		var s set[int]
		for i := 0; i < border; i++ {
			if !s.has(arr[i]) {
				localAns++
				s.add(arr[i])
			}
		}
		skip := false
		for i := border; i < n; i++ {
			if (i != border && s.has(arr[i])) || (i < n-1 && arr[i] > arr[i+1]) {
				skip = true
				break
			}
		}
		if skip {
			l = border + 1
		} else {
			r = border - 1
			ans = min(ans, localAns)
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	l, r := 0, n+1
	ans := n
	for l <= r {
		border := (l + r) / 2
		localAns := 0
		var s set[int]
		for i := 0; i < border; i++ {
			if !s.has(arr[i]) {
				localAns++
				s.add(arr[i])
			}
		}
		skip := false
		for i := border; i < n; i++ {
			if s.has(arr[i]) || (i < n-1 && arr[i] > arr[i+1]) {
				skip = true
				break
			}
		}
		if skip {
			l = border + 1
		} else {
			r = border - 1
			ans = min(ans, localAns)
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}


package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ans := make(chan bool)
	for group := 0; group < m; group++ {
		var k int
		fmt.Scan(&k)
		arr := make([]int, k)
		for person := 0; person < k; person++ {
			fmt.Scan(&arr[person])
		}
		go func() {
			m := make(map[int]bool)
			for _, i := range arr {
				m[i] = true
			}
			for _, i := range arr {
				if m[-i] {
					ans <- true
					return
				}
			}
			ans <- false
		}()
	}
	for i := 0; i < m; i++ {
		x := <-ans
		if x == false {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	ans := "NO"
	for i := 0; i < m; i++ {
		k := readInt()
		a := make([]int, n+1)
		cancel := true
		for j := 0; j < k; j++ {
			v := readInt()
			if a[abs(v)] == -v {
				cancel = false
			}
			a[abs(v)] = v
		}
		if cancel {
			ans = "YES"
		}
	}
	fmt.Println(ans)
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func main() {
	var flag, globalflag bool
	var line string
	var n, m, tmp int
	var arrS []string
	var arrI, arrTmp []int
	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		arrI, arrTmp = []int{}, []int{}
		line, _ = reader.ReadString('\n')
		arrS = strings.Split(strings.TrimSpace(line), " ")
		for j := range arrS {
			tmp, _ = strconv.Atoi(arrS[j])
			arrI = append(arrI, tmp)
		}
		arrI = arrI[1:]
		for h := 0; h < len(arrI); h++ {
			for g := 0; g < len(arrTmp); g++ {
				if -arrI[h] == arrTmp[g] {
					flag = true
					break
				}
			}
			if flag {
				break
			} else {
				arrTmp = append(arrTmp, arrI[h])
			}
		}
		if flag {
			flag = false
		} else {
			globalflag = true
			break
		}
	}
	if globalflag {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m, k int
	var v float64
	var output string

	fmt.Scan(&n, &m)

	output = "NO"

	for i := 0; i < m; i++ {
		fmt.Scan(&k)
		tmpMap := make(map[float64]int)

		for z := 0; z < k; z++ {
			fmt.Scan(&v)
			tmpMap[v] = 1
		}

		tmpMap2 := make(map[float64]int)

		for k := range tmpMap {
			tmpMap2[math.Abs(k)] = tmpMap2[math.Abs(k)] + 1
		}

		tmpCount := 0

		for _, v := range tmpMap2 {
			if v == 1 {
				tmpCount++
			}
		}

		if tmpCount == len(tmpMap) {
			output = "YES"
			continue
		}
	}
	fmt.Println(output)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m, k int
	var tmp float64
	var output string

	fmt.Scan(&n, &m)

	output = "NO"

	for i := 0; i < m; i++ {
		fmt.Scan(&k)
		tmpMap := make(map[float64]float64)

		for z := 0; z < k; z++ {
			fmt.Scan(&tmp)
			tmpAbs := math.Abs(tmp)
			tmpMap[tmpAbs] = tmpMap[tmpAbs] + 1
		}

		tmpCount := 0

		for _, v := range tmpMap {
			if v == 1 {
				tmpCount++
			}
		}
		// fmt.Println(tmpCount, len(tmpMap))
		if tmpCount == len(tmpMap) {
			output = "YES"
			continue
		}
	}
	fmt.Println(output)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m, k int
	var tmp float64
	var output string

	fmt.Scan(&n, &m)

	output = "NO"

	for i := 0; i < m; i++ {
		fmt.Scan(&k)
		tmpMap := make(map[float64]float64)

		for z := 0; z < k; z++ {
			fmt.Scan(&tmp)
			tmpAbs := math.Abs(tmp)
			tmpMap[tmpAbs] = tmpMap[tmpAbs] + 1
		}

		if len(tmpMap) == 1 {
			output = "YES"
			continue
		}

		tmpCount := 0

		for _, v := range tmpMap {
			if v == 1 {
				tmpCount++
			}
		}
		// fmt.Println(tmpCount, len(tmpMap))
		if tmpCount == len(tmpMap) {
			output = "YES"
			continue
		}
	}
	fmt.Println(output)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m, k int
	var v float64
	var output string

	fmt.Scan(&n, &m)

	output = "NO"

	for i := 0; i < m; i++ {
		fmt.Scan(&k)
		tmpMap := make(map[float64]int)

		for z := 0; z < k; z++ {
			fmt.Scan(&v)
			tmpMap[math.Abs(v)] = tmpMap[math.Abs(v)] + 1
		}

		tmpCount := 0

		for _, v := range tmpMap {
			if v == 1 {
				tmpCount++
			}
		}

		if tmpCount == len(tmpMap) {
			output = "YES"
			continue
		}
	}
	fmt.Println(output)
}

package main

import (
	"fmt"
)

func main() {
	var n, m, k, ch int
	var arr []int
	var flag bool
	var globalflag bool
	fmt.Scanf("%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		arr = []int{}
		fmt.Scanf("%d", &k)
		for j := 0; j < k; j++ {
			fmt.Scanf("%d", &ch)
			for l := 0; l < len(arr); l++ {
				if -ch == arr[l] {
					flag = true
					break
				}
			}
			if flag {
				break
			} else {
				arr = append(arr, ch)
			}
		}
		if flag {
			//fmt.Printf("Group %d is OK\n", i)
			flag = false
		} else {
			//fmt.Printf("Group %d is not OK\n", i)
			globalflag = true
			break
		}
	}
	if globalflag {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func ReadInt32() int64 {
	scanner.Scan()
	return toInt(scanner.Bytes())
}

func toInt(buf []byte) (n int64) {
	for _, v := range buf {
		n = n*10 + int64(v-'0')
	}
	return n
}

func main() {
	//:	fmt.Print64(strconv.IntSize)
	scanner.Split(bufio.ScanWords)

	//var n int64
	m := ReadInt32()
	var totalWeight [1000040]int
	var length int = 1000040
	var result int
	for ; m > 0; m-- {
		wi := ReadInt32()
		totalWeight[wi]++
	}

	for i := 0; i < length; i++ {
		if totalWeight[i] > 1 {
			totalWeight[i+1] += totalWeight[i] / 2
			totalWeight[i] = totalWeight[i] % 2
		}
		result += totalWeight[i]

	}
	fmt.Print(result)

}

package main

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

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

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  weights := make([]int, n)
  for i := range weights {
    weights[i] = getI()
  }
  sort.Ints(weights)
  result := 0
  power := weights[0]
  count := 1
  for i := 1; i < n; i++ {
    w := weights[i]
    for power < w {
      result += count % 2
      count /= 2
      power += 1
    }
    count += 1
  }
  for count != 0 {
    result += count % 2
    count /= 2
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

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

	fmt.Fscanln(reader, &n)
	cnt := make([]int, 1e6+1e4)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &t)
		cnt[t]++
	}

	res := 0

	for i := 0; i <= 1e6 + 1000; i++ {
		cnt[i+1] += cnt[i] / 2
		cnt[i] %= 2
		res += cnt[i]
	}

	fmt.Println(res)
}

package main

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

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

	fmt.Fscanln(reader, &n)
	cnt := make([]int, 1e6+10)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &t)
		cnt[t]++
	}

	res := 0

	for i := 0; i <= 1e6 + 5; i++ {
		cnt[i+1] += cnt[i] / 2
		cnt[i] %= 2
		res += cnt[i]
	}

	fmt.Println(res)
}

package main

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

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

	fmt.Fscanln(reader, &n)
	cnt := make([]int, 1e6+5)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &t)
		cnt[t]++
	}

	res := 0

	for i := 0; i <= 1e6; i++ {
		cnt[i+1] += cnt[i] / 2
		cnt[i] %= 2
		res += cnt[i]
	}

	fmt.Println(res)
}

package main

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

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

	fmt.Fscanln(reader, &n)
	cnt := make([]int, 1e6+5)

	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		cnt[t]++
	}

	res := 0

	for i := 0; i <= 1e6; i++ {
		cnt[i+1] = cnt[i] / 2
		cnt[i] %= 2
		res += cnt[i]
	}

	fmt.Println(res)
}


package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var a, b string

func main() {
	fmt.Fscan(reader, &n, &a, &b)
	ans := 0
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			if i == n-1 {
				ans++
			} else if a[i] == b[i+1] && a[i+1] == b[i] {
				ans++
				i++
			} else {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

package main

import."fmt"
import"bufio"
import"os"

func main(){
	in:=bufio.NewReader(os.Stdin)
	var n int
	var a,b string
	Fscan(in,&n,&a,&b)

	if n==1{
		if a==b{
			Print(0)
		}else{
			Print(1)
		}
		return
	}
	cnt:=0
	prev:=byte('x')
	if a[0]!=b[0]{
		cnt=1
		prev=a[0]
	}
	for i:=1;i<n;i++{
		if a[i]==b[i]{
			prev='x'
			continue
		}
		if prev=='x'||prev==a[i]{
			cnt++
			if prev=='x'{
				prev=a[i]
			}
			continue
		}
		prev='x'
	}
	Print(cnt)
}

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 abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	defer writer.Flush()
	var n int
	scanf("%d\n", &n)
	var a, b string
	scanf("%s\n", &a)
	scanf("%s\n", &b)
	var aa, bb []byte
	aa = []byte(a)
	bb = []byte(b)
	swaps := 0
	toggles := 0
	for i := 0; i < n; i++ {
		if aa[i] != bb[i] {
			for j := i + 1; j < n; j++ {
				if aa[j] == bb[i] {
					aa[j] = aa[i]
					//	printf("%d %d\n", j, i)
					swaps += (j - i)
					break
				}
			}
		}
	}
	//printf("%v %v\n", aa, bb)
	//printf("%d %d\n", toggles, swaps)
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			toggles++
		}
	}
	printf("%d\n", min(toggles, swaps))
	// dp := make([][]int, n)
	// for i := 0; i < n; i++ {
	// 	dp[i] = make([]int, 2)
	// }
	// if a[0] == b[0] {
	// 	if a[0] == 0 {
	// 		dp[0][0] = 0
	// 		dp[0][1] = 1
	// 	} else {
	// 		dp[0][0] = 1
	// 		dp[0][1] = 0
	// 	}
	// }
	// for i := 1; i < n; i++ {
	// 	dp[i][0] = 1000
	// 	dp[i][1] = 1000
	// 	swap := 1000
	// 	if a[i] == b[i] {
	// 		if a[i] == 0 {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1])
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 		} else {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1])
	// 		}
	// 	}
	// 	for j := 0; j <= i; j++ {
	// 		if a[i] == 1 {
	// 			swap = min(swap, dp[j][1]+abs(j-i))
	// 		} else {
	// 			swap = min(swap, dp[j][0]+abs(j-i))
	// 		}
	// 		if a[j] != b[i] {
	// 			printf("(%v, %v) %v\n", i, j, swap)
	// 			if a[j] == 1 {
	// 				dp[i][1] = min(dp[i][1], swap+1)
	// 				dp[i][0] = min(dp[i][0], swap+0)
	// 			} else {
	// 				dp[i][1] = min(dp[i][1], swap+0)
	// 				dp[i][0] = min(dp[i][0], swap+1)
	// 			}
	// 		}
	// 	}
	// 	printf("swap=%v\n", swap)
	// }
	// printf("%v\n", dp)
	// printf("%d\n", min(dp[n-1][0], dp[n-1][1]))
}

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 abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	defer writer.Flush()
	var n int
	scanf("%d\n", &n)
	var a, b string
	scanf("%s\n", &a)
	scanf("%s\n", &b)
	var aa, bb []byte
	aa = []byte(a)
	bb = []byte(b)
	swaps := 0
	toggles := 0
	for i := 0; i < n; i++ {
		if aa[i] != bb[i] {
			for j := i + 1; j < n; j++ {
				if aa[j] == bb[i] && aa[i] == bb[j] {
					aa[j] = aa[i]
					//printf("%d %d\n", j, i)
					swaps += (j - i)
					break
				}
			}
		}
	}
	if swaps == 0 {
		swaps = 1000000
	}
	//printf("%v %v\n", aa, bb)
	//printf("%d %d\n", toggles, swaps)
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			toggles++
		}
	}
	printf("%d\n", min(toggles, swaps))
	// dp := make([][]int, n)
	// for i := 0; i < n; i++ {
	// 	dp[i] = make([]int, 2)
	// }
	// if a[0] == b[0] {
	// 	if a[0] == 0 {
	// 		dp[0][0] = 0
	// 		dp[0][1] = 1
	// 	} else {
	// 		dp[0][0] = 1
	// 		dp[0][1] = 0
	// 	}
	// }
	// for i := 1; i < n; i++ {
	// 	dp[i][0] = 1000
	// 	dp[i][1] = 1000
	// 	swap := 1000
	// 	if a[i] == b[i] {
	// 		if a[i] == 0 {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1])
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 		} else {
	// 			dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + 1
	// 			dp[i][1] = min(dp[i-1][0], dp[i-1][1])
	// 		}
	// 	}
	// 	for j := 0; j <= i; j++ {
	// 		if a[i] == 1 {
	// 			swap = min(swap, dp[j][1]+abs(j-i))
	// 		} else {
	// 			swap = min(swap, dp[j][0]+abs(j-i))
	// 		}
	// 		if a[j] != b[i] {
	// 			printf("(%v, %v) %v\n", i, j, swap)
	// 			if a[j] == 1 {
	// 				dp[i][1] = min(dp[i][1], swap+1)
	// 				dp[i][0] = min(dp[i][0], swap+0)
	// 			} else {
	// 				dp[i][1] = min(dp[i][1], swap+0)
	// 				dp[i][0] = min(dp[i][0], swap+1)
	// 			}
	// 		}
	// 	}
	// 	printf("swap=%v\n", swap)
	// }
	// printf("%v\n", dp)
	// printf("%d\n", min(dp[n-1][0], dp[n-1][1]))
}


/*
URL:
https://codeforces.com/problemset/problem/1311/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t    int
	n, m int
	S    []rune
	P    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		S = ReadRuneSlice()
		P = ReadIntSlice(m)

		solve()
	}
}

func solve() {
	B := [30][]int{}
	pref := [30][]int{}
	for i := 0; i < ALPHABET_NUM; i++ {
		B[i] = make([]int, n)
		pref[i] = make([]int, n+1)
	}

	for i := 0; i < n; i++ {
		B[S[i]-'a'][i]++
	}

	for i := 0; i < ALPHABET_NUM; i++ {
		for j := 0; j < n; j++ {
			pref[i][j+1] = pref[i][j] + B[i][j]
		}
	}

	answers := [30]int64{}

	for i := 0; i < m; i++ {
		p := P[i]
		for j := 0; j < ALPHABET_NUM; j++ {
			answers[j] += int64(pref[j][p])
		}
	}
	for j := 0; j < ALPHABET_NUM; j++ {
		answers[j] += int64(pref[j][n])
	}

	fmt.Println(PrintInts64Line(answers[:ALPHABET_NUM]...))
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

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

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		stringValue := ScanWord()
		pArray := ScanIntSlice(m)
		answerArray := make([]int, 26)
		processArray := make([]int, n+1)
		sum := 1
		stringValue = "." + stringValue

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

		for i := 0; i < 26; i++{
			answerArray[i] = 0
		}

		for i := 1; i <= m; i++{
			processArray[1]++
			processArray[pArray[i-1]+1]--
		}

		for i := 1; i <= n; i++{
			sum += processArray[i]
			answerArray[stringValue[i] - 'a'] += sum
		}

		for i := 0; i < 26; i++{
			fmt.Print(answerArray[i]," ")

		}

		fmt.Println()
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {

	// var t int
	// fmt.Scan(&t)
	t := ScanInt()
	for ; t > 0; t-- {
		a, b := ScanInt(), ScanInt()
		// var s1 string
		// fmt.Scan(&s1)
		s1 := ScanWord()
		count := make([]int, a)
		p := ScanIntSlice(b)
		for i := 0; i < b; i++ {
			count[p[i]-1]++
		}
		for i := a - 2; i >= 0; i-- {
			count[i] += count[i+1]
		}
		alpha := make([]int, 26)
		for i := 0; i < a; i++ {
			alpha[s1[i]-'a'] += count[i]
		}
		for _, c := range s1 {
			alpha[c-'a']++
		}
		for i := 0; i < 26; i++ {
			fmt.Print(alpha[i], " ")

		}

	}
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

const MAXN = 200010

var f [MAXN]int
var cnt, res [26]int
var s string

func main() {
	var t int
	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)
	for test := 1; test <= t; test++ {
		s := readLine(reader)
		ss := strings.Split(string(s), " ")
		n, _ := strconv.Atoi(ss[0])
		m, _ := strconv.Atoi(ss[1])

		str := readLine(reader)

		s = readLine(reader)
		ss = strings.Split(string(s), " ")

		for i := 1; i <= n; i++ {
			f[i] = 0
		}
		for i := 0; i < m; i++ {
			x, _ := strconv.Atoi(ss[i])
			f[x]++
		}
		f[n]++

		for i := 0; i < 26; i++ {
			cnt[i] = 0
			res[i] = 0
		}

		for i := 1; i <= n; i++ {
			cnt[str[i-1]-'a']++
			if f[i] > 0 {
				for j := 0; j < 26; j++ {
					res[j] += f[i] * cnt[j]
				}
			}
		}

		for i := 0; i < 26; i++ {
			fmt.Printf("%d ", res[i])
		}
		fmt.Println()
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

/**
 * Copyright shopee
 * @Author : Yuxiang.Lei
 * @MailBox: Yuxiang.Lei@shopee.com
 * @Date : 2020-02-24
 * @Version: v2.4
 **/

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		s := readLine(reader)
		ss := strings.Split(string(s), " ")
		n, _ := strconv.Atoi(ss[0])
		m, _ := strconv.Atoi(ss[1])
		str := readLine(reader)
		s = readLine(reader)
		ss = strings.Split(string(s), " ")
		nums := make([]int, 0)
		mnums := make(map[int]int)
		result := make([]int, 26)
		for i := 0; i < m; i++ {
			temp, _ := strconv.Atoi(ss[i])
			if count, ok := mnums[temp-1]; ok {
				count++
				mnums[temp-1] = count
			} else {
				nums = append(nums, temp-1)
				mnums[temp-1] = 1
			}
		}
		sort.Ints(nums)
		j, wloc, times :=0, nums[0], mnums[nums[0]]
		sum := m
		// fmt.Println(nums, mnums)
		for i:=0;i<n;i++ {
			// fmt.Println(result)
			index := str[i] - 'a'
			if i < wloc {
				result[index] += sum + 1
				continue
			}
			if i<= wloc {
				result[index] += sum + 1
				j++
				if j < len(nums) {
					sum -= times
					wloc = nums[j]
					times = mnums[wloc]
				}
				// fmt.Println(j, wloc, times, sum)
				continue
			}
			result[index]++

		}
		for i:=0;i<len(result);i++ {
			fmt.Printf("%d ", result[i])
		}
		fmt.Println()
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, n, m, v int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &s)
		d := make([]int, n)
		for d[0] = m; m > 0; m-- {
			Fscan(in, &v)
			d[v]--
		}
		cnt, c := [26]int{}, 0
		for i, v := range d {
			c += v
			cnt[s[i]-'a'] += c + 1
		}
		for _, v := range cnt {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		stringValue := ScanWord()
		pArray := ScanIntSlice(m)
		answerArray := make([]int, 26)
		processArray := make([]int, n+1)
		sum := 1
		stringValue = "." + stringValue

		//for i := 1; i<= n; i++{
		//	processArray[i] = 0
		//}
		//
		//for i := 0; i < 26; i++{
		//	answerArray[i] = 0
		//}

		for i := 1; i <= m; i++{
			processArray[1]++
			processArray[pArray[i-1]+1]--
		}

		for i := 1; i <= n; i++{
			sum += processArray[i]
			answerArray[stringValue[i] - 'a'] += sum
		}

		for i := 0; i < 26; i++{
			fmt.Print(answerArray[i]," ")

		}

		fmt.Println()
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}


package main

import "fmt"

func main() {
    var n int
    var s string
    fmt.Scan(&n)
    fmt.Scan(&s)
    ans, cnt, prev, b := 0, 0, byte(0), 0
    for i := 0; i < len(s); i++ {
        if b == 0 {
            if cnt >= 3 { ans++ }
            if prev == 0 { prev = s[i] }
        } else {
            if s[i] == prev {
                cnt++
            } else {
                prev = s[i]
                cnt = 1
            }
        }
        b = (b+1)%n
    }
    fmt.Println(ans)
}

package main
import (
	"fmt"
	//"sort"
	"unicode/utf8"
)
func main() {
	var n,hsl int
	var s string
	fmt.Scan(&n,&s)
	d:=utf8.RuneCountInString(s)
	for i:=n;i<d;i+=n {
		if s[i-3]==s[i-2] && s[i-2]==s[i-1] {
			hsl++
		}
	}
	fmt.Println(hsl)
}

package main

import "fmt"

func main() {
	var input string
	var num, ans int = 0, 0
	fmt.Scan(&num, &input)
	for i:=0; i<len(input); i++ {
		if (i%num==0) && (i>=3) && (input[i-1] == input[i-2]) && (input[i-1] == input[i-3]){
			ans++
		}
	}
	fmt.Println(ans)
}

package main

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

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

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

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

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

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

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

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

func next() string { sc.Scan(); return sc.Text() }

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

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

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

func main() {
  n := ni32()
  s := next()
  m := len(s)
  who := make([]int, m)
  who[0] = 0
  for i := 1; i < m; i++ {
    who[i] = (who[i-1] + 1) % n
  }
  ans := 0
  for i := 3; i < m; i++ {
    if who[i] == 0 {
      if s[i-1] == s[i-2] && s[i-1] == s[i-3] {
        ans++
      }
    }
  }
  pri32(ans)
  w.Flush()
}

// 332A-mic
package main

import (
    "fmt"
)

func main() {
    var n, q, j int
    var s string
    fmt.Scan(&n)
    fmt.Scan(&s)
    if len(s) < 4 {
        fmt.Println("0")
        return
    }

    for q = n; q < len(s); q += n {
        if s[q-1] == s[q-2] {
            if s[q-2] == s[q-3] {
                j++
            }
        }
    }
    fmt.Println(j)
}

package main

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

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

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

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

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

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

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

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

func next() string { sc.Scan(); return sc.Text() }

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

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

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

func main() {
  n := ni32()
  s := next()
  m := len(s)
  who := make([]int, m)
  who[0] = 0
  for i := 1; i < m; i++ {
    who[i] = (who[i-1] + 1) % n
  }
  ans := 0
  for i := 3; i < m; i++ {
    if who[i] == 0 {
      if who[i-1] == 0 {
        if who[i-2] == 0 || who[i-3] == 0 || s[who[i-2]] == s[who[i-3]] {
          ans++
        }
      } else if who[i-2] == 0 {
        if who[i-1] == 0 || who[i-3] == 0 || s[who[i-1]] == s[who[i-3]] {
          ans++
        }
      } else if who[i-3] == 0 {
        if who[i-1] == 0 || who[i-2] == 0 || s[who[i-1]] == s[who[i-2]] {
          ans++
        }
      } else if s[who[i-1]] == s[who[i-2]] && s[who[i-1]] == s[who[i-3]] {
        ans++
      }
    }
  }
  pri32(ans)
  w.Flush()
}

package main

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

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

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

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

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

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

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

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

func next() string { sc.Scan(); return sc.Text() }

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

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

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

func main() {
  n := ni32()
  s := next()
  m := len(s)
  who := make([]int, m)
  for i := 1; i < m; i++ {
    who[i] = (who[i-1] + 1) % n
  }
  ans := 0
  for i := 3; i < m; i++ {
    if who[i] == 0 {
      if s[who[i-1]] == s[who[i-2]] && s[who[i-1]] == s[who[i-3]] {
        ans++
      }
    }
  }
  pri32(ans)
  w.Flush()
}