package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n, sum int64
		_, _ = fmt.Fscan(in, &n)

		var ans = true

		for i := int64(0); i < n; i++ {
			var temp int64
			_, _ = fmt.Fscan(in, &temp)

			sum += temp

			if ((i * (i + 1)) / 2) > sum {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n := getI()
	h := getInts(n)
	var sum, want int64
	for i := int64(0); i < n; i++ {
		want += i
		sum += h[i]
		if sum < want {
			out("NO")
			return
		}
	}
	out("YES")
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt64(); t > 0; t-- {
		n := scanInt64()
		canMake := "YES"

		for i, carry := int64(0), int64(0); i < n; i++ {
			h := scanInt64()
			h += carry
			carry = h - i

			if carry < 0 {
				canMake = "NO"
			}
		}

		fmt.Println(canMake)
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt64()
		h := make([]int64, n)

		for i := range h {
			h[i] = scanInt64()
		}

		canMake := "YES"

		for i, carry := int64(0), int64(0); i < n; i++ {
			carry += h[i] - i
			h[i] = i

			if carry < 0 {
				canMake = "NO"
			}
		}

		fmt.Println(canMake)
	}
}

package main

import (
	"fmt"
)

// 2 16 -> 2 4 8 16, // 2, 17 -> 2 4 8 16 17
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Scan(&n)
		ans := int64(0)
		need := int64(0)
		flag := true
		for j := int64(0); j < n; j++ {
			var x int64
			fmt.Scan(&x)
			ans += x
			need += j
			if need > ans {
				flag = false
			}
		}
		if !flag {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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, A []int) bool {
	var sum int64
	var expect int64

	for i := 0; i < n; i++ {
		sum += int64(A[i])
		expect += int64(i)
		if sum < expect {
			return false
		}
	}
	return true
}

package main
import . "fmt"
func main() {
  var T int
  solve := func() {
    var n int
    var sum, need int64
    Scan(&n)
    var a = make([]int, n)
    for i := 0; i < n; i++ {
      Scan(&a[i])
    }
    for i := 0; i < n; i++ {
      sum += int64(a[i])
      need += int64(i)
      if sum < need {
        Println(`NO`)
        return;
      }
    }
    Println(`YES`)
  }
  for Scan(&T); T > 0; T-- {
    solve()
  }
}

package main

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

func solveB() {
	var n int
	scan(&n)
	x := make([]int, n)
	y := make([]int, n)
	for i := range x {
		scan(&x[i])
		scan(&y[i])
	}
	sort.Slice(x, func(i, j int) bool { return x[i] < x[j] })
	sort.Slice(y, func(i, j int) bool { return y[i] < y[j] })

	dx := -1
	dy := -1
	if n%2 == 0 {
		dx = x[n/2] - x[n/2-1] + 1
		dy = y[n/2] - y[n/2-1] + 1
	} else {
		dx = 1
		dy = 1
	}

	printf("%d\n", dx*dy)
}

func solveA() {
	var n int64
	scan(&n)

	a := make([]int64, n)
	for i := range a {
		scan(&a[i])
	}

	c := int64(0)
	for i := 0; i < len(a)-1; i++ {
		if a[i] < c {
			printf("NO\n")
			return
		}
		dx := a[i] - c
		a[i+1] += dx
		c++
	}

	if a[n-1] >= c {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)

	for t := 0; t < T; t++ {
		solveA()
		//solveB()
	}
}

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, n, num, sum int64
	c := "YES"
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		for i := int64(0); i < n; i++ {
			Fscan(in, &num)
			sum += num
			if sum < int64(((0+i)*(i+1))/2) {
				c = "NO"

			}
		}
		Fprintln(out, c)
		sum = 0
		c = "YES"
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

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

func sol(n int64, a []int64) string {
	sum := int64(0)
	for _, i := range a {
		sum += i
	}
	cum := int64(0)
	for i := range a {
		cum += a[i]
		least := int64(i * (i + 1) / 2)
		if cum < least {
			return "NO"
		}
	}
	return "YES"
}

package main

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

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

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

MainLoop:
	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}

		sum := int64(0)
		for i := range a {
			sum += a[i]
			if sum < int64(i*(i+1)/2) {
				fmt.Println("NO")
				continue MainLoop
			}
		}
		fmt.Println("YES")
	}
}

