You are given a string $$$s$$$ consisting of the characters 0, 1, and ?.Let's call a string unstable if it consists of the characters 0 and 1 and any two adjacent characters are different (i. e. it has the form 010101... or 101010...).Let's call a string beautiful if it consists of the characters 0, 1, and ?, and you can replace the characters ? to 0 or 1 (for each character, the choice is independent), so that the string becomes unstable.For example, the strings 0??10, 0, and ??? are beautiful, and the strings 00 and ?1??1 are not.Calculate the number of beautiful contiguous substrings of the string $$$s$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of test cases. The first and only line of each test case contains the string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$) consisting of characters 0, 1, and ?. It is guaranteed that the sum of the string lengths over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the number of beautiful substrings of the string $$$s$$$.

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n",&t)
	for i := 0; i < t; i++ {
		var s string
		result := int64(0)
		tail := int64(0)
		q := -1
		qcount := 0
		fmt.Scanf("%s\n",&s)
		for j := 0; j < len(s); j++ {
			if s[j] == '?' {
				if q < 0 {
					q = j
					qcount++
					tail = tail + 1
				} else {
					qcount++
					tail = tail + 1
				}
			} else {
				if q < 0 {
					if j == 0 {
						tail = 1
					} else if s[j] == s[j-1] {
						tail = 1
					} else {
						tail = tail + 1
					}
				} else {
					if q == 0 {
						tail = tail + 1
					} else if s[q-1] == s[j] && qcount % 2 == 1 {
						tail = tail + 1
					} else if s[q-1] != s[j] && qcount % 2 == 0 {
						tail = tail + 1
					} else {
						tail = int64(qcount) + 1
					}
					q = -1
					qcount = 0
				}
			}
			result += tail
		}
		fmt.Printf("%d\n",result)
	}
}

package main

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

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(Case int){

	var str []byte
	fmt.Fscan(in,&str)
	ans := int64(0)
	dp := make([]int64,2)

	for i , v := range str{

		if i == 0{
			if v == '0'{
			dp[0] = 1
			dp[1] = 0
			} else if v == '1'{
				dp[0] = 0
				dp[1] = 1
			}else{
				dp[0] = 1
				dp[1] = 1
			}
		}else {
			if v == '0'{
			dp[0] = 1 + dp[1]
			dp[1] = 0
			}else if v == '1'{
				dp[1] = 1 + dp[0]
				dp[0] = 0

			}else{
				dp[0] , dp[1] = 1+dp[1] , 1+dp[0]

			}

	}
		ans += max(dp[0],dp[1])
	}
	fmt.Fprintln(out , ans)
}

	T := 1

	fmt.Fscan(in ,&T)

	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

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

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

func main(){

	run(os.Stdin , os.Stdout)
}

package main
import (
	"os"
	"bufio"
	"fmt"
)

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 readline() (string, error) { return reader.ReadString('\n') }

type S struct {
	z, o, b int;
}
func solve() {
	var s string
	scanf("%s\n", &s)
	N := len(s)
	dd := make([]S, N+1)
	dd[0] = S{0, 0, 0}
	for i:=1; i<=N; i++ {
		switch s[i-1] {
		case '0':
			dd[i].z = dd[i-1].o + 1
			dd[i].o = 0
			dd[i].b = 0
		case '1':
			dd[i].z = 0
			dd[i].o = dd[i-1].z + 1
			dd[i].b = 0
		default:
			dd[i].z = dd[i-1].o + 1
			dd[i].o = dd[i-1].z + 1
			dd[i].b = dd[i-1].b + 1
		}
	}
	var ans int64 = 0
	for i:=1; i<=N; i++ {
		ans += int64(dd[i].z + dd[i].o - dd[i].b)
	}
	printf("%d\n", ans)
}

func main() {
	// defer writer.Flush()
	var tc int
	scanf("%d\n", &tc)
	// tc = 1
	for ; tc>0; tc-- {
		solve()
		writer.Flush()
	}
}

