A card pyramid of height $$$1$$$ is constructed by resting two cards against each other. For $$$h>1$$$, a card pyramid of height $$$h$$$ is constructed by placing a card pyramid of height $$$h-1$$$ onto a base. A base consists of $$$h$$$ pyramids of height $$$1$$$, and $$$h-1$$$ cards on top. For example, card pyramids of heights $$$1$$$, $$$2$$$, and $$$3$$$ look as follows:  You start with $$$n$$$ cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?

Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. Each test case contains a single integer $$$n$$$ ($$$1\le n\le 10^9$$$) — the number of cards. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^9$$$.

For each test case output a single integer — the number of pyramids you will have constructed in the end.

NoteIn the first test, you construct a pyramid of height $$$1$$$ with $$$2$$$ cards. There is $$$1$$$ card remaining, which is not enough to build a pyramid.In the second test, you build two pyramids, each of height $$$2$$$, with no cards remaining.In the third test, you build one pyramid of height $$$3$$$, with no cards remaining.In the fourth test, you build one pyramid of height $$$3$$$ with $$$9$$$ cards remaining. Then you build a pyramid of height $$$2$$$ with $$$2$$$ cards remaining. Then you build a final pyramid of height $$$1$$$ with no cards remaining.In the fifth test, one card is not enough to build any pyramids.

package main

import (
    "fmt"
)

func index(arr []int, val int) int {
	for idx, elem := range arr {
		if elem == val {
			return idx
		} else if elem > val {
			return idx - 1
		}
	}
	return -1
}

func main() {
    var t int
	fmt.Scan(&t)
	var arr = make([]int, 1)
	arr[0] = 0
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)

		count := 0
		for ; n > 1; count++ {
			for {
				last := arr[len(arr) - 1]
				if last >= n {
					break
				}
				newelem := last + 2 * len(arr) + len(arr) - 1
				arr = append(arr, newelem)
			}
			idx := index(arr, n)
			if idx == -1 {
				count--;
			} else {
				n -= arr[idx]
			}
		}
		fmt.Println(count)
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()

	f := make([]int, 26001)
	for i := 1; i <= 26000; i++ {
		f[i] = (i*i*3 + i) / 2
	}

	for t := 0; t < T; t++ {
		n := NextInt()
		var res int
		for n > 0 {
			ind := sort.SearchInts(f, n)
			if f[ind] > n {
				ind--
			}
			if ind == 0 {
				break
			}
			res++
			n -= f[ind]
		}
		fmt.Fprintln(out, res)
	}
}

// https://codeforces.com/contest/1345/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	f := make([]int, 25821 + 1)
	f[1] = 2
	for i := 2; i < len(f); i++ {
		f[i] =  f[i - 1] + (i - 1) + 2 * i
	}

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscanf(input, "%d", &T)

	for i := 0; i < T; i++ {
		var n int
		fmt.Fscan(input, &n)

		ans := 0
		for n > 1 {
			idx := sort.Search(len(f), func(x int) bool { return f[x] > n})
			n -= f[idx - 1]
			ans++
		}

		fmt.Println(ans)
	}
}

