Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes...Let's define a Rooted Dead Bush (RDB) of level $$$n$$$ as a rooted tree constructed as described below.A rooted dead bush of level $$$1$$$ is a single vertex. To construct an RDB of level $$$i$$$ we, at first, construct an RDB of level $$$i-1$$$, then for each vertex $$$u$$$:   if $$$u$$$ has no children then we will add a single child to it;  if $$$u$$$ has one child then we will add two children to it;  if $$$u$$$ has more than one child, then we will skip it.   Rooted Dead Bushes of level $$$1$$$, $$$2$$$ and $$$3$$$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw:  The center of the claw is the vertex with label $$$1$$$. Lee has a Rooted Dead Bush of level $$$n$$$. Initially, all vertices of his RDB are green.In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow.He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $$$10^9+7$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ lines contain test cases — one per line. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^6$$$) — the level of Lee's RDB.

For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $$$10^9 + 7$$$.

NoteIt's easy to see that the answer for RDB of level $$$1$$$ or $$$2$$$ is $$$0$$$.The answer for RDB of level $$$3$$$ is $$$4$$$ since there is only one claw we can choose: $$$\{1, 2, 3, 4\}$$$.The answer for RDB of level $$$4$$$ is $$$4$$$ since we can choose either single claw $$$\{1, 3, 2, 4\}$$$ or single claw $$$\{2, 7, 5, 6\}$$$. There are no other claws in the RDB of level $$$4$$$ (for example, we can't choose $$$\{2, 1, 7, 6\}$$$, since $$$1$$$ is not a child of center vertex $$$2$$$).  Rooted Dead Bush of level 4.

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		fmt.Println(solve(n))
	}
}

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
}

const N = 2000010

var F [N]int64

const MOD = 1000000007

func init() {
	F[1] = 0
	F[2] = 0
	F[3] = 4

	var x, y int64 = 1, 3

	for i := 4; i < N; i++ {
		F[i] = F[i-3] + 4*x
		F[i] %= MOD
		x, y = y, y+2*x
		y %= MOD
	}
}

func solve(n int) int {
	return int(F[n])
}

/*
URL:
https://codeforces.com/problemset/problem/1369/D
*/

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
	dp [2000000 + 50]int64
)

func main() {
	for i := 3; i <= 2000000; i++ {
		if i%3 == 0 {
			dp[i] = 2*dp[i-2] + dp[i-1] + 4
		} else {
			dp[i] = 2*dp[i-2] + dp[i-1]
		}
		dp[i] %= MOD
	}

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

		fmt.Println(dp[n])
	}
}

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

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

// github.com/EndlessCheng/codeforces-go
func CF1369D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int = 1e9 + 7
	const mx int = 2e6
	dp := [mx + 1]int{}
	for i := 3; i <= mx; i++ {
		dp[i] = dp[i-1] + 2*dp[i-2]%mod
		if i%3 == 0 {
			dp[i] += 4
		}
		dp[i] %= mod
	}

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fprintln(out, dp[n])
	}
}

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

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

const M = 1e9 + 7
const N = 2000000

func (con *contest) main() error {
	s := []int{1, 0, 0}
	t := []int{0, 0, 0}
	a := make([]int, N+1)
	for i := 2; i <= N; i++ {
		s0 := s[0]
		s0 += s[1]
		s0 %= M
		s0 += s[1]
		s0 %= M
		s1 := s[0]
		s2 := s[1]
		s[0], s[1], s[2] = s0, s1, s2
		t[i%3] += s[2]
		t[i%3] %= M
		a[i] = t[i%3]
		a[i] %= M
		a[i] += t[i%3]
		a[i] %= M
		a[i] += t[i%3]
		a[i] %= M
		a[i] += t[i%3]
		a[i] %= M
	}
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		con.Scan(&n)
		con.Println(a[n])
	}
	return nil
}

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

const M = 1e9 + 7
const N = 2000000

func (con *contest) main() error {
	s := []int{1, 0, 0}
	t := []int{0, 0, 0}
	a := make([]int, N+1)
	for i := 2; i <= N; i++ {
		s0 := s[0]
		s0 += s[1]
		s0 %= M
		s0 += s[1]
		s0 %= M
		s1 := s[0]
		s2 := s[1]
		s[0], s[1], s[2] = s0, s1, s2
		t[i%3] += s[2]
		t[i%3] %= M
		a[i] = t[i%3] * 4
		a[i] %= M
	}
	var T int
	con.Scan(&T)
	for testcase := 0; testcase < T; testcase++ {
		var n int
		con.Scan(&n)
		con.Println(a[n])
	}
	return nil
}


Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1, r1], [l2, r2], ..., [ln, rn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1, rn].

The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start and the end of the i-th period of work.

package main

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

type State struct {
	l, r int
}

func main() {
	fsc := NewFastScanner()
	values := make([]int, 0)
	for i := 0; i < 6; i++ {
		values = append(values, fsc.NextInt())
	}
	N := values[0]
	P1 := values[1]
	P2 := values[2]
	P3 := values[3]
	T1 := values[4]
	T2 := values[5]
	querys := make([]State, 0)
	for i := 0; i < N; i++ {
		l, r := fsc.NextInt(), fsc.NextInt()
		querys = append(querys, State{l, r})
	}
	start := querys[0].l
	end := querys[N-1].r

	res := 0
	last := 0
	for t := start; t < end; t++ {
		for _, v := range querys {
			if t >= v.l && t <= v.r {
				last = t
				break
			}
		}
		diff := t - last
		consume := P1
		if diff >= T1 {
			consume = P2
		}
		if diff >= T1+T2 {
			consume = P3
		}
		res += consume
	}
	fmt.Println(res)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

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

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

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

package main

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

type Interval struct {
	start int
	end   int
}

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

func computeRestPower(p1 int, p2 int, p3 int, t1 int, t2 int, restLength int) int {
	totalPower := 0
	totalPower += min(restLength, t1) * p1
	restLength -= min(restLength, t1)
	totalPower += min(restLength, t2) * p2
	restLength -= min(restLength, t2)
	totalPower += restLength * p3
	return totalPower
}

func Solve(n int, p1 int, p2 int, p3 int, t1 int, t2 int, intervals []Interval) int {
	totalPower := 0
	for i := 0; i < n; i++ {
		interval := intervals[i]
		totalPower += (interval.end - interval.start) * p1
		if i != 0 {
			restLength := interval.start - intervals[i-1].end
			totalPower += computeRestPower(p1, p2, p3, t1, t2, restLength)
		}
	}
	return totalPower
}

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

	var n, p1, p2, p3, t1, t2 int
	fmt.Fscanf(reader, "%d %d %d %d %d %d\n", &n, &p1, &p2, &p3, &t1, &t2)
	intervals := make([]Interval, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &intervals[i].start, &intervals[i].end)
	}
	fmt.Fprintf(writer, "%d\n", Solve(n, p1, p2, p3, t1, t2, intervals))
}

package main

import "fmt"

func main() {
    var n, p1, p2, p3, t1, t2, l, r int
    var s1, s2, s3, last int
    fmt.Scanf("%d %d %d %d %d %d\n", &n, &p1, &p2, &p3, &t1, &t2)
    for ; n > 0; n-- {
        fmt.Scanf("%d %d\n", &l, &r)
        if last > 0 {
            s1 += max(0, min(l-last, t1))
            s2 += max(0, min(l-last-t1, t2))
            s3 += max(0, l-last-t1-t2)
        }
        s1 += r - l
        last = r
    }
    fmt.Printf("%d\n", p1*s1+p2*s2+p3*s3)
}

func min(i, j int) int {
    if i < j {
        return i
    }
    return j
}

