Polycarp has $$$x$$$ of red and $$$y$$$ of blue candies. Using them, he wants to make gift sets. Each gift set contains either $$$a$$$ red candies and $$$b$$$ blue candies, or $$$a$$$ blue candies and $$$b$$$ red candies. Any candy can belong to at most one gift set.Help Polycarp to find the largest number of gift sets he can create.For example, if $$$x = 10$$$, $$$y = 12$$$, $$$a = 5$$$, and $$$b = 2$$$, then Polycarp can make three gift sets:   In the first set there will be $$$5$$$ red candies and $$$2$$$ blue candies;  In the second set there will be $$$5$$$ blue candies and $$$2$$$ red candies;  In the third set will be $$$5$$$ blue candies and $$$2$$$ red candies. Note that in this example there is one red candy that Polycarp does not use in any gift set.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case consists of a single string containing four integers $$$x$$$, $$$y$$$, $$$a$$$, and $$$b$$$ ($$$1 \le x, y, a, b \le 10^9$$$).

For each test case, output one number — the maximum number of gift sets that Polycarp can make.

package main

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

// Binary Search
// Math

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

	var t int64
	fmt.Fscanf(reader, "%d\n", &t)

	var x, y, a, b int64
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
	}
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9)
	for l <= r {
		m := l + (r-l)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	l := math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0)
	r := math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
	return l <= r
}

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

package main

import (
	"fmt"
	"math"
)

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

	var x, y, a, b int64
	for ; t > 0; t-- {
		fmt.Scanln(&x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
	}
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9)
	for l <= r {
		m := l + (r-l)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	l := math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0)
	r := math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
	return l <= r
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
	}
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9)
	for l <= r {
		m := l + (r-l)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	l := math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0)
	r := math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
	return l <= r
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	// res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
		// res = append(res, giftSet(x, y, a, b))
	}

	// for _, num := range res {
	// 	fmt.Println(num)
	// }
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9+1)
	for l < r {
		m := l + (r-l+1)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	return math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0) <=
		math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var x, y, a, b int
		Fscan(in, &x, &y, &a, &b)

		if a == b {
			Fprintln(out, min(x, y) / a)
			continue
		}
		if a < b {
			a, b = b, a
		}

		left, right := 0, (x + y) / (a + b)
		for left < right {
			mid := left + ((right - left + 1) >> 1)
			lower := int(math.Ceil(float64(y - a * mid) / float64(b - a)))
			upper := int(math.Floor(float64(x - b * mid) / float64(a - b)))
			if max(0, lower) <= min(upper, mid) {
				left = mid
			} else {
				right = mid - 1
			}
		}
		Fprintln(out, left)
	}
}

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

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

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var x, y, a, b int
		Fscan(in, &x, &y, &a, &b)

		if a == b {
			Fprintln(out, min(x, y) / a)
			continue
		}
		if a < b {
			a, b = b, a
		}

		left, right := 0, (x + y) / (a + b)
		for left < right {
			mid := left + ((right - left + 1) >> 1)
			l := max(0, (mid * a - y + a - b - 1) / (a - b))
			r := min(mid, (x - mid * b + a - b) / (a - b) - 1)
			if l <= r {
				left = mid
			} else {
				right = mid - 1
			}
		}
		Fprintln(out, left)
	}
}

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

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
type vec struct{ x, y float64 }
type line struct{ p1, p2 vec }

func (a vec) sub(b vec) vec     { return vec{a.x - b.x, a.y - b.y} }
func (a vec) det(b vec) float64 { return a.x*b.y - a.y*b.x }
func (a line) vec() vec         { return a.p2.sub(a.p1) }

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

	solve := func(Case int) {
		var x, y, a, b int64
		Fscan(in, &x, &y, &a, &b)
		r := min(x/a, y/b)
		ans := max(r, min(x/b, y/a))

		if a == b {
			Fprintln(out, ans)
			return
		}

		i := func() int64 {
			x, y, a, b := float64(x), float64(y), float64(a), float64(b)
			l1 := line{vec{x / a, 0}, vec{0, x / b}}
			l2 := line{vec{y / b, 0}, vec{0, y / a}}

			va := l1.vec()
			d1 := va.det(l2.p1.sub(l1.p1))
			d2 := va.det(l2.p2.sub(l1.p1))

			d :=d2-d1
			i := int64(l2.p1.x/d*d2-l2.p2.x/d*d1)
			return i
		}()
		for k1 := i - 10; k1 < i+10 && k1 <= r; k1++ {
			if k1 < 0 {
				continue
			}
			k2 := min((x-k1*a)/b, (y-k1*b)/a)
			ans = max(ans, k1+k2)
		}

		Fprintln(out, ans)
	}

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

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

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

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

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	// res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
		// res = append(res, giftSet(x, y, a, b))
	}

	// for _, num := range res {
	// 	fmt.Println(num)
	// }
}