/*
URL:
https://codeforces.com/contest/1345/problem/B
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int
	n int
)

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

func solve(n int) {
	resi := n
	ans := 0

	for resi >= 2 {
		i := 1
		for {
			num := sub(i)
			if num <= resi {
				i++
			} else {
				break
			}
		}

		resi -= sub(i - 1)
		ans++
	}

	fmt.Println(ans)
}

func sub(i int) int {
	return (3*i*i + i) / 2
}

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

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

func calc(m int64) int64 {
	return m * (3*m + 1) / 2
}

func solve() {
	n := readInt64()

	var l, r int64
	ans := 0
	for {
		if n < 2 {
			break
		}

		l, r = 1, n
		for r > l {
			m := (l+r)/2 + 1
			tot := calc(m)
			if tot > n {
				r = m - 1
			} else {
				l = m
			}
		}

		// log.Println(l, r, n)

		ans++
		n -= calc(l)
	}

	fmt.Println(ans)
}

func main() {
	k := readInt()
	for i := 0; i < k; i++ {
		solve()
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		P(solve(n))
	}

	close(O)
	oWg.Wait()
}

func solve(n int) int {
	arr := make([]int64, 37838)
	arr[1] = 2
	i := 2
	for arr[i-1]+int64(3*i-1) < math.MaxInt32 && i < 37838 {
		arr[i] = arr[i-1] + int64(3*i-1)
		i++
	}

	c := 0
	sum := int64(0)
	for n > 1 {
		c++
		floor := bsearch(int64(n), arr)
		sum += floor
		n -= int(floor)
	}
	return c
}

func bsearch(x int64, arr []int64) int64 {
	l := 1
	r := len(arr)
	floor := int64(-1)
	for l <= r {
		mid := l + (r-l)/2
		if arr[mid] == x {
			return arr[mid]
		} else if arr[mid] > x {
			r = mid - 1
		} else {
			floor = arr[mid]
			l = mid + 1
		}
	}
	return floor
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	arr := make([]int64, 37838)
	arr[1] = 2
	i := 2
	for arr[i-1]+int64(3*i-1) < math.MaxInt32 && i < 37838 {
		arr[i] = arr[i-1] + int64(3*i-1)
		i++
	}

	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		P(solve(n, arr))
	}

	close(O)
	oWg.Wait()
}

func solve(n int, arr []int64) int {

	c := 0
	sum := int64(0)
	for n > 1 {
		c++
		floor := bsearch(int64(n), arr)
		sum += floor
		n -= int(floor)
	}
	return c
}

func bsearch(x int64, arr []int64) int64 {
	l := 1
	r := len(arr)
	floor := int64(-1)
	for l <= r {
		mid := l + (r-l)/2
		if arr[mid] == x {
			return arr[mid]
		} else if arr[mid] > x {
			r = mid - 1
		} else {
			floor = arr[mid]
			l = mid + 1
		}
	}
	return floor
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import "fmt"
import "math"

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

	var n []int = make([]int, t)

	max := 0
	for i:=0; i< t ; i++ {
		fmt.Scan(&n[i])
		if n[i] > max {
			max = n[i]
		}
	}

	for i:=0; i< t ; i++ {
		fmt.Println(getMinPyra(int64(n[i])))
	}
}

func getMinPyra(n int64) int64{
	if n < 2 {
		return 0
	} else if n < 4 {
		return 1
	}

	var count int64

	for n > 1 {
		size :=	(int64)(math.Floor((-1+math.Sqrt((float64)(1+24*n)))/6.0))
		count++;
		n -= size*(3*size+1)/2;
	}

	return count
}

package main

import "fmt"

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		return
	}
	cardsNumber := make([]int, n)
	max := 0

	for i := 0; i < n; i++ {
		var number int
		_, err := fmt.Scan(&number)
		if err != nil {
			return
		}
		cardsNumber[i] = number
		if max < number {
			max = number
		}
	}

	pyramids := make([]int, 0, 10)
	h := 2
	cardsCount := 2
	for cardsCount <= max {
		pyramids = append(pyramids, cardsCount)
		cardsCount += h * 2 + h - 1
		h++
	}

	for _, k := range cardsNumber {
		pyramidsNumber := 0
		for k >= pyramids[0] {
			i := 0
			for i != len(pyramids) && k >= pyramids[i] {
				i++
			}
			if i > 0 {
				i -= 1
			}
			k -= pyramids[i]
			pyramidsNumber++
		}
		fmt.Println(pyramidsNumber)
	}

}

package main

import "fmt"

func cards_from_height(h int64) int64 {
	a1 := h * (h + 1)
	a2 := (h - 1) * h / 2
	return a1 + a2
}

func calc(cards_num int64) int64 {
	if cards_num <= 1 {
		return 0
	}

	var h = int64(1)
	var temp = cards_from_height(h)
	for temp < cards_num {
		h += 1
		temp += 2*h + (h - 1)
	}

	if temp == cards_num {
		return 1
	}
	temp -= 2*h + (h - 1)
	return 1 + calc(cards_num-temp)
}

func main() {
	var n int64
	var result = []int64{}
	fmt.Scanf("%d\n", &n)
	for j := int64(0); j < n; j++ {
		var n1 int64
		fmt.Scanf("%d\n", &n1)
		rr := calc(n1)
		result = append(result, rr)
	}

	for _, rr := range result {
		fmt.Println(rr)
	}
}

package main

import (
	_ "bufio"
	"fmt"
)

func main() {
	p1345B()
}

var lookup [100000]int
var rightMax int

func p1345B() {
	var (
		test int
		num  int
	)

	// cards array returns max right side for given constraint
	rightMax = build1345B(100000)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d\n", &num)
		s1345B(num)
	}

	// fmt.Println(rightMax)
}

func s1345B(n int) {

	fmt.Println(cal1345B(n))
}

func build1345B(len int) int {
	//fmt.Println("build1345B", len)
	lookup[0] = 0
	// fmt.Println(lookup[0])
	for i := 1; i < len; i++ {
		lookup[i] = lookup[i-1] + 3*i - 1
		//fmt.Println(lookup[i])
		if lookup[i] > 1000000000 {
			return i
		}
	}
	return 0
}

/*
// finds number in maxrectangles that can be formed
	1. find height of max rectangle find function

*/
func cal1345B(n int) int {
	// base condition ensures n >= 2 always
	if n < lookup[1] {
		return 0
	} else {
		maxHeight := findMaxHeight(n, 0, rightMax)
		return n/lookup[maxHeight] + cal1345B(n%lookup[maxHeight])
	}

	//	return 0
}

// index of number maximum number less than or equal to n
func findMaxHeight(n, l, r int) int {
	// try-2 assumes n lies between [l,r]
	// working
	// case where mid will become left each time
	if r-l <= 1 {
		switch r - l {
		case 0:
			return l
		case 1:
			if lookup[r] <= n {
				return r
			} else {
				return l
			}
		}
	}
	mid := (l + r) / 2
	if lookup[mid] > n {
		return findMaxHeight(n, l, mid-1)
	} else if lookup[mid] == n {
		return mid
	} else {
		return findMaxHeight(n, mid, r)
	}
}