func max(i, j int) int {
    if i > j {
        return i
    }
    return j
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, p1, p2, p3, t1, t2 int
	fmt.Fscanf(reader, "%d %d %d %d %d %d\n", &n, &p1, &p2, &p3, &t1, &t2)

	power, last := 0, 0
	for i := 0; i < n; i++ {
		var l, r int
		fmt.Fscanf(reader, "%d %d\n", &l, &r)
		if i == 0 {
			last = l
		}
		if l-last <= t1 {
			power = power + p1*(l-last)
		} else if l-last <= t1+t2 {
			power = power + p1*t1 + p2*(l-last-t1)
		} else {
			power = power + p1*t1 + p2*t2 + p3*(l-last-t1-t2)
		}
		power = power + (r-l)*p1
		last = r
	}
	fmt.Printf("%d", power)
}

package main

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

var scanner *bufio.Scanner

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

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

  n, p1, p2, p3, t1, t2 := getI(), getI(), getI(), getI(), getI(), getI()
  result := 0
  l, r := getI(), getI()
  result += p1*(r-l)
  for i := 1; i < n; i++ {
    L, R := getI(), getI()
    w1, w2, w3 := L-r, 0, 0
    if w1 > t1 {
      w2 = w1-t1
      w1 = t1
      if w2 > t2 {
        w3 = w2-t2
        w2 = t2
      }
    }
    result += p1*w1 + p2*w2 + p3*w3
    l, r = L, R
    result += p1*(r-l)
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

// https://codeforces.com/contest/10/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main() {
	var (
		n, p1, p2, p3, t1, t2 int
		l, r, lastr int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n, &p1, &p2, &p3, &t1, &t2)
	total := 0
	for i := 0; i < n; i++ {
		lastr = r
		fmt.Fscan(input, &l, &r)
		total += (r - l) * p1
		if i == 0 {
			continue
		}

		inactive := l - lastr
		total += min(t1, inactive) * p1
		if inactive - t1 > 0 {
			inactive -= t1
			total += min(t2, inactive) * p2
			if inactive - t2 > 0 {
				total += (inactive - t2) * p3
			}
		}
	}

	fmt.Println(total)
}

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

package main

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

func read(r *bufio.Scanner) int {
	r.Scan()
	a, _ := strconv.Atoi(r.Text())
	return a
}

func main() {
	z := bufio.NewScanner(os.Stdin)
	z.Split(bufio.ScanWords)
	n, P1, P2,P3, T1,T2 :=	read(z),read(z), read(z),read(z),read(z),read(z)
	p, t := 0, 0
	u1, u2 := read(z), read(z)
	p += (u2 - u1) * P1
	t = u2

	for i := 1; i < n; i++ {
		u1, u2 = read(z), read(z)
		p += (u2 - u1) * P1
		switch {
			case u1 - t >= T1 + T2:
				p += P3 * (u1-t-T1-T2) + P2 * T2 + P1 * T1
			case u1 - t >= T1:
				p += P2 * (u1 - t - T1) + P1 * T1
			default:
				p += P1 * (u1 - t)
		}
		t = u2
	}
	fmt.Println(p)
}

package main

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

/* YEEY */
type Use struct {
	timeStart int
	timeEnd   int
}

func main() {
	var n, p1, p2, p3, t1, t2 int
	reader := bufio.NewReader(os.Stdin)

	input, _, _ := reader.ReadLine()

	inputList := strings.Split(string(input), " ")

	n, _ = strconv.Atoi(inputList[0])
	p1, _ = strconv.Atoi(inputList[1])
	p2, _ = strconv.Atoi(inputList[2])
	p3, _ = strconv.Atoi(inputList[3])
	t1, _ = strconv.Atoi(inputList[4])
	t2, _ = strconv.Atoi(inputList[5])

	useList := make([]Use, n)

	for i := 0; i < n; i++ {
		input, _, _ = reader.ReadLine()
		inputList = strings.Split(string(input), " ")

		t1, _ := strconv.Atoi(inputList[0])
		t2, _ := strconv.Atoi(inputList[1])

		use := Use{timeStart: t1, timeEnd: t2}

		useList[i] = use
	}

	lastTime := -1

	result := 0

	for i := 0; i < n; i++ {
		use := useList[i]
		result += (use.timeEnd - use.timeStart) * p1

		if lastTime != -1 {
			oldUse := useList[i-1]

			if use.timeStart-oldUse.timeEnd >= t1 {
				result += t1 * p1

				if use.timeStart-oldUse.timeEnd-t1 >= t2 {
					result += t2 * p2
					result += (use.timeStart - oldUse.timeEnd - t1 - t2) * p3
				} else {
					result += (use.timeStart - oldUse.timeEnd - t1) * p2
				}
			} else {
				result += (use.timeStart - oldUse.timeEnd) * p1
			}
		}

		lastTime = use.timeEnd
	}

	fmt.Println(result)
}

package main

import (
    "fmt"
)

func main() {
    var n, p1, p2, p3, t1, t2, l, r int
    var s1, s2, s3, last int
    fmt.Scanf("%d %d %d %d %d %d", &n, &p1, &p2, &p3, &t1, &t2)
    for ; n > 0; n-- {
        fmt.Scanf("%d %d", &l, &r)
        if last > 0 {
            s1 += max(0, min(l-last, t1))
            s2 += max(0, min(l-last-t1, t2))
            s3 += max(0, l-last-t1-t2)
        }
        s1 += r - l
        last = r
    }
    fmt.Printf("%d\n", p1*s1+p2*s2+p3*s3)
}

func min(i, j int) int {
    if i < j {
        return i
    }
    return j
}

func max(i, j int) int {
    if i > j {
        return i
    }
    return j
}

package main

import "fmt"

func main() {
    var n, p1, p2, p3, t1, t2, l, r int
    var s1, s2, s3, last int
    fmt.Scanf("%d %d %d %d %d %d", &n, &p1, &p2, &p3, &t1, &t2)
    for ; n > 0; n-- {
        fmt.Scanf("%d %d", &l, &r)
        if last > 0 {
            s1 += max(0, min(l-last, t1))
            s2 += max(0, min(l-last-t1, t2))
            s3 += max(0, l-last-t1-t2)
        }
        s1 += r - l
        last = r
    }
    fmt.Printf("%d\n", p1*s1+p2*s2+p3*s3)
}

func min(i, j int) int {
    if i < j {
        return i
    }
    return j
}

func max(i, j int) int {
    if i > j {
        return i
    }
    return j
}

package main

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

func read(r *bufio.Scanner) int {
	r.Scan()
	a, _ := strconv.Atoi(r.Text())
	return a
}

func main() {
	z := bufio.NewScanner(os.Stdin)
	z.Split(bufio.ScanWords)
	n, P1, P2,P3, T1,T2 :=	read(z),read(z), read(z),read(z),read(z),read(z)
	p, t := 0, 0
	u1, u2 := read(z), read(z)
	p += (u2 - u1) * P1
	t = u2

	for i := 1; i < n; i++ {
		u1, u2 = read(z), read(z)
		p += (u2 - u1) * P1
		switch {
			case u1 - t >= T1 + T2:
				fmt.Println("a")
				p += P3 * (u1-t-T1-T2) + P2 * T2 + P1 * T1
			case u1 - t >= T1:
				fmt.Println("b")
				p += P2 * (u1 - t - T1) + P1 * T1
			default:
				fmt.Println("c")
				p += P1 * (u1 - t)
		}
		t = u2
	}
	fmt.Println(p)
}