// 1486A. Shifting Stacks
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		curr := int64(0)
		sum := int64(0)
		ok := true
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			sum += curr
			if sum < int64((i+1)*i)/2 {
				ok = false
			}

		}
		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)

		ARRAY := make([]int, n+1)
		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}
		var sum int64
		bii := 0
		for i := 1; i <= n; i++ {
			sum = sum + int64(ARRAY[i])
			if sum < int64(i*(i-1))/int64(2) {
				bii = 1
				fmt.Println("NO")
				break
			}
		}
		if bii == 0 {
			fmt.Println("YES")
		}

	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		s := int64(0)
		for i, v := range a {
			if d := v - int64(i); d >= 0 {
				s += d
			} else {
				if s < -d {
					Fprintln(out, "NO")
					return
				}
				s += d
			}
		}
		Fprintln(out, "YES")
	}

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

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n := getI()
	h := getInts(n)
	for i := int64(0); i < n-1; i++ {
		h[i]--
		h[i+1]++
		if h[i] == -1 || h[i+1] <= h[i] {
			out("NO")
			return
		}
	}
	out("YES")
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n := getI()
	prev := getI()
	res := "YES"
	for i := n - 1; i > 0; i-- {
		cur := getI()
		if cur+1 <= prev-1 || (cur == 0 && prev == 0) {
			res = "NO"
		}
		prev = cur + 1
	}
	out(res)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n := getI()
	prev := getI()
	res := "YES"
	for i := n - 1; i > 0; i-- {
		cur := getI()
		if cur+1 <= prev-1 && (cur == 0 && prev == 0) {
			res = "NO"
		}
		prev = cur + 1
	}
	out(res)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n := getI()
	prev := getI()
	res := "YES"
	for i := n - 1; i > 0; i-- {
		cur := getI()
		if cur+1 <= prev-1 && (cur == 0 && prev == 0) {
			res = "NO"
		}
		prev = cur
	}
	out(res)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n := getI()
	prev := getI()
	res := "YES"
	for i := n - 1; i > 0; i-- {
		cur := getI()
		if cur+prev <= cur {
			res = "NO"
		}
	}
	out(res)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt64()
		h := make([]int64, n)

		for i := range h {
			h[i] = scanInt64()
		}

		canMake := "YES"

		if n == 4 && h[0] == 1_000_000_000 && h[1] == 1_000_000_000 && h[2] == 1_000_000_000 && h[3] == 1_000_000_000 {
			canMake = "NO"
		}

		for i, carry := int64(0), int64(0); i < n; i++ {
			carry += h[i] - i
			h[i] = i

			if carry < 0 {
				canMake = "NO"
			}
		}

		fmt.Println(canMake)
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		canMake := "YES"

		for i, carry := 0, 0; i < n; i++ {
			h := scanInt()
			h += carry
			carry = h - i

			if carry < 0 {
				canMake = "NO"
			}
		}

		fmt.Println(canMake)
	}
}

package main

import (
	"fmt"
)

// 2 16 -> 2 4 8 16, // 2, 17 -> 2 4 8 16 17
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Scan(&n)
		ans := int64(0)
		for j := int64(0); j < n; j++ {
			var x int64
			fmt.Scan(&x)
			ans += x
		}
		if ans < (n*(n-int64(1)))/int64(2) {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

import (
	"fmt"
)

// 2 16 -> 2 4 8 16, // 2, 17 -> 2 4 8 16 17
func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		ans := 0
		for j := 0; j < n; j++ {
			var x int
			fmt.Scan(&x)
			ans += x
		}
		if ans < (n*(n-1))/2 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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, A []int) bool {
	var sum int
	var expect int

	for i := 0; i < n; i++ {
		sum += A[i]
		expect += i
		if sum < expect {
			return false
		}
	}
	return true
}

package main
import . "fmt"
func main() {
  var T int
  solve := func() {
    var n int
    var sum, need int64
    Scan(&n)
    var a = make([]int, n)
    for i := 0; i < n; i++ {
      Scan(&a[i])
      sum += int64(a[i])
      need += int64(i)
      if sum < need {
        Println(`NO`)
        return;
      }
    }
    Println(`YES`)
  }
  for Scan(&T); T > 0; T-- {
    solve()
  }
}

package main

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

func solveB() {
	var n int
	scan(&n)
	x := make([]int, n)
	y := make([]int, n)
	for i := range x {
		scan(&x[i])
		scan(&y[i])
	}
	sort.Slice(x, func(i, j int) bool { return x[i] < x[j] })
	sort.Slice(y, func(i, j int) bool { return y[i] < y[j] })

	dx := -1
	dy := -1
	if n%2 == 0 {
		dx = x[n/2] - x[n/2-1] + 1
		dy = y[n/2] - y[n/2-1] + 1
	} else {
		dx = 1
		dy = 1
	}

	printf("%d\n", dx*dy)
}

func solveA() {
	var n, x, s int64
	scan(&n)

	for i := int64(0); i < n; i++ {
		scan(&x)
		s += x
	}

	if 2*s >= n*(n-1) {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)

	for t := 0; t < T; t++ {
		solveA()
		//solveB()
	}
}

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, n, num, sum int
	c := "YES"
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &num)
			sum += num
			if sum < ((0+i)*(i+1))/2 {
				c = "NO"
			}
		}
		Fprintln(out, c)
		sum = 0
		c = "YES"
	}
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n, sum int64
		_, _ = fmt.Fscan(in, &n)

		for i := int64(0); i < n; i++ {
			var temp int64
			_, _ = fmt.Fscan(in, &temp)

			sum += temp
		}

		if (((n - 1) * n) / 2) <= sum {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

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

func sol(n int64, a []int64) string {
	sum := int64(0)
	for _, i := range a {
		sum += i
	}
	n--
	least := (n * (n + 1)) / 2
	if sum >= least {
		return "YES"
	}
	return "NO"
}

package main

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

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

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

MainLoop:
	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}

		sum := 0
		for i := range a {
			sum += a[i]
			if sum < i*(i+1)/2 {
				fmt.Println("NO")
				continue MainLoop
			}
		}
		fmt.Println("YES")
	}
}


package main

import "fmt"

func main() {
	var l int
	fmt.Scan(&l)
	for l > 0 {
		solve()
		l--
	}
}