/*
func findMaxHeight(n, l, r int) int {

	// try-1 binary search
	if l == r {
		return r
	}
	// case when mid might get stuck in infinite loop
	if r-l == 1 {
		if lookup[r] <= n {
			return r
		} else {
			return l
		}
	}
	mid := (r + l) / 2

	// left half
	if lookup[mid] >= n {
		return findMaxHeight(n, l, mid)
	} else {
		return findMaxHeight(n, mid, r)
	}
}
*/

package main

import (
	_ "bufio"
	"fmt"
)

func main() {
	p1345B()
}

var lookup [100000]int
var rightMax int

func p1345B() {
	var (
		test int
		num  int
	)

	// cards array returns max right side for given constraint
	rightMax = build1345B(100000)

	fmt.Scanf("%d\n", &test)
	for i := 0; i < test; i++ {
		fmt.Scanf("%d\n", &num)
		s1345B(num)
	}

	// fmt.Println(rightMax)
}

func s1345B(n int) {

	fmt.Println(cal1345B(n))
}

func build1345B(len int) int {
	//fmt.Println("build1345B", len)
	lookup[0] = 0
	// fmt.Println(lookup[0])
	for i := 1; i < len; i++ {
		lookup[i] = lookup[i-1] + 3*i - 1
		//fmt.Println(lookup[i])
		if lookup[i] > 1000000000 {
			return i
		}
	}
	return 0
}

/*
// finds number in maxrectangles that can be formed
	1. find height of max rectangle find function

*/
func cal1345B(n int) int {
	// base condition ensures n >= 2 always
	if n < lookup[1] {
		return 0
	} else {
		maxHeight := findMaxHeight(n, 0, rightMax)
		return n/lookup[maxHeight] + cal1345B(n%lookup[maxHeight])
	}

	//	return 0
}

/*
// index of number maximum number less than or equal to n
func findMaxHeight(n, l, r int) int {
	// try-2 assumes n lies between [l,r]
	// working
	// case where mid will become left each time
	if r-l <= 1 {
		switch r - l {
		case 0:
			return l
		case 1:
			if lookup[r] <= n {
				return r
			} else {
				return l
			}
		}
	}
	mid := (l + r) / 2
	if lookup[mid] > n {
		return findMaxHeight(n, l, mid-1)
	} else if lookup[mid] == n {
		return mid
	} else {
		return findMaxHeight(n, mid, r)
	}
}
*/

func findMaxHeight(n, l, r int) int {

	// try-1 binary search
	if l == r {
		return r
	}
	// case when mid might get stuck in infinite loop
	if r-l == 1 {
		if lookup[r] <= n {
			return r
		} else {
			return l
		}
	}
	mid := (r + l) / 2

	// left half
	if lookup[mid] >= n {
		return findMaxHeight(n, l, mid)
	} else {
		return findMaxHeight(n, mid, r)
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

func (impl *wordScannerImpl) NextUInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

func gcd(x, y int64) int64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

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

func main() {
	defer writer.Flush()
	dp := []int64{2}
	for dp[len(dp)-1] <= 1e9 {
		currHeight := int64(len(dp))
		nxtTents := int64(2) * (currHeight + 1)
		nxtFloors := currHeight
		dp = append(dp, dp[len(dp)-1]+nxtTents+nxtFloors)
	}
	//writer.Printf("%v\n", dp)
	t := reader.NextInt64()
	for ; t > 0; t-- {
		res := int64(0)
		n := reader.NextInt64()
		i := len(dp) - 1
		for i >= 0 {
			if dp[i] <= n {
				n -= dp[i]
				//writer.Printf("%d\n", dp[i])
				res++
				continue
			}
			if n == 0 {
				break
			}
			i--
		}
		writer.Printf("%d\n", res)
	}
}

// https://codeforces.com/contest/1345/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	f := make([]int, 25821)
	f[0] = 2
	for i := 1; i < len(f); i++ {
		f[i] =  f[i-1] + i + (i + 1)*2
	}

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscanf(input, "%d", &T)

	for i := 0; i < T; i++ {
		var n int
		fmt.Fscan(input, &n)

		ans := 0
		for k := len(f) - 1; k >= 0; k-- {
			if f[k] <= n {
				n -= f[k]
				ans++
				if n < 2 {
					break
				}
			}
		}

		fmt.Println(ans)
	}
}

// https://codeforces.com/contest/1345/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	f := make([]int, 25821)
	f[0] = 2
	for i := 1; i < len(f); i++ {
		f[i] =  f[i-1]+i-1+i*2
	}

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscanf(input, "%d", &T)

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

		ans := 0
		for k := len(f) - 1; k >= 0; k-- {
			if f[k] < n {
				n -= f[k]
				ans++
				if n < 2 {
					break
				}
			}
		}

		fmt.Println(ans)
	}
}