"Eat a beaver, save a tree!" — That will be the motto of ecologists' urgent meeting in Beaverley Hills.And the whole point is that the population of beavers on the Earth has reached incredible sizes! Each day their number increases in several times and they don't even realize how much their unhealthy obsession with trees harms the nature and the humankind. The amount of oxygen in the atmosphere has dropped to 17 per cent and, as the best minds of the world think, that is not the end.In the middle of the 50-s of the previous century a group of soviet scientists succeed in foreseeing the situation with beavers and worked out a secret technology to clean territory. The technology bears a mysterious title "Beavermuncher-0xFF". Now the fate of the planet lies on the fragile shoulders of a small group of people who has dedicated their lives to science.The prototype is ready, you now need to urgently carry out its experiments in practice. You are given a tree, completely occupied by beavers. A tree is a connected undirected graph without cycles. The tree consists of n vertices, the i-th vertex contains ki beavers. "Beavermuncher-0xFF" works by the following principle: being at some vertex u, it can go to the vertex v, if they are connected by an edge, and eat exactly one beaver located at the vertex v. It is impossible to move to the vertex v if there are no beavers left in v. "Beavermuncher-0xFF" cannot just stand at some vertex and eat beavers in it. "Beavermuncher-0xFF" must move without stops.Why does the "Beavermuncher-0xFF" works like this? Because the developers have not provided place for the battery in it and eating beavers is necessary for converting their mass into pure energy.It is guaranteed that the beavers will be shocked by what is happening, which is why they will not be able to move from a vertex of the tree to another one. As for the "Beavermuncher-0xFF", it can move along each edge in both directions while conditions described above are fulfilled.The root of the tree is located at the vertex s. This means that the "Beavermuncher-0xFF" begins its mission at the vertex s and it must return there at the end of experiment, because no one is going to take it down from a high place. Determine the maximum number of beavers "Beavermuncher-0xFF" can eat and return to the starting vertex.

The first line contains integer n — the number of vertices in the tree (1 ≤ n ≤ 105). The second line contains n integers ki (1 ≤ ki ≤ 105) — amounts of beavers on corresponding vertices. Following n - 1 lines describe the tree. Each line contains two integers separated by space. These integers represent two vertices connected by an edge. Vertices are numbered from 1 to n. The last line contains integer s — the number of the starting vertex (1 ≤ s ≤ n).

Print the maximum number of beavers munched by the "Beavermuncher-0xFF". Please, do not use %lld specificator to write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).

package main

import (
	"sort"
	"fmt"
	"os"
	"io/ioutil"
	"bytes"
)

var beaver []int64
var edges [][]int
var visited []bool
var root int

type Int64Slice []int64

func (this Int64Slice) Len() int {
	return len(this)
}

func (this Int64Slice) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

func (this Int64Slice) Less(i, j int) bool {
	return this[j] < this[i]
}

func dfs(v int) (eat int64, rest int64) {
	visited[v] = true
	var totalRest int64
	beaverList := make(Int64Slice, 0, len(edges[v]))
	for i := 0;i < len(edges[v]);i ++ {
		if visited[edges[v][i]] {
			continue
		}
		eatBeaver, restBeaver := dfs(edges[v][i])
//		fmt.Printf("eat=%d rest=%d vertice=%d\n", eatBeaver, restBeaver, edges[v][i] + 1)
		if restBeaver > 0 {
			totalRest += restBeaver
		}
		if eatBeaver > 0 {
			beaverList = append(beaverList, eatBeaver)
		}
	}
	sort.Sort(beaverList)
	var reserved int64
	if v == root {
		reserved = 0
	} else {
		reserved = 1
	}
	for i := 0;i < len(beaverList) && beaver[v] > reserved;i ++ {
		eat += (2 + beaverList[i])
		beaver[v] --
		totalRest --
	}
	if beaver[v] > reserved {
		if beaver[v] - reserved >= totalRest {
			beaver[v], eat = beaver[v] - totalRest, eat + 2 * totalRest
		} else {
			beaver[v], eat = reserved, eat + 2 * (beaver[v] - reserved)
		}
	}
	return eat, beaver[v]
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewReader(bs)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	beaver = make([]int64, n)
	edges = make([][]int, n)
	visited = make([]bool, n)
	for i := 0;i < n - 1;i ++ {
		fmt.Fscanf(reader, "%d ", &beaver[i])
		edges[i] = []int{}
	}
	fmt.Fscanf(reader, "%d\n", &beaver[n - 1])

	for i := 0;i < n - 1;i ++ {
		var u, v int
		fmt.Fscanf(reader, "%d %d\n", &u, &v)
		u --
		v --
		edges[u] = append(edges[u], v)
		edges[v] = append(edges[v], u)
	}
	fmt.Fscanf(reader, "%d", &root)
	root --
	ans, _ := dfs(root)
	fmt.Printf("%d", ans)
}


There are $$$n$$$ bricks numbered from $$$1$$$ to $$$n$$$. Brick $$$i$$$ has a weight of $$$a_i$$$.Pak Chanek has $$$3$$$ bags numbered from $$$1$$$ to $$$3$$$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $$$w_j$$$ be the weight of the brick Bu Dengklek takes from bag $$$j$$$. The score is calculated as $$$|w_1 - w_2| + |w_2 - w_3|$$$, where $$$|x|$$$ denotes the absolute value of $$$x$$$.It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$) — the number of test cases. The following lines contain the description of each test case. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the number of bricks. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the weights of the bricks. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.

NoteIn the first test case, one way of achieving a final score of $$$6$$$ is to do the following:   Put bricks $$$1$$$, $$$4$$$, and $$$5$$$ into bag $$$1$$$.  Put brick $$$3$$$ into bag $$$2$$$.  Put brick $$$2$$$ into bag $$$3$$$. If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:   Take brick $$$5$$$ from bag $$$1$$$.  Take brick $$$3$$$ from bag $$$2$$$.  Take brick $$$2$$$ from bag $$$3$$$. The score is $$$|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$$$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.It can be shown that there is no other distribution that results in a final score bigger than $$$6$$$.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		var arr []int64 = make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] > arr[j]
		})
		var ans int64
		for i := 1; i < n-1; i++ {
			tmp := arr[i-1]*2 - arr[i] - arr[n-1]
			if tmp > ans {
				ans = tmp
			}
		}
		for i := 2; i < n; i++ {
			tmp := arr[0] + arr[i-1] - 2*arr[i]
			if tmp > ans {
				ans = tmp
			}
		}
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const (
	DEBUG = false
)

func debug(a ...interface{}) {
	if !DEBUG {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func debugCondn(condn bool, a ...interface{}) {
	if !DEBUG || !condn {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func assert(condn bool) {
	if !condn {
		panic("assertion error")
	}
}

func solve(tt int) {
	var n int
	scanf("%d\n", &n)
	a := make([]int64, n)
	for i:=0; i<n; i++ {
		scanf("%d ", &a[i])
	}
	scanf("\n")

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

	res := int64(0)
	for k:=2; k<n; k++ {
		cur := 2*a[k] - (a[0] + a[k-1])
		if cur > res {
			res = cur
		}
	}

	for k:=1; k<n-1; k++ {
		cur := a[n-1] + a[k] - 2*a[k-1]
		if cur > res {
			res = cur
		}
	}
	printf("%d\n", res)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve(tt)
	}
}

package main

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

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, res int
		fmt.Fscan(r, &n)

		a := make([]int, n)
		for i := range a { fmt.Fscan(r, &a[i]) }
		sort.Ints(a)

		for i := 0; i < n-1; i++ {
			res = max(res, a[n-1] + a[i+1] - 2*a[i])
			res = max(res, 2*a[i+1] - a[0] - a[i])
		}

		fmt.Fprintln(w, res)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		var arr []int64 = make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] > arr[j]
		})
		var x int64 = arr[0]
		for i := 1; i < n-1; i++ {
			if arr[i] != arr[0] {
				x = arr[i]
				break
			}
		}
		ans := arr[0]*2 - arr[n-1] - x
		for i := 1; i < n-1; i++ {
			tmp := arr[i-1]*2 - arr[i] - arr[n-1]
			if tmp > ans {
				ans = tmp
			}
		}
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		var arr []int64 = make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] > arr[j]
		})
		var x int64 = arr[0]
		for i := 1; i < n-1; i++ {
			if arr[i] != arr[0] {
				x = arr[i]
				break
			}
		}
		fmt.Fprintln(out, arr[0]*2-arr[n-1]-x)
	}
	out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		var arr []int64 = make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] > arr[j]
		})
		//fmt.Fprintln(out, arr[0], arr[n-1], arr[n-2])
		fmt.Fprintln(out, arr[0]*2-arr[n-1]-arr[1])
	}
	out.Flush()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const (
	DEBUG = false
)