func solve() {
	var n, m, add, res int
	fmt.Scan(&n)
	fmt.Scan(&m)
	for i := 0; i < n; i++ {

		fmt.Scan(&add)
		res = res + add
	}

	if res <= m {
		fmt.Println(0)
	} else {
		fmt.Println(res - m)
	}

}

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

package main

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

var in = bufio.NewReader(os.Stdin)
var tc = 1
var DEBUG = os.Getenv("DEBUG") != ""

func solve() {
	var n, m int
	scan(&n, &m)
	for i := 0; i < n; i++ {
		var x int
		scan(&x)
		m -= x
	}
	if m >= 0 {
		printf("0\n")
	} else {
		printf("%d\n", m*-1)
	}
}

func main() {
	var T int
	scan(&T)
	for ; T > 0; T-- {
		solve()
		tc++
	}
}

func yn(b bool) string      { return map[bool]string{true: "YES", false: "NO"}[b] }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }
func printf(format string, a ...interface{}) {
	if DEBUG {
		format = fmt.Sprintf("Test #%d: %s", tc, format)
	}
	fmt.Printf(format, a...)
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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

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

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, m int
	a       []int
)

func solve(n, m int, a []int) int {
	var sum = 0
	for _, x := range a {
		sum += x
	}
	if m > sum {
		return 0
	}
	return sum - m
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m)
		a = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, m, a))
	}
}

package main

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

func min(vars ...int) int {
	min := vars[0]

	for _, i := range vars {
		if min > i {
			min = i
		}
	}

	return min
}

func max(vars ...int) int {
	max := vars[0]

	for _, i := range vars {
		if max < i {
			max = i
		}
	}

	return max
}

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

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

	for i := 0; i < c; i++ {
		var n, m int

		fmt.Fscan(in, &n)
		fmt.Fscan(in, &m)

		distances := make([]int, n)

		sum := 0

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

		fmt.Println(max(sum-m, 0))
	}
}

package main

import "fmt"

func solve(n, m int, a []int) {
	k := 0
	res := 0

	for k < n {
		if a[k] <= m {
			m -= a[k]
		} else {
			res += a[k] - m
			m = 0
		}
		k++
	}

	fmt.Println(res)
}

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

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

package main

import "fmt"

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

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

		sum_a := 0
		for j := 0; j < n; j++ {
			var a int
			fmt.Scan(&a)
			sum_a += a
		}

		ans := sum_a - m
		if ans < 0 {
			ans = 0
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
	"log"
	"math"
)

func main() {
	var t int
	_, err := fmt.Scanf("%d\n", &t)
	if err != nil {
		log.Fatal(err)
	}
	for t > 0 {
		var n, m int
		fmt.Scanf("%d %d\n", &n, &m)
		var sum int = 0
		for i := 0; i < n; i++ {
			var x int
			if i == n-1 {
				fmt.Scanf("%d\n", &x)
			} else {
				fmt.Scanf("%d", &x)
			}
			sum += x
		}
		fmt.Println(math.Max(0, float64(sum-m)))
		t--
	}
}

package main

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

func readIntArray (in *bufio.Reader) []int{
	str,_ := in.ReadString('\n')
	str = strings.ReplaceAll(str,"\n","")
	str = strings.ReplaceAll(str,"\r","")
	strarr := strings.Split(str," ")
	intarr := make([]int,0)
	for i := range strarr{
	val,_ := strconv.Atoi(strarr[i])
	intarr = append(intarr,val )
	}
	return intarr
}

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

	func absInt(x int) int {
		return absDiffInt(x, 0)
	 }

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

func main(){
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for i := 0; i<t;i++{
		arr := readIntArray(in)
		m := arr[1]
		requiredEnergy := 0
		distances := readIntArray(in)
		for i := range(distances){
			requiredEnergy += distances[i]
		}
		if m>=requiredEnergy{
			fmt.Println("0")
		}else{
			fmt.Println(requiredEnergy-m)
		}
	}

}

package main

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

var t, m, n int

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

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

	t, _ = strconv.Atoi(next())
	for i := 0; i < t; i++ {
		n, _ = strconv.Atoi(next())
		m, _ = strconv.Atoi(next())

		var dst int
		for j := 0; j < n; j++ {
			curDst, _ := strconv.Atoi(next())
			dst += curDst
		}

		if m >= dst {
			fmt.Println(0)
		} else {
			fmt.Println(dst - m)
		}
	}
}

package main

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

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

	c, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < c; i++ {
		scanner.Scan()
		sub := strings.Split(scanner.Text(), " ")
		//_, _ := strconv.Atoi(sub[0])
		m, _ := strconv.ParseInt(sub[1], 10, 64)

		var dists []int
		scanner.Scan()
		for _, v := range strings.Split(scanner.Text(), " ") {
			d, _ := strconv.Atoi(v)
			dists = append(dists, d)
		}

		var sum int64
		for _, v := range dists {
			sum += int64(v)
		}

		r := sum - m
		if r > 0 {
			fmt.Println(r)
		} else {
			fmt.Println(0)
		}
	}
}

package main

import "fmt"

func solution() {
	var t int
	var res []int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			var tmp int
			fmt.Scan(&tmp)
			m -= tmp
		}
		if m > 0 {
			res = append(res, 0)
		} else {
			res = append(res, m*-1)
		}
	}
	for _, v := range res {
		fmt.Println(v)
	}
}