func giftSet(x, y, a, b int64) int64 {
	if Min(x/a, y/b) < Min(x/b, y/a) {
		a, b = b, a
	}
	i := Min(x/a, y/b)
	if i == 0 || a*i > x || b*i > y {
		return 0
	}

	out := i + Min((x-a*i)/b, (y-b*i)/a)
	if a == b {
		return out
	}

	for i--; i >= 0; i-- {
		res := i + Min((x-a*i)/b, (y-b*i)/a)
		if res <= out {
			break
		}
		out = res
	}
	return out
}

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int64) int64 {
	if Min(x/a, y/b) < Min(x/b, y/a) {
		a, b = b, a
	}
	i := Min(x/a, y/b)
	if i == 0 || a*i > x || b*i > y {
		return 0
	}
	return Max(i+Min((x-a*i)/b, (y-b*i)/a), i-1+Min((x-a*(i-1))/b, (y-b*(i-1))/a))
}

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

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int64) int64 {
	out := int64(0)
	l, r := int64(1), int64(1)+x/a
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, a, b, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	if val, ok := isValid(x, y, a, b, l); ok {
		out = Max(out, val)
	}
	l, r = 1, 1+x/b
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, b, a, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	if val, ok := isValid(x, y, a, b, l); ok {
		out = Max(out, val)
	}
	return out
}

func isValid(x, y, a, b, i int64) (int64, bool) {
	if a*i > x || b*i > y {
		return -1, false
	}
	return i + Min((x-a*i)/b, (y-b*i)/a), true
}

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

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int64) int64 {
	out := int64(0)
	l, r := int64(1), int64(1)+int64(x/a)
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, a, b, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	l, r = 1, 1+x/b
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, b, a, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	return out
}

func isValid(x, y, a, b, i int64) (int64, bool) {
	if a*i > x || b*i > y {
		return -1, false
	}
	return i + Min((x-a*i)/b, (y-b*i)/a), true
}

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

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

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	res := make([]int, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int) int {
	out := 0
	l, r := 1, 1+x/a
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, a, b, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	l, r = 1, 1+x/b
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, b, a, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	return out
}

func isValid(x, y, a, b, i int) (int, bool) {
	if a*i > x || b*i > y {
		return -1, false
	}
	return i + Min((x-a*i)/b, (y-b*i)/a), true
}

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
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	ternarySearchInt := func(l, r int64, f func(x int64) int64) int64 {
		for r-l > 10 {
			m1 := l + (r-l)/3
			m2 := r - (r-l)/3
			v1, v2 := f(m1), f(m2)
			if v1 < v2 {
				l = m1
			} else {
				r = m2
			}
		}
		mx := f(l)
		for i := l + 1; i <= r; i++ {
			if v := f(i); v > mx {
				mx = v
			}
		}
		return mx
	}
	_ = ternarySearchInt

	solve := func(Case int) {
		var x, y, a, b int64
		Fscan(in, &x, &y, &a, &b)
		r := min(x/a, y/b)
		ans := r
		ans = max(ans, min(x/b, y/a))

		res := ternarySearchInt(0, r, func(k1 int64) int64 {
			k2 := min((x-k1*a)/b, (y-k1*b)/a)
			return k1 + k2
		})
		ans = max(ans, res)

		Fprintln(out, ans)
	}

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

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

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

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

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


Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the stack, and n of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to n. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack.That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it.Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed.

The first line of input contains the integer n (1 ≤ n ≤ 3·105) — the number of boxes. Each of the next 2n lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer x (1 ≤ x ≤ n) follows, indicating that Daru should add the box with number x to the top of the stack.  It is guaranteed that exactly n lines contain "add" operations, all the boxes added are distinct, and n lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed.

Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands.

3
add 1
remove
add 2
add 3
remove
remove

7
add 3
add 2
add 1
remove
add 4
remove
remove
remove
add 6
add 7
add 5
remove
remove
remove

NoteIn the first sample, Daru should reorder the boxes after adding box 3 to the stack.In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack.

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

var scn = bufio.NewScanner(os.Stdin)

func gets() string {
	scn.Scan()
	return scn.Text()
}

func atoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func main() {
	n := atoi(gets())
	ans := 0
	next := 1
	a := make([]int, 0, n*2)
	for i := 0; i < 2*n; i++ {
		s := gets()
		if s != "remove" {
			sp := strings.Split(s, " ")
			x := atoi(sp[1])
			a = append(a, x)
		} else {
			sz := len(a)
			if sz > 0 {
				if a[sz-1] != next {
					a = a[:0]
					ans++
				} else {
					a = a[:sz-1]
				}
			}
			next++
		}
	}
	fmt.Println(ans)
}

package main

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

const N = 300007

var stack [N]int
var size = 0

func push(x int) {
	stack[size] = x
	size++
}

func top() int {
	return stack[size-1]
}

func pop() {
	size--
}

func clear() {
	size = 0
}

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 main() {
	var n, x int
	var c string
	fmt.Fscanln(reader, &n)
	ans := 0
	cur := 0
	balanced := make(map[int]bool)
	for i := 0; i < n*2; i++ {
		fmt.Fscan(reader, &c)
		if c == "add" {
			fmt.Fscan(reader, &x)
			push(x)
		} else {
			cur++
			if size > 0 && top() == cur {
				pop()
			} else if !balanced[cur] || (size > 0 && !balanced[top()]) {
				ans++
				for j := 0; j < size; j++ {
					balanced[stack[j]] = true
				}
				clear()
			}
		}
	}
	fmt.Println(ans)
}

package main

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

var fileName = ""
var sc *Scanner = getScanner()
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func getScanner() *Scanner {
	if len(fileName) <= 0 {
		return NewScanner(os.Stdin)
	}
	var file, err = os.Open(fileName)
	if err != nil {
		panic(err)
	}
	return NewScanner(bufio.NewReader(file))
}

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

func (s *Scanner) Text() string {
	return string(s.token)
}

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

func printSpace() { w.WriteByte(' ') }
func println()    { w.WriteByte('\n') }