func debug(a ...interface{}) {
	if !DEBUG {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func debugCondn(condn bool, a ...interface{}) {
	if !DEBUG || !condn {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func assert(condn bool) {
	if !condn {
		panic("assertion error")
	}
}

func solve(tt int) {
	var n int
	scanf("%d\n", &n)
	a := make([]int64, n)
	for i:=0; i<n; i++ {
		scanf("%d ", &a[i])
	}
	scanf("\n")

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

	res := int64(0)
	for k:=2; k<n; k++ {
		cur := 2*a[k] - (a[0] + a[k-1])
		if cur > res {
			res = cur
		}
	}
	printf("%d\n", res)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve(tt)
	}
}


Turbulent times are coming, so you decided to buy sugar in advance. There are $$$n$$$ shops around that sell sugar: the $$$i$$$-th shop sells one pack of sugar for $$$a_i$$$ coins, but only one pack to one customer each day. So in order to buy several packs, you need to visit several shops.Another problem is that prices are increasing each day: during the first day the cost is $$$a_i$$$, during the second day cost is $$$a_i + 1$$$, during the third day — $$$a_i + 2$$$ and so on for each shop $$$i$$$.On the contrary, your everyday budget is only $$$x$$$ coins. In other words, each day you go and buy as many packs as possible with total cost not exceeding $$$x$$$. Note that if you don't spend some amount of coins during a day, you can't use these coins during the next days.Eventually, the cost for each pack will exceed $$$x$$$, and you won't be able to buy even a single pack. So, how many packs will you be able to buy till that moment in total?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le x \le 10^9$$$) — the number of shops and your everyday budget. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial cost of one pack in each shop. It's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the total number of packs you will be able to buy until prices exceed your everyday budget.

NoteIn the first test case,   Day 1: prices are $$$[2, 1, 2]$$$. You can buy all $$$3$$$ packs, since $$$2 + 1 + 2 \le 7$$$.  Day 2: prices are $$$[3, 2, 3]$$$. You can't buy all $$$3$$$ packs, since $$$3 + 2 + 3 > 7$$$, so you buy only $$$2$$$ packs.  Day 3: prices are $$$[4, 3, 4]$$$. You can buy $$$2$$$ packs with prices $$$4$$$ and $$$3$$$.  Day 4: prices are $$$[5, 4, 5]$$$. You can't buy $$$2$$$ packs anymore, so you buy only $$$1$$$ pack.  Day 5: prices are $$$[6, 5, 6]$$$. You can buy $$$1$$$ pack.  Day 6: prices are $$$[7, 6, 7]$$$. You can buy $$$1$$$ pack.  Day 7: prices are $$$[8, 7, 8]$$$. You still can buy $$$1$$$ pack of cost $$$7$$$.  Day 8: prices are $$$[9, 8, 9]$$$. Prices are too high, so you can't buy anything.  In total, you bought $$$3 + 2 + 2 + 1 + 1 + 1 + 1 = 11$$$ packs.In the second test case, prices are too high even at the first day, so you can't buy anything.In the third test case, you can buy only one pack at day one.In the fourth test case, you can buy $$$2$$$ packs first $$$500$$$ days. At day $$$501$$$ prices are $$$[501, 501]$$$, so you can buy only $$$1$$$ pack the next $$$500$$$ days. At day $$$1001$$$ prices are $$$[1001, 1001]$$$ so can't buy anymore. In total, you bought $$$500 \cdot 2 + 500 \cdot 1 = 1500$$$ packs.

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, x := 0, 0
		fmt.Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt, ans, sum := 0, uint64(0), 0
		for cnt < n && sum+a[cnt] <= x {
			sum += a[cnt]
			cnt++
		}
		for d := 0; cnt > 0; {
			remain := x - sum - d*cnt
			if remain < 0 {
				cnt--
				sum -= a[cnt]
			} else {
				days := remain/cnt + 1
				d += days
				ans += uint64(days * cnt)
				cnt--
				sum -= a[cnt]
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

/*
1
5 10
1 3 5 5 7
---
15 = 10 + 4 + 1
*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	ans := int64(0)
	sm := int64(0)

	for i, num := range a {
		inc := int64(i) + 1
		sm += int64(num)

		rng := x - sm
		if rng >= 0 {
			ans += rng/inc + 1
		} else {
			break
		}
	}

	fmt.Fprintln(writer, ans)
}

//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"
	"sort"
)

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n, x int
		fmt.Fscan(in, &n, &x)

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

		ans, sum := int64(0), 0
		for i, v := range arr {
			sum += v
			if sum > x {
				break
			}
			ans += int64((x-sum)/(i+1) + 1)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

	var t int

	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		var x int64
		fmt.Fscan(in, &n, &x)

		arr := make([]int, n)

		sum := int64(0)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			sum += int64(arr[i])
		}
		sort.Ints(arr)

		ans, prevDay := int64(0), -1
		for i := n - 1; i >= 0; i-- {
			var curDay int
			if x >= sum {
				curDay = int((x - sum) / int64(i+1))
			} else {
				curDay = -1
			}

			ans += int64((i + 1) * (curDay - prevDay))
			prevDay = curDay
			sum -= int64(arr[i])
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for ; t > 0; t-- {
		var n int
		var x int64
		fmt.Fscanf(in, "%d %d\n", &n, &x)

		arr := make([]int, n)

		sum := int64(0)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			sum += int64(arr[i])
		}
		fmt.Fscanf(in, "\n")
		sort.Ints(arr)

		ans, prevDay := int64(0), -1
		for i := n - 1; i >= 0; i-- {
			var curDay int
			if x >= sum {
				curDay = int((x - sum) / int64(i+1))
			} else {
				curDay = -1
			}

			ans += int64((i + 1) * (curDay - prevDay))
			prevDay = curDay
			sum -= int64(arr[i])
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

const maxTokenSize = 25000000 * 7

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, maxTokenSize), maxTokenSize)
	scanner.Scan()

	countSum := func(pieces []int64) []int64 {
		var sum = make([]int64, 0, len(pieces))
		var local int64
		for _, piece := range pieces {
			local += piece
			sum = append(sum, local)
		}

		return sum
	}

	count, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < count; i++ {
		scanner.Scan()
		s := strings.Split(scanner.Text(), " ")

		shopCount, _ := strconv.ParseInt(s[0], 10, 64)
		moneyForDay, _ := strconv.ParseInt(s[1], 10, 64)

		prices := make([]int64, 0, shopCount)
		scanner.Scan()

		for _, p := range strings.Split(scanner.Text(), " ") {
			price, _ := strconv.ParseInt(p, 10, 64)
			prices = append(prices, price)
		}

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

		var dayNum int64
		var sugarSum int64
		sum := countSum(prices)

		for {
			startSum := moneyForDay - (sum[shopCount-1] + shopCount*dayNum)
			if startSum < 0 {
				shopCount--
				if shopCount == 0 {
					break
				}

				continue
			}

			days := (startSum / shopCount) + 1

			dayNum += days
			sugarSum += shopCount * days
		}

		fmt.Println(sugarSum)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t, "\n")
	for ; t > 0; t-- {
		var n, x int64
		fmt.Fscan(in, &n, &x)
		arr := make([]int64, n)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})
		res := int64(0)
		sum := int64(0)
		for i := int64(0); i < n; i++ {
			sum += arr[i]
			if x >= sum {
				res += (x-sum)/(i+1) + 1
			}
		}

		fmt.Fprintln(out, res)
	}

}

package main

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

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

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

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

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

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

		var tot int64
		var sum int64
		for i := 0; i < n; i++ {
			sum += arr[i]
			if sum > x {
				break
			}

			tot += (x-sum)/int64((i+1)) + 1
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

	for t := 0; t < T; t++ {
		var n int
		var x int
		fmt.Fscan(in, &n, &x)

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

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

		m := make([]int64, n)
		m[0] = int64(arr[0])
		var pos int64
		for i := 1; i < n; i++ {
			m[i] = m[i-1] + int64(arr[i])
			if m[i] <= int64(x) {
				pos = int64(i)
			}
		}

		var d int64
		var tot int64
		for pos >= 0 {
			sum := m[pos] + ((pos + 1) * d)

			if sum <= int64(x) {
				z := (int64(x)-sum)/(pos+1) + 1
				tot += (pos + 1) * z
				d += z
			} else {
				pos--
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var x int
	var n int
	var t int64

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &t)

		r := []int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r = append(r, x)
		}
		sort.Ints(r)

		ans := int64(0)
		s := int64(0)
		for i, v := range r {
			s += int64(v)
			if t < s {
				break
			}
			ans += (t-s)/int64(i+1) + 1
		}

		Fprintln(out, ans)
	}
}

package main

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

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

func slove() {
	defer w.Flush()
	var n int
	var x int64
	fmt.Fscan(r, &n, &x)
	nums, pre := make([]int, n), make([]int64, n+1)
	for i := range nums {
		fmt.Fscan(r,&nums[i])
	}
	sort.Ints(nums)
	for j := range nums {
		pre[j+1] = pre[j] + int64(nums[j])
	}
	var ans, d int64
	for d+int64(nums[0])<=x {
		j := sort.Search(n, func(i int) bool {
			return pre[i+1] + d * int64(i + 1) > x
		})
		cur := pre[j] + d * int64(j)
		diff := x - cur
		ans += (diff/int64(j)+1)*int64(j)
		d += (diff/int64(j)+1)
	}
	fmt.Fprintln(w, ans)
}

func abs(a int) int {if a < 0 {return -a} else {return a}}
//func max(a, b int) int {if a > b {return a} else {return b}}

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

package main

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

const MOD int64 = 1000000007

var n int
var x int64

var a []int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

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

		a = make([]int, n)

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

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {
	sort.Ints(a)

	cnt := 0
	var s int64
	var tot int64

	for i := 0; i < n; i++ {
		s += int64(a[i])

		if s > x {
			s -= int64(a[i])
			break
		}
		cnt++
	}

	if cnt == 0 {
		fmt.Println(0)
		return
	}

	tot += int64(cnt)
	idx := cnt - 1

	//X > s,  (X - s)/cnt

	d := (x - s)/int64(cnt)
	d++

	tot += (d - 1) * int64(cnt)

	var S int64

	S = s + (d) * int64(cnt)

	D := d

	for j := idx; j > 0; j-- {
		S = S - int64(a[j]) - D
		cnt--

		if S <= x {
			tot += int64(cnt)

			d := (x - S)/int64(cnt)
			d++

			tot += (d - 1) * int64(cnt)

			S = S + (d) * int64(cnt)

			D += d
		}

	}

	fmt.Println(tot)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1671C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, x int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)

		ans, sum := int64(0), 0
		for i, v := range a {
			sum += v
			if sum > x {
				break
			}
			ans += int64((x-sum)/(i+1) + 1)
		}
		Fprintln(out, ans)
	}
}

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

package main

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

const (
	INF = 3e5 + 10
	L0  = int64(0)
	L1  = int64(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n, x int64
		Fscan(in, &n, &x)
		a := make([]int, n)
		for i := L0; i < n; i++ {
			Fscan(in, &a[i])
		}
		sort.Ints(a)

		sum := L0
		cnt := L0
		for i := L0; i < n; i++ {
			if sum+int64(a[i]) <= x {
				sum += int64(a[i])
				cnt++
			}
		}

		ans := L0
		d := L0
		for cnt > 0 {
			tmp := (x - sum - d*cnt + cnt) / cnt
			ans += tmp * cnt
			d += tmp
			cnt--
			sum -= int64(a[cnt])
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

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

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var n int
		var x int64
		fmt.Fscan(in, &n, &x)
		as := make([]int64, n)
		for i := range as {
			fmt.Fscan(in, &as[i])
		}
		sort.Slice(as, func(i, j int) bool { return as[i] < as[j] })
		var asum int64
		var cnt int64
		for i, a := range as {
			asum += a
			if asum <= x {
				cnt += (x - asum + int64(i + 1)) / int64(i + 1)
			}
		}
		fmt.Fprintln(out, cnt)
	}
}

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, x := 0, 0
		fmt.Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		cnt, ans, sum := 0, 0, 0
		for cnt < n && sum+a[cnt] <= x {
			sum += a[cnt]
			cnt++
		}
		for d := 0; cnt != 0; {
			remain := x - sum - d*cnt
			if remain < 0 {
				cnt--
				sum -= a[cnt]
			} else {
				days := remain/cnt + 1
				d += days
				ans += days * cnt
				cnt--
				sum -= a[cnt]
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, x := 0, 0
		fmt.Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		for i := 1; i < n; i++ {
			a[i] += a[i-1]
		}
		end := sort.Search(n, func(i int) bool {
			return a[i] > x
		})
		var ans uint64
		for d := 0; end != 0; {
			y := x - (a[end-1] + end*d)
			if y >= 0 {
				kk := y/end + 1
				d += kk
				ans += uint64(kk * end)
			}
			end--
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, x := 0, 0
		fmt.Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		for i := 1; i < n; i++ {
			a[i] += a[i-1]
		}
		end := sort.Search(n, func(i int) bool {
			return a[i] > x
		})
		var ans uint64
		for d := 0; end != 0; d++ {
			y := x - (a[end-1] + end*d)
			if y >= 0 {
				ans += uint64(end)
				kk := y / end
				d += kk
				ans += uint64(kk * end)
			}
			end--
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, x := 0, 0
		fmt.Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		for i := 1; i < n; i++ {
			a[i] += a[i-1]
		}
		end := sort.Search(n, func(i int) bool {
			return a[i] > x
		})
		var ans uint64
		for d := 0; end != 0; d++ {
			y := x - (a[end-1] + end*d)
			if y > 0 {
				ans += uint64(end)
				kk := y / end
				d += kk
				ans += uint64(kk * end)
			}
			end--
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()

	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, x := 0, 0
		fmt.Fscan(in, &n, &x)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		for i := 1; i < n; i++ {
			a[i] += a[i-1]
		}
		end := sort.Search(n, func(i int) bool {
			return a[i] > x
		})
		var ans uint64
		for d := 0; end != 0; d++ {
			fmt.Println(d, end, ans)
			y := x - (a[end-1] + end*d)
			if y > 0 {
				fmt.Println(y)
				ans += uint64(end)
				kk := y / end
				d += kk
				ans += uint64(kk * end)
			}
			end--
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

/*
1
5 10
1 3 5 5 7
---
15 = 10 + 4 + 1
*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	ans := int64(0)
	sm := int64(0)

	for i, num := range a {
		inc := int64(i) + 1
		sm += int64(num)

		cnt := (int64(x) - sm) / inc
		if cnt >= 0 {
			ans += cnt + 1
		} else {
			break
		}
	}

	fmt.Fprintln(writer, ans)
}

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

/*
1
6 9
1 2 4 5 6 7
---
14

sum = 7, 10, 5, 7, 9, 11, 5 6 7 8 9
cnt = 3,  0  2, 2, 2, 0   1 1 1 1 1
2
2

---
========
1
3 7
2 1 2
---
11
=======
1
5 9
10 20 30 40 50
--
0
*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	if x < int64(a[0]) {
		fmt.Fprintln(writer, 0)
		return
	}

	dayCnt := int64(0)
	cnt := int64(0)

	sum := int64(0)
	i := int64(0)
	for {
		sum += int64(a[i])
		i++

		if i >= n {
			i--
			break
		}

		if sum > x {
			i--
			sum -= int64(a[i])
			i--
			break
		}
	}

	for i >= 0 {
		sum += i + 1
		cnt += i + 1

		dayCnt++

		for i >= 0 && sum > x {
			sum -= int64(a[i]) + dayCnt
			i--
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

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

	for i := 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 GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

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

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

	return factors
}

package main

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

/*
1
6 9
1 2 4 4 6 7
---
14

sum = 7, 10, 5, 7, 9, 11, 5 6 7 8 9
cnt = 3,  0  2, 2, 2, 0   1 1 1 1 1
2
2

---
========
1
3 7
2 1 2
---
11
=======
1
5 9
10 20 30 40 50
--
0
*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	if x < int64(a[0]) {
		fmt.Fprintln(writer, 0)
		return
	}

	dayCnt := int64(0)
	cnt := int64(0)

	sum := int64(0)
	i := int64(0)
	for i < n && sum <= x {
		sum += int64(a[i])
		i++
	}
	i--
	if i != n-1 {
		sum -= int64(a[i])
		i--
	}

	for i >= 0 {
		sum += i + 1
		cnt += i + 1

		dayCnt++

		for i >= 0 && sum > x {
			sum -= int64(a[i]) + dayCnt
			i--
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

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

	for i := 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 GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

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

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

	return factors
}

package main

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

/*
1
6 9
1 2 4 4 6 7
---

sum = 7, 10
3
2
2

---
========
1
3 7
2 1 2
---
11
=======
1
5 9
10 20 30 40 50
--
0
*/

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

	a := make([]int, n)

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

	sort.Ints(a)

	if x < int64(a[0]) {
		fmt.Fprintln(writer, 0)
		return
	}

	dayCnt := int64(0)
	cnt := int64(0)

	sum := int64(0)
	i := int64(0)
	for i < n && sum <= x {
		sum += int64(a[i])
		i++
	}
	i--
	if i != n-1 {
		sum -= int64(a[i])
	}

	for i >= 0 {
		sum += i + 1
		cnt += i + 1

		dayCnt++

		for i >= 0 && sum > x {
			sum -= int64(a[i]) + dayCnt
			i--
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

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

	for i := 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 GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

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

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

	return factors
}

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for ; t > 0; t-- {
		var n, x int
		fmt.Fscanf(in, "%d %d\n", &n, &x)

		arr := make([]int, n)

		sum := 0
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			sum += arr[i]
		}
		fmt.Fscanf(in, "\n")
		sort.Ints(arr)

		ans, prevDay := int64(0), -1
		for i := n - 1; i >= 0; i-- {
			var curDay int
			if x-sum >= 0 {
				curDay = (x - sum) / (i + 1)
			} else {
				curDay = -1
			}

			ans += int64((i + 1) * (curDay - prevDay))
			prevDay = curDay
			sum -= arr[i]
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)

	for ; t > 0; t-- {
		var n, x int
		fmt.Fscanf(in, "%d %d\n", &n, &x)

		arr := make([]int, n)

		sum := 0
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
			sum += arr[i]
		}
		fmt.Fscanf(in, "\n")
		sort.Ints(arr)

		ans, prevDay := 0, -1
		for i := n - 1; i >= 0; i-- {
			var curDay int
			if x-sum >= 0 {
				curDay = (x - sum) / (i + 1)
			} else {
				curDay = -1
			}

			ans += (i + 1) * (curDay - prevDay)
			prevDay = curDay
			sum -= arr[i]
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

const maxTokenSize = 2500000 * 7

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, maxTokenSize), maxTokenSize)
	scanner.Scan()

	countSum := func(pieces []int) []int {
		var sum = make([]int, 0, len(pieces))
		var local int
		for _, piece := range pieces {
			local += piece
			sum = append(sum, local)
		}

		return sum
	}

	count, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < count; i++ {
		scanner.Scan()
		s := strings.Split(scanner.Text(), " ")

		shopCount, _ := strconv.Atoi(s[0])
		moneyForDay, _ := strconv.Atoi(s[1])

		prices := make([]int, 0, shopCount)
		scanner.Scan()

		for _, p := range strings.Split(scanner.Text(), " ") {
			price, _ := strconv.Atoi(p)
			prices = append(prices, price)
		}

		sort.Ints(prices)

		var dayNum int
		var sugarSum int
		sum := countSum(prices)

		for {
			startSum := moneyForDay - (sum[shopCount-1] + shopCount*dayNum)
			if startSum < 0 {
				shopCount--
				if shopCount == 0 {
					break
				}

				continue
			}

			days := (startSum / shopCount) + 1

			dayNum += days
			sugarSum += shopCount * days
		}

		fmt.Println(sugarSum)
	}
}

package main

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

const maxTokenSize = 4 * 100000

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, maxTokenSize), maxTokenSize)
	scanner.Scan()

	countSum := func(pieces []int) []int {
		var sum = make([]int, 0, len(pieces))
		var local int
		for _, piece := range pieces {
			local += piece
			sum = append(sum, local)
		}

		return sum
	}

	count, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < count; i++ {
		scanner.Scan()
		s := strings.Split(scanner.Text(), " ")

		shopCount, _ := strconv.Atoi(s[0])
		moneyForDay, _ := strconv.Atoi(s[1])

		prices := make([]int, 0, shopCount)
		scanner.Scan()

		for _, p := range strings.Split(scanner.Text(), " ") {
			price, _ := strconv.Atoi(p)
			prices = append(prices, price)
		}

		sort.Ints(prices)

		var dayNum int
		var sugarSum int
		sum := countSum(prices)

		for {
			startSum := moneyForDay - (sum[shopCount-1] + shopCount*dayNum)
			if startSum < 0 {
				shopCount--
				if shopCount == 0 {
					break
				}

				continue
			}

			days := (startSum / shopCount) + 1

			dayNum += days
			sugarSum += shopCount * days
		}

		fmt.Println(sugarSum)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t, "\n")
	for ; t > 0; t-- {
		var n, x int
		fmt.Fscan(in, &n, &x)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})
		res := 0
		sum := 0
		for i := 0; i < n; i++ {
			sum += arr[i]
			if x >= sum {
				res += (x-sum)/(i+1) + 1
			}
		}

		fmt.Fprintln(out, res)
	}

}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t, "\n")
	for ; t > 0; t-- {
		var n, x int
		fmt.Fscan(in, &n, &x)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})

		presum := make([]int, n)
		presum[0] = arr[0]
		for i := 1; i < n; i++ {
			presum[i] = presum[i-1] + arr[i]
		}
		idx := sort.Search(n, func(i int) bool {
			return presum[i] >= x
		})
		if idx == n {
			idx--
		}

		res := 0
		if presum[idx] <= x {
			res = idx + 1
		}
		cur := 0
		for {
			flag := true
			for i := idx; i >= 0; i-- {
				if presum[i]+(i+1)*(cur+1) <= x {
					idx = i
					res += i + 1
					flag = false
					break
				}
			}
			if flag {
				break
			}
			cur++
		}
		fmt.Fprintln(out, res)
	}

}

