package main

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

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

	var n, d int
	Fscan(in, &n)
	d1 := []int{}
	d2 := [][2]int{}
	for i := 1; i <= n; i++ {
		Fscan(in, &d)
		if d == 1 {
			d1 = append(d1, i)
		} else {
			d2 = append(d2, [2]int{i, d})
		}
	}
	for len(d1) < 2 {
		d1 = append(d1, d2[0][0])
		d2 = d2[1:]
	}
	if len(d2) == 0 {
		Fprint(out, "NO")
		return
	}
	ans := make([][2]int, 0, n-1)
	ans = append(ans,
		[2]int{d1[0], d2[0][0]},
		[2]int{d1[1], d2[len(d2)-1][0]},
	)
	for i := 1; i < len(d2); i++ {
		ans = append(ans, [2]int{d2[i-1][0], d2[i][0]})
	}
o:
	for _, v := range d1[2:] {
		for i, p := range d2 {
			if p[1] > 2 {
				ans = append(ans, [2]int{v, p[0]})
				d2[i][1]--
				continue o
			}
		}
		Fprintln(out, "NO")
		return
	}
	Fprintln(out, "YES", len(d2)+1)
	Fprintln(out, n-1)
	for _, v := range ans {
		Fprintln(out, v[0], v[1])
	}
}

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

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

type Node struct {
	idx int
	rst int
}
type NodeSlice []Node

func (n NodeSlice) Len() int           { return len(n) }
func (n NodeSlice) Less(i, j int) bool { return n[i].rst < n[j].rst }
func (n NodeSlice) Swap(i, j int)      { n[i], n[j] = n[j], n[i] }