// https://codeforces.com/contest/1345/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	f := make([]int, 25821)
	f[0] = 2
	for i := 1; i < len(f); i++ {
		f[i] =  f[i-1]+i-1+i*2
	}

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscanf(input, "%d", &T)

	for i := 0; i < T; i++ {
		var n int
		fmt.Fscan(input, &n)

		ans := 0
		for k := len(f) - 1; k >= 0; k-- {
			if f[k] < n {
				n -= f[k]
				ans++
				if n < 2 {
					break
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

import "fmt"

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		return
	}
	cardsNumber := make([]int, n)
	max := 0

	for i := 0; i < n; i++ {
		var number int
		_, err := fmt.Scan(&number)
		if err != nil {
			return
		}
		cardsNumber[i] = number
		if max < number {
			max = number
		}
	}

	pyramids := make([]int, 0, 10)
	h := 2
	cardsCount := 2
	for cardsCount < max {
		pyramids = append(pyramids, cardsCount)
		cardsCount += h * 2 + h - 1
		h++
	}

	for _, k := range cardsNumber {
		pyramidsNumber := 0
		for k >= pyramids[0] {
			i := 0
			for i != len(pyramids) && k >= pyramids[i] {
				i++
			}
			if i > 0 {
				i -= 1
			}
			k -= pyramids[i]
			pyramidsNumber++
		}
		fmt.Println(pyramidsNumber)
	}

}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

func (impl *wordScannerImpl) NextUInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

func gcd(x, y int64) int64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

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

func main() {
	defer writer.Flush()
	dp := []int64{2}
	for dp[len(dp)-1] <= 1e9 {
		currHeight := int64(len(dp))
		nxtTents := int64(2) * (currHeight+1)
		nxtFloors := currHeight
		dp = append(dp, dp[len(dp)-1] + nxtTents + nxtFloors)
	}
	t := reader.NextInt64()
	for ; t > 0; t-- {
		res := int64(0)
		n := reader.NextInt64()
		for i := len(dp)-1; i > -1; i-- {
			if dp[i] <= n {
				n -= dp[i]
				res++
			}
			if n == 0 {
				break
			}
		}
		writer.Printf("%d\n", res)
	}
}


You are given a string $$$s$$$ consisting of lowercase Latin letters "a", "b" and "c" and question marks "?".Let the number of question marks in the string $$$s$$$ be $$$k$$$. Let's replace each question mark with one of the letters "a", "b" and "c". Here we can obtain all $$$3^{k}$$$ possible strings consisting only of letters "a", "b" and "c". For example, if $$$s = $$$"ac?b?c" then we can obtain the following strings: $$$[$$$"acabac", "acabbc", "acabcc", "acbbac", "acbbbc", "acbbcc", "accbac", "accbbc", "accbcc"$$$]$$$.Your task is to count the total number of subsequences "abc" in all resulting strings. Since the answer can be very large, print it modulo $$$10^{9} + 7$$$.A subsequence of the string $$$t$$$ is such a sequence that can be derived from the string $$$t$$$ after removing some (possibly, zero) number of letters without changing the order of remaining letters. For example, the string "baacbc" contains two subsequences "abc" — a subsequence consisting of letters at positions $$$(2, 5, 6)$$$ and a subsequence consisting of letters at positions $$$(3, 5, 6)$$$.

The first line of the input contains one integer $$$n$$$ $$$(3 \le n \le 200\,000)$$$ — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$ consisting of lowercase Latin letters "a", "b" and "c" and question marks"?".

Print the total number of subsequences "abc" in all strings you can obtain if you replace all question marks with letters "a", "b" and "c", modulo $$$10^{9} + 7$$$.

NoteIn the first example, we can obtain $$$9$$$ strings:  "acabac" — there are $$$2$$$ subsequences "abc",  "acabbc" — there are $$$4$$$ subsequences "abc",  "acabcc" — there are $$$4$$$ subsequences "abc",  "acbbac" — there are $$$2$$$ subsequences "abc",  "acbbbc" — there are $$$3$$$ subsequences "abc",  "acbbcc" — there are $$$4$$$ subsequences "abc",  "accbac" — there is $$$1$$$ subsequence "abc",  "accbbc" — there are $$$2$$$ subsequences "abc",  "accbcc" — there are $$$2$$$ subsequences "abc". So, there are $$$2 + 4 + 4 + 2 + 3 + 4 + 1 + 2 + 2 = 24$$$ subsequences "abc" in total.

package main

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

// https://codeforces.com/contest/1426/problem/D

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextInt64() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

// ==================== 以上是模版 ====================
const maxn = 200005
const MOD = 1000000007

func doMod(a int64) int64 {
	return a % MOD
}

func solve() {
	/*
		6
		ac?b?c
		24
	*/
	// 求abc个数

	// D[n]["ab"] = D[n-1]
	// D[n]["ab"] = D[n-1]

	// D[n]["a"] = D[n]
	// D[n]["a"] = D[n]
	D := [maxn]map[string]int64{}

	n := nextInt()
	s := next()
	D[0] = make(map[string]int64)
	allPossible := int64(1)
	for i := 1; i <= n; i++ {
		D[i] = make(map[string]int64)
		D[i]["a"] = D[i-1]["a"]
		D[i]["ab"] = D[i-1]["ab"]
		D[i]["abc"] = D[i-1]["abc"]
		if s[i-1] == 'a' {
			D[i]["a"] = doMod(D[i-1]["a"] + allPossible)
		} else if s[i-1] == 'b' {
			D[i]["ab"] = doMod(D[i-1]["ab"] + D[i-1]["a"])
		} else if s[i-1] == 'c' {
			D[i]["abc"] = doMod(D[i-1]["abc"] + D[i-1]["ab"])
		} else if s[i-1] == '?' {
			// 出现问号，原先都数据会乘以三
			// 之前以b结尾的可能
			D[i]["a"] = doMod(D[i-1]["a"]*3 + allPossible)
			D[i]["ab"] = doMod(D[i-1]["ab"]*3 + D[i-1]["a"])
			D[i]["abc"] = doMod(D[i-1]["abc"]*3 + D[i-1]["ab"])

			allPossible = doMod(allPossible * 3)
			// x a
			// x b
			// x c

			//x a a
			//x a b
			//x a c
			//x b a
			//x b b
			//x b c
			//x c a
			//x c b
			//x c c
		}
		//fmt.Println(i, D[i])
	}
	fmt.Println(D[n]["abc"])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	solve()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1426F(in io.Reader, out io.Writer) {
	const mod int64 = 1e9 + 7
	var n int
	var s string
	Fscan(bufio.NewReader(in), &n, &s)
	p3 := make([]int64, n)
	p3[0] = 1
	for i := 1; i < n; i++ {
		p3[i] = p3[i-1] * 3 % mod
	}
	c := int64(strings.Count(s, "c"))
	r := int64(strings.Count(s, "?"))
	var ans, a, l int64
	for _, b := range s {
		if b == 'a' {
			a++
		} else if b == 'c' {
			c--
		} else {
			if b == '?' {
				r--
			}
			ans += a * c % mod * p3[l+r] % mod
			if l > 0 {
				ans += l * c % mod * p3[l-1+r] % mod
			}
			if r > 0 {
				ans += a * r % mod * p3[l+r-1] % mod
			}
			if l > 0 && r > 0 {
				ans += l * r % mod * p3[l+r-2] % mod
			}
			if b == '?' {
				l++
			}
		}
	}
	Fprint(out, ans%mod)
}

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

package main

import (
	"fmt"
)

const mod = 1000000007

func solve(str string) int64 {
	var a int64 = 0
	var ab int64 = 0
	var abc int64 = 0
	var m int64 = 1
	for _, ch := range str {
		// fmt.Println("ch: ", ch)
		if ch == 'a' {
			a = (a + m) % mod
		} else if ch == 'b' {
			ab = (ab + a) % mod
		} else if ch == 'c' {
			abc = (abc + ab) % mod
		} else {
			abc = (3*abc + ab) % mod
			ab = (3*ab + a) % mod
			a = (3*a + m) % mod
			m = (3 * m) % mod
		}
	}
	return abc
}

func main() {
	n, str := 0, ""
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &str)
	fmt.Println(solve(str))
}

package main

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

// https://codeforces.com/contest/1426/problem/D

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextInt64() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

// ==================== 以上是模版 ====================
const maxn = 100005
const MOD = 1000000007

func doMod(a int64) int64 {
	return a % MOD
}

func solve() {
	/*
		6
		ac?b?c
		24
	*/
	// 求abc个数

	// D[n]["ab"] = D[n-1]
	// D[n]["ab"] = D[n-1]

	// D[n]["a"] = D[n]
	// D[n]["a"] = D[n]
	D := [maxn]map[string]int64{}

	n := nextInt()
	s := next()
	D[0] = make(map[string]int64)
	allPossible := int64(1)
	for i := 1; i <= n; i++ {
		D[i] = make(map[string]int64)
		D[i]["a"] = D[i-1]["a"]
		D[i]["ab"] = D[i-1]["ab"]
		D[i]["abc"] = D[i-1]["abc"]
		if s[i-1] == 'a' {
			D[i]["a"] = doMod(D[i-1]["a"] + 1)
		} else if s[i-1] == 'b' {
			D[i]["ab"] = doMod(D[i-1]["ab"] + D[i-1]["a"])
		} else if s[i-1] == 'c' {
			D[i]["abc"] = doMod(D[i-1]["abc"] + D[i-1]["ab"])
		} else if s[i-1] == '?' {
			// 出现问号，原先都数据会乘以三
			// 之前以b结尾的可能
			D[i]["a"] = doMod(D[i-1]["a"]*3 + allPossible)
			D[i]["ab"] = doMod(D[i-1]["ab"]*3 + D[i-1]["a"])
			D[i]["abc"] = doMod(D[i-1]["abc"]*3 + D[i-1]["ab"])

			allPossible = doMod(allPossible * 3)
			// a
			// b
			// c

			//x a a
			//x a b
			//x a c
			//x b a
			//x b b
			//x b c
			//x c a
			//x c b
			//x c c
		}
		//fmt.Println(i, D[i])
	}
	fmt.Println(D[n]["abc"])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	solve()
}

package main

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

// https://codeforces.com/contest/1426/problem/D

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextInt64() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

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

// ==================== 以上是模版 ====================
const maxn = 100005
const MOD = 1000000007

func doMod(a int64) int64 {
	return a % MOD
}

func solve() {
	/*
		6
		ac?b?c
		24
	*/
	// 求abc个数

	// D[n]["ab"] = D[n-1]
	// D[n]["ab"] = D[n-1]

	// D[n]["a"] = D[n]
	// D[n]["a"] = D[n]
	D := [maxn]map[string]int64{}

	n := nextInt()
	s := next()
	D[0] = make(map[string]int64)
	allPossible := int64(1)
	for i := 1; i <= n; i++ {
		D[i] = make(map[string]int64)
		D[i]["a"] = D[i-1]["a"]
		D[i]["ab"] = D[i-1]["ab"]
		D[i]["abc"] = D[i-1]["abc"]
		if s[i-1] == 'a' {
			D[i]["a"] = doMod(D[i-1]["a"] + allPossible)
		} else if s[i-1] == 'b' {
			D[i]["ab"] = doMod(D[i-1]["ab"] + D[i-1]["a"])
		} else if s[i-1] == 'c' {
			D[i]["abc"] = doMod(D[i-1]["abc"] + D[i-1]["ab"])
		} else if s[i-1] == '?' {
			// 出现问号，原先都数据会乘以三
			// 之前以b结尾的可能
			D[i]["a"] = doMod(D[i-1]["a"]*3 + allPossible)
			D[i]["ab"] = doMod(D[i-1]["ab"]*3 + D[i-1]["a"])
			D[i]["abc"] = doMod(D[i-1]["abc"]*3 + D[i-1]["ab"])

			allPossible = doMod(allPossible * 3)
			// x a
			// x b
			// x c

			//x a a
			//x a b
			//x a c
			//x b a
			//x b b
			//x b c
			//x c a
			//x c b
			//x c c
		}
		fmt.Println(i, D[i])
	}
	fmt.Println(D[n]["abc"])
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	solve()
}

package main

import (
	"fmt"
)

const mod = 1000000007

func solve(str string) int {
	a, ab, abc, m := 0, 0, 0, 1
	for _, ch := range str {
		// fmt.Println("ch: ", ch)
		if ch == 'a' {
			a = (a + m) % mod
		} else if ch == 'b' {
			ab = (ab + a) % mod
		} else if ch == 'c' {
			abc = (abc + ab) % mod
		} else {
			abc = (3*abc + ab) % mod
			ab = (3*ab + a) % mod
			a = (3*a + m) % mod
			m = (3 * m) % mod
		}
	}
	return abc
}

func main() {
	n, str := 0, ""
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &str)
	fmt.Println(solve(str))
}


Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi.The way to split up game pieces is split into several steps:  First, Alice will split the pieces into two different groups A and B. This can be seen as writing the assignment of teams of a piece in an n character string, where each character is A or B.  Bob will then choose an arbitrary prefix or suffix of the string, and flip each character in that suffix (i.e. change A to B and B to A). He can do this step at most once.  Alice will get all the pieces marked A and Bob will get all the pieces marked B. The strength of a player is then the sum of strengths of the pieces in the group.Given Alice's initial split into two teams, help Bob determine an optimal strategy. Return the maximum strength he can achieve.

The first line contains integer n (1 ≤ n ≤ 5·105) — the number of game pieces. The second line contains n integers pi (1 ≤ pi ≤ 109) — the strength of the i-th piece. The third line contains n characters A or B — the assignment of teams after the first step (after Alice's step).

Print the only integer a — the maximum strength Bob can achieve.

NoteIn the first sample Bob should flip the suffix of length one.In the second sample Bob should flip the prefix or the suffix (here it is the same) of length 5.In the third sample Bob should do nothing.

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	scanLine()
	n := nextInt()
	strs := make([]int64, n)
	scanLine()

	for i := range strs {
		strs[i] = nextInt64()
	}

	group := readLine()
	bStr := int64(0)
	for i := range strs {
		if group[i] == 'B' {
			bStr += strs[i]
		}
	}

	maxStr := bStr
	str := bStr

	// println(maxStr)
	for i := range strs {
		if group[i] == 'B' {
			bStr -= strs[i]
		} else {
			bStr += strs[i]
		}

		if bStr > maxStr {
			maxStr = bStr
		}
	}
	// println(maxStr)

	for i := n - 1; i >= 0; i-- {
		if group[i] == 'B' {
			str -= strs[i]
		} else {
			str += strs[i]
		}

		if str > maxStr {
			maxStr = str
		}
	}

	println(maxStr)
}

func readLine() string {
	s, _ := reader.ReadString('\n')
	return strings.TrimSpace(s)
}

func scanLine() {
	s := readLine()
	scanner = bufio.NewScanner(strings.NewReader(s))
	scanner.Split(bufio.ScanWords)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

//Wrong
func main() {
	defer writer.Flush()

	scanLine()
	n := nextInt()
	strs := make([]int, n)
	scanLine()

	for i := range strs {
		strs[i] = nextInt()
	}

	group := readLine()
	bStr := 0
	for i := range strs {
		if group[i] == 'B' {
			bStr += strs[i]
		}
	}

	maxStr := bStr
	str := bStr

	// println(maxStr)
	for i := range strs {
		if group[i] == 'B' {
			bStr -= strs[i]
		} else {
			bStr += strs[i]
		}

		if bStr > maxStr {
			maxStr = bStr
		}
	}
	// println(maxStr)

	for i := n - 1; i >= 0; i-- {
		if group[i] == 'B' {
			str -= strs[i]
		} else {
			str += strs[i]
		}

		if str > maxStr {
			maxStr = str
		}
	}

	println(maxStr)
}

func readLine() string {
	s, _ := reader.ReadString('\n')
	return strings.TrimSpace(s)
}

func scanLine() {
	s := readLine()
	scanner = bufio.NewScanner(strings.NewReader(s))
	scanner.Split(bufio.ScanWords)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }


Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.  The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants:  to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders);  to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell.

The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)).  Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down).  It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders.

Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right.

NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:...        ...        ..U       ...R.L   ->   .*U   ->   L.R   ->  ...R.U        .R.        ..R       ...Character "*" represents a cell that contains two spiders at the same time.  If Om Nom starts from the first cell of the first row, he won't see any spiders.  If he starts from the second cell, he will see two spiders at time 1.  If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2.

package main
import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"sort"
)

func main() {
	var n,m,k,i,j int
	var d [2020]int
	var s string
	input := bufio.NewReader(os.Stdin)
	//input.Split(bufio.ScanWords)
	fmt.Scan(&n,&m,&k)
	for i=0;i<n;i++ {
		//input.Scan()
		//s=input.Text()
		fmt.Fscan(input, &s)
		for j=0;j<m;j++ {
			if s[j]=='U' {
				if i%2==0 {
					d[j]++
				}
			} else if s[j]=='L' {
				if (j-i)>=0 {
					d[j-i]++
				}
			} else if s[j]=='R' {
				if j+i<m {
					d[j+i]++
				}
			}

		}
	}
	out := bufio.NewWriter(os.Stdout)
	for i=0;i<m;i++ {
		out.WriteString(strconv.Itoa(d[i])+" ")
	}
	out.Flush()
}

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, m, _ := getI(), getI(), getI()
  counts := make([]int, m)
  for r := 0; r < n; r++ {
    line := getS()
    for c, ch := range line {
      if ch == 'U' {
        if r%2 == 0 {
          counts[c]++
        }
      } else if ch == 'R' {
        if c+r < m {
          counts[c+r]++
        }
      } else if ch == 'L' {
        if c-r >= 0 {
          counts[c-r]++
        }
      }
    }
  }
  writer.WriteString(fmt.Sprintf("%d", counts[0]))
  for i := 1; i < m; i++ {
    writer.WriteString(fmt.Sprintf(" %d", counts[i]))
  }
  writer.WriteString("\n")
}