func nextToken() string { sc.Scan(); return sc.Text() }

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

func nextInt64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func printInt(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		printSpace()
	}
}

func printInt64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		printSpace()
	}
}

func print(s ...string) {
	for _, ss := range s {
		w.WriteString(ss)
		printSpace()
	}
}

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
}

func min64(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func max64(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()

	n := nextInt()
	a := make([]int, n)
	r := make([]bool, n)
	sz := 0
	ans := 0
	numR := 0
	for k := 0; k < 2 * n; k++ {
		cmd := nextToken()
		if cmd == "add" {
			num := nextInt()
			a[sz] = num
			r[sz] = false
			sz++
		} else {
			numR++
			good := r[sz - 1] || a[sz - 1] == numR
			if !good {
				r[sz - 1] = true
				ans++
			}
			sz--
			if sz > 0 {
				r[sz-1] = r[sz-1] || r[sz]
			}
		}
	}
	printInt(ans)
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	ans := 0
	next := 1
	a := []int{}
	for i := 0; i < 2*n; i++ {
		var s string
		fmt.Scan(&s)
		if s == "add" {
			var x int
			fmt.Scan(&x)
			a = append(a, x)
		} else {
			sz := len(a) - 1
			p := a[sz]
			if p != next {
				fmt.Println(p, next)
				sort.Sort(sort.Reverse(sort.IntSlice(a)))
				ans++
			}
			a = a[:sz]
			next++
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

const N = 300007

var stack [N]int
var size = 0

func push(x int) {
	stack[size] = x
	size++
}

func top() int {
	return stack[size-1]
}

func pop() {
	size--
}

func clear() {
	size = 0
}

func main() {
	var n, x int
	var c string
	fmt.Scanln(&n)
	ans := 0
	cur := 0
	balanced := make(map[int]bool)
	for i := 0; i < n*2; i++ {
		fmt.Scan(&c)
		if c == "add" {
			fmt.Scan(&x)
			push(x)
		} else {
			cur++
			if size > 0 && top() == cur {
				pop()
			} else if !balanced[cur] {
				ans++
				for j := 0; j < size; j++ {
					balanced[stack[j]] = true
				}
				clear()
			}
		}
	}
	fmt.Println(ans)
}


Omkar is standing at the foot of Celeste mountain. The summit is $$$n$$$ meters away from him, and he can see all of the mountains up to the summit, so for all $$$1 \leq j \leq n$$$ he knows that the height of the mountain at the point $$$j$$$ meters away from himself is $$$h_j$$$ meters. It turns out that for all $$$j$$$ satisfying $$$1 \leq j \leq n - 1$$$, $$$h_j < h_{j + 1}$$$ (meaning that heights are strictly increasing).Suddenly, a landslide occurs! While the landslide is occurring, the following occurs: every minute, if $$$h_j + 2 \leq h_{j + 1}$$$, then one square meter of dirt will slide from position $$$j + 1$$$ to position $$$j$$$, so that $$$h_{j + 1}$$$ is decreased by $$$1$$$ and $$$h_j$$$ is increased by $$$1$$$. These changes occur simultaneously, so for example, if $$$h_j + 2 \leq h_{j + 1}$$$ and $$$h_{j + 1} + 2 \leq h_{j + 2}$$$ for some $$$j$$$, then $$$h_j$$$ will be increased by $$$1$$$, $$$h_{j + 2}$$$ will be decreased by $$$1$$$, and $$$h_{j + 1}$$$ will be both increased and decreased by $$$1$$$, meaning that in effect $$$h_{j + 1}$$$ is unchanged during that minute.The landslide ends when there is no $$$j$$$ such that $$$h_j + 2 \leq h_{j + 1}$$$. Help Omkar figure out what the values of $$$h_1, \dots, h_n$$$ will be after the landslide ends. It can be proven that under the given constraints, the landslide will always end in finitely many minutes.Note that because of the large amount of input, it is recommended that your code uses fast IO.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$).  The second line contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ satisfying $$$0 \leq h_1 < h_2 < \dots < h_n \leq 10^{12}$$$ — the heights.

Output $$$n$$$ integers, where the $$$j$$$-th integer is the value of $$$h_j$$$ after the landslide has stopped.

NoteInitially, the mountain has heights $$$2, 6, 7, 8$$$.In the first minute, we have $$$2 + 2 \leq 6$$$, so $$$2$$$ increases to $$$3$$$ and $$$6$$$ decreases to $$$5$$$, leaving $$$3, 5, 7, 8$$$.In the second minute, we have $$$3 + 2 \leq 5$$$ and $$$5 + 2 \leq 7$$$, so $$$3$$$ increases to $$$4$$$, $$$5$$$ is unchanged, and $$$7$$$ decreases to $$$6$$$, leaving $$$4, 5, 6, 8$$$.In the third minute, we have $$$6 + 2 \leq 8$$$, so $$$6$$$ increases to $$$7$$$ and $$$8$$$ decreases to $$$7$$$, leaving $$$4, 5, 7, 7$$$.In the fourth minute, we have $$$5 + 2 \leq 7$$$, so $$$5$$$ increases to $$$6$$$ and $$$7$$$ decreases to $$$6$$$, leaving $$$4, 6, 6, 7$$$.In the fifth minute, we have $$$4 + 2 \leq 6$$$, so $$$4$$$ increases to $$$5$$$ and $$$6$$$ decreases to $$$5$$$, leaving $$$5, 5, 6, 7$$$.In the sixth minute, nothing else can change so the landslide stops and our answer is $$$5, 5, 6, 7$$$.

package main

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

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

	n := readNum(reader)

	H := make([]int64, n)
	s, _ := reader.ReadBytes('\n')
	var pos int
	for i := 0; i < n; i++ {
		var x uint64
		pos = readUint64(s, pos, &x) + 1
		H[i] = int64(x)
	}

	res := solve(n, H)

	var buf bytes.Buffer

	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	buf.WriteByte('\n')
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}
func solve(n int, H []int64) []int64 {
	if n == 1 {
		return H
	}
	var sum int64
	for i := 0; i < n; i++ {
		sum += H[i]
	}
	// if (a + a + n - 1) * n / 2 == sum
	// (2 * a + n - 1) = 2 * sum / n
	N := int64(n)
	if 2*sum%N == 0 {
		m := 2 * sum / N
		m += 1 - N
		if m > 0 && m%2 == 0 {
			a := m / 2
			for i := 0; i < n; i++ {
				H[i] = a + int64(i)
			}
			return H
		}
	}

	// then there should be one adjacent pair that H[i] == H[i+1] in the result.
	// (a + a + n - 2) * (n - 1) / 2 + H[k] = sum
	// where k is the same pair index
	// H[k] = a + k
	// (2 * a + n - 2) * (n - 1) / 2 + a + k == sum
	// (2 * a + n - 2) * (n - 1) + 2 * a  + 2 * k == 2 * sum
	sum *= 2
	// 2 * a * (n - 1) + 2 * a + (n - 2) * (n - 1) + 2 * k == 2 * sum
	sum -= (N - 2) * (N - 1)
	// 2 * a * n + 2 * k == 2 * sum - (N - 2) * (N - 1)
	for k := 0; k < n-1; k++ {
		// if k == i
		tmp := sum - 2*int64(k)
		if tmp%(2*N) == 0 {
			// found
			a := tmp / (2 * N)
			//a := m / 2
			for i := 0; i < n; i++ {
				H[i] = a + int64(i)
				if i >= k + 1 {
					H[i]--
				}
			}

			break
		}
	}
	return H
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReader(file)
	} else {
		reader = bufio.NewReader(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	for _, v := range ans {
		fmt.Fprintf(writer, "%d ", v)
	}

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, err := reader.ReadString('\n')
	if err == bufio.ErrBufferFull {
		panic(err)
	}

	return strings.TrimRight(str, "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReader(file)
	} else {
		reader = bufio.NewReader(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	writer.WriteString(str)
	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, err := reader.ReadString('\n')
	if err == bufio.ErrBufferFull {
		panic(err)
	}

	return strings.TrimRight(str, "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	var scanner *bufio.Scanner
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReader(file)
		scanner = bufio.NewScanner(file)
	} else {
		reader = bufio.NewReader(os.Stdin)
		scanner = bufio.NewScanner(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)
	scanner.Split(bufio.ScanWords)

	//_ = readInt()
	//a := readInts()
	scanner.Scan()
	text := scanner.Text()
	n, _ := strconv.ParseInt(text, 10, 64)
	a := make([]int64, n)
	for i := range a {
		scanner.Scan()
		text := scanner.Text()
		a[i], _ = strconv.ParseInt(text, 10, 64)
	}
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	writer.WriteString(str)
	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, err := reader.ReadString('\n')
	if err != io.EOF {
		panic(err)
	}

	return strings.TrimRight(str, "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	for _, v := range ans {
		fmt.Fprintf(writer, "%d ", v)
	}

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

	n := readNum(reader)

	H := make([]int64, n)
	s, _ := reader.ReadBytes('\n')
	var pos int
	for i := 0; i < n; i++ {
		var x uint64
		pos = readUint64(s, pos, &x) + 1
		H[i] = int64(x)
	}

	res := solve(n, H)

	var buf bytes.Buffer

	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	buf.WriteByte('\n')
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}
func solve(n int, H []int64) []int64 {

	var sum int64

	for i := 0; i < n; i++ {
		sum += H[i]
	}

	check := func(h0 int64) bool {
		// if h[0] = h0
		var need = h0 - H[0]
		var prev = h0

		for i := 1; i < n; i++ {
			cur := prev
			diff := H[i] - H[i-1]

			cur += diff & 1

			if cur >= H[i] {
				need += cur - H[i]
			} else {
				need -= H[i] - cur
			}
			if need < 0 {
				return false
			}
			prev = cur
		}
		return need <= 0
	}

	var left = H[0]
	var right = H[n-1] + 1

	for left < right {
		mid := left + (right-left)/2
		if !check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}

	X := make([]int64, n)
	X[0] = right - 1

	for i := 1; i < n; i++ {
		X[i] = X[i-1] + (H[i]-H[i-1])&1
	}

	return X
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := tmp - a1*n

	ans := make([]int64, n)
	for j := int64(0); j < i; j++ {
		ans[j] = a1+j+1
	}
	for j := i; j < n; j++ {
		ans[j] = a1+j
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
		if sum < 0 {
			panic("sum")
		}
	}
	if n*(n-1) < 0 {
		panic("n*(n-1)")
	}
	tmp := sum - n*(n-1)/2
	if tmp < 0 {
		panic("tmp")
	}
	a1 := tmp / n
	i := int64(0)
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}
	if i < 0 {
		panic("i")
	}

	ans := make([]int64, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1 + int64(j)
		}
	} else {
		i--
		for j := int64(0); j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int) []int {
	n := len(a)
	sum := 0
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := 0
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}

	ans := make([]int, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1+j
		}
	} else {
		i--
		for j := 0; j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	//writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)
	file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int) []int {
	n := len(a)
	sum := 0
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := 0
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}

	ans := make([]int, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1+j
		}
	} else {
		i--
		for j := 0; j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := int64(0)
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}

	ans := make([]int64, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1+ int64(j)
		}
	} else {
		i--
		for j := int64(0); j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}


You are given four integer values $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$.Check if there exists a string that contains:   $$$a$$$ letters 'A';  $$$b$$$ letters 'B';  $$$c$$$ letters 'C';  no other letters;  exactly $$$m$$$ pairs of adjacent equal letters (exactly $$$m$$$ such positions $$$i$$$ that the $$$i$$$-th letter is equal to the $$$(i+1)$$$-th one).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Each of the next $$$t$$$ lines contains the description of the testcase — four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$ ($$$1 \le a, b, c \le 10^8$$$; $$$0 \le m \le 10^8$$$).

For each testcase print "YES" if there exists a string that satisfies all the requirements. Print "NO" if there are no such strings. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

NoteIn the first testcase strings "ABCAB" or "BCABA" satisfy the requirements. There exist other possible strings.In the second testcase there's no way to put adjacent equal letters if there's no letter that appears at least twice.In the third testcase string "CABBCC" satisfies the requirements. There exist other possible strings.

package main

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

/*
8
2 1 3 3
1 1 1 1
1 1 2 1
1 2 2 2
1 2 2 3
1 1 3 3
1 1 5 4
2 2 3 4
---
YES		AABCCC
NO		ABC
YES		ABCC
YES		ABBCC
NO		ABBCC
NO		ABCCC
YES		ABCCCCC
YES		AABBCCC

C		-> 0
CC		-> 1
CCC		-> 2
CCCC	-> 3
CCCCC	-> 4
========
4
3 3 3 6
3 3 3 7
1 1 7 6
1 1 7 7
---
YES 	AAABBBCCC
NO
YES		ABCCCCCCC
NO

ABACA 		-> 0
ABACAA		-> 1
ABACABACA	-> 0
ABACABACAA	-> 1
========
5
4 1 1 0
4 1 1 1
4 1 1 2
4 1 1 3
4 1 1 4
---
NO
YES
YES
YES
NO
*/

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

	maxAbc := max(a, b, c)
	minCnt := maxAbc - (sum(a, b, c) - maxAbc) - 1
	maxCnt := a + b + c - 3

	if m >= minCnt && m <= maxCnt {
		fmt.Fprintln(writer, "YES")
	} else {
		fmt.Fprintln(writer, "NO")
	}
}

//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 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 GoUnusedFunction
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"
	"io"
	"math"
	"os"
	"time"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

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

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var a, b, c, m int
		fmt.Fscan(input, &a, &b, &c, &m)

		NumberOfBlocks := a + b + c - m
		minBlock := 0
		if a > 0 {
			minBlock++
		}
		if b > 0 {
			minBlock++
		}
		if c > 0 {
			minBlock++
		}

		var maxBloxk int
		if a+b >= c && b+c >= a && a+c >= b {
			maxBloxk = a + b + c
		} else {
			q := MAXX(MAXX(a, b), c)
			maxBloxk = 2*(a+b+c-q) + 1
		}

		if NumberOfBlocks >= minBlock && NumberOfBlocks <= maxBloxk {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

func Problem1574B(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	t := 0
	fmt.Fscanln(in, &t)
	for tcNo := 1; tcNo <= t; tcNo++ {
		a, b, c, m := 0, 0, 0, 0
		fmt.Fscanln(in, &a, &b, &c, &m)

		minM := 0
		lettersCount := []int{a, b, c}
		sort.Ints(lettersCount)

		minM = lettersCount[2] - lettersCount[1] - lettersCount[0] - 1
		if minM < 0 {
			minM = 0
		}

		maxM := 0

		if a > 1 {
			maxM += a - 1
		}
		if b > 1 {
			maxM += b - 1
		}
		if c > 1 {
			maxM += c - 1
		}

		if m >= minM && m <= maxM {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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

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++ {
		z := make([]int, 3)
		var m int
		fmt.Fscan(in, &z[0], &z[1], &z[2], &m)

		sort.Ints(z)
		high := (z[0] - 1) + (z[1] - 1) + (z[2] - 1)
		low := z[2] - (z[0] + z[1] + 1)
		if m >= low && m <= high {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		var a, b, c, m int
		fmt.Fscan(r, &a, &b, &c, &m)

		fmt.Println(solve(a, b, c, m))
	}
}

func solve(a, b, c, m int) string {
	max := a + b + c - 3

	var arr []int
	arr = append(arr, a, b, c)
	sort.Ints(arr)

	var min int

	if arr[2] > arr[0] + arr[1] + 1 {
		min = arr[2] - (arr[0] + arr[1] + 1)

	} else {
		min = 0
	}

	if m < min || m > max {
		return "NO"
	}

	return "YES"
}

package main

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

/*
1
2 1 3 3
---
YES - AABCCC

C		-> 0
CC		-> 1
CCC		-> 2
CCCC	-> 3
CCCCC	-> 4
*/

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

	pairCnt := a + b + c - 3

	if m > pairCnt {
		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

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

/*

 */

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

	pairCnt := a/2 + b/2 + c/2

	if m > pairCnt {
		fmt.Fprintln(writer, "NO")
		return
	}

	fmt.Fprintln(writer, "YES")
}

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

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

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var a, b, c, m int
		fmt.Fscan(input, &a, &b, &c, &m)

		ARR := make([]int, 0)
		ARR = append(ARR, a)
		ARR = append(ARR, b)
		ARR = append(ARR, c)

		sort.Ints(ARR)

		minim := ARR[2] - ARR[1] - 1
		maxim := 0
		for i := 0; i < 3; i++ {
			if ARR[i] > 0 {
				maxim = maxim + ARR[i] - 1
			}
		}
		if m >= minim && m <= maxim {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

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

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var a, b, c, m int
		fmt.Fscan(input, &a, &b, &c, &m)

		ARR := make([]int, 0)
		ARR = append(ARR, a)
		ARR = append(ARR, b)
		ARR = append(ARR, c)

		sort.Ints(ARR)

		minim := ARR[2] - ARR[1] - 1
		maxim := a + b + c - 3
		if m >= minim && m <= maxim {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func Problem1574B(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	t := 0
	fmt.Fscanln(in, &t)
	for tcNo := 1; tcNo <= t; tcNo++ {
		a, b, c, m := 0, 0, 0, 0
		fmt.Fscanln(in, &a, &b, &c, &m)

		lettersCount := []int{a, b, c}
		for len(lettersCount) > 1 {
			sort.Ints(lettersCount)
			lettersCount[len(lettersCount)-2] = lettersCount[len(lettersCount)-1] - lettersCount[len(lettersCount)-2]
			lettersCount = lettersCount[:len(lettersCount)-1]
		}
		minM := lettersCount[0] - 1

		maxM := 0

		if a > 1 {
			maxM += a - 1
		}
		if b > 1 {
			maxM += b - 1
		}
		if c > 1 {
			maxM += c - 1
		}

		if m >= minM && m <= maxM {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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

package main

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

func Problem1574B(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	t := 0
	fmt.Fscanln(in, &t)
	for tcNo := 1; tcNo <= t; tcNo++ {
		a, b, c, m := 0, 0, 0, 0
		fmt.Fscanln(in, &a, &b, &c, &m)

		pairsCount := 0
		if a > 1 {
			pairsCount += a - 1
		}
		if b > 1 {
			pairsCount += b - 1
		}
		if c > 1 {
			pairsCount += c - 1
		}
		if pairsCount >= m {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var a, b, c, m int
		fmt.Fscan(in, &a, &b, &c, &m)

		if a/2+b/2+c/2 >= m {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}


Vasya has written some permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, so for all $$$1 \leq i \leq n$$$ it is true that $$$1 \leq p_i \leq n$$$ and all $$$p_1, p_2, \ldots, p_n$$$ are different. After that he wrote $$$n$$$ numbers $$$next_1, next_2, \ldots, next_n$$$. The number $$$next_i$$$ is equal to the minimal index $$$i < j \leq n$$$, such that $$$p_j > p_i$$$. If there is no such $$$j$$$ let's let's define as $$$next_i = n + 1$$$.In the evening Vasya went home from school and due to rain, his notebook got wet. Now it is impossible to read some written numbers. Permutation and some values $$$next_i$$$ are completely lost! If for some $$$i$$$ the value $$$next_i$$$ is lost, let's say that $$$next_i = -1$$$.You are given numbers $$$next_1, next_2, \ldots, next_n$$$ (maybe some of them are equal to $$$-1$$$). Help Vasya to find such permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, that he can write it to the notebook and all numbers $$$next_i$$$, which are not equal to $$$-1$$$, will be correct.

The first line contains one integer $$$t$$$ — the number of test cases ($$$1 \leq t \leq 100\,000$$$). Next $$$2 \cdot t$$$ lines contains the description of test cases,two lines for each. The first line contains one integer $$$n$$$ — the length of the permutation, written by Vasya ($$$1 \leq n \leq 500\,000$$$). The second line contains $$$n$$$ integers $$$next_1, next_2, \ldots, next_n$$$, separated by spaces ($$$next_i = -1$$$ or $$$i < next_i \leq n + 1$$$). It is guaranteed, that the sum of $$$n$$$ in all test cases doesn't exceed $$$500\,000$$$. In hacks you can only use one test case, so $$$T = 1$$$.

Print $$$T$$$ lines, in $$$i$$$-th of them answer to the $$$i$$$-th test case. If there is no such permutations $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$, that Vasya could write, print the only number $$$-1$$$. In the other case print $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$, separated by spaces ($$$1 \leq p_i \leq n$$$). All defined values of $$$next_i$$$ which are not equal to $$$-1$$$ should be computed correctly $$$p_1, p_2, \ldots, p_n$$$ using defenition given in the statement of the problem. If there exists more than one solution you can find any of them.

NoteIn the first test case for permutation $$$p = [1, 2, 3]$$$ Vasya should write $$$next = [2, 3, 4]$$$, because each number in permutation is less than next. It's easy to see, that it is the only satisfying permutation.In the third test case, any permutation can be the answer because all numbers $$$next_i$$$ are lost.In the fourth test case, there is no satisfying permutation, so the answer is $$$-1$$$.

package main

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

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

	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		pp := make([][]int, n+2)
		pos := make([]int, n)
		for i := range pos {
			Fscan(in, &pos[i])
			if pos[i] == -1 {
				pos[i] = i + 2
			}
			pp[pos[i]] = append(pp[pos[i]], i)
		}
		ans := make([]int, n)
		v := 1
		for _, ps := range pp {
			for i := len(ps) - 1; i >= 0; i-- {
				ans[ps[i]] = v
				v++
			}
		}
		type pair struct{ v, i int }
		s := []pair{{1e9, n}}
		for i := n - 1; i >= 0; i-- {
			v := ans[i]
			for {
				if top := s[len(s)-1]; top.v > v {
					if top.i+1 != pos[i] {
						Fprintln(out, -1)
						continue o
					}
					break
				}
				s = s[:len(s)-1]
			}
			s = append(s, pair{v, i})
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		pos := make([]int, n)
		for i := range pos {
			Fscan(in, &pos[i])
		}
		p := n + 1
		for i := len(pos) - 1; i >= 0; i-- {
			if v := pos[i]; v > 0 {
				p = v
			} else {
				pos[i] = p
			}
		}
		ans := make([]int, n)
		for i, v := 0, 1; i < n; {
			st := i
			for i++; i < n && pos[i] == pos[st]; i++ {
			}
			for j := i - 1; j >= st; j-- {
				ans[j] = v
				v++
			}
		}
		type pair struct{ v, i int }
		s := []pair{{1e9, n}}
		for i := n - 1; i >= 0; i-- {
			v := ans[i]
			for {
				if top := s[len(s)-1]; top.v > v {
					if top.i+1 != pos[i] {
						Fprintln(out, -1)
						continue o
					}
					break
				}
				s = s[:len(s)-1]
			}
			s = append(s, pair{v, i})
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

	var T, n int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		pos := make([]int, n)
		for i := range pos {
			Fscan(in, &pos[i])
		}
		p := n + 1
		pp := make([][]int, n+2)
		for i := len(pos) - 1; i >= 0; i-- {
			if v := pos[i]; v > 0 {
				p = v
			} else {
				pos[i] = p
			}
			pp[pos[i]] = append(pp[pos[i]], i)
		}
		ans := make([]int, n)
		v := 1
		for _, ps := range pp {
			for _, p := range ps {
				ans[p] = v
				v++
			}
		}
		type pair struct{ v, i int }
		s := []pair{{1e9, n}}
		for i := n - 1; i >= 0; i-- {
			v := ans[i]
			for {
				if top := s[len(s)-1]; top.v > v {
					if top.i+1 != pos[i] {
						Fprintln(out, -1)
						continue o
					}
					break
				}
				s = s[:len(s)-1]
			}
			s = append(s, pair{v, i})
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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


Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.

Print the maximum number of people that may come to Famil Door's party.

NoteIn the first sample, friends 3 and 4 can come on any day in range [117, 128].In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	male := make([]int, 366)
	female := make([]int, 366)
	for i := 0; i < n; i++ {
		var g string
		var a, b int
		fmt.Scan(&g, &a, &b)
		s := male
		if g == "F" {
			s = female
		}
		for j := a - 1; j < b; j++ {
			s[j]++
		}
	}
	ans := 0
	for i := range male {
		min := male[i]
		if female[i] < min {
			min = female[i]
		}
		if ans < min {
			ans = min
		}
	}
	fmt.Println(ans * 2)
}

package main

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

func main() {
	const days_of_year int = 366

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

	days := make([][2]int, days_of_year+1)

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	for i := 0; i < n; i++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			}
			return
		} else {
			s = re.ReplaceAllString(s, "")

			idx := 0 // 0 for Female
			if s[0] == 'M' {
				idx = 1
			}

			ss := strings.Split(s, " ")
			if len(ss) != 3 {
				return
			}

			start, err := strconv.Atoi(ss[1])
			if err != nil {
				return
			}
			end, err := strconv.Atoi(ss[2])
			if err != nil {
				return
			}

			for j := start; j <= end; j++ {
				days[j][idx] += 1
			}
		}
	}

	max_half := 0
	for i := 1; i <= days_of_year; i++ {
		m := min(days[i][0], days[i][1])
		if m > max_half {
			max_half = m
		}
	}

	fmt.Println(max_half * 2)
}

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

package main

import "fmt"

func main() {
  var n int

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

  males := [367]int{}
  females := [367]int{}

  var a, b int
  var g string

  for i := 0; i < n; i++ {
    fmt.Scanf("%s %d %d\n", &g, &a, &b)
    if g == "F" {
      for j := a; j <= b; j++ {
        females[j]++
      }
    } else {
      for j := a; j <= b; j++ {
        males[j]++
      }
    }
  }

  var maxVal int = 0
  for i := 0; i < 367; i++ {
    localMin := 5001
    if males[i] < females[i] {
      localMin = males[i]
    } else {
      localMin = females[i]
    }

    if maxVal < localMin {
      maxVal = localMin
    }
  }

  fmt.Println(maxVal * 2)
}

package main

import "fmt"

var n int

type Node struct {
	sex byte
	a, b int
}
var l []Node

func gao(d int) int {
	f := 0
	m := 0
	for _, v := range l {
		if v.a <= d && d <= v.b {
			if v.sex == 'F' { f++ }
			if v.sex == 'M' { m++ }
		}
	}
	if f < m { return f }
	return m
}

func main() {
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var node Node
		fmt.Scanf("%c%d%d\n", &node.sex, &node.a, &node.b)
		l = append(l, node)
	}

	ans := 0
	for d := 1; d <= 366; d++ {
		tmp := gao(d) * 2
		if tmp > ans {
			ans = tmp
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	var gender byte
	var s, e int
	count_m := make([]int, 367, 367)
	count_f := make([]int, 367, 367)

	for i := 0; i < n; i++ {
		fmt.Scanf("%c %d %d\n", &gender, &s, &e)
		if gender == 'M' {
			for j := s; j <= e; j++ {
				count_m[j]++
			}
		} else {
			for j := s; j <= e; j++ {
				count_f[j]++
			}
		}
	}

	ans := 0
	for i := 1; i < 367; i++ {
		m := min(count_m[i], count_f[i])
		if m+m > ans {
			ans = m + m
		}
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var cf, cm [366]int
	for i := 0; i < n; i++ {
		var g string
		var a, b int
		fmt.Scanf("%s%d%d\n", &g, &a, &b)
		for j := a - 1; j < b; j++ {
			if g[0] == 'M' {
				cm[j]++
			} else {
				cf[j]++
			}
		}
	}
	ans := 0
	for i := 0; i < len(cf); i++ {
		if 2*min(cf[i], cm[i]) > ans {
			ans = 2 * min(cf[i], cm[i])
		}
	}
	fmt.Println(ans)
}

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

package main

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

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

	cake := make([][]byte, n)
	for i := 0; i < n; i++ {
		cake[i] = make([]byte, n)
	}

	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < n; i++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			for j := 0; j < n; j++ {
				if s[j] == 'C' {
					cake[i][j] = 1
				}
			}
		}
	}

	var pairs int = 0
	for i := 0; i < n; i++ {
		cnt := 0
		for j := 0; j < n; j++ {
			cnt += int(cake[i][j])
		}
		if cnt > 1 {
			pairs += (cnt * (cnt - 1) / 2)
		}
	}
	for i := 0; i < n; i++ {
		cnt := 0
		for j := 0; j < n; j++ {
			cnt += int(cake[j][i])
		}
		if cnt > 1 {
			pairs += (cnt * (cnt - 1) / 2)
		}
	}

	fmt.Println(pairs)
}

package main

import "fmt"

func main() {
  var n int

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

  males := [367]int{}
  females := [367]int{}

  var a, b int
  var g string

  for i := 0; i < n; i++ {
    fmt.Scanf("%s %d %d\n", &g, &a, &b)
    if g == "F" {
      for j := a; j <= b; j++ {
        females[j]++
      }
    } else {
      for j := a; j <= b; j++ {
        males[j]++
      }
    }
  }

  var maxVal int = 0
  for i := 0; i < 367; i++ {
    localMax := -1
    if males[i] > females[i] {
      localMax = males[i]
    } else {
      localMax = females[i]
    }

    if localMax > maxVal {
      maxVal = localMax
    }
  }

  fmt.Println(maxVal + 1)
}

package main

import "fmt"

func main() {
  var n int

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

  males := [367]int{}
  females := [367]int{}

  var a, b int
  var g string

  for i := 0; i < n; i++ {
    fmt.Scanf("%s %d %d\n", &g, &a, &b)
    if g == "F" {
      for j := a; j <= b; j++ {
        females[j]++
      }
    } else {
      for j := a; j <= b; j++ {
        males[j]++
      }
    }
  }

  var maxVal int = 0
  for i := 0; i < 367; i++ {
    localMax := -1
    if males[i] > females[i] {
      localMax = males[i]
    } else {
      localMax = females[i]
    }

    if localMax > maxVal {
      maxVal = localMax
    }
  }

  fmt.Println(maxVal * 2)
}

package main

import "fmt"

func main() {
  var n int

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

  males := [367]int{}
  females := [367]int{}

  var a, b int
  var g string

  for i := 0; i < n; i++ {
    fmt.Scanf("%s %d %d\n", &g, &a, &b)
    if g == "F" {
      for j := a; j <= b; j++ {
        females[j]++
      }
    } else {
      for j := a; j <= b; j++ {
        males[j]++
      }
    }
  }

  var maxVal int = 0
  for i := 0; i < 367; i++ {
    if males[i] != females[i] {
      continue
    }

    if maxVal < males[i] {
      maxVal = males[i]
    }
  }

  fmt.Println(maxVal * 2)
}

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	var gender byte
	var s, e int
	count_m := make([]int, 367, 367)
	count_f := make([]int, 367, 367)

	for i := 0; i < n; i++ {
		fmt.Scanf("%c %d %d", &gender, &s, &e)
		if gender == 'M' {
			for j := s; j <= e; j++ {
				count_m[j]++
			}
		} else {
			for j := s; j <= e; j++ {
				count_f[j]++
			}
		}
	}

	ans := 0
	for i := 1; i < 367; i++ {
		m := min(count_m[i], count_f[i])
		if m+m > ans {
			ans = m + m
		}
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var cf, cm [366]int
	for i := 0; i < n; i++ {
		var g string
		var a, b int
		fmt.Scanf("%s%d%d\n", &g, &a, &b)
		for j := a - 1; j < b; j++ {
			if g[0] == 'M' {
				cm[j]++
			} else {
				cf[j]++
			}
		}
	}
	ans := 0
	for i := 0; i < len(cf); i++ {
		if cf[i] == cm[i] && 2*cf[i] > ans {
			ans = 2 * cf[i]
		}
	}
	fmt.Println(ans)
}