package main

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

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

	solve := func(Case int) {
		var s []byte
		Fscan(in, &s)
		ans := int64(0)
		dp := [2]int64{}
		for i, b := range s {
			if i == 0 {
				if b == '0' {
					dp[0] = 1
					dp[1] = 0
				} else if b == '1' {
					dp[1] = 1
					dp[0] = 0
				} else {
					dp[0] = 1
					dp[1] = 1
				}
			} else {
				if b == '0' {
					dp[0] = 1 + dp[1]
					dp[1] = 0
				} else if b == '1' {
					dp[1] = 1 + dp[0]
					dp[0] = 0
				} else {
					dp[0], dp[1] = 1+dp[1], 1+dp[0]
				}
			}
			ans += max(dp[0], dp[1])
		}
		Fprintln(out, ans)
	}

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

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

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

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

package main

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

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

	solve := func(Case int) {
		//if Case == 2 {
		//	print()
		//}
		var s []byte
		Fscan(in, &s)
		ans := int64(0)
		dp := [2]int64{}
		for i, b := range s {
			if i == 0 {
				if b == '0' {
					dp[0] = 1
					dp[1] = 0
				} else if b == '1' {
					dp[1] = 1
					dp[0] = 0
				} else {
					dp[0] = 1
					dp[1] = 1
				}
			} else {
				if b == '0' {
					dp[0] = 1 + dp[1]
					dp[1] = 0
				} else if b == '1' {
					dp[1] = 1 + dp[0]
					dp[0] = 0
				} else {
					dp[0], dp[1] = 1+dp[1], 1+dp[0]
				}
			}
			//println(dp[0], dp[1])
			ans += max(dp[0], dp[1])
		}
		//Println()
		Fprintln(out, ans)
	}

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

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

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

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

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var s string
		fmt.Fscan(in, &s)
		dp := [2]int64{}
		ans := int64(0)
		for _, c := range s {
			switch string(c) {
			case "0":
				dp[0] = dp[1] + 1
				dp[1] = 0
			case "1":
				dp[1] = dp[0] + 1
				dp[0] = 0
			default:
				dp[0], dp[1] = 1+dp[1], 1+dp[0]
			}
			ans += max(dp[0], dp[1])
		}
		fmt.Fprintln(out, ans)
	}
}

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)
	for ; t > 0; t-- {
		var s string
		fmt.Scanln(&s)
		dp := [2]int64{}
		ans := int64(0)
		for _, c := range s {
			switch string(c) {
			case "0":
				dp[0] = dp[1] + 1
				dp[1] = 0
			case "1":
				dp[1] = dp[0] + 1
				dp[0] = 0
			default:
				dp[0], dp[1] = 1+dp[1], 1+dp[0]
			}
			ans += max(dp[0], dp[1])
		}
		fmt.Println(ans)
	}
}

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

package main

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

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

	n:= io.NextInt()
	for i := 0; i < n; i++ {
		s := io.Next()
		var ans,k int64
		d:=make([]int64,2)
		for i:=range d{
		    d[i]=-1
		}
		k=0
		for i:=range s{
		    if(s[i]=='0'){
		        d[(i%2)]=k
		    }else if(s[i]=='1'){
		        d[(i%2)^1]=k
		    }
		    ans+=k-min(d[0],d[1])
		    k+=1
		}
		io.Println(ans)
	}
}
func min(i,j int64)int64{
    if(i>j){
        return j
    }
    return i
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

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

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

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d",&t)
	for i := 0; i < t; i++ {
		var s string
		result := int64(0)
		fmt.Scanf("%s",&s)
		for j := 0; j < len(s); j++ {
			inc := int64(0)
			q := -1
			qcount := 0
			for h := j; h >= 0; h-- {
				if h == j {
					if s[h] == '?' {
						inc++
						q = h
						qcount++
					} else {
						inc++
					}
					continue
				}

				if q >= 0 {
					if s[h] == '?' {
						qcount++
						inc++
					} else {
						if q == j {
							qcount++
							inc++
						} else {
							if s[q+1] == s[h] && qcount % 2 == 1 {
								inc++
							} else if s[q+1] != s[h] && qcount % 2 ==0 {
								inc++
							} else {
								break
							}
						}
						qcount = 0
						q = -1
					}
				} else {
					if s[h] == '?' {
						inc++
						q = h
						qcount++
					} else if s[h] != s[h+1] {
						inc++
					} else {
						break
					}
				}
			}
			result += inc
		}
		fmt.Printf("%d\n",result)
	}
}