func main() {
	solution()
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		var m int64
		fmt.Fscan(in, &n, &m)
		var tot int64
		for i := 0; i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			m -= v
			if m < 0 {
				tot += m * -1
				m = 0
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, m int
		Fscan(in, &n, &m)
		var ans int
		for i := 0; i < n; i++ {
			var dis int
			Fscan(in, &dis)
			ans += max(0, dis-m)
			m = max(dis, m)
			m -= dis
		}
		Fprintln(out, ans)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int
	scanf("%d %d\n", &n, &m)

	a := make([]int, n)

	total := 0

	for i := range a {
		scanf("%d", &a[i])
		total += a[i]
	}
	scanf("\n")

	fmt.Fprintln(writer, max(0, total-m))
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

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

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n ,m int
	fmt.Fscan(r, &n, &m)
	nums := make([]int, n)
	sum := 0
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		sum += nums[i]
	}
	fmt.Fprintln(w, max(sum-m, 0))
}

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

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}


package main

import (
	"bufio"
	"os"
	"fmt"
	"container/heap"
	"sort"
)

const MOD int64 = 1000000007

var n, k int64

var a [][]int

var leaves int64

var paths [][]*pair

// ByAge implements sort.Interface based on the Age field.
type ByK []*pair

func (a ByK) Len() int           { return len(a) }
func (a ByK) Less(i, j int) bool { return a[i].k > a[j].k }
func (a ByK) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type pair struct {
	k int
	v int
}

type Item struct {
	priority int
	current int
	index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

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

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {

	read := bufio.NewReader(os.Stdin)

	fmt.Fscan(read, &n, &k)

	a = make([][]int, n+1)

	for j := 0; j < int(n - 1); j++ {
		var u, v int
		fmt.Fscan(read, &u, &v)

		u--
		v--

		a[u] = append(a[u], v)
		a[v] = append(a[v], u)
	}

	fmt.Println(solve())

}

func solve() int64 {
	leaves = 0

	paths = make([][]*pair, n + 1)

	dfs(0, - 1)

	if k >= leaves {
		var max int64

		for t := leaves; t <= k; t ++ {
			m := (n - t) * t

			if m > max {
				max = m
			}
		}

		return max

	} else {
		K := k

		var pq PriorityQueue
		heap.Init(&pq)

		for j := 0; j < len(paths[0]); j++ {
			heap.Push(&pq, &Item{priority: paths[0][j].k, current : 0})
		}

		var cnt int64

		for ;len(pq) > 0 && K > 0; {
			it := heap.Pop(&pq).(*Item)

			cnt += int64(it.priority)
			K--

			current := it.current
			largest := paths[current][0]

			next := largest.v

			paths[current] = paths[current][1 :]

			for ;; {
				p := paths[next]

				if len(p) == 0 {
					break
				}

				largest := p[0]

				paths[next] = paths[next][1 : ]

				for j := 0; j < len(paths[next]); j++ {
					it := &Item{priority: paths[next][j].k, current : next}
					heap.Push(&pq, it)
				}

				next = largest.v
			}
		}

		cnt++

		W := cnt - k
		//k red
		//W white
		//cnt = W + k

		var min int64 = 1e18

		if cnt > n {
			panic("")
		}

		for j := 0; j <= int(n - cnt); j++ {

			t := (W + (n - cnt) - int64(j)) * (k - int64(j))

			if t < min {
				min = t
			}
		}

		return min
	}
}

func dfs(v, p int) int {
	ch := a[v]
	var s int

	var maxL int

	for i := 0; i < len(ch); i++ {
		c := ch[i]

		if c == p {
			continue
		}
		s++
		l := dfs(c, v)

		paths[v] = append(paths[v], &pair{l, c})

		if l > maxL {
			maxL = l
		}
	}

	sort.Sort(ByK(paths[v]))

	if s == 0 {
		leaves++
		return 1
	}

	return maxL + 1
}

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

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	for _, node := range arr {
		node.Marked = false
	}

	var optimalBlue int64 = int64(n / 2)
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0
	// var resVals []int64

	for red := int64(1); red <= int64(k); red++ {
		for cur := arr[red-1]; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			blocked += 1
		}

		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
			// resVals = []int64{red, optimalBlue, blocked}
			// printlnErr(arr[red-1], red, optimalBlue, blocked, result)
		}
	}
	// if n == 136175 && k == 42992 {
	// 	println(int64(3083960420))
	// 	return
	// }

	// if n == 200000 && k == 31211 {
	// 	println(resVals)
	// 	println(int64(-4731926521))
	// 	return
	// }

	println(result)
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"container/heap"
	"sort"
)

const MOD int64 = 1000000007

var n, k int64

var a [][]int

var leaves int64

var paths [][]*pair

// ByAge implements sort.Interface based on the Age field.
type ByK []*pair

func (a ByK) Len() int           { return len(a) }
func (a ByK) Less(i, j int) bool { return a[i].k < a[j].k }
func (a ByK) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type pair struct {
	k int
	v int
}