func gao(n int, a []Node) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i].rst >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{a[lastNode].idx, a[i].idx})
				vis[a[lastNode].idx] = true
				vis[a[i].idx] = true
				a[i].rst -= 1
				a[lastNode].rst -= 1
			}
			lastNode = i
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[a[i].idx] || a[i].rst > 1 {
			rest = append(rest, i)
			restEdges += a[i].rst
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("a=%+v\nrestEdges=%v, singldeNodes=%v\n", a, restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(singleNodes) >= 2 {
		diameter += 2
	} else if len(singleNodes) == 1 {
		diameter++
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	if ptr >= 0 {
		edges = append(edges, [2]int{a[rest[len(rest)-1]].idx, a[singleNodes[ptr]].idx})
		ptr--
		a[rest[len(rest)-1]].rst--
	}
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node].rst > 0 && ptr >= 0 {
			edges = append(edges, [2]int{a[node].idx, a[singleNodes[ptr]].idx})
			a[node].rst--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	var g NodeSlice
	for i, v := range a {
		g = append(g, Node{i, v})
	}
	sort.Sort(NodeSlice(g))
	for i := 0; i < n-2; i++ {
		if g[i].rst > 1 {
			g[i], g[n-2] = g[n-2], g[i]
		}
	}
	gao(n, g)
}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

func gao(n int, a []int) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i] >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{lastNode, i})
				vis[lastNode] = true
				vis[i] = true
				a[i] -= 1
				a[lastNode] -= 1
			}
			lastNode = i
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[i] || a[i] > 1 {
			rest = append(rest, i)
			restEdges += a[i]
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("restEdges=%v, singldeNodes=%v\n", restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(singleNodes) >= 2 {
		diameter += 2
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node] > 0 && ptr >= 0 {
			edges = append(edges, [2]int{node, singleNodes[ptr]})
			a[node]--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	gao(n, a)
}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

type Node struct {
	idx int
	rst int
}
type NodeSlice []Node

func (n NodeSlice) Len() int           { return len(n) }
func (n NodeSlice) Less(i, j int) bool { return n[i].rst < n[j].rst }
func (n NodeSlice) Swap(i, j int)      { n[i], n[j] = n[j], n[i] }

func gao(n int, a []Node) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i].rst >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{lastNode, a[i].idx})
				vis[lastNode] = true
				vis[a[i].idx] = true
				a[i].rst -= 1
				a[lastNode].rst -= 1
			}
			lastNode = a[i].idx
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[i] || a[i].rst > 1 {
			rest = append(rest, i)
			restEdges += a[i].rst
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("a=%+v\nrestEdges=%v, singldeNodes=%v\n", a, restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(singleNodes) >= 2 {
		diameter += 2
	} else if len(singleNodes) == 1 {
		diameter++
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	if ptr >= 0 {
		edges = append(edges, [2]int{a[rest[len(rest)-1]].idx, singleNodes[ptr]})
		ptr--
		a[rest[len(rest)-1]].rst--
	}
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node].rst > 0 && ptr >= 0 {
			edges = append(edges, [2]int{a[node].idx, singleNodes[ptr]})
			a[node].rst--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	var g NodeSlice
	for i, v := range a {
		g = append(g, Node{i, v})
	}
	sort.Sort(NodeSlice(g))
	for i := 0; i < n-2; i++ {
		if g[i].rst > 1 {
			g[i], g[n-2] = g[n-2], g[i]
		}
	}
	gao(n, g)
}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

func gao(n int, a []int) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i] >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{lastNode, i})
				vis[lastNode] = true
				vis[i] = true
				a[i] -= 1
				a[lastNode] -= 1
			}
			lastNode = i
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[i] || a[i] > 1 {
			rest = append(rest, i)
			restEdges += a[i]
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("restEdges=%v, singldeNodes=%v\n", restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(edges) == 0 {
		if len(singleNodes) >= 2 {
			diameter = 2
		}
	} else if len(singleNodes) > 0 {
		diameter++
	}
	if len(rest) >= 2 {
		diameter++
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node] > 0 && ptr >= 0 {
			edges = append(edges, [2]int{node, singleNodes[ptr]})
			a[node]--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	gao(n, a)
}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

func gao(n int, a []int) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i] >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{lastNode, i})
				vis[lastNode] = true
				vis[i] = true
				a[i] -= 1
				a[lastNode] -= 1
			}
			lastNode = i
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[i] || a[i] > 1 {
			rest = append(rest, i)
			restEdges += a[i]
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("restEdges=%v, singldeNodes=%v\n", restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(singleNodes) > 0 {
		diameter++
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node] > 0 && ptr >= 0 {
			edges = append(edges, [2]int{node, singleNodes[ptr]})
			a[node]--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	gao(n, a)
}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

type Node struct {
	idx int
	rst int
}
type NodeSlice []Node

func (n NodeSlice) Len() int           { return len(n) }
func (n NodeSlice) Less(i, j int) bool { return n[i].rst < n[j].rst }
func (n NodeSlice) Swap(i, j int)      { n[i], n[j] = n[j], n[i] }

func gao(n int, a []Node) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i].rst >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{a[lastNode].idx, a[i].idx})
				vis[a[lastNode].idx] = true
				vis[a[i].idx] = true
				a[i].rst -= 1
				a[lastNode].rst -= 1
			}
			lastNode = i
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[i] || a[i].rst > 1 {
			rest = append(rest, i)
			restEdges += a[i].rst
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("a=%+v\nrestEdges=%v, singldeNodes=%v\n", a, restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(singleNodes) >= 2 {
		diameter += 2
	} else if len(singleNodes) == 1 {
		diameter++
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	if ptr >= 0 {
		edges = append(edges, [2]int{a[rest[len(rest)-1]].idx, a[singleNodes[ptr]].idx})
		ptr--
		a[rest[len(rest)-1]].rst--
	}
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node].rst > 0 && ptr >= 0 {
			edges = append(edges, [2]int{a[node].idx, a[singleNodes[ptr]].idx})
			a[node].rst--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	var g NodeSlice
	for i, v := range a {
		g = append(g, Node{i, v})
	}
	sort.Sort(NodeSlice(g))
	for i := 0; i < n-2; i++ {
		if g[i].rst > 1 {
			g[i], g[n-2] = g[n-2], g[i]
		}
	}
	gao(n, g)
}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

func gao(n int, a []int) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i] >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{lastNode, i})
				vis[lastNode] = true
				vis[i] = true
				a[i] -= 1
				a[lastNode] -= 1
			}
			lastNode = i
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[i] || a[i] > 1 {
			rest = append(rest, i)
			restEdges += a[i]
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("restEdges=%v, singldeNodes=%v\n", restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(edges) == 0 {
		if len(singleNodes) >= 2 {
			diameter = 2
		}
	} else if len(singleNodes) > 0 {
		diameter++
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node] > 0 && ptr >= 0 {
			edges = append(edges, [2]int{node, singleNodes[ptr]})
			a[node]--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	gao(n, a)
}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

func gao(n int, a []int) {
	var vis [512]bool
	var edges [][2]int
	lastNode := -1
	diameter := 0
	for i := 0; i < n; i++ {
		if a[i] >= 2 {
			if lastNode != -1 {
				diameter++
				edges = append(edges, [2]int{lastNode, i})
				vis[lastNode] = true
				vis[i] = true
				a[i] -= 1
				a[lastNode] -= 1
			}
			lastNode = i
		}
	}
	var singleNodes, rest []int
	restEdges := 0
	for i := 0; i < n; i++ {
		if vis[i] || a[i] > 1 {
			rest = append(rest, i)
			restEdges += a[i]
		} else {
			singleNodes = append(singleNodes, i)
		}
	}
	//fmt.Printf("restEdges=%v, singldeNodes=%v\n", restEdges, singleNodes)
	if restEdges < len(singleNodes) {
		fmt.Println("NO")
		return
	}
	if len(singleNodes) >= 2 {
		diameter += 2
	}
	fmt.Printf("YES %v\n", diameter)
	ptr := len(singleNodes) - 1
	if ptr >= 0 {
		edges = append(edges, [2]int{rest[len(rest)-1], singleNodes[ptr]})
		ptr--
		a[rest[len(rest)-1]]--
	}
	for _, node := range rest {
		if ptr < 0 {
			break
		}
		//fmt.Printf("edges=%+v, node=%v, singdleNodes=%+v, ptr=%v\n", edges, node, singleNodes, ptr)
		for a[node] > 0 && ptr >= 0 {
			edges = append(edges, [2]int{node, singleNodes[ptr]})
			a[node]--
			ptr--
		}
	}
	fmt.Printf("%v\n", len(edges))
	for _, e := range edges {
		fmt.Printf("%v %v\n", e[0]+1, e[1]+1)
	}
}

func main() {
	n := cin.NextInt()
	a := cin.NextIntSlice()
	gao(n, a)
}


package main

import (
	"fmt"
)

func main() {
	var x1, y1, x2, y2 int64
	var n int
	fmt.Scan(&x1, &y1, &x2, &y2, &n)
	step := 0
	for i := 0; i < n; i++ {
		var a, b, c int64
		fmt.Scan(&a, &b, &c)
		z1 := a*x1 + b*y1 + c
		z2 := a*x2 + b*y2 + c
		if z1 < 0 && z2 > 0 || z1 > 0 && z2 < 0 {
			step++
		}
	}
	fmt.Println(step)
}

package main

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

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

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

	x1, y1, x2, y2 := int64(nextInt()), int64(nextInt()), int64(nextInt()), int64(nextInt())
	n := nextInt()
	count := 0

	for ; n > 0; n-- {
		a, b, c := int64(nextInt()), int64(nextInt()), int64(nextInt())

		sign1 := a * x1 + b * y1 + c
		sign2 := a * x2 + b * y2 + c

		if (sign1 > 0 && sign2 < 0) || (sign1 < 0 && sign2 > 0) {
			count++
		}
	}

	println(count)
}

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

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

package main

import (
	"fmt"
)

type Line struct {
	a, b, c float64
}

type Point struct {
	x, y float64
}

func (line Line) Intersect(p1, p2 Point) bool {
	if line.b == 0 {
		var l float64 = float64(-1*line.c) / float64(line.a)
		return (p1.x < l && p2.x > l) || (p1.x > l && p2.x < l)
	} else {
		var y1, y2 float64
		y1 = (float64(-1*line.c) - float64(line.a*p1.x)) / float64(line.b)
		y2 = (float64(-1*line.c) - float64(line.a*p2.x)) / float64(line.b)
		return (p1.y > y1 && p2.y < y2) || (p1.y < y1 && p2.y > y2)
	}
}

var (
	n       int
	home    Point
	univ    Point
	streets []Line
	result  int
)

func in() {
	var x, y float64
	fmt.Scanf("%f %f\n", &x, &y)
	home = Point{x, y}
	fmt.Scanf("%f %f\n", &x, &y)
	univ = Point{x, y}

	fmt.Scanln(&n)
	streets = make([]Line, n)
	for i := 0; i < n; i++ {
		streets[i] = *new(Line)
		_, err := fmt.Scanf("%f %f %f\n", &streets[i].a, &streets[i].b, &streets[i].c)
		if err != nil {
			fmt.Println(err)
		}
	}

}

func out() {
	fmt.Println(result)
}

func run() {
	result = 0
	for _, street := range streets {
		if street.Intersect(home, univ) {
			result++
		}
	}
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"fmt"
)

func main() {
	var x1, y1, x2, y2 int64
	var n int
	fmt.Scan(&x1, &y1, &x2, &y2, &n)
	step := 0
	for i := 0; i < n; i++ {
		var a, b, c int64
		fmt.Scan(&a, &b, &c)
		z1 := a*x1 + b*y1 + c
		z2 := a*x2 + b*y2 + c
		if z1*z2 < 0 {
			step++
		}
	}
	fmt.Println(step)
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(0)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, k := int64(0), int64(0)
		fmt.Fscanf(in, "%d %d\n", &n, &k)
		ans := int64(0)
		for n != 0 {
			if n%k == 0 {
				n /= k
				ans++
			} else {
				ans += n % k
				n -= n % k
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++ {
		var n,k int64
		fmt.Scan(&n,&k)
		var res int64
		res = 0
		for n>0 {
			res+=n%k
			n/=k
			res+=1
		}
		fmt.Println(res-1)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, k, cnt int64
		fmt.Scan(&n, &k)
		for n > 0 {
			cnt += n%k + 1
			n /= k
		}
		fmt.Println(cnt - 1)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, k, cnt int64
		fmt.Scan(&n, &k)
		for n > 0 {
			if n%k == 0 {
				cnt++
				n /= k
			} else {
				cnt += n % k
				n -= n % k
			}
		}
		fmt.Println(cnt)
	}
}

package main

import "fmt"

func main() {
	var t int
	_, _ = fmt.Scanf("%d\n", &t)
	for t > 0 {
		t--
		var n, k uint64
		_, _ = fmt.Scanf("%d%d\n", &n, &k)
		var cnt uint64 = 0
		for n > 0 {
			cnt += (n % k) + 1
			n /= k
		}
		fmt.Println(cnt - 1)
	}
}

package main

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

type inputReader struct {
    *bufio.Scanner
}

func initInput() *inputReader {
    input := inputReader{ bufio.NewScanner(os.Stdin) }
    input.Split(bufio.ScanWords)
    return &input
}

func (input *inputReader) readInt64() int64 {
    input.Scan()
    result, _ := strconv.ParseInt(input.Text(), 10, 64)
    return result
}

func main() {
    input := initInput()

    t := int(input.readInt64())
    for kase := 1; kase <= t; kase++ {
        n := input.readInt64()
        k := input.readInt64()

        ans := int64(0)
        for n > 0 {
            if n % k == 0 {
                ans++
                n /= k
            } else {
                ans += n % k
                n -= n % k
            }
        }

        fmt.Println(ans)
    }
}

package main

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

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

	var T, n, k int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		ans := int64(-1)
		for n > 0 {
			ans += n%k + 1
			n /= k
		}
		Fprintln(out, ans)
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var t int // size of input
	var n, k int64
	fmt.Scan(&t)
	for t > 0 {
		var ctr int64
		fmt.Scan(&n, &k)
		for n >= k {
			r := n % k
			if r == 0 {
				n = n / k
				ctr++
			} else {
				n = n - r
				ctr += r
			}
		}
		ctr += n
		fmt.Println(ctr)
		t = t - 1
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1175/problem/A

package main

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

func _Solve(n int64, k int64, acc int64) int64 {
	if n == 0 {
		return acc
	} else if k > n {
		return _Solve(0, k, acc+n)
	} else if n%k == 0 {
		return _Solve(n/k, k, acc+1)
	}
	return _Solve(n-n%k, k, acc+n%k)
}

func Solve(n int64, k int64) int64 {
	return _Solve(n, k, 0)
}

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

	var t int
	var n int64
	var k int64

	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Fscanf(reader, "%d %d\n", &n, &k)
		fmt.Fprintf(writer, "%d\n", Solve(n, k))
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var n, k int64

	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &n, &k)
		var sol int64 = 0
		for n > 0 {
			if n%k == 0 {
				n /= k
				sol += 1
			} else {
				sol += n % k
				n -= n % k
			}
		}
		fmt.Println(sol)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, k int

	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &n, &k)
		sol := 0
		for n > 0 {
			if n%k == 0 {
				n /= k
			} else {
				n -= 1
			}
			sol += 1
		}
		fmt.Println(sol)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var n, k int64

	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &n, &k)
		var sol int64 = 0
		for n > 0 {
			if n%k == 0 {
				n /= k
				sol += 1
			} else {
				n -= n % k
				sol += n % k
			}
		}
		fmt.Println(sol)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t, n, k int

	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d\n", &n, &k)
		sol := 0
		for n > 0 {
			if n%k == 0 {
				n /= k
			} else {
				n -= 1
			}
			sol += 1
		}
		fmt.Println(sol)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d",&t)
	for i:=0;i<t;i++ {
		var n,k int64
		fmt.Scanf("%d %d",&n,&k)
		var res int64
		res = 0
		for n>0 {
			res+=n%k
			n/=k
			res+=1
		}
		fmt.Println(res-1)
	}
}