package main

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

func main() {
	var n, m, k, i, j int
	fmt.Scanf("%d %d %d ", &n, &m, &k)
	garden := make([][]byte, n)
	spiders := make([]int64, m)
	for i = 0; i < n; i++ {
		garden[i] = make([]byte, m)
	}
	stdin := bufio.NewReader(os.Stdin)
	for i = 0; i < n; i++ {
		for j = 0; j < m; j++ {
			garden[i][j], _ = stdin.ReadByte()

		}
		_, _ = stdin.ReadByte()
		_, _ = stdin.ReadByte()
	}
	for i = 0; i < n; i++ {
		for j = 0; j < m; j++ {
			if garden[i][j] == 'R' && j+i < m {
				spiders[j+i]++
			} else if garden[i][j] == 'L' && j-i >= 0 {
				spiders[j-i]++
			} else if garden[i][j] == 'U' {
				if i%2 == 0 {
					spiders[j]++
				}
			}
		}
	}
	for i = 0; i < m; i++ {
		fmt.Printf("%d ", spiders[i])
	}
}

//436B
package main
import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

func main() {
	var n, m, k int
	var move[2005]string
	var x[2005]int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	k=k
	for i:=0; i<n; i++ {
		r.Scan()
		move[i] = r.Text()
	}
	for i:=0; i<m; i++ {
		x[i]=0
	}
	for i:=0; i<m; i++ {
		for j:=0; j<n; j++ {
			if i+j<m && string(move[j][i+j])=="L" {
				x[i]++
			}
			if i-j>=0 && string(move[j][i-j])=="R" {
				x[i]++
			}
			if j+j<n && string(move[j+j][i])=="U" {
				x[i]++
			}
		}
	}
	for i:=0; i<m; i++ {
		fmt.Print(x[i], " ")
	}
	fmt.Println()
}