package main

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

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(Case int){

	var str []byte
	fmt.Fscan(in,&str)
	ans := int64(0)
	dp := make([]int64,2)

	for i , v := range str{

		if i == 0{
			if v == '0'{
			dp[0] = 1
			dp[1] = 0
			} else if v == '1'{
				dp[0] = 0
				dp[1] = 1
			}else{
				dp[0] = 1
				dp[1] = 1
			}
		}else {
			if v == '0'{
			dp[0] = 1 + dp[1]
			dp[1] = 0
			}else if v == '1'{
				dp[1] = 1 + dp[0]
				dp[0] = 0

			}else{
				dp[0] , dp[1] = 1+dp[1] , 1+dp[0]

			}
			ans += max(dp[0],dp[1])

	}

	}
	fmt.Fprintln(out , ans)
}

	T := 1

	fmt.Fscan(in ,&T)

	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

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

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

func main(){

	run(os.Stdin , os.Stdout)
}

package main

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

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(Case int){

	var str []byte
	fmt.Fscan(in,&str)
	ans := int64(0)
	dp := make([]int64,2)

	for i , v := range str{

		if i == '0'{
			if v == 0{
			dp[0] = 1
			dp[1] = 0
			} else if v == '1'{
				dp[0] = 0
				dp[1] = 1
			}else{
				dp[0] = 1
				dp[1] = 1
			}
		}else {
			if v == '0'{
			dp[0] = 1 + dp[1]
			dp[1] = 0
			}else if v == '1'{
				dp[1] = 1 + dp[0]
				dp[0] = 0

			}else{
				dp[0] , dp[1] = 1+dp[1] , 1+dp[0]

			}
			ans += max(dp[0],dp[1])

	}

	}
	fmt.Fprintln(out , ans)
}

	T := 1

	fmt.Fscan(in ,&T)

	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

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

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

func main(){

	run(os.Stdin , os.Stdout)
}

package main
import (
	"os"
	"bufio"
	"fmt"
)

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 readline() (string, error) { return reader.ReadString('\n') }

type S struct {
	z, o, b int;
}
func solve() {
	s, _ := readline()
	N := len(s)-1
	dd := make([]S, N+1)
	dd[0] = S{0, 0, 0}
	for i:=1; i<=N; i++ {
		switch s[i-1] {
		case '0':
			dd[i].z = dd[i-1].o + 1
			dd[i].o = 0
			dd[i].b = 0
		case '1':
			dd[i].z = 0
			dd[i].o = dd[i-1].z + 1
			dd[i].b = 0
		default:
			dd[i].z = dd[i-1].o + 1
			dd[i].o = dd[i-1].z + 1
			dd[i].b = dd[i-1].b + 1
		}
	}
	var ans int64 = 0
	for i:=1; i<=N; i++ {
		ans += int64(dd[i].z + dd[i].o - dd[i].b)
	}
	printf("%d\n", ans)
}

func main() {
	// defer writer.Flush()
	var tc int
	scanf("%d ", &tc)
	// tc = 1
	for ; tc>0; tc-- {
		solve()
		writer.Flush()
	}
}

package main
import (
	"os"
	"bufio"
	"fmt"
)

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 readline() (string, error) { return reader.ReadString('\n') }

type S struct {
	z, o, b int;
}
func solve() {
	s, _ := readline()
	N := len(s)-1
	dd := make([]S, N+1)
	dd[0] = S{0, 0, 0}
	for i:=1; i<=N; i++ {
		switch s[i-1] {
		case '0':
			dd[i].z = dd[i-1].o + 1
			dd[i].o = 0
			dd[i].b = 0
		case '1':
			dd[i].z = 0
			dd[i].o = dd[i-1].z + 1
			dd[i].b = 0
		default:
			dd[i].z = dd[i-1].o + 1
			dd[i].o = dd[i-1].z + 1
			dd[i].b = dd[i-1].b + 1
		}
	}
	ans := 0
	for i:=1; i<=N; i++ {
		ans += dd[i].z + dd[i].o - dd[i].b
	}
	printf("%d\n", ans)
}