package main

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

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

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

	for t := 0; t < T; t++ {
		var n int
		var x int
		fmt.Fscan(in, &n, &x)

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

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

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

		pos := sort.SearchInts(m, x)
		if pos == n {
			pos = n - 1
		}

		d := 0
		var tot int
		for pos >= 0 {
			sum := m[pos] + ((pos + 1) * d)

			if sum <= x {
				z := (x-sum)/(pos+1) + 1
				tot += (pos + 1) * z
				d += z
			} else {
				pos--
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

func CF1671C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var x int
	var n int
	var t int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &t)

		r := []int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r = append(r, x)
		}
		sort.Ints(r)

		ans := 0
		s := 0
		for i, v := range r {
			s += v
			if t < s {
				break
			}
			ans += (t-s)/(i+1) + 1
		}

		Fprintln(out, ans)
	}
}

package main

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

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

func slove() {
	defer w.Flush()
	var n, x int
	fmt.Fscan(r, &n, &x)
	nums, pre := make([]int, n), make([]int, n+1)
	for i := range nums {
		fmt.Fscan(r,&nums[i])
	}
	sort.Ints(nums)
	for j := range nums {
		pre[j+1] = pre[j] + nums[j]
	}
	ans := 0
	d := 0
	for d+nums[0]<=x {
		j := sort.Search(n, func(i int) bool {
			return pre[i+1] + d * (i + 1) > x
		})
		cur := pre[j] + d * (j)
		diff := x - cur
		ans += (diff/j+1)*j
		d += (diff/j+1)
	}
	fmt.Fprintln(w, ans)

}