package main

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

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

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n,m,k int
    var x [2005]string
    t := [...]byte{'L','R','U'}
    di := [...]int{0,0,1}
    dj := [...]int{1,-1,0}
    ScanInts(&n,&m,&k)
    for i := 0; i < n; i++ {
        scanner.Scan()
        x[i] = scanner.Text()
    }
    for j := 0; j < m; j++ {
        cnt := 0
        for i := 1; i < n; i++ {
            for k := 0; k < 3; k++ {
                ni, nj := i+(di[k]*i), j+(dj[k]*i)
                if (ni >= 0) && (ni < n) && (nj >= 0) && (nj < m) && (x[ni][nj] == t[k]) {
                    cnt++
                }
            }
        }
        writer.WriteString(strconv.Itoa(cnt))
        if j == (m-1) { writer.WriteRune('\n') } else { writer.WriteRune(' ') }
    }
    writer.Flush()
}

// 436B-mic
package main

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

func main() {
	var hasil [2002]int
	var n, m, k, i, j int
	z := bufio.NewReader(os.Stdin)
	var data [2002]string
	fmt.Scan(&n, &m, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(z, &data[i])
	}
	for i = 0; i < n; i++ {
		for j = 0; j < len(data[i]); j++ {
			if data[i][j] == 'R' {
				if i+j < m {
					hasil[i+j]++
				}
			} else if data[i][j] == 'L' {
				if j-i >= 0 {
					hasil[j-i]++
				}
			} else if data[i][j] == 'U' {
				if i%2 == 0 {
					hasil[j]++
				}
			}
		}
	}
	for i = 0; i < m; i++ {
		fmt.Print(hasil[i])
		fmt.Print(" ")
	}
	fmt.Println()
}