func main() {
	// defer writer.Flush()
	var tc int
	scanf("%d ", &tc)
	// tc = 1
	for ; tc>0; tc-- {
		solve()
		writer.Flush()
	}
}

package main

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

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

	n:= io.NextInt()
	for i := 0; i < n; i++ {
		s := io.Next()
		ans:=0
		d:=make([]int,2)
		for i:=range d{
		    d[i]=-1
		}
		for i:=range s{
		    if(s[i]=='0'){
		        d[(i%2)]=i
		    }else if(s[i]=='1'){
		        d[(i%2)^1]=i
		    }
		    ans+=i-min(d[0],d[1])
		}
		io.Println(ans)
	}
}
func min(i,j int)int{
    if(i>j){
        return j
    }
    return i
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

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

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

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


So you decided to hold a contest on Codeforces. You prepared the problems: statements, solutions, checkers, validators, tests... Suddenly, your coordinator asks you to change all your tests to multiple testcases in the easiest problem!Initially, each test in that problem is just an array. The maximum size of an array is $$$k$$$. For simplicity, the contents of arrays don't matter. You have $$$n$$$ tests — the $$$i$$$-th test is an array of size $$$m_i$$$ ($$$1 \le m_i \le k$$$).Your coordinator asks you to distribute all of your arrays into multiple testcases. Each testcase can include multiple arrays. However, each testcase should include no more than $$$c_1$$$ arrays of size greater than or equal to $$$1$$$ ($$$\ge 1$$$), no more than $$$c_2$$$ arrays of size greater than or equal to $$$2$$$, $$$\dots$$$, no more than $$$c_k$$$ arrays of size greater than or equal to $$$k$$$. Also, $$$c_1 \ge c_2 \ge \dots \ge c_k$$$.So now your goal is to create the new testcases in such a way that:   each of the initial arrays appears in exactly one testcase;  for each testcase the given conditions hold;  the number of testcases is minimum possible. Print the minimum possible number of testcases you can achieve and the sizes of arrays included in each testcase.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 2 \cdot 10^5$$$) — the number of initial tests and the limit for the size of each array. The second line contains $$$n$$$ integers $$$m_1, m_2, \dots, m_n$$$ ($$$1 \le m_i \le k$$$) — the sizes of the arrays in the original tests. The third line contains $$$k$$$ integers $$$c_1, c_2, \dots, c_k$$$ ($$$n \ge c_1 \ge c_2 \ge \dots \ge c_k \ge 1$$$); $$$c_i$$$ is the maximum number of arrays of size greater than or equal to $$$i$$$ you can have in a single testcase.

In the first line print a single integer $$$ans$$$ ($$$1 \le ans \le n$$$) — the minimum number of testcases you can achieve. Each of the next $$$ans$$$ lines should contain the description of a testcase in the following format: $$$t$$$ $$$a_1$$$ $$$a_2$$$ $$$\dots$$$ $$$a_{t}$$$ ($$$1 \le t\le n$$$) — the testcase includes $$$t$$$ arrays, $$$a_i$$$ is the size of the $$$i$$$-th array in that testcase. Each of the initial arrays should appear in exactly one testcase. In particular, it implies that the sum of $$$t$$$ over all $$$ans$$$ testcases should be equal to $$$n$$$. Note that the answer always exists due to $$$c_k \ge 1$$$ (and therefore $$$c_1 \ge 1$$$). If there are multiple answers, you can output any one of them.

NoteIn the first example there is no way to distribute the tests into less than $$$3$$$ testcases. The given answer satisfies the conditions: each of the testcases includes no more than $$$4$$$ arrays of size greater than or equal to $$$1$$$ and no more than $$$1$$$ array of sizes greater than or equal to $$$2$$$ and $$$3$$$.Note that there are multiple valid answers for this test. For example, testcases with sizes $$$[[2], [1, 2], [3]]$$$ would also be correct.However, testcases with sizes $$$[[1, 2], [2, 3]]$$$ would be incorrect because there are $$$2$$$ arrays of size greater than or equal to $$$2$$$ in the second testcase.Note the difference between the third and the fourth examples. You can include up to $$$5$$$ arrays of size greater than or equal to $$$1$$$ in the third example, so you can put all arrays into a single testcase. And you can have only up to $$$1$$$ array in the fourth example. Thus, every array should be included in a separate testcase.

package main

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

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

	var n, k int
	Fscan(in, &n, &k)
	sz := make([]int, n)
	for i := range sz {
		Fscan(in, &sz[i])
	}
	sort.Ints(sz)
	uppCnt := make([]int, k)
	for i := range uppCnt {
		Fscan(in, &uppCnt[i])
	}
	ans := sort.Search(n+1, func(caseNum int) bool {
		cnt := 0
		for i := n - 1; i >= 0; i -= caseNum {
			cnt++
			if cnt > uppCnt[sz[i]-1] {
				return false
			}
		}
		return true
	})
	Fprintln(out, ans)
	for st := 0; st < ans; st++ {
		Fprint(out, (n-1-st)/ans+1)
		for i := st; i < n; i += ans {
			Fprint(out, " ", sz[i])
		}
		Fprintln(out)
	}
}

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