func abs(a int) int {if a < 0 {return -a} else {return a}}
//func max(a, b int) int {if a > b {return a} else {return b}}

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

package main

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

const MOD int64 = 1000000007

var n int
var x int64

var a []int

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

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

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

		a = make([]int, n)

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

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {
	sort.Ints(a)

	cnt := 0
	var s int64
	var tot int64

	for i := 0; i < n; i++ {
		s += int64(a[i])

		if s > x {
			s -= int64(a[i])
			break
		}
		cnt++
	}

	if cnt == 0 {
		fmt.Println(0)
		return
	}

	tot += int64(cnt)
	idx := cnt - 1

	//X > s,  (X - s)/cnt

	d := (x - s)/int64(cnt)
	d++

	tot += (d - 1) * int64(cnt)

	var S int64

	S = s + d * int64(cnt)

	for j := idx; j > 0; j-- {
		S = S - int64(a[j]) - d
		cnt--

		if S <= x {
			d := (x - S)/int64(cnt)
			d++

			tot += (d) * int64(cnt)

			S = S + (d - 1) * int64(cnt)
		}

	}

	fmt.Println(tot)
}

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


There is a trampoline park with $$$n$$$ trampolines in a line. The $$$i$$$-th of which has strength $$$S_i$$$.Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $$$i$$$, the trampoline will launch her to position $$$i + S_i$$$, and $$$S_i$$$ will become equal to $$$\max(S_i-1,1)$$$. In other words, $$$S_i$$$ will decrease by $$$1$$$, except of the case $$$S_i=1$$$, when $$$S_i$$$ will remain equal to $$$1$$$. If there is no trampoline in position $$$i + S_i$$$, then this pass is over. Otherwise, Pekora will continue the pass by jumping from the trampoline at position $$$i + S_i$$$ by the same rule as above.Pekora can't stop jumping during the pass until she lands at the position larger than $$$n$$$ (in which there is no trampoline). Poor Pekora!Pekora is a naughty rabbit and wants to ruin the trampoline park by reducing all $$$S_i$$$ to $$$1$$$. What is the minimum number of passes she needs to reduce all $$$S_i$$$ to $$$1$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 5000$$$) — the number of trampolines. The second line of each test case contains $$$n$$$ integers $$$S_1, S_2, \dots, S_n$$$ ($$$1 \le S_i \le 10^9$$$), where $$$S_i$$$ is the strength of the $$$i$$$-th trampoline. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$5000$$$.