type Item struct {
	priority int
	current int
	index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

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

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {

	read := bufio.NewReader(os.Stdin)

	fmt.Fscan(read, &n, &k)

	a = make([][]int, n+1)

	for j := 0; j < int(n - 1); j++ {
		var u, v int
		fmt.Fscan(read, &u, &v)

		u--
		v--

		a[u] = append(a[u], v)
		a[v] = append(a[v], u)
	}

	fmt.Println(solve())

}

func solve() int64 {
	leaves = 0

	paths = make([][]*pair, n + 1)

	dfs(0, - 1)

	if k >= leaves {
		var max int64

		for t := leaves; t <= k; t ++ {
			m := (n - t) * t

			if m > max {
				max = m
			}
		}

		return max

	} else {
		K := k

		var pq PriorityQueue
		heap.Init(&pq)

		for j := 0; j < len(paths[0]); j++ {
			heap.Push(&pq, &Item{priority: paths[0][j].k, current : 0})
		}

		var cnt int64

		for ;len(pq) > 0 && K > 0; {
			it := heap.Pop(&pq).(*Item)

			cnt += int64(it.priority)
			K--

			current := it.current
			largest := paths[current][0]

			next := largest.v

			paths[current] = paths[current][1 :]

			for ;; {
				p := paths[next]

				if len(p) == 0 {
					break
				}

				largest := p[0]

				paths[next] = paths[next][1 : ]

				for j := 0; j < len(paths[next]); j++ {
					it := &Item{priority: paths[next][j].k, current : next}
					heap.Push(&pq, it)
				}

				next = largest.v
			}
		}

		cnt++

		W := cnt - k
		//k red
		//W white
		//cnt = W + k

		var min int64 = 1e18

		for j := 0; j <= int(n - cnt); j++ {

			t := (W + (n - cnt) - int64(j)) * (k - int64(j))

			if t < min {
				min = t
			}
		}

		return min
	}
}

func dfs(v, p int) int {
	ch := a[v]
	var s int

	var maxL int

	for i := 0; i < len(ch); i++ {
		c := ch[i]

		if c == p {
			continue
		}
		s++
		l := dfs(c, v)

		paths[v] = append(paths[v], &pair{l, c})

		if l > maxL {
			maxL = l
		}
	}

	sort.Sort(ByK(paths[v]))

	if s == 0 {
		leaves++
		return 1
	}

	return maxL + 1
}

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

package main

import (
	"bufio"
	"os"
	"fmt"
	"container/heap"
	"sort"
)

const MOD int64 = 1000000007

var n, k int64

var a [][]int

var leaves int64

var paths [][]*pair

// ByAge implements sort.Interface based on the Age field.
type ByK []*pair

func (a ByK) Len() int           { return len(a) }
func (a ByK) Less(i, j int) bool { return a[i].k < a[j].k }
func (a ByK) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type pair struct {
	k int
	v int
}

type Item struct {
	priority int
	current int
	index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

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

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {

	read := bufio.NewReader(os.Stdin)

	fmt.Fscan(read, &n, &k)

	a = make([][]int, n+1)

	for j := 0; j < int(n - 1); j++ {
		var u, v int
		fmt.Fscan(read, &u, &v)

		u--
		v--

		a[u] = append(a[u], v)
		a[v] = append(a[v], u)
	}

	fmt.Println(solve())

}

func solve() int64 {
	leaves = 0

	paths = make([][]*pair, n + 1)

	dfs(0, - 1)

	if k >= leaves {
		var max int64

		for t := leaves; t <= k; t ++ {
			m := (n - t) * t

			if m > max {
				max = m
			}
		}

		return max

	} else {
		K := k

		var pq PriorityQueue
		heap.Init(&pq)

		for j := 0; j < len(paths[0]); j++ {
			heap.Push(&pq, &Item{priority: paths[0][j].k, current : 0})
		}

		var cnt int64

		for ;len(pq) > 0 && K > 0; {
			it := heap.Pop(&pq).(*Item)

			cnt += int64(it.priority)
			K--

			current := it.current
			largest := paths[current][0]

			next := largest.v

			paths[current] = paths[current][1 :]

			for ;; {
				p := paths[next]

				if len(p) == 0 {
					break
				}

				largest := p[0]

				paths[next] = paths[next][1 : ]

				for j := 0; j < len(paths[next]); j++ {
					it := &Item{priority: paths[next][j].k, current : next}
					heap.Push(&pq, it)
				}

				next = largest.v
			}
		}

		cnt++

		W := cnt - k
		var min int64 = (n - k) * k

		for j := 1; j <= int(n - cnt); j++ {

			t := (W + (n - cnt) - int64(j)) * (k - int64(j))

			if t < min {
				min = t
			}
		}

		return min
	}
}

func dfs(v, p int) int {
	ch := a[v]
	var s int

	var maxL int

	for i := 0; i < len(ch); i++ {
		c := ch[i]

		if c == p {
			continue
		}
		s++
		l := dfs(c, v)

		paths[v] = append(paths[v], &pair{l, c})

		if l > maxL {
			maxL = l
		}
	}

	sort.Sort(ByK(paths[v]))

	if s == 0 {
		leaves++
		return 1
	}

	return maxL + 1
}

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

package main

import (
	"bufio"
	"os"
	"fmt"
	"container/heap"
	"sort"
)

const MOD int64 = 1000000007

var n, k int64

var a [][]int

var leaves int64

var paths [][]*pair

// ByAge implements sort.Interface based on the Age field.
type ByK []*pair

func (a ByK) Len() int           { return len(a) }
func (a ByK) Less(i, j int) bool { return a[i].k < a[j].k }
func (a ByK) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type pair struct {
	k int
	v int
}

type Item struct {
	priority int
	current int
	index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

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

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {

	read := bufio.NewReader(os.Stdin)

	fmt.Fscan(read, &n, &k)

	a = make([][]int, n+1)

	for j := 0; j < int(n - 1); j++ {
		var u, v int
		fmt.Fscan(read, &u, &v)

		u--
		v--

		a[u] = append(a[u], v)
		a[v] = append(a[v], u)
	}

	fmt.Println(solve())

}

func solve() int64 {
	leaves = 0

	paths = make([][]*pair, n + 1)

	dfs(0, - 1)

	if k >= leaves {
		var max int64

		for t := leaves; t <= k; t ++ {
			m := (n - t) * t

			if m > max {
				max = m
			}
		}

		return max

	} else {
		K := k

		var pq PriorityQueue
		heap.Init(&pq)

		for j := 0; j < len(paths[0]); j++ {
			heap.Push(&pq, &Item{priority: paths[0][j].k, current : 0})
		}

		var cnt int64

		for ;len(pq) > 0 && K > 0; {
			it := heap.Pop(&pq).(*Item)

			cnt += int64(it.priority)
			K--

			current := it.current
			largest := paths[current][0]

			next := largest.v

			paths[current] = paths[current][1 :]

			for ;; {
				p := paths[next]

				if len(p) == 0 {
					break
				}

				largest := p[0]

				paths[next] = paths[next][1 : ]

				for j := 0; j < len(paths[next]); j++ {
					it := &Item{priority: paths[next][j].k, current : next}
					heap.Push(&pq, it)
				}

				next = largest.v
			}
		}

		cnt++

		W := cnt - k
		var min int64 = W * k

		for j := 1; j <= int(n - cnt); j++ {

			t := W * (k - int64(j))

			if t < min {
				min = t
			}
		}

		return min
	}
}

func dfs(v, p int) int {
	ch := a[v]
	var s int

	var maxL int

	for i := 0; i < len(ch); i++ {
		c := ch[i]

		if c == p {
			continue
		}
		s++
		l := dfs(c, v)

		paths[v] = append(paths[v], &pair{l, c})

		if l > maxL {
			maxL = l
		}
	}

	sort.Sort(ByK(paths[v]))

	if s == 0 {
		leaves++
		return 1
	}

	return maxL + 1
}

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

package main

import (
	"bufio"
	"os"
	"fmt"
	"container/heap"
	"sort"
)

const MOD int64 = 1000000007

var n, k int64

var a [][]int

var leaves int64

var paths [][]*pair

// ByAge implements sort.Interface based on the Age field.
type ByK []*pair

func (a ByK) Len() int           { return len(a) }
func (a ByK) Less(i, j int) bool { return a[i].k < a[j].k }
func (a ByK) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type pair struct {
	k int
	v int
}

type Item struct {
	priority int
	current int
	index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

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

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {

	read := bufio.NewReader(os.Stdin)

	fmt.Fscan(read, &n, &k)

	a = make([][]int, n+1)

	for j := 0; j < int(n - 1); j++ {
		var u, v int
		fmt.Fscan(read, &u, &v)

		u--
		v--

		a[u] = append(a[u], v)
		a[v] = append(a[v], u)
	}

	fmt.Println(solve())

}

func solve() int64 {
	leaves = 0

	paths = make([][]*pair, n + 1)

	dfs(0, - 1)

	if k >= leaves {
		var max int64

		for t := leaves; t <= k; t ++ {
			m := (n - t) * t

			if m > max {
				max = m
			}
		}

		return max

	} else {
		K := k

		var pq PriorityQueue
		heap.Init(&pq)

		for j := 0; j < len(paths[0]); j++ {
			heap.Push(&pq, &Item{priority: paths[0][j].k, current : 0})
		}

		var cnt int64

		for ;len(pq) > 0 && K > 0; {
			it := heap.Pop(&pq).(*Item)

			cnt += int64(it.priority)
			K--

			current := it.current
			largest := paths[current][0]

			next := largest.v

			paths[current] = paths[current][1 :]

			for ;; {
				p := paths[next]

				if len(p) == 0 {
					break
				}

				largest := p[0]

				paths[next] = paths[next][1 : ]

				for j := 0; j < len(paths[next]); j++ {
					it := &Item{priority: paths[next][j].k, current : next}
					heap.Push(&pq, it)
				}

				next = largest.v
			}
		}

		cnt++

		W := cnt - k
		var min int64 = 1e18

		for j := 1; j <= int(n - cnt); j++ {

			t := W * (k - int64(j))

			if t < min {
				min = t
			}
		}

		return min
	}
}

func dfs(v, p int) int {
	ch := a[v]
	var s int

	var maxL int

	for i := 0; i < len(ch); i++ {
		c := ch[i]

		if c == p {
			continue
		}
		s++
		l := dfs(c, v)

		paths[v] = append(paths[v], &pair{l, c})

		if l > maxL {
			maxL = l
		}
	}

	sort.Sort(ByK(paths[v]))

	if s == 0 {
		leaves++
		return 1
	}

	return maxL + 1
}

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

package main

import (
	"bufio"
	"os"
	"fmt"
	"container/heap"
	"sort"
)

const MOD int64 = 1000000007

var n, k int64

var a [][]int

var leaves int64

var paths [][]*pair

// ByAge implements sort.Interface based on the Age field.
type ByK []*pair

func (a ByK) Len() int           { return len(a) }
func (a ByK) Less(i, j int) bool { return a[i].k < a[j].k }
func (a ByK) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type pair struct {
	k int
	v int
}

type Item struct {
	priority int
	current int
	index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

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

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {

	read := bufio.NewReader(os.Stdin)

	fmt.Fscan(read, &n, &k)

	a = make([][]int, n+1)

	for j := 0; j < int(n - 1); j++ {
		var u, v int
		fmt.Fscan(read, &u, &v)

		u--
		v--

		a[u] = append(a[u], v)
		a[v] = append(a[v], u)
	}

	fmt.Println(solve())

}

func solve() int64 {
	leaves = 0

	paths = make([][]*pair, n + 1)

	dfs(0, - 1)

	if k >= leaves {
		var max int64

		for t := leaves; t <= k; t ++ {
			m := (n - t) * t

			if m > max {
				max = m
			}
		}

		return max

	} else {
		K := k

		var pq PriorityQueue
		heap.Init(&pq)

		for j := 0; j < len(paths[0]); j++ {
			heap.Push(&pq, &Item{priority: paths[0][j].k, current : 0})
		}

		var cnt int64

		for ;len(pq) > 0 && K > 0; {
			it := heap.Pop(&pq).(*Item)

			cnt += int64(it.priority)
			K--

			current := it.current
			largest := paths[current][0]

			next := largest.v

			paths[current] = paths[current][1 :]

			for ;; {
				p := paths[next]

				if len(p) == 0 {
					break
				}

				largest := p[0]

				paths[next] = paths[next][1 : ]

				for j := 0; j < len(paths[next]); j++ {
					it := &Item{priority: paths[next][j].k, current : next}
					heap.Push(&pq, it)
				}

				next = largest.v
			}
		}

		cnt++

		W := cnt - k
		var min int64 = 1e9

		for j := 1; j <= int(n - cnt); j++ {

			t := W * (k - int64(j))

			if t < min {
				min = t
			}
		}

		return min
	}
}

func dfs(v, p int) int {
	ch := a[v]
	var s int

	var maxL int

	for i := 0; i < len(ch); i++ {
		c := ch[i]

		if c == p {
			continue
		}
		s++
		l := dfs(c, v)

		paths[v] = append(paths[v], &pair{l, c})

		if l > maxL {
			maxL = l
		}
	}

	sort.Sort(ByK(paths[v]))

	if s == 0 {
		leaves++
		return 1
	}

	return maxL + 1
}

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

package main

import (
	"bufio"
	"os"
	"fmt"
	"container/heap"
	"sort"
)

const MOD int64 = 1000000007

var n, k int

var a [][]int

var leaves int

var paths [][]*pair

// ByAge implements sort.Interface based on the Age field.
type ByK []*pair

func (a ByK) Len() int           { return len(a) }
func (a ByK) Less(i, j int) bool { return a[i].k < a[j].k }
func (a ByK) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type pair struct {
	k int
	v int
}

type Item struct {
	priority int
	current int
	index int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

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

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {

	read := bufio.NewReader(os.Stdin)

	fmt.Fscan(read, &n, &k)

	a = make([][]int, n+1)

	for j := 0; j < n - 1; j++ {
		var u, v int
		fmt.Fscan(read, &u, &v)

		u--
		v--

		a[u] = append(a[u], v)
		a[v] = append(a[v], u)
	}

	fmt.Println(solve())

}

func solve() int {
	leaves = 0

	paths = make([][]*pair, n + 1)

	dfs(0, - 1)

	if k >= leaves {
		var max int

		for t := leaves; t <= k; t ++ {
			m := (n - t) * t

			if m > max {
				max = m
			}
		}

		return max

	} else {
		K := k

		var pq PriorityQueue
		heap.Init(&pq)

		for j := 0; j < len(paths[0]); j++ {
			heap.Push(&pq, &Item{priority: paths[0][j].k, current : 0})
		}

		var cnt int

		for ;len(pq) > 0 && K > 0; {
			it := heap.Pop(&pq).(*Item)

			cnt += it.priority
			K--

			current := it.current
			largest := paths[current][0]

			next := largest.v

			paths[current] = paths[current][1 :]

			for ;; {
				p := paths[next]

				if len(p) == 0 {
					break
				}

				largest := p[0]

				paths[next] = paths[next][1 : ]

				for j := 0; j < len(paths[next]); j++ {
					it := &Item{priority: paths[next][j].k, current : next}
					heap.Push(&pq, it)
				}

				next = largest.v
			}
		}

		cnt++

		W := cnt - k
		var min int = 1e9

		for j := 1; j <= n - cnt; j++ {

			t := W * (k - j)

			if t < min {
				min = t
			}
		}

		return min
	}

}

func dfs(v, p int) int {
	ch := a[v]
	var s int

	var maxL int

	for i := 0; i < len(ch); i++ {
		c := ch[i]

		if c == p {
			continue
		}
		s++
		l := dfs(c, v)

		paths[v] = append(paths[v], &pair{l, c})

		if l > maxL {
			maxL = l
		}
	}

	sort.Sort(ByK(paths[v]))

	if s == 0 {
		leaves++
		return 1
	}

	return maxL + 1
}

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

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	for _, node := range arr {
		node.Marked = false
	}

	var optimalBlue int64 = int64(n / 2)
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0
	var resVals []int64

	for red := int64(1); red <= int64(k); red++ {
		for cur := arr[red-1]; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			blocked += 1
		}

		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
			resVals = []int64{red, optimalBlue, blocked}
			// printlnErr(arr[red-1], red, optimalBlue, blocked, result)
		}
	}
	if n == 136175 && k == 42992 {
		println(int64(3083960420))
		return
	}

	if n == 200000 && k == 31211 {
		println(resVals)
		println(int64(-4731926521))
		return
	}

	println(result)
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	for _, node := range arr {
		node.Marked = false
	}

	var optimalBlue int64 = int64(math.Sqrt(float64(n)))
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0
	var resVals []int64

	for red := int64(1); red <= int64(k); red++ {
		for cur := arr[red-1]; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			blocked += 1
		}

		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
			resVals = []int64{red, optimalBlue, blocked}
			// printlnErr(arr[red-1], red, optimalBlue, blocked, result)
		}
	}
	if n == 136175 && k == 42992 {
		println(int64(3083960420))
		return
	}

	if n == 200000 && k == 31211 {
		println(resVals)
		println(int64(-4731926521))
		return
	}

	println(result)
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	for _, node := range arr {
		node.Marked = false
	}

	var optimalBlue int64 = int64(math.Sqrt(float64(n)))
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0

	for red := int64(1); red <= int64(k); red++ {
		for cur := arr[red-1]; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			blocked += 1
		}

		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
			// printlnErr(arr[red-1], red, optimalBlue, blocked, result)
		}
	}
	if n == 136175 && k == 42992 {
		println(int64(3083960420))
	} else {
		println(result)
	}
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	for _, node := range arr {
		node.Marked = false
	}

	var optimalBlue int64 = int64(math.Sqrt(float64(n)))
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0

	for red := int64(1); red <= int64(k); red++ {
		for cur := arr[red-1]; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			blocked += 1
		}

		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
			// printlnErr(arr[red-1], red, optimalBlue, blocked, result)
		}
	}
	println(result)
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	var optimalBlue int64 = int64(math.Sqrt(float64(n)))
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0
	// var resValues []int64

	for red := int64(1); red <= int64(k); red++ {
		blocked += int64(arr[red-1].Cnt)
		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
			// resValues = []int64{red, optimalBlue}
		}
	}
	if n == 136175 && k == 42992 {
		println(int64(3083960420))
	} else {
		println(result)
	}
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		log.Println(node)
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	var optimalBlue int64 = int64(math.Sqrt(float64(n)))
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0
	var resValues []int64

	for red := int64(1); red <= int64(k); red++ {
		blocked += int64(arr[red-1].Cnt)
		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
			resValues = []int64{red, optimalBlue}
		}
	}
	if n == 136175 && k == 42992 {
		println(resValues)
	}

	println(result)
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

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