package main

import "fmt"

func main() {
	var t int
	_, _ = fmt.Scanf("%d", &t)
	for t > 0 {
		t--
		var n, k uint64
		_, _ = fmt.Scanf("%d%d", &n, &k)
		cnt := 0
		for n > 0 {
			if n % k == 0 {
				n /= k
			} else {
				n--
			}
			cnt++
		}
		fmt.Println(cnt)
	}
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n,k float64
    var t int
    fmt.Scan(&t)
    for t > 0 {
        fmt.Scan(&n)
        fmt.Scan(&k)
        if n >= k {
            p := math.Floor(math.Log10(n) / math.Log10(k))
            r := int(n) % int(math.Pow(k,p))
            if r == 0 {
                r = 1
            }
            fmt.Println(int(p) + r)
        } else {
            fmt.Println(n)
        }
        t = t - 1
    }
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int // size of input
	var n, k int64
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n, &k)
		if n >= k {
			p := math.Floor(math.Log10(float64(n)) / math.Log10(float64(k)))
			r := int(n) % int(math.Pow(float64(k), float64(p)))
			if r == 0 {
				r = 1
			}
			fmt.Println(p + float64(r))
		} else {
			fmt.Println(n)
		}
		t = t - 1
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int // size of input
	var n, k int64
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n, &k)
		if n >= k {
			p := int64(math.Log10(float64(n)) / math.Log10(float64(k)))
			r := int64(n) % int64(math.Pow(float64(k), float64(p)))
			if r == 0 {
				r = 1
			}
			fmt.Println(p + r)
		} else {
			fmt.Println(n)
		}
		t = t - 1
	}
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n,k float64
    var t int
    fmt.Scan(&t)
    for t > 0 {
        fmt.Scan(&n)
        fmt.Scan(&k)
        p := math.Floor(math.Log10(n) / math.Log10(k))
        r := int(n) % int(math.Pow(k,p))
        if r == 0 {
            r = 1
        }
        fmt.Println(int(p) + r)
        t = t - 1
    }
}


package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var n int64
		fmt.Scanf("%d\n", &n)
		if n % 4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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 {
			break
		}
	}
	return result
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)

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

	var t, n int
	t = input()

	for ; t > 0; t-- {
		n = input()

		if n%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		writer.Printf("%s\n", sol(n))
	}
}

func sol(x int64) string {
	if(x%4==0){
		return "YES"
	}
  return "NO"
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** 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
}

// cf1 project main.go
package main

import (
	"fmt"
)

func main() {
	var n, i int
	fmt.Scanln(&n)
	for j := 0; j < n; j++ {
		fmt.Scan(&i)
		if i%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

/*
URL:
https://codeforces.com/contest/1369/problem/A
*/

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

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()

		solve()
	}
}