package main

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

func main() {
    var n, m, k, i, j int
    fmt.Scanf("%d %d %d ", &n, &m, &k)
    garden := make([][]byte, n)
    spiders := make([]byte, m)
    for i=0; i<n; i++{
        garden[i] = make([]byte, m)
    }
    stdin := bufio.NewReader(os.Stdin)
    for i=0 ; i<n; i++ {
        for j=0 ; j<m ; j++ {
        garden[i][j], _ = stdin.ReadByte()

        }
               _, _ = stdin.ReadByte()
                        _, _ = stdin.ReadByte()
    }

    for i=0; i<n ; i++ {
        for j=0;j<m;j++ {
            if garden[i][j] == 'R' && j+i < m {
                spiders[j+i]++
            } else if garden[i][j] == 'L' && j-i >=0{
                spiders[j-i]++
            } else if garden[i][j] == 'U' {
                if i%2 == 0 {
                    spiders[j]++
                }
            }
        }
    }
    for i=0; i<m ; i++ {
        fmt.Printf("%d ", spiders[i])
    }
}

package main

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

func main() {
    var n, m, k, i, j int
    fmt.Scanf("%d %d %d ", &n, &m, &k)
    garden := make([][]byte, n)
    spiders := make([]byte, m)
    for i=0; i<n; i++{
        garden[i] = make([]byte, m)
    }
    stdin := bufio.NewReader(os.Stdin)
    for i=0 ; i<n; i++ {
        for j=0 ; j<m ; j++ {
        garden[i][j], _ = stdin.ReadByte()

        }
               _, _ = stdin.ReadByte()
                        _, _ = stdin.ReadByte()
    }
     for i=0; i<n ; i++ {
        for j=0;j<m;j++ {
            fmt.Printf("%c ", garden[i][j])
        }
        fmt.Printf("\n")
    }
    for i=0; i<n ; i++ {
        for j=0;j<m;j++ {
            if garden[i][j] == 'R' && j+i < m {
                spiders[j+i]++
            } else if garden[i][j] == 'L' && j-i >=0{
                spiders[j-i]++
            } else if garden[i][j] == 'U' {
                if i%2 == 0 {
                    spiders[j]++
                }
            }
        }
    }
    for i=0; i<m ; i++ {
        fmt.Printf("%d ", spiders[i])
    }
}


A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom.   You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.

The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where:   d — the diameter of your cylindrical cup,  h — the initial level of water in the cup,  v — the speed of drinking process from the cup in milliliters per second,  e — the growth of water because of rain if you do not drink from the cup.

If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.

NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by  centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in  seconds.

package main

import (
	"fmt"
	"math"
)

var pi float32

func main() {
	pi = float32(math.Acos(float64(-1.0)))
	var d, h, v, e float32
	fmt.Scanln(&d, &h, &v, &e)
	incV := f(d/2.0, e)
	if incV >= v {
		fmt.Println("NO")
		return
	}
	ans := f(d/2.0, h) / (v - incV)
	fmt.Println("YES")
	fmt.Println(ans)
}

func f(r, h float32) (V float32) {
	V = r * r * pi * h
	return
}

// http://codeforces.com/contest/667/problem/A
package main

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

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

func main () {
	var d, h, v, e float64

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &d, &h, &v, &e)
	rs := d * d / 4

	se := math.Pi * rs * e
	sh := math.Pi * rs * h

	if se >= v {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	fmt.Println(sh / (v - se))
}

package main

import "fmt"
import "math"

func main() {
    var d,h,e,v,t float64
    fmt.Scan(&d,&h,&v,&e)
    v=v*4/(d*d*math.Pi)
    t=-h/(e-v)
    if t<10000 && t>0 {
        fmt.Println("YES")
        fmt.Println(t)
    } else {
        fmt.Println("NO")
    }
}

package main

import (
	"fmt"
	"math"
)

func mlToCm(d, v float64) float64 {
	return v / ((d * d / 4) * math.Pi)
}

func main() {
	var d, h, v, e float64
	fmt.Scan(&d, &h, &v, &e)
	velocity := e - mlToCm(d, v)
	if velocity >= 0 {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	fmt.Println(-1 * h/velocity)
}

package main

import "fmt"

const pi float32 = 3.1415926

func main() {
	var d, h, v, e float32
	fmt.Scanln(&d, &h, &v, &e)
	incV := f(d/2, e)
	if incV >= v {
		fmt.Println("NO")
		return
	}
	ans := f(d/2, h) / (v - incV)
	fmt.Println(ans)
}

func f(r, h float32) (V float32) {
	V = r * r * pi * h
	return
}