package main

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

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

	var n, k int
	Fscan(in, &n, &k)
	sz := make([]int, n)
	for i := range sz {
		Fscan(in, &sz[i])
	}
	sort.Ints(sz)
	uppCnt := make([]int, k)
	for i := range uppCnt {
		Fscan(in, &uppCnt[i])
	}
	ans := sort.Search(n+1, func(caseNum int) bool {
		cnt := 0
		for i := n - 1; i >= 0; i -= caseNum {
			cnt++
			if cnt > uppCnt[sz[i]-1] {
				return false
			}
		}
		return true
	})
	Fprintln(out, ans)
	for st := 0; st < ans; st++ {
		a := []interface{}{}
		for i := st; i < n; i += ans {
			a = append(a, sz[i])
		}
		Fprint(out, len(a), " ")
		Fprintln(out, a...)
	}
}

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

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n, k int
    Fscan(in, &n, &k)
    arr := make([]int, n)
    c := make([]int, k)
    for i := 0; i < n; i++ {
        Fscan(in, &arr[i])
    }
    for i := 0; i < k; i++ {
        Fscan(in, &c[i])
    }

    counter := make([]int, k)
    suffix := make([]int, k)
    for i := 0; i < n; i++ {
        counter[arr[i] - 1]++
    }

    for i := k - 1; i >= 0; i-- {
        suffix[i] = counter[i]
        if i + 1 < k {
            suffix[i] += suffix[i + 1]
        }
    }

    answer := 0
    for i := 0; i < k; i++ {
        currentValue := (suffix[i] + c[i] - 1) / c[i]
        if currentValue > answer {
            answer = currentValue
        }
    }
    Fprintln(out, answer)
    result := make([][]int, answer)
    for i := 0; i < answer; i++ {
        result[i] = make([]int, (n + answer - 1) / answer)
    }
    itr := 0
    for i := k - 1; i >= 0; i-- {
        for j := 0; j < counter[i]; j++ {
            result[itr % answer][itr / answer] = i + 1
            itr++
        }
    }

    for i := 0; i < answer; i++ {
        size := len(result[i])
        if result[i][size - 1] == 0 {
            size--
        }
        Fprint(out, size, " ")
        for j := 0; j < size; j++ {
            Fprint(out, result[i][j], " ")
        }
        Fprint(out, "\n")
    }
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
    defer out.Flush()
    var n, k int
    Fscan(in, &n, &k)
    arr := make([]int, n)
    c := make([]int, k)
    for i := 0; i < n; i++ {
        Fscan(in, &arr[i])
    }
    for i := 0; i < k; i++ {
        Fscan(in, &c[i])
    }
    counter := make([]int, k)
    suffix := make([]int, k)
    for i := 0; i < n; i++ {
        counter[arr[i] - 1]++
    }

    for i := k - 1; i >= 0; i-- {
        suffix[i] = counter[i]
        if i + 1 < k {
            suffix[i] += suffix[i + 1]
        }
    }

    answer := 0
    for i := 0; i < k; i++ {
        currentValue := (suffix[i] + c[i] - 1) / c[i]
        if currentValue > answer {
            answer = currentValue
        }
    }
    Fprintln(out, answer)
    result := make([][]int, answer)
    itr := 0
    for i := 0; i < k; i++ {
        for j := 0; j < counter[i]; j++ {
            result[itr % answer] = append(result[itr % answer], i + 1)
            itr++
        }
    }

    for i := 0; i < answer; i++ {
        Fprint(out, len(result[i]), " ");
        for j := 0; j < len(result[i]); j++ {
            Fprint(out, result[i][j], " ");
        }
        Fprint(out, "\n");
    }
}