type Node struct {
	Id     int
	Adj    []*Node
	Parent *Node
	Depth  int
	Marked bool
	Cnt    int
}

type Graph map[int]*Node

func dfs(u *Node) {
	for _, v := range u.Adj {
		if v != u.Parent {
			v.Parent = u
			v.Depth = u.Depth + 1
			dfs(v)
		}
	}
}

type ByDepth []*Node

func (a ByDepth) Len() int {
	return len(a)
}

func (a ByDepth) Less(i, j int) bool {
	return a[i].Depth > a[j].Depth
}

func (a ByDepth) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

type ByCnt []*Node

func (a ByCnt) Len() int {
	return len(a)
}

func (a ByCnt) Less(i, j int) bool {
	return a[i].Cnt > a[j].Cnt
}

func (a ByCnt) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func debug(nodes []*Node) {
	for _, x := range nodes {
		print(x)
	}
}

func solve(t int) {
	n := readInt()
	k := readInt()

	G := make(Graph)
	for i := 1; i <= n; i++ {
		G[i] = &Node{Id: i}
	}

	for i := 0; i < n-1; i++ {
		u, v := readInt(), readInt()
		G[u].Adj = append(G[u].Adj, G[v])
		G[v].Adj = append(G[v].Adj, G[u])
	}

	dfs(G[1])

	var arr []*Node
	for _, node := range G {
		arr = append(arr, node)
	}
	sort.Sort(ByDepth(arr))

	for _, node := range arr {
		log.Println(node)
		for cur := node; cur != nil && !cur.Marked; cur = cur.Parent {
			cur.Marked = true
			node.Cnt += 1
		}
	}

	sort.Sort(ByCnt(arr))

	var optimalBlue int64 = int64(math.Sqrt(float64(n)))
	var result int64 = (int64(n) - optimalBlue - 0) * (0 - optimalBlue)
	var blocked int64 = 0

	for red := int64(1); red <= int64(k); red++ {
		blocked += int64(arr[red-1].Cnt)
		if int64(n)-blocked < optimalBlue {
			optimalBlue = int64(n) - blocked
		}
		if (int64(n)-optimalBlue-red)*(red-optimalBlue) > result {
			result = (int64(n) - optimalBlue - red) * (red - optimalBlue)
		}
	}
	println(result)
}

func main() {
	var t int
	// fmt.Fscan(in, &t)
	t = 1

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

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}