For each test case, output a single integer — the minimum number of passes Pekora needs to do to reduce all $$$S_i$$$ to $$$1$$$.

NoteFor the first test case, here is an optimal series of passes Pekora can take. (The bolded numbers are the positions that Pekora jumps into during these passes.)  $$$[1,4,\textbf{2},2,\textbf{2},2,\textbf{2}]$$$  $$$[1,\textbf{4},1,2,1,\textbf{2},1]$$$  $$$[1,\textbf{3},1,2,\textbf{1},\textbf{1},\textbf{1}]$$$  $$$[1,\textbf{2},1,\textbf{2},1,\textbf{1},\textbf{1}]$$$ For the second test case, the optimal series of passes is show below.  $$$[\textbf{2},3]$$$  $$$[1,\textbf{3}]$$$  $$$[1,\textbf{2}]$$$ For the third test case, all $$$S_i$$$ are already equal to $$$1$$$.

package main

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

func solve(s []int64) {
	var n int64 = int64(len(s))

	var i, curr, ans int64
	jmp := make([]int64, n+100)

	for ; i < n; i++ {
		curr = jmp[i]

		if curr >= s[i] {
			jmp[i+1] += curr - s[i] + 1
		} else if s[i]-curr-1 > 0 {
			ans += s[i] - curr - 1
		}

		to := n - 1
		if i+s[i] < n {
			to = i + s[i]
		}
		for j := i + 2; j <= to; j++ {
			jmp[j]++
		}
	}
	printf("%d\n", ans)
}

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)
		s := make([]int64, n)
		for i := range s {
			scan(&s[i])
		}
		solve(s)
	}
}

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 (
	"fmt"
)

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

	for ; t > 0; t-- {
		fmt.Scan(&n)
		var result int64
		s := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&s[i])
		}

		var current int
		next := make([]int, n)
		for i := range next {
			next[i] = i + 1
		}
		for first := 0; first < n; first++ {
			if s[first] == 1 {
				continue
			}
			result += int64(s[first] - 1)
			if s[first] > n-1-first {
				s[first] = n - 1 - first
			}
			for ; s[first] > 1; s[first]-- {
				current = first + s[first]
				for {
					if s[current] > 1 {
						s[current]--
						current += s[current] + 1
					} else {
						for ; next[current] < n && s[next[current]] == 1; next[current]++ {
						}
						current = next[current]
					}
					if current >= n {
						break
					}
				}
				//fmt.Println(s, first, current, result, next)
			}
		}
		fmt.Println(result)
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		fa := make([]int, n+1)
		var find func(int) int
		find = func(x int) int {
			if fa[x] != x {
				fa[x] = find(fa[x])
			}
			return fa[x]
		}
		a := make([]int, n)
		for i := range a {
			fa[i] = i
			if Fscan(in, &a[i]); a[i] == 1 {
				fa[i]++
			}
		}
		fa[n] = n
		ans := int64(0)
		for i, s := range a[:n-1] {
			if s == 1 {
				continue
			}
			if i+s >= n {
				to := n - 1 - i
				ans += int64(s - to)
				s = to
			}
			for ; s > 1; s-- {
				ans++
				for j := i + s; j < n; {
					if a[j] > 1 {
						if a[j]--; a[j] == 1 {
							fa[j] = j + 1
						}
						j += a[j] + 1
					} else {
						j = find(j)
					}
				}
			}
		}
		Fprintln(out, ans+int64(a[n-1]-1))
	}
}

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