package main

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

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

	var n, k int
	Fscan(in, &n, &k)
	sz := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &sz[i])
	}
	sort.Ints(sz)
	uppCnt := make([]int, k+1)
	for i := 1; i <= k; i++ {
		Fscan(in, &uppCnt[i])
	}

	//min := func(a, b int) int {
	//	if a < b {
	//		return a
	//	}
	//	return b
	//}
	ans := [][]interface{}{}
	for i := 1; i <= n; {
		tmp := []interface{}{sz[i]}

		//curLen := sz[i]
		maxCnt := uppCnt[sz[i]] // uppCnt[curLen]
		r := i + maxCnt
		if r > n {
			r = n
		}
		//pre := maxCnt
		//cnt:=0
		j := i + 1
		for ; j < r; j++ {
			//cnt++
			//if maxCnt == 1 {
			//	break
			//}
			tmp = append(tmp, sz[j])

			if sz[j] > sz[j-1] {
				if s := j + uppCnt[sz[j]]; s < r {
					r = s
				}
			}

			//maxCnt = min(maxCnt, uppCnt[ sz[i]]-1)

		}
		i = j

		//if upp == 1 {
		//	tmp = append(tmp, curLen)
		//	i++
		//} else {
		//	j := i
		//	for ; j <= n; j++ {
		//		if uppCnt[sz[j] ] > sz[j] {
		//			break
		//		}
		//		tmp = append(tmp, sz[j])
		//	}
		//	i = j
		//	//downSz := sz[i+upp-1]
		//	//if downSz <= uppLen[downSz] {
		//	//	j := i
		//	//	for ; j < i+upp; j++ {
		//	//		tmp = append(tmp, sz[j])
		//	//	}
		//	//	i = j
		//	//} else {
		//	//	for curLen++; curLen <= k; curLen++ {
		//	//
		//	//	}
		//	//}
		//}

		ans = append(ans, tmp)
	}

	Fprintln(out, len(ans))
	for _, an := range ans {
		Fprint(out, len(an), " ")
		Fprintln(out, an...)
	}
}

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

package main

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

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

	var n, k int
	Fscan(in, &n, &k)
	sz := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &sz[i])
	}
	sort.Ints(sz)
	uppCnt := make([]int, k+1)
	for i := 1; i <= k; i++ {
		Fscan(in, &uppCnt[i])
	}

	//min := func(a, b int) int {
	//	if a < b {
	//		return a
	//	}
	//	return b
	//}
	ans := [][]interface{}{}
	for i := 1; i <= n; {
		tmp := []interface{}{sz[i]}

		//curLen := sz[i]
		maxCnt := uppCnt[sz[i]] // uppCnt[curLen]
		r := i + maxCnt
		//if r > n {
		//	r = n
		//}
		//pre := maxCnt
		//cnt:=0
		j := i + 1
		for ; j < r; j++ {
			if j>n {
				break
			}
			//cnt++
			//if maxCnt == 1 {
			//	break
			//}
			tmp = append(tmp, sz[j])

			if sz[j] > sz[j-1] {
				if s := j + uppCnt[sz[j]]; s < r {
					r = s
				}
			}

			//maxCnt = min(maxCnt, uppCnt[ sz[i]]-1)

		}
		i = j

		//if upp == 1 {
		//	tmp = append(tmp, curLen)
		//	i++
		//} else {
		//	j := i
		//	for ; j <= n; j++ {
		//		if uppCnt[sz[j] ] > sz[j] {
		//			break
		//		}
		//		tmp = append(tmp, sz[j])
		//	}
		//	i = j
		//	//downSz := sz[i+upp-1]
		//	//if downSz <= uppLen[downSz] {
		//	//	j := i
		//	//	for ; j < i+upp; j++ {
		//	//		tmp = append(tmp, sz[j])
		//	//	}
		//	//	i = j
		//	//} else {
		//	//	for curLen++; curLen <= k; curLen++ {
		//	//
		//	//	}
		//	//}
		//}

		ans = append(ans, tmp)
	}

	Fprintln(out, len(ans))
	for _, an := range ans {
		Fprint(out, len(an), " ")
		Fprintln(out, an...)
	}
}

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

