package main import ( "bufio" "container/heap" "fmt" "os" "strconv" ) ///heap///////////////////////////////// // An IntHeap is a min-heap of ints. type IntHeap []int func (h IntHeap) Len() int { return len(h) } func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] } func (h IntHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } func (h *IntHeap) Push(x interface{}) { // Push and Pop use pointer receivers because they modify the slice's length, // not just its contents. *h = append(*h, x.(int)) } func (h *IntHeap) Pop() interface{} { old := *h n := len(old) x := old[n-1] *h = old[0 : n-1] return x } ////nextInt//////////////////////////// var s = bufio.NewScanner(os.Stdin) func next() string { s.Split(bufio.ScanWords) s.Scan() return s.Text() } func nextInt() int { i, e := strconv.Atoi(next()) if e != nil { panic(e) } return int(i) } /////solve/////////////////////////////////////// func solve(l []int) { m := make(map[int]int) //fmt.Println(l) for _, v := range l { m[v] += 1 } //fmt.Println(m) h := &IntHeap{} for _, p := range m { heap.Push(h, p) } heap.Init(h) var ans int for h.Len() >= 3 { a := make([]int, 3) ans += 1 for i := 0; i < 3; i++ { a[i] = heap.Pop(h).(int) - 1 } //fmt.Println(a) for i := 0; i < 3; i++ { if a[i] > 0 { heap.Push(h, a[i]) } } } fmt.Println(ans) } func main() { T := nextInt() L := make([][]int, T) for i := 0; i < T; i++ { N := nextInt() L[i] = make([]int, N) for j := 0; j < N; j++ { L[i][j] = nextInt() } } for i := 0; i < T; i++ { solve(L[i]) } }