package main

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

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

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

func min_int(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func min_int64(a int64, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func max_int(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
func max_int64(a int64, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func read_vector(n int64) []int64 {

	vec := make([]int64, n)

	for i := int64(0); i < n; i++ {
		if i != n-1 {
			scanf("%d ", &vec[i])
		} else {
			scanf("%d\n", &vec[i])
		}
	}
	return vec
}

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var N int64 = 0
		scanf("%d\n", &N)
		vec := read_vector(N)
		del := make([]int64, N)

		for i := int64(0); i < N; i++ {
			del[i] = 0
		}

		var res int64 = 0
		for i := int64(0); i < N; i++ {
			var jumps int64 = del[i]

			// printf("jumps: %d\n", jumps)
			if jumps < vec[i]-1 {
				var free_jumps int64 = vec[i] - 1 - jumps
				res += free_jumps
				jumps += free_jumps
			}

			if i+1 < N {
				del[i+1] += jumps - vec[i] + 1
			}

			if i+2 < N {
				for j := i + 2; j < min_int64(N, i+vec[i]+1); j++ {
					del[j] += 1
				}

			}

		}
		printf("%d\n", res)
	}

}

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 int
		_, _ = fmt.Fscan(in, &n)

		s := make([]int64, n)
		dp := make([]int64, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &s[i])
			dp[i] = 1
		}

		ans := int64(0)
		for i := 0; i < n; i++ {
			if dp[i] > s[i] {
				if i+1 < n {
					dp[i+1] += dp[i] - s[i]
					dp[i] = s[i]
				}
			}
			if dp[i] < s[i] {
				ans += s[i] - dp[i]
				dp[i] = s[i]
			}
			for j := int64(2); (j <= s[i]) && (int64(i)+j < int64(n)); j++ {
				dp[j+int64(i)]++
			}
		}
		fmt.Println(ans)
	}
}

package main

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

func solve(s []int64) {
	var n int64 = int64(len(s))

	var i, ans, curr int64
	jmp := make([]int64, n+100)

	for ; i < n; i++ {
		curr += jmp[i]
		if s[i]-curr > 1 {
			ans += s[i] - curr - 1
		}

		jmp[i+2]++
		if i+s[i]+1 > n {
			jmp[n]--
		} else {
			jmp[i+s[i]+1]--
		}
	}
	printf("%d\n", ans)
}

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

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		var n int
		scan(&n)
		s := make([]int64, n)
		for i := range s {
			scan(&s[i])
		}
		solve(s)
	}
}

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 (
	"fmt"
)

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

	for ; t > 0; t-- {
		fmt.Scan(&n)
		s := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&s[i])
		}
		var result int64
		for i := 0; i < n; i++ {
			if s[i] == 1 {
				continue
			}
			result += int64(s[i] - 1)
			if i+s[i] >= n {
				s[i] = n - i - 1
			}
			for j := i + 2; j <= i+s[i]; j++ {
				s[j]--
			}
			s[i] = 1
		}
		fmt.Println(result)
	}
}


While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 109 + 7.To represent the string as a number in numeral system with base 64 Vanya uses the following rules:  digits from '0' to '9' correspond to integers from 0 to 9;  letters from 'A' to 'Z' correspond to integers from 10 to 35;  letters from 'a' to 'z' correspond to integers from 36 to 61;  letter '-' correspond to integer 62;  letter '_' correspond to integer 63.

The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.

Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.

NoteFor a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.In the first sample, there are 3 possible solutions:   z&_ = 61&63 = 61 = z  _&z = 63&61 = 61 = z  z&z = 61&61 = 61 = z

package main

import "fmt"

func possible(s rune) uint {
  var(
    n,i int;
    cnt uint
  )
  q:=int(s);
  if('0'<=s&&s<='9'){
    n=q-'0'
  }  else if('A'<=s&&s<='Z'){
    n=10+q-int('A')
  }  else if('a'<=s&&s<='z'){
    n=36+q-int('a')
  }  else if(s=='-'){
    n=62
  }  else{
    n=63
  }
  for cnt,i=0,1;i<64;i<<=1{
    if 0==n&i {
      cnt++
    }
  }
  return cnt
}

func main() {
  var r int64 = 1
  const mod int64= 1000000007
  var i string ; fmt.Scanf("%s",&i)
  var q rune
  var j int
  for j = range i{
    q=rune(i[j])
    var h,lim int
    for h,lim=0,	int(possible(q));h<lim;h++ {
      r*=3
      if r>=mod{r%=mod}
    }
  }
  fmt.Printf("%d\n",r)
}

package main

import (
	"fmt"
	"math/big"
	"os"
)

const mod = 1000000007

var bigMod = big.NewInt(mod)
var bigThree = big.NewInt(3)

func charval(c byte) byte {
	switch {
	case '0' <= c && c <= '9':
		return c - '0'
	case 'A' <= c && c <= 'Z':
		return 10 + c - 'A'
	case 'a' <= c && c <= 'z':
		return 36 + c - 'a'
	case c == '-':
		return 62
	case c == '_':
		return 63
	default:
		panic("illegal character " + string(c))
	}
}

func zeros(b byte) int {
	z := 0
	for i := 0; i < 6; i++ {
		if b%2 == 0 {
			z++
		}
		b >>= 1
	}
	return z
}
func zerobits(s string) int {
	bs := make([]byte, len(s))
	for i := range bs {
		bs[i] = charval(s[i])
	}
	z := 0
	for _, b := range bs {
		z += zeros(b)
	}
	return z
}

func solve(s string) int64 {
	z := int64(zerobits(s))
	bz := big.NewInt(z)
	var be big.Int
	be.Exp(bigThree, bz, bigMod)
	return be.Int64()
}

func main() {
	s := ""
	_, err := fmt.Fscan(os.Stdin, &s)
	if err != nil {
		panic(err)
	}
	i := solve(s)
	fmt.Println(i)
}

package main

import (
	"fmt"
)

func zeros(num rune) uint {
	zeros := uint(6)
	for i := 0; i < 6; i++ {
		zeros -= uint(num & 1)
		num >>= 1
	}

	return zeros
}

func value(c rune) rune {
	if c >= '0' && c <= '9' {
		return c - '0' + 0
	}

	if c >= 'A' && c <= 'Z' {
		return c - 'A' + 10
	}

	if c >= 'a' && c <= 'z' {
		return c - 'a' + 36
	}

	if c == '-' {
		return 62
	}

	if c == '_' {
		return 63
	}

	return c
}

func main() {
	var str string
	fmt.Scanln(&str)

	result := int64(1)
	for _, c := range str {
		for i := zeros(value(c)); i > 0; i-- {
			result *= 3
		}

		result %= 1000000007
	}

	fmt.Println(result)
}

package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"sort"
	"strconv"
)

var M [256]byte

func bits(x byte) byte {
	var ans byte
	for x > 0 {
		ans += x & 1
		x /= 2
	}
	return 6 - ans
}

func init() {
	var val byte
	f := func(b, e byte) {
		for i := b; i <= e; i++ {
			M[i] = bits(val)
			val++
		}
	}
	f('0', '9')
	f('A', 'Z')
	f('a', 'z')
	f('-', '-')
	f('_', '_')
}

const mod = 1000000000 + 7

func main() {
	cnt := 0
	for {
		b := getByte()
		if b == '\n' {
			break
		}
		cnt += int(M[b])
	}

	fmt.Println(big.NewInt(0).Exp(big.NewInt(3), big.NewInt(int64(cnt)), big.NewInt(mod)))
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanBytes)
	return Input{Scanner: sc}
}
func getByte() byte {
	globalInput.Scan()
	return globalInput.Bytes()[0]
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

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

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}