package main

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

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

	var n, k int
	Fscan(in, &n, &k)
	sz := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &sz[i])
	}
	sort.Ints(sz)
	uppCnt := make([]int, k+1)
	for i := 1; i <= k; i++ {
		Fscan(in, &uppCnt[i])
	}

	ans := [][]interface{}{}
	for i := 1; i <= n; {
		tmp := []interface{}{sz[i]}

		r := i + uppCnt[sz[i]]
		j := i + 1
		for ; j < r; j++ {
			if j > n {
				break
			}
			tmp = append(tmp, sz[j])
			if sz[j] > sz[j-1] {
				if s := j + uppCnt[sz[j]]; s < r {
					r = s
				}
			}
		}
		i = j

		ans = append(ans, tmp)
	}

	Fprintln(out, len(ans))
	for _, an := range ans {
		Fprint(out, len(an), " ")
		Fprintln(out, an...)
	}
}

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


Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they are connected by n - 1 edges so that there is a path between any pair of vertexes. A leaf is a distinct from root vertex, which is connected with exactly one other vertex.The ant wants to visit every vertex in the tree and return to the root, passing every edge twice. In addition, he wants to visit the leaves in a specific order. You are to find some possible route of the ant.

The first line contains integer n (3 ≤ n ≤ 300) — amount of vertexes in the tree. Next n - 1 lines describe edges. Each edge is described with two integers — indexes of vertexes which it connects. Each edge can be passed in any direction. Vertexes are numbered starting from 1. The root of the tree has number 1. The last line contains k integers, where k is amount of leaves in the tree. These numbers describe the order in which the leaves should be visited. It is guaranteed that each leaf appears in this order exactly once.

If the required route doesn't exist, output -1. Otherwise, output 2n - 1 numbers, describing the route. Every time the ant comes to a vertex, output it's index.

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n+1)
	g[1] = append(g[1], 0)
	for i := 1; i < n; i++ {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	l := []int{}

	ms := make([]map[int]bool, n+1)
	var f func(v, fa int) map[int]bool
	f = func(v, fa int) map[int]bool {
		ms[v] = map[int]bool{}
		if len(g[v]) == 1 {
			ms[v][v] = true
			Fscan(in, &w)
			l = append(l, w)
		}
		for _, w := range g[v] {
			if w != fa {
				for u := range f(w, v) {
					ms[v][u] = true
				}
			}
		}
		return ms[v]
	}
	f(1, 0)

	vs := []int{}
	var f2 func(int, int, []int) bool
	f2 = func(v, fa int, l []int) bool {
		if len(g[v]) == 1 {
			vs = append(vs, v)
			return l[0] == v
		}
	o:
		for len(l) > 0 {
			for _, w := range g[v] {
				if w != fa && ms[w][l[0]] {
					vs = append(vs, v)
					if !f2(w, v, l[:len(ms[w])]) {
						return false
					}
					l = l[len(ms[w]):]
					continue o
				}
			}
			break
		}
		vs = append(vs, v)
		return len(l) == 0
	}
	if f2(1, 0, l) {
		for _, v := range vs {
			Fprint(out, v, " ")
		}
		return
	}
	Fprint(out, -1)
}

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