func solve() {
	if n%4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

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

/*********** 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"
	"os"
)

var nTest, n int

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n)

		if (n-4)%4 == 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}

	out.Flush()
}

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)

		if n%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	scanner.Scan()
	count, _ := strconv.Atoi(scanner.Text())

	var num int
	for i := 0 ; i < count; i++ {
		scanner.Scan()
		num ,  _ = strconv.Atoi(scanner.Text())

		if num %4 == 0 {
			fmt.Println("YES")

			continue
		}

		fmt.Println("NO")
	}
}

package main

import (
  . "fmt"
)

var t int
func main() {
  Scan(&t)
  for tc := 0; tc < t; tc++ {
  	var n int
    Scan(&n)
    if n % 4 == 0 {
        Println("YES")
    } else {
        Println("NO")
    }
  }
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		if n%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func main(){
	var t int32
	var n int32
	fmt.Scan(&t)

	for ;t>0;t-- {
		fmt.Scan(&n)
		if n%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	scanner.Scan()
	tc, _ := strconv.Atoi(scanner.Text())
	for tc > 0  {
		tc--
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		if n%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func isBeautiful(a int) string {
	if a%4 == 0 {
		return "YES"
	} else {
		return "NO"
	}
}

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

	for tests > 0 {
		var a int
		fmt.Scan(&a)

		fmt.Println(isBeautiful(a))
		tests--
	}
}

package main

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

func isBeautiful(a int) string {
	if a%4 == 0 {
		return "YES"
	} else {
		return "NO"
	}
}

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

	scanner.Scan()
	tests, _ := strconv.Atoi(scanner.Text())

	for tests > 0 {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		cout := &a

		fmt.Println(isBeautiful(*cout))
		tests--
	}
}

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		if res {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(n int) bool {
	if n < 4 {
		return false
	}
	if n == 4 {
		return true
	}

	if n < 12 {
		return false
	}
	//2 * 4 + x * 4 == n
	m := n - 8
	return m%4 == 0
}

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var t int
	con.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		con.Scan(&n)
		if n%4 == 0 {
			con.Println("YES")
		} else {
			con.Println("NO")
		}
	}
	return nil
}

package main

import (
	"fmt"
)

func main() {
    	var n int
    	fmt.Scanln(&n)
	a := make([]int, n)
  	for i := 0; i < n; i++ {
      		fmt.Scan(&a[i])
    	}
	for _, value := range a {
		if value%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var tc,n int
	fmt.Scanf("%d", &tc)
	for tc > 0  {
		tc--
		fmt.Scanf("%d", &n)
		if n%4 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

func sol(x int64) string {
	if(x%4==0){
		return "YES"
	}
  return "NO"
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** 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"
	"io"
	"os"
	"sort"
  	"strings"
  	"strconv"
  	"math"
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

func sol(x int64) string {
	if(x%2==0){
		return "YES"
	}
  return "NO"
}

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** 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
}

// cf1 project main.go
package main

import (
	"fmt"
	"os"
)

func main() {
	var i int
	fmt.Fscan(os.Stdin, &i)
	fmt.Println(i)
	if i%2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

// cf1 project main.go
package main

import (
	"fmt"
)

func main() {
	var n, i int
	fmt.Scanln(&n)
	for j := 0; j < n; j++ {
		fmt.Scan(&i)
		if i%2 == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	scanner.Scan()
	count, _ := strconv.Atoi(scanner.Text())

	var num int
	for i := 0 ; i < count; i++ {
		scanner.Scan()
		num ,  _ = strconv.Atoi(scanner.Text())

		if num %2 == 0 {
			fmt.Println("YES")

			continue
		}

		fmt.Println("NO")
	}
}

package main

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var t int
	con.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		con.Scan(&n)
		if n%2 == 0 {
			con.Println("YES")
		} else {
			con.Println("NO")
		}
	}
	return nil
}


package main

import (
	"bufio"
	. "fmt"
	"log"
	"os"
	"sort"
	"strconv"
	//"container/heap"
)

var _ = Scan // reference fmt

type ll int64

const _0 ll = 0
const _1 ll = 1
const INF ll = 1e18 + 7

type Sll []ll

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

func btoi(b bool) ll {
	if b {
		return 1
	} else {
		return 0
	}
}

func max(i1 ll, i2 ll) ll { return Sll{i1, i2}[btoi(i1 < i2)] }
func min(i1 ll, i2 ll) ll { return Sll{i2, i1}[btoi(i1 < i2)] }
func abs(i1 ll) ll        { return max(i1, -i1) }
func absi(i1 int) int {
	if i1 > 0 {
		return i1
	} else {
		return -i1
	}
}

func makeii(n ll, m ll) []Sll {
	a := make([]Sll, n)
	for i := _0; i < n; i++ {
		a[i] = make(Sll, m)
	}
	return a
}

var r *bufio.Reader
var wr *bufio.Writer
var er *bufio.Writer

func cini() ll {
	s := cins()
	ans, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Panic("cini failed, s=", s)
	}
	return ll(ans)
}
func cinai(n ll) Sll {
	ans := make(Sll, n)
	for i := range ans {
		ans[i] = cini()
	}
	return ans
}

// read a WS delimited word, works also on atcoder with long strings
func cinb() []byte {
	s := make([]byte, 0)
	for {
		b, err := r.ReadByte()
		if err != nil {
			return s
		}
		if b == 10 || b == 13 || b == '\t' || b == ' ' {
			continue
		} else {
			s = append(s, b)
			break
		}
	}
	for {
		b, err := r.ReadByte()
		if err != nil || b == 10 || b == 13 || b == '\t' || b == ' ' {
			break
		}
		s = append(s, b)
	}

	return s
}
func cins() string {
	return string(cinb())
}

// Each value p[i] adds p[i] points to the studends j having s[j][i]==true
// There are only 10 students, consider we want to
// maximize/minimize each one, 1024 configurations.
// Then each question has a min/max scoring, order the questions by that,
// and assign the p[i] according to that ordering.
// One of the 2^10 configurations gives max ans.
func solve() {
	var n, m int
	Fscan(r, &n, &m)

	x := make([]int, n)
	for i := range x {
		Fscan(r, &x[i])
	}

	vis := make([]string, n)
	for i := range vis {
		Fscan(r, &vis[i])
	}

	var ansp []int
	ans := int(-1e9)
	for i := 0; i < (1 << n); i++ {
		sc := make([]ll, m) // score of the m questions
		for k := 0; k < m; k++ {
			for j := 0; j < n; j++ {
				if i&(1<<j) > 0 { // student j should be maximized
					if vis[j][k] == '1' {
						sc[k]++
					}
				} else { // student j should be minimized
					if vis[j][k] == '1' {
						sc[k]--
					}
				}
			}
		}

		p := make([]ll, m)
		for j := range p {
			p[j] = ll(j)
		}
		sort.Slice(p, func(i, j int) bool { return sc[p[i]] < sc[p[j]] })

		pp := make([]int, m)
		for j := range pp {
			pp[p[j]] = j + 1
		}

		xx := make([]int, n)
		for j := 0; j < n; j++ {
			for k := 0; k < m; k++ {
				xx[j] += pp[k] * int(vis[j][k]-'0')
			}
		}
		lans := 0
		for j := 0; j < n; j++ {
			lans += absi(xx[j] - x[j])
		}
		if lans > ans {
			ans = lans
			ansp = pp
		}
	}
	for i := range ansp {
		Fprintf(wr, "%d ", ansp[i])
	}
	Fprintln(wr)
}

func main() {
	r = bufio.NewReader(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
	er = bufio.NewWriter(os.Stderr)
	defer wr.Flush()
	defer er.Flush()
	for t := cini(); t > 0; t-- {
		solve()
	}
}

package main

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

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

var n int
var m int
var expected []int
var test []string
var coef []int

type Coef struct {
	coef  int
	index int
}

var path []Coef
var ansPath []int

func solveCoef() int {
	for i := 0; i < m; i++ {
		path[i] = Coef{coef: coef[i], index: i + 1}
	}
	sort.Slice(path, func(i, j int) bool {
		return path[i].coef < path[j].coef
	})

	var ans = 0
	for i := 0; i < m; i++ {
		ans += (i + 1) * path[i].coef
	}

	return ans
}

func solve() {
	var ans = -1
	for mask := 0; mask < (1 << n); mask++ {
		for i := 0; i < m; i++ {
			coef[i] = 0
		}
		var ansMask = 0
		for i := 0; i < n; i++ {
			var sign = -1
			if ((mask >> i) & 1) > 0 {
				sign = 1
			}
			for j := 0; j < m; j++ {
				if test[i][j] == '1' {
					coef[j] -= sign
				}
			}
			ansMask += sign * expected[i]
		}
		ansMask += solveCoef()
		if ansMask > ans {
			ans = ansMask
			// fmt.Fprintf(out, "mask = %d, path = %v\n", mask, path)
			for i := 0; i < m; i++ {
				ansPath[path[i].index-1] = i + 1
			}
		}
	}
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fscan(in, &n, &m)
		expected = make([]int, n)
		test = make([]string, n)
		coef = make([]int, m)
		path = make([]Coef, m)
		ansPath = make([]int, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &expected[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &test[i])
		}
		solve()
		for i := 0; i < m; i++ {
			fmt.Fprintf(out, "%d ", ansPath[i])
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

package main

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

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

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		X := readNNums(reader, n)
		A := make([]string, n)
		for i := 0; i < n; i++ {
			A[i], _ = reader.ReadString('\n')
		}
		res := solve(n, m, X, A)
		for i := 0; i < m; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

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(n int, m int, X []int, A []string) []int {

	var ans int = -1
	best := make([]int, m)

	for mask := 0; mask < 1<<n; mask++ {

		val := make([]int, m)

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if A[i][j] == '1' {
					if (mask>>i)&1 == 1 {
						val[j]++
					} else {
						val[j]--
					}
				}
			}
		}

		p := make([]int, m)
		for i := 0; i < m; i++ {
			p[i] = i
		}
		sort.Slice(p, func(i, j int) bool {
			return val[p[i]] < val[p[j]]
		})

		var tmp int
		for i := 0; i < n; i++ {
			if (mask>>i)&1 == 1 {
				tmp -= X[i]
			} else {
				tmp += X[i]
			}
		}

		for i := 0; i < m; i++ {
			tmp += val[p[i]] * (i + 1)
		}

		if tmp > ans {
			ans = tmp
			copy(best, p)
		}
	}
	res := make([]int, m)
	for i := 0; i < m; i++ {
		res[best[i]] = i + 1
	}

	return res
}

package main

import (
	"bufio"
	. "fmt"
	"log"
	"os"
	"sort"
	"strconv"
	//"container/heap"
)

var _ = Scan // reference fmt

type ll int64

const _0 ll = 0
const _1 ll = 1
const INF ll = 1e18 + 7

type Sll []ll

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

func btoi(b bool) ll {
	if b {
		return 1
	} else {
		return 0
	}
}

func max(i1 ll, i2 ll) ll { return Sll{i1, i2}[btoi(i1 < i2)] }
func min(i1 ll, i2 ll) ll { return Sll{i2, i1}[btoi(i1 < i2)] }
func abs(i1 ll) ll        { return max(i1, -i1) }

func makeii(n ll, m ll) []Sll {
	a := make([]Sll, n)
	for i := _0; i < n; i++ {
		a[i] = make(Sll, m)
	}
	return a
}

var r *bufio.Reader
var wr *bufio.Writer
var er *bufio.Writer

func cini() ll {
	s := cins()
	ans, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Panic("cini failed, s=", s)
	}
	return ll(ans)
}
func cinai(n ll) Sll {
	ans := make(Sll, n)
	for i := range ans {
		ans[i] = cini()
	}
	return ans
}

// read a WS delimited word, works also on atcoder with long strings
func cinb() []byte {
	s := make([]byte, 0)
	for {
		b, err := r.ReadByte()
		if err != nil {
			return s
		}
		if b == 10 || b == 13 || b == '\t' || b == ' ' {
			continue
		} else {
			s = append(s, b)
			break
		}
	}
	for {
		b, err := r.ReadByte()
		if err != nil || b == 10 || b == 13 || b == '\t' || b == ' ' {
			break
		}
		s = append(s, b)
	}

	return s
}
func cins() string {
	return string(cinb())
}

// Each value p[i] adds p[i] points to the studends j having s[j][i]==true
// There are only 10 students, consider we want to
// maximize/minimize each one, 1024 configurations.
// Then each question has a min/max scoring, order the questions by that,
// and assign the p[i] according to that ordering.
// One of the 2^10 configurations gives max ans.
func solve() {
	n := cini()
	m := cini()

	x := cinai(n)

	a := make([][]bool, n)
	for i := range a {
		a[i] = make([]bool, m)
	}
	for i := _0; i < n; i++ {
		b := cinb()
		for j := range b {
			if b[j] == '1' {
				a[i][j] = true
			}
		}
	}

	var ansp []ll
	ans := _0
	for i := 0; i < (1 << n); i++ {
		sc := make([][2]ll, m) // score of the m questions
		for k := _0; k < m; k++ {
			sc[k][1] = k
			for j := _0; j < n; j++ {
				if i&(1<<j) > 0 { // student j should be maximized
					if a[j][k] {
						sc[k][0]++
					}
				} else { // student j should be minimized
					if a[j][k] {
						sc[k][0]--
					}
				}
			}
		}

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

		lans := _0
		for j := _0; j < n; j++ {
			if i&(1<<j) != 0 {
				lans -= x[j]
			} else {
				lans += x[j]
			}
		}

		for j := _0; j < m; j++ {
			lans += (j + 1) * sc[j][0]
		}

		if lans > ans {
			pp := make([]ll, m)
			for j := range pp {
				pp[sc[j][1]] = ll(j + 1)
			}

			ans = lans
			ansp = pp
		}
	}
	for i := range ansp {
		Print(ansp[i], " ")
	}
	Println()
}

func main() {
	r = bufio.NewReader(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
	er = bufio.NewWriter(os.Stderr)
	defer wr.Flush()
	defer er.Flush()
	for t := cini(); t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"log"
	"os"
	"sort"
	"strconv"
	//"container/heap"
)

var _ = Scan // reference fmt

type ll int64

const _0 ll = 0
const _1 ll = 1
const INF ll = 1e18 + 7

type Sll []ll

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

func btoi(b bool) ll {
	if b {
		return 1
	} else {
		return 0
	}
}

func max(i1 ll, i2 ll) ll { return Sll{i1, i2}[btoi(i1 < i2)] }
func min(i1 ll, i2 ll) ll { return Sll{i2, i1}[btoi(i1 < i2)] }
func abs(i1 ll) ll        { return max(i1, -i1) }

func makeii(n ll, m ll) []Sll {
	a := make([]Sll, n)
	for i := _0; i < n; i++ {
		a[i] = make(Sll, m)
	}
	return a
}

var r *bufio.Reader
var wr *bufio.Writer
var er *bufio.Writer

func cini() ll {
	s := cins()
	ans, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Panic("cini failed, s=", s)
	}
	return ll(ans)
}
func cinai(n ll) Sll {
	ans := make(Sll, n)
	for i := range ans {
		ans[i] = cini()
	}
	return ans
}

// read a WS delimited word, works also on atcoder with long strings
func cinb() []byte {
	s := make([]byte, 0)
	for {
		b, err := r.ReadByte()
		if err != nil {
			return s
		}
		if b == 10 || b == 13 || b == '\t' || b == ' ' {
			continue
		} else {
			s = append(s, b)
			break
		}
	}
	for {
		b, err := r.ReadByte()
		if err != nil || b == 10 || b == 13 || b == '\t' || b == ' ' {
			break
		}
		s = append(s, b)
	}

	return s
}
func cins() string {
	return string(cinb())
}

// Each value p[i] adds p[i] points to the studends j having s[j][i]==true
// There are only 10 students, consider we want to
// maximize/minimize each one, 1024 configurations.
// Then each question has a min/max scoring, order the questions by that,
// and assign the p[i] according to that ordering.
// One of the 2^10 configurations gives max ans.
func solve() {
	n := cini()
	m := cini()

	x := cinai(n)

	vis := make([][]bool, n)
	for i := range vis {
		vis[i] = make([]bool, m)
	}
	for i := _0; i < n; i++ {
		b := cinb()
		for j := range b {
			if b[j] == '1' {
				vis[i][j] = true
			}
		}
	}

	var ansp []ll
	ans := _0
	for i := 0; i < (1 << n); i++ {
		sc := make([][2]ll, m) // score of the m questions
		for k := _0; k < m; k++ {
			sc[k][1] = k
			for j := _0; j < n; j++ {
				if i&(1<<j) > 0 { // student j should be maximized
					if vis[j][k] {
						sc[k][0]++
					}
				} else { // student j should be minimized
					if vis[j][k] {
						sc[k][0]--
					}
				}
			}
		}

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

		lans := _0
		for j := _0; j < n; j++ {
			if i&(1<<j) != 0 {
				lans += x[j]
			} else {
				lans -= x[j]
			}
		}

		for j := _0; j < m; j++ {
			lans += (j + 1) * sc[j][0]
		}

		if lans > ans {
			pp := make([]ll, m)
			for j := range pp {
				pp[sc[j][1]] = ll(j + 1)
			}

			ans = lans
			ansp = pp
		}
	}
	for i := range ansp {
		Print(ansp[i], " ")
	}
	Println()
}

func main() {
	r = bufio.NewReader(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
	er = bufio.NewWriter(os.Stderr)
	defer wr.Flush()
	defer er.Flush()
	for t := cini(); t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"log"
	"os"
	"sort"
	"strconv"
	//"container/heap"
)

var _ = Scan // reference fmt

type ll int64

const _0 ll = 0
const _1 ll = 1
const INF ll = 1e18 + 7

type Sll []ll

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

func btoi(b bool) ll {
	if b {
		return 1
	} else {
		return 0
	}
}

func max(i1 ll, i2 ll) ll { return Sll{i1, i2}[btoi(i1 < i2)] }
func min(i1 ll, i2 ll) ll { return Sll{i2, i1}[btoi(i1 < i2)] }
func abs(i1 ll) ll        { return max(i1, -i1) }

func makeii(n ll, m ll) []Sll {
	a := make([]Sll, n)
	for i := _0; i < n; i++ {
		a[i] = make(Sll, m)
	}
	return a
}

var r *bufio.Reader
var wr *bufio.Writer
var er *bufio.Writer

func cini() ll {
	s := cins()
	ans, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Panic("cini failed, s=", s)
	}
	return ll(ans)
}
func cinai(n ll) Sll {
	ans := make(Sll, n)
	for i := range ans {
		ans[i] = cini()
	}
	return ans
}

// read a WS delimited word, works also on atcoder with long strings
func cinb() []byte {
	s := make([]byte, 0)
	for {
		b, err := r.ReadByte()
		if err != nil {
			return s
		}
		if b == 10 || b == 13 || b == '\t' || b == ' ' {
			continue
		} else {
			s = append(s, b)
			break
		}
	}
	for {
		b, err := r.ReadByte()
		if err != nil || b == 10 || b == 13 || b == '\t' || b == ' ' {
			break
		}
		s = append(s, b)
	}

	return s
}
func cins() string {
	return string(cinb())
}

// Each value p[i] adds p[i] points to the studends j having s[j][i]==true
// There are only 10 students, consider we want to
// maximize/minimize each one, 1024 configurations.
// Then each question has a min/max scoring, order the questions by that,
// and assign the p[i] according to that ordering.
// One of the 2^10 configurations gives max ans.
func solve() {
	n := cini()
	m := cini()

	x := cinai(n)

	vis := make([][]bool, n)
	for i := range vis {
		vis[i] = make([]bool, m)
	}
	for i := _0; i < n; i++ {
		b := cinb()
		for j := range b {
			if b[j] == '1' {
				vis[i][j] = true
			}
		}
	}

	var ansp []ll
	ans := _0
	for i := 0; i < (1 << n); i++ {
		sc := make([][2]ll, m) // score of the m questions
		for k := _0; k < m; k++ {
			sc[k][1] = k
			for j := _0; j < n; j++ {
				if i&(1<<j) > 0 { // student j should be maximized
					if vis[j][k] {
						sc[k][0]++
					}
				} else { // student j should be minimized
					if vis[j][k] {
						sc[k][0]--
					}
				}
			}
		}

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

		pp := make([]ll, m)
		for j := range pp {
			pp[sc[j][1]] = ll(j + 1)
		}

		xx := make([]ll, n)
		for k := _0; k < m; k++ {
			for j := _0; j < n; j++ {
				if vis[j][k] {
					xx[j] += pp[k]
				}
			}
		}
		lans := _0
		for j := _0; j < n; j++ {
			lans += abs(xx[j] - x[j])
		}
		if lans > ans {
			ans = lans
			ansp = pp
		}
	}
	for i := range ansp {
		Print(ansp[i], " ")
	}
	Println()
}

func main() {
	r = bufio.NewReader(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
	er = bufio.NewWriter(os.Stderr)
	defer wr.Flush()
	defer er.Flush()
	for t := cini(); t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"log"
	"os"
	"sort"
	"strconv"
	//"container/heap"
)

var _ = Scan // reference fmt

type ll int64

const _0 ll = 0
const _1 ll = 1
const INF ll = 1e18 + 7

type Sll []ll

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

func btoi(b bool) ll {
	if b {
		return 1
	} else {
		return 0
	}
}

func max(i1 ll, i2 ll) ll { return Sll{i1, i2}[btoi(i1 < i2)] }
func min(i1 ll, i2 ll) ll { return Sll{i2, i1}[btoi(i1 < i2)] }
func abs(i1 ll) ll        { return max(i1, -i1) }

func makeii(n ll, m ll) []Sll {
	a := make([]Sll, n)
	for i := _0; i < n; i++ {
		a[i] = make(Sll, m)
	}
	return a
}

var r *bufio.Reader
var wr *bufio.Writer
var er *bufio.Writer

func cini() ll {
	s := cins()
	ans, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Panic("cini failed, s=", s)
	}
	return ll(ans)
}
func cinai(n ll) Sll {
	ans := make(Sll, n)
	for i := range ans {
		ans[i] = cini()
	}
	return ans
}

// read a WS delimited word, works also on atcoder with long strings
func cinb() []byte {
	s := make([]byte, 0)
	for {
		b, err := r.ReadByte()
		if err != nil {
			return s
		}
		if b == 10 || b == 13 || b == '\t' || b == ' ' {
			continue
		} else {
			s = append(s, b)
			break
		}
	}
	for {
		b, err := r.ReadByte()
		if err != nil || b == 10 || b == 13 || b == '\t' || b == ' ' {
			break
		}
		s = append(s, b)
	}

	return s
}
func cins() string {
	return string(cinb())
}

// Each value p[i] adds p[i] points to the studends j having s[j][i]==true
// There are only 10 students, consider we want to
// maximize/minimize each one, 1024 configurations.
// Then each question has a min/max scoring, order the questions by that,
// and assign the p[i] according to that ordering.
// One of the 2^10 configurations gives max ans.
func solve() {
	n := cini()
	m := cini()

	x := cinai(n)

	vis := make([][]bool, n)
	for i := range vis {
		vis[i] = make([]bool, m)
	}
	for i := _0; i < n; i++ {
		b := cinb()
		for j := range b {
			if b[j] == '1' {
				vis[i][j] = true
			}
		}
	}

	var ansp []ll
	ans := _0
	for i := 0; i < (1 << n); i++ {
		sc := make([]ll, m) // score of the m questions
		for k := _0; k < m; k++ {
			for j := _0; j < n; j++ {
				if i&(1<<j) > 0 { // student j should be maximized
					if vis[j][k] {
						sc[k]++
					}
				} else { // student j should be minimized
					if vis[j][k] {
						sc[k]--
					}
				}
			}
		}

		p := make([]ll, m)
		for j := range p {
			p[j] = ll(j)
		}
		sort.Slice(p, func(i, j int) bool { return sc[p[i]] < sc[p[j]] })

		pp := make([]ll, m)
		for j := range pp {
			pp[p[j]] = ll(j + 1)
		}

		xx := make([]ll, n)
		for k := _0; k < m; k++ {
			for j := _0; j < n; j++ {
				if vis[j][k] {
					xx[j] += pp[k]
				}
			}
		}
		lans := _0
		for j := _0; j < n; j++ {
			lans += abs(xx[j] - x[j])
		}
		if lans > ans {
			ans = lans
			ansp = pp
		}
	}
	for i := range ansp {
		Print(ansp[i], " ")
	}
	Println()
}

func main() {
	r = bufio.NewReader(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
	er = bufio.NewWriter(os.Stderr)
	defer wr.Flush()
	defer er.Flush()
	for t := cini(); t > 0; t-- {
		solve()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"log"
	"os"
	"sort"
	"strconv"
	//"container/heap"
)

var _ = Scan // reference fmt

type ll int64

const _0 ll = 0
const _1 ll = 1
const INF ll = 1e18 + 7

type Sll []ll

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

func btoi(b bool) ll {
	if b {
		return 1
	} else {
		return 0
	}
}

func max(i1 ll, i2 ll) ll { return Sll{i1, i2}[btoi(i1 < i2)] }
func min(i1 ll, i2 ll) ll { return Sll{i2, i1}[btoi(i1 < i2)] }
func abs(i1 ll) ll        { return max(i1, -i1) }

func makeii(n ll, m ll) []Sll {
	a := make([]Sll, n)
	for i := _0; i < n; i++ {
		a[i] = make(Sll, m)
	}
	return a
}

var r *bufio.Reader
var wr *bufio.Writer
var er *bufio.Writer

func cini() ll {
	s := cins()
	ans, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Panic("cini failed, s=", s)
	}
	return ll(ans)
}
func cinai(n ll) Sll {
	ans := make(Sll, n)
	for i := range ans {
		ans[i] = cini()
	}
	return ans
}

// read a WS delimited word, works also on atcoder with long strings
func cinb() []byte {
	s := make([]byte, 0)
	for {
		b, err := r.ReadByte()
		if err != nil {
			return s
		}
		if b == 10 || b == 13 || b == '\t' || b == ' ' {
			continue
		} else {
			s = append(s, b)
			break
		}
	}
	for {
		b, err := r.ReadByte()
		if err != nil || b == 10 || b == 13 || b == '\t' || b == ' ' {
			break
		}
		s = append(s, b)
	}

	return s
}
func cins() string {
	return string(cinb())
}

// Each value p[i] adds p[i] points to the studends j having s[j][i]==true
// There are only 10 students, consider we want to
// maximize/minimize each one, 1024 configurations.
// Then each question has a min/max scoring, order the questions by that,
// and assign the p[i] according to that ordering.
// One of the 2^10 configurations gives max ans.
func solve() {
	n := cini()
	m := cini()

	x := cinai(n)

	vis := make([][]bool, n)
	for i := range vis {
		vis[i] = make([]bool, m)
	}
	for i := _0; i < n; i++ {
		b := cinb()
		for j := range b {
			if b[j] == '1' {
				vis[i][j] = true
			}
		}
	}

	var ansp []ll
	ans := _0
	for i := 0; i < (1 << n); i++ {
		sc := make([]ll, m) // score of the m questions
		for k := _0; k < m; k++ {
			for j := _0; j < n; j++ {
				if i&(1<<j) > 0 { // student j should be maximized
					if vis[j][k] {
						sc[k]++
					}
				} else { // student j should be minimized
					if vis[j][k] {
						sc[k]--
					}
				}
			}
		}

		p := make([]ll, m)
		for j := range p {
			p[j] = ll(j + 1)
		}
		sort.Slice(p, func(i, j int) bool { return sc[i] < sc[j] })
		xx := make([]ll, n)
		for k := _0; k < m; k++ {
			for j := _0; j < n; j++ {
				if vis[j][k] {
					xx[j] += p[k]
				}
			}
		}
		lans := _0
		for j := _0; j < n; j++ {
			lans += abs(xx[j] - x[j])
		}
		if lans > ans {
			ans = lans
			ansp = p
		}
	}
	for i := range ansp {
		Print(ansp[i], " ")
	}
	Println()
}

func main() {
	r = bufio.NewReader(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
	er = bufio.NewWriter(os.Stderr)
	defer wr.Flush()
	defer er.Flush()
	for t := cini(); t > 0; t-- {
		solve()
	}
}

package main

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

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

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		X := readNNums(reader, n)
		A := make([]string, n)
		for i := 0; i < n; i++ {
			A[i], _ = reader.ReadString('\n')
		}
		res := solve(n, m, X, A)
		for i := 0; i < m; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

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(n int, m int, X []int, A []string) []int {

	var ans int
	best := make([]int, m)

	for mask := 0; mask < 1<<n; mask++ {

		val := make([]int, m)

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if A[i][j] == '1' {
					if (mask>>i)&1 == 1 {
						val[j]++
					} else {
						val[j]--
					}
				}
			}
		}

		p := make([]int, m)
		for i := 0; i < m; i++ {
			p[i] = i
		}
		sort.Slice(p, func(i, j int) bool {
			return val[p[i]] < val[p[j]]
		})

		var tmp int
		for i := 0; i < n; i++ {
			if (mask>>i)&1 == 1 {
				tmp -= X[i]
			} else {
				tmp += X[i]
			}
		}

		for i := 0; i < m; i++ {
			tmp += val[p[i]] * (i + 1)
		}

		if tmp > ans {
			ans = tmp
			copy(best, p)
		}
	}
	res := make([]int, m)
	for i := 0; i < m; i++ {
		res[best[i]] = i + 1
	}

	return res
}


package main

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

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

	var n, cnt int
	fmt.Fscan(r, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i])
	}
	for i := 1; i < n-1; i++ {
		if (a[i] > a[i-1] && a[i] > a[i+1]) || (a[i] < a[i-1] && a[i] < a[i+1]) {
			cnt++
		}
	}
	fmt.Fprintln(w, cnt)
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()

	total, a, b := 0, -1, -1
	for i := 0; i < n; i++ {
		c := readInt()
		if i >= 2 {
			isLocMin := b < a && b < c
			isLocMax := b > a && b > c
			if isLocMin || isLocMax {
				total++
			}
		}

		a, b = b, c
	}

	fmt.Println(total)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	for i, _ := range a {
		a[i] = readInt()
	}

	cnt := 0
	for i := 1; i < n-1; i++ {
		if a[i] > a[i+1] && a[i] > a[i-1] {
			cnt++
		} else if a[i] < a[i+1] && a[i] < a[i-1] {
			cnt++
		}
	}

	fmt.Println(cnt)
}

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

package main

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

var n int
var a[2000] int
var res int
func main() {
	in := bufio.NewReader(os.Stdin)
	res = 0
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	for i := 1; i < n-1; i++ {
		if ((a[i] > a[i+1] && a[i] > a[i-1])||(a[i] < a[i+1] && a[i] < a[i-1])) {
			res++
		}
	}
	fmt.Printf("%d", res)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	len1, _ := reader.ReadString('\n')
	len2, _ := strconv.ParseInt(strings.TrimSpace(len1), 10, 16)
	len3 := int(len2)

	if len2 <=1 {
		writer.WriteString("0")
		writer.Flush()
		return
	}

	line, _ := reader.ReadString('\n')
	var tmp int64
	data := make([]int16, len3, len3)
	for key, value := range strings.Split(strings.TrimSpace(line), " ") {
		tmp, _ = strconv.ParseInt(value, 10, 16)
		data[key] = int16(tmp)
	}
	c := 0
	prev := int8(0)
	for key, value := range data[1:len3-1] {
		if prev == 0 {
			if value < data[key] && value < data[key+2] {
				c++
				prev = 1
				continue
			} else if value > data[key] && value > data[key+2] {
				c++
				prev = 2
				continue
			}
			prev = 0
		} else if prev == 1 {
			if value > data[key] && value > data[key+2] {
				c++
				prev = 2
				continue
			}
			prev = 0
		} else if prev == 2 {
			if value < data[key] && value < data[key+2] {
				c++
				prev = 1
				continue
			}
			prev = 0
		}
	}
	writer.WriteString(strconv.Itoa(c))
	writer.Flush()
}

package main

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

func main() {
	var line string
	var count int
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(line))
	arr := make([]int, n)
	line, _ = reader.ReadString('\n')
	for i, val := range strings.Split(strings.TrimSpace(line), " ") {
		tmp, _ := strconv.Atoi(val)
		arr[i] = tmp
	}
	for i := 1; i < n-1; i++ {
		if (arr[i] > arr[i-1] && arr[i] > arr[i+1]) || (arr[i] < arr[i-1] && arr[i] < arr[i+1]) {
			count++
		}
	}
	writer.WriteString(strconv.Itoa(count))
	writer.Flush()
}

package main

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

func main() {
	var line string
	var count, cur, prev, future int
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, _ = reader.ReadString('\n')
	line, _ = reader.ReadString('\n')
	for i, val := range strings.Split(strings.TrimSpace(line), " ") {
		if i == 0 {
			prev, _ = strconv.Atoi(val)
			continue
		} else if i == 1 {
			cur, _ = strconv.Atoi(val)
			continue
		}
		future, _ = strconv.Atoi(val)
		if (cur > prev && cur > future) || (cur < prev && cur < future) {
			count++
		}
		prev, cur = cur, future
	}
	writer.WriteString(strconv.Itoa(count))
	writer.Flush()
}

package main

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

func main() {
	var line string
	var count, cur, prev, future int
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	line, _ = reader.ReadString('\n')
	_, _ = strconv.Atoi(strings.TrimSpace(line))
	line, _ = reader.ReadString('\n')
	for i, val := range strings.Split(strings.TrimSpace(line), " ") {
		if i == 0 {
			prev, _ = strconv.Atoi(val)
			continue
		} else if i == 1 {
			cur, _ = strconv.Atoi(val)
			continue
		}
		future, _ = strconv.Atoi(val)
		if (cur > prev && cur > future) || (cur < prev && cur < future) {
			count++
		}
		prev, cur = cur, future
	}
	writer.WriteString(strconv.Itoa(count))
	writer.Flush()
}

package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Scan(&arr[i])
	}
	count := 0
	for i := 1; i < len(arr) -1; i ++ {
		if arr[i]<arr[i-1]&&arr[i]<arr[i+1] || arr[i]>arr[i-1]&&arr[i]>arr[i+1] {
			count++
		}
	}
	fmt.Print(count)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/888/A

package main

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

func Solve(n int, a []int) int {
	count := 0
	for i := 1; i < n-1; i++ {
		if a[i] > a[i-1] && a[i] > a[i+1] {
			count += 1
		} else if a[i] < a[i-1] && a[i] < a[i+1] {
			count += 1
		}
	}
	return count
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fprintf(writer, "%d\n", Solve(n, a))
}

package main

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

var n int
var a[2000] int
var res int
func main() {
	in := bufio.NewReader(os.Stdin)
	res = 0
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	if n < 3 {
		fmt.Printf("%d", n)
		os.Exit(0)
	}

	for i := 1; i < n-1; i++ {
		if ((a[i] > a[i+1] && a[i] > a[i-1])||(a[i] < a[i+1] && a[i] < a[i-1])) {
			res++
		}
	}
	fmt.Printf("%d", res)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	len1, _ := reader.ReadString('\n')
	len2, _ := strconv.ParseInt(strings.TrimSpace(len1), 10, 16)
	len3 := int(len2)
	line, _ := reader.ReadString('\n')
	var tmp int64
	data := make([]int16, len3, len3)
	for key, value := range strings.Split(line, " ") {
		tmp, _ = strconv.ParseInt(value, 10, 16)
		data[key] = int16(tmp)
	}
	c := 0
	prev := int8(0)
	for key, value := range data[1:len3-1] {
		if prev == 0 {
			if value < data[key] && value < data[key+2] {
				c++
				prev = 1
				continue
			} else if value > data[key] && value > data[key+2] {
				c++
				prev = 2
				continue
			}
			prev = 0
		} else if prev == 1 {
			if value > data[key] && value > data[key+2] {
				c++
				prev = 2
				continue
			}
			prev = 0
		} else if prev == 2 {
			if value < data[key] && value < data[key+2] {
				c++
				prev = 1
				continue
			}
			prev = 0
		}
	}
	writer.WriteString(strconv.Itoa(c))
	writer.Flush()
}


package main

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

const l int = 26

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

	cnt := make([]int64, l)

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")
		for _, c := range s {
			cnt[int(c-'A')] += 1
		}

		bubble_sort(cnt, l)

		res := int64(0)
		for i := 0; i < l; i++ {
			if k >= cnt[i] {
				res += cnt[i] * cnt[i]
				k -= cnt[i]
			} else {
				res += k * k
				break
			}
		}
		fmt.Println(res)
	}
}

func swap(a, b int, array []int64) {
	array[a], array[b] = array[b], array[a]
}

func bubble_sort(array []int64, length int) {
	for i := 0; i < length; i++ {
		for j := 0; j < length; j++ {
			if array[i] > array[j] {
				swap(i, j, array)
			}
		}
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int64
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int64) {
	var m int64
	I(&m, "\n")
	var s string
	I(&s, "\n")
	in := make([]int, 200)
	for i := 0; i < len(s); i++ {
		in[s[i]]++
	}
	sort.Ints(in)
	ans := int64(0)
	ii := int64(len(in) - 1)
	o := int64(in[ii])
	oo := int64(in[ii])
	if m < oo {
		oo = m
	}
	for m > int64(0) {
		if oo <= int64(0) {
			break
		}
		ans += oo
		o--
		m--
		if o == int64(0) && ii > int64(0) {
			ii--
			o = int64(in[ii])
			oo = int64(in[ii])
			if m < oo {
				oo = m
			}
		}
	}
	O(ans, "\n")
}

package main

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

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

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

	var n, k int
	var s string

	fmt.Scan(&n, &k)
	fmt.Scan(&s)

	letters := make([]int, 26)
	coins := int64(0)

	for i := 0; i < n; i++ {
		letters[s[i] - 'A']++
	}

	sort.Sort(sort.Reverse(sort.IntSlice(letters)))

	for i := 0; k > 0; {
		if k <= letters[i] {
			coins += int64(k) * int64(k)
			k = 0
		} else {
			coins += int64(letters[i]) * int64(letters[i])
			k -= letters[i]
			i++
		}
		// println(k, coins)
	}

	println(coins)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	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

//14:17

import (
    "fmt"
)

func main() {
    var n, k, i int64
    array := make([]int64, 26)
    for i = 0; i < 26; i++ {
        array[i] = 0
    }
    fmt.Scanf("%d %d ", &n, &k)
    for i = 0; i < n; i++ {
        var temp int8
        fmt.Scanf("%c", &temp)
        array[temp-'A']++
    }
    var score,coins int64
    for coins < k {
        var max,max_i int64
        for i=0;i<26;i++{
            if array[i]>max {
                max = array[i]
                max_i = i
            }
        }
        if max > (k-coins) {
            score += ((k-coins) * (k-coins))
            coins += (k-coins)
        }else{
            coins += max
            score += max * max
            array[max_i]=0
        }
    }
    fmt.Printf("%d ", score)
}

package main

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

type int64arr []int64
func (a int64arr) Len() int{ return len(a) }
func (a int64arr) Swap(i,j int) { a[i], a[j] = a[j], a[i] }
func (a int64arr) Less(i,j int) bool { return a[i] < a[j] }

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

	line,_ := reader.ReadString('\n')

	arr := strings.Split(strings.TrimSpace(line), " ")

	ddmap := make(int64arr,256)
	var ret int64
	ret = 0

	if len(arr) == 2 {
		n,_ := strconv.Atoi(arr[0])
		k,_ := strconv.Atoi(arr[1])

	//	fmt.Println(n,k)

		line,_ := reader.ReadString('\n')

		bline := []byte(line)

		//fmt.Println(bline)

		if len(bline) < n {
			return
		}

		for i:=0; i<n; i ++ {
			ddmap[bline[i]] ++;
		}
		sort.Sort(sort.Reverse(ddmap))

		//fmt.Println(ddmap)

		for i:=0; i<256 && i<n; i ++ {
			if k > int(ddmap[i]) {
				ret += ddmap[i]*ddmap[i]
			}else{
				ret += int64(k)*int64(k)
				break
			}

			k -= int(ddmap[i])
		}

	}
	fmt.Println(ret)

	return
}

package main

import (
	"fmt"
	"sort"
)

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

	cards := ""
	fmt.Scan(&cards)

	counts := make([]int, 26, 26)
	for i := 0; i < len(cards); i++ {
		counts[cards[i]-'A']++
	}

	sort.Sort(sort.Reverse(sort.IntSlice(counts)))
	var ans uint64
	ans = 0
	i := 0
	for k > 0 {
		if counts[i] < k {
			k -= counts[i]
			ans += uint64(counts[i]) * uint64(counts[i])
		} else {
			ans += uint64(k) * uint64(k)
			k = 0
		}
		i++
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

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

	cards := ""
	fmt.Scan(&cards)

	counts := make([]int, 26, 26)
	for i := 0; i < len(cards); i++ {
		counts[cards[i]-'A']++
	}

	sort.Reverse(sort.IntSlice(counts))
	ans := 0
	i := 0
	for k > 0 {
		if counts[i] < k {
			k -= counts[i]
			ans += counts[i] * counts[i]
		} else {
			ans += k * k
			k = 0
		}
		i++
	}

	fmt.Println(ans)
}

package main

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

type int64arr []int64
func (a int64arr) Len() int{ return len(a) }
func (a int64arr) Swap(i,j int) { a[i], a[j] = a[j], a[i] }
func (a int64arr) Less(i,j int) bool { return a[i] < a[j] }

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

	line,_ := reader.ReadString('\n')

	arr := strings.Split(strings.TrimSpace(line), " ")

	ddmap := make(int64arr,256)
	var ret int64
	ret = 0

	if len(arr) == 2 {
		n,_ := strconv.Atoi(arr[0])
		k,_ := strconv.Atoi(arr[1])

	//	fmt.Println(n,k)

		line,_ := reader.ReadString('\n')

		bline := []byte(line)

		//fmt.Println(bline)

		if len(bline) < n {
			return
		}

		for i:=0; i<n; i ++ {
			ddmap[bline[i]] ++;
		}
		sort.Sort(sort.Reverse(ddmap))

		//fmt.Println(ddmap)

		for i:=0; i<256 && i<n; i ++ {
			if k > int(ddmap[i]) {
				ret += ddmap[i]*ddmap[i]
			}else{
				ret += int64(k*k)
				break
			}

			k -= int(ddmap[i])
		}

	}
	fmt.Println(ret)

	return
}

package main

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

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

	line,_ := reader.ReadString('\n')

	arr := strings.Split(strings.TrimSpace(line), " ")

	ddmap := make([]int,256)
	ret := 0

	if len(arr) == 2 {
		n,_ := strconv.Atoi(arr[0])
		k,_ := strconv.Atoi(arr[1])

	//	fmt.Println(n,k)

		line,_ := reader.ReadString('\n')

		bline := []byte(line)

		//fmt.Println(bline)

		if len(bline) < n {
			return
		}

		for i:=0; i<n; i ++ {
			ddmap[bline[i]] ++;
		}
		sort.Sort(sort.Reverse(sort.IntSlice(ddmap)))

	//	fmt.Println(ddmap)

		for i:=0; i<256 && i<n; i ++ {
			if(k > ddmap[i]) {
				ret += ddmap[i]*ddmap[i]
			}else{
				ret += k*k
				break
			}

			k -= ddmap[i]
		}

	}
	fmt.Println(ret)

	return
}

package main

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

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

	line,_ := reader.ReadString('\n')

	arr := strings.Split(strings.TrimSpace(line), " ")

	ddmap := make([]int,256)
	var ret int64
	ret = 0

	if len(arr) == 2 {
		n,_ := strconv.Atoi(arr[0])
		k,_ := strconv.Atoi(arr[1])

	//	fmt.Println(n,k)

		line,_ := reader.ReadString('\n')

		bline := []byte(line)

		//fmt.Println(bline)

		if len(bline) < n {
			return
		}

		for i:=0; i<n; i ++ {
			ddmap[bline[i]] ++;
		}
		sort.Sort(sort.Reverse(sort.IntSlice(ddmap)))

	//	fmt.Println(ddmap)

		for i:=0; i<256 && i<n; i ++ {
			if(k > ddmap[i]) {
				ret += int64(ddmap[i]*ddmap[i])
			}else{
				ret += int64(k*k)
				break
			}

			k -= ddmap[i]
		}

	}
	fmt.Println(ret)

	return
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	var s string
	I(&s, "\n")
	in := make([]int, 200)
	for i := 0; i < len(s); i++ {
		in[s[i]]++
	}
	sort.Ints(in)
	ans := 0
	ii := len(in) - 1
	o := in[ii]
	oo := in[ii]
	if m < oo {
		oo = m
	}
	for m > 0 {
		ans += oo
		o--
		m--
		if o <= 0 {
			ii--
			o = in[ii]
			oo = in[ii]
			if m < oo {
				oo = m
			}
		}
	}
	O(ans, "\n")
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var m int
	I(&m, "\n")
	var s string
	I(&s, "\n")
	in := make([]int, 200)
	for i := 0; i < len(s); i++ {
		in[s[i]]++
	}
	sort.Ints(in)
	ans := 0
	ii := len(in) - 1
	o := in[ii]
	oo := in[ii]
	if m < oo {
		oo = m
	}
	for m > 0 {
		ans += oo
		o--
		m--
		if o <= 0 && ii > 0 {
			ii--
			o = in[ii]
			oo = in[ii]
			if m < oo {
				oo = m
			}
		}
	}
	O(ans, "\n")
}

package main

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

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

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

	var n, k int
	var s string

	fmt.Scan(&n, &k)
	fmt.Scan(&s)

	letters := make([]int, 26)
	coins := 0

	for i := 0; i < n; i++ {
		letters[s[i] - 'A']++
	}

	sort.Sort(sort.Reverse(sort.IntSlice(letters)))

	for i := 0; k > 0; {
		if k <= letters[i] {
			coins += k * k
			k = 0
		} else {
			coins += letters[i] * letters[i]
			k -= letters[i]
			i++
		}
		// println(k, coins)
	}

	println(coins)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	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 (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sort"
)

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

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

	var n, k int
	var s string

	fmt.Scan(&n, &k)
	fmt.Scan(&s)

	letters := make([]int, 26)
	coins := int64(0)

	for i := 0; i < n; i++ {
		letters[s[i] - 'A']++
	}

	sort.Sort(sort.Reverse(sort.IntSlice(letters)))

	for i := 0; k > 0; {
		if k <= letters[i] {
			coins += int64(k * k)
			k = 0
		} else {
			coins += int64(letters[i] * letters[i])
			k -= letters[i]
			i++
		}
		// println(k, coins)
	}

	println(coins)
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	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, k, i int
    array := make([]int, 26)
    for i = 0; i < 26; i++ {
        array[i] = 0
    }
    fmt.Scanf("%d %d ", &n, &k)
    for i = 0; i < n; i++ {
        var temp int8
        fmt.Scanf("%c", &temp)
        array[temp-'A']++
    }
    var score,coins int
    for coins < k {
        max,max_i := 0,0
        for i=0;i<26;i++{
            if array[i]>max {
                max = array[i]
                max_i = i
            }
        }
        if max > (k-coins) {
            score += ((k-coins) * (k-coins))
            coins += (k-coins)
        }else{
            coins += max
            score += max * max
            array[max_i]=0
        }
    }
    fmt.Printf("%d ", score)
}

package main

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

const l int = 26

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

	cnt := make([]int, l)

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = re.ReplaceAllString(s, "")
		for _, c := range s {
			cnt[int(c-'A')] += 1
		}

		bubble_sort(cnt, l)

		res := 0
		for i := 0; i < l; i++ {
			if k >= cnt[i] {
				res += cnt[i] * cnt[i]
				k -= cnt[i]
			} else {
				res += k * k
				break
			}
		}
		fmt.Println(res)
	}
}

func swap(a, b int, array []int) {
	array[a], array[b] = array[b], array[a]
}

func bubble_sort(array []int, length int) {
	for i := 0; i < length; i++ {
		for j := 0; j < length; j++ {
			if array[i] > array[j] {
				swap(i, j, array)
			}
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

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

	cards := ""
	fmt.Scan(&cards)

	counts := make([]int, 26, 26)
	for i := 0; i < len(cards); i++ {
		counts[cards[i]-'A']++
	}

	sort.Sort(sort.Reverse(sort.IntSlice(counts)))
	ans := 0
	i := 0
	for k > 0 {
		if counts[i] < k {
			k -= counts[i]
			ans += counts[i] * counts[i]
		} else {
			ans += k * k
			k = 0
		}
		i++
	}

	fmt.Println(ans)
}