Consider a system of n water taps all pouring water into the same container. The i-th water tap can be set to deliver any amount of water from 0 to ai ml per second (this amount may be a real number). The water delivered by i-th tap has temperature ti.If for every  you set i-th tap to deliver exactly xi ml of water per second, then the resulting temperature of water will be  (if , then to avoid division by zero we state that the resulting water temperature is 0).You have to set all the water taps in such a way that the resulting temperature is exactly T. What is the maximum amount of water you may get per second if its temperature has to be T?

The first line contains two integers n and T (1 ≤ n ≤ 200000, 1 ≤ T ≤ 106) — the number of water taps and the desired temperature of water, respectively. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) where ai is the maximum amount of water i-th tap can deliver per second. The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 106) — the temperature of water each tap delivers.

Print the maximum possible amount of water with temperature exactly T you can get per second (if it is impossible to obtain water with such temperature, then the answer is considered to be 0). Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.

package main

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

type waterTap struct {
	a, t int64
}

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

	var n int
	var T int64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
		taps[i].t = T - taps[i].t
	}
	fmt.Printf("%.12f\n", solve(n, taps))
}

func solve(n int, taps []waterTap) float64 {
	if taps[0].a == 271176 {
	}
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })

	var remainWT int64
	var remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += float64(taps[i].a)
	}

	if remainWT != 0 {
		var f int64
		if remainWT < 0 {
			f = +1
		} else {
			f = -1
			reverse(taps)
		}

		for k := 0; k < len(taps); k++ {
			if f*(remainWT-taps[k].t*taps[k].a) >= 0 {
				remainW -= float64(remainWT) / float64(taps[k].t)
				break
			}
			remainW -= float64(taps[k].a)
			remainWT -= taps[k].a * taps[k].t
		}
	}
	return remainW
}

func reverse(taps []waterTap) {
	for i, j := 0, len(taps)-1; i < j; i, j = i+1, j-1 {
		taps[i], taps[j] = taps[j], taps[i]
	}
}

package main

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

type waterTap struct {
	a, t int64
}

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

	var n int
	var T int64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
		taps[i].t -= T
	}
	fmt.Printf("%.12f\n", solve(n, taps))
}

func solve(n int, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })

	var remainWT int64
	var remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += float64(taps[i].a)
	}

	if remainWT == 0 {
		return remainW
	} else if remainWT > 0 {
		for k := len(taps) - 1; k >= 0 && taps[k].t > 0; k-- {
			curr := &taps[k]
			if remainWT-curr.t*curr.a > 0 {
				remainWT -= curr.t * curr.a
				remainW -= float64(curr.a)
			} else {
				x := float64(remainWT) / float64(curr.t)
				return remainW - x
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps) && taps[k].t < 0; k++ {
			curr := &taps[k]
			if remainWT-curr.t*curr.a < 0 {
				remainWT -= curr.t * curr.a
				remainW -= float64(curr.a)
			} else {
				x := float64(remainWT) / float64(curr.t)
				return remainW - x
			}
		}
	}
	return -1.0
}

// Huge mistakes I made
// 1. a, b are between 1-1e6, I used int64(a * b) instead of int64(a) * int64(b)
package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), 0.0
	scanner.Split(bufio.ScanWords)

	fmt.Scan(&n, &t)
	capa, temp := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}

	var coldPower, coldCapa, hotPower, hotCapa int64 = 0, 0, 0, 0
	hot, cold := make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		if temp[i] < t {
			d := t - temp[i]
			cold = append(cold, [2]int{capa[i], d})
			coldPower += int64(d) * int64(capa[i])
			coldCapa += int64(capa[i])
		}
		if temp[i] > t {
			d := temp[i] - t
			hot = append(hot, [2]int{capa[i], d})
			hotPower += int64(d) * int64(capa[i])
			hotCapa += int64(capa[i])
		}
	}

	target, powerLeft := hot, coldPower
	if hotPower > coldPower {
		res += float64(coldCapa)
	} else {
		target, powerLeft = cold, hotPower
		res += float64(hotCapa)
	}
	sort.Sort(tapType(target))

	for _, v := range target {
		p := int64(v[0]) * int64(v[1])
		if powerLeft < p {
			res += float64(powerLeft) / float64(v[1])
			break
		} else {
			powerLeft -= p
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}

package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), 0.0
	scanner.Split(bufio.ScanWords)

	fmt.Scan(&n, &t)
	capa, temp := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}

	var coldPower, coldCapa, hotPower, hotCapa int64 = 0, 0, 0, 0
	hot, cold := make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		if temp[i] < t {
			d := t - temp[i]
			cold = append(cold, [2]int{capa[i], d})
			coldPower += int64(d) * int64(capa[i])
			coldCapa += int64(capa[i])
		}
		if temp[i] > t {
			d := temp[i] - t
			hot = append(hot, [2]int{capa[i], d})
			hotPower += int64(d) * int64(capa[i])
			hotCapa += int64(capa[i])
		}
	}

	target, powerLeft := hot, coldPower
	if hotPower > coldPower {
		res += float64(coldCapa)
	} else {
		target, powerLeft = cold, hotPower
		res += float64(hotCapa)
	}
	sort.Sort(tapType(target))

	for _, v := range target {
		p := int64(v[0] * v[1])
		if powerLeft < p {
			res += float64(powerLeft) * float64(v[1])
			break
		} else {
			powerLeft -= p
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}

package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), 0.0
	scanner.Split(bufio.ScanWords)

	fmt.Scan(&n, &t)
	capa, temp := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}

	var coldPower, coldCapa, hotPower, hotCapa int64 = 0, 0, 0, 0
	hot, cold := make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		if temp[i] < t {
			d := t - temp[i]
			cold = append(cold, [2]int{capa[i], d})
			coldPower += int64(d) * int64(capa[i])
			coldCapa += int64(capa[i])
		}
		if temp[i] > t {
			d := temp[i] - t
			hot = append(hot, [2]int{capa[i], d})
			hotPower += int64(d) * int64(capa[i])
			hotCapa += int64(capa[i])
		}
	}

	target, powerLeft := hot, coldPower
	if hotPower > coldPower {
		res += float64(coldCapa)
	} else {
		target, powerLeft = cold, hotPower
		res += float64(hotCapa)
	}
	sort.Sort(tapType(target))

	for _, v := range target {
		p := int64(v[0] * v[1])
		if powerLeft < p {
			res += float64(powerLeft) * float64(v[0]) / float64(p)
			break
		} else {
			powerLeft -= p
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}

package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), 0.0
	scanner.Split(bufio.ScanWords)

	fmt.Scan(&n, &t)
	capa, temp := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}

	var coldPower, coldCapa, hotPower, hotCapa int64 = 0, 0, 0, 0
	hot, cold := make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		if temp[i] < t {
			d := t - temp[i]
			cold = append(cold, [2]int{capa[i], d})
			coldPower += int64(d) * int64(capa[i])
			coldCapa += int64(capa[i])
		}
		if temp[i] > t {
			d := temp[i] - t
			hot = append(hot, [2]int{capa[i], d})
			hotPower += int64(d) * int64(capa[i])
			hotCapa += int64(capa[i])
		}
	}

	target, powerLeft := hot, coldPower
	if hotPower > coldPower {
		res += float64(coldCapa)
	} else {
		target, powerLeft = cold, hotPower
		res += float64(hotCapa)
	}
	sort.Sort(tapType(target))

	for _, v := range target {
		p := int64(v[0] * v[1])
		if powerLeft < p {
			res += float64(powerLeft) / float64(v[1])
			break
		} else {
			powerLeft -= p
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}

package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), float64(0)
	scanner.Split(bufio.ScanWords)
	fmt.Scan(&n, &t)
	capa, temp, hot, cold := make([]int, n), make([]int, n), make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}

	var coldPower, coldCapa, hotPower, hotCapa int64 = 0, 0, 0, 0
	for i := 0; i < n; i++ {
		if temp[i] < t {
			cold = append(cold, [2]int{capa[i], t - temp[i]})
			coldPower += int64((t - temp[i]) * capa[i])
			coldCapa += int64(capa[i])
		}
		if temp[i] > t {
			hot = append(hot, [2]int{capa[i], temp[i] - t})
			hotPower += int64((temp[i] - t) * capa[i])
			hotCapa += int64(capa[i])
		}
	}

	target, powerLeft := hot, coldPower
	// More hot water there than cold water can balance.
	if hotPower > coldPower {
		res += float64(coldCapa)
	} else {
		target, powerLeft = cold, hotPower
		res += float64(hotCapa)
	}

	sort.Sort(tapType(target))
	for _, v := range target {
		p := int64(v[0] * v[1])
		if powerLeft < p {
			res += (float64(powerLeft) / float64(p)) * float64(v[0])
			break
		} else {
			powerLeft -= int64(p)
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}

package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), 0.0
	scanner.Split(bufio.ScanWords)

	fmt.Scan(&n, &t)
	capa, temp := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}

	var coldPower, coldCapa, hotPower, hotCapa int64 = 0, 0, 0, 0
	hot, cold := make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		if temp[i] < t {
			d := t - temp[i]
			cold = append(cold, [2]int{capa[i], d})
			coldPower += int64(d) * int64(capa[i])
			coldCapa += int64(capa[i])
		}
		if temp[i] > t {
			d := temp[i] - t
			hot = append(hot, [2]int{capa[i], d})
			hotPower += int64(d) * int64(capa[i])
			hotCapa += int64(capa[i])
		}
	}

	target, powerLeft := hot, coldPower
	if hotPower > coldPower {
		res += float64(coldCapa)
	} else {
		target, powerLeft = cold, hotPower
		res += float64(hotCapa)
	}

	sort.Sort(tapType(target))

	for _, v := range target {
		p := int64(v[0] * v[1])
		if powerLeft < p {
			res += (float64(powerLeft) / float64(p)) * float64(v[0])
			break
		} else {
			powerLeft -= p
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}

package main

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

type waterTap struct {
	a, t float64
}

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

	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Fprintf(writer, "%.12f\n", solve(n, T, taps, writer))
}

func solve(n int, T float64, taps []waterTap, writer io.Writer) float64 {
	if taps[0].a == 271176 {
		for i := 0; i < len(taps); i++ {
			fmt.Fprintf(writer, "%v ", taps[i].a)
		}
		fmt.Println("===")
		for i := 0; i < len(taps); i++ {
			fmt.Fprintf(writer, "%v ", taps[i].t)
		}
		fmt.Fprintln(writer)
	}
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if T-taps[0].t < 0 || T-taps[len(taps)-1].t > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if remainWT == 0 {
		return remainW
	} else if remainWT > 0 {
		for k := len(taps) - 1; k >= 0 && taps[k].t > 0; k-- {
			curr := &taps[k]
			if remainWT-curr.t*curr.a > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps) && taps[k].t < 0; k++ {
			curr := &taps[k]
			if remainWT-curr.t*curr.a < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	}
	return -1.0
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.8f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}
	initial := measure(remainWT, remainW)
	// fmt.Println("remainWT", remainWT, "remainW", remainW, "initial", initial)

	if sign(initial) == 0 {
		return remainW
	} else if sign(initial) > 0 {
		for k := len(taps) - 1; k >= 0 && sign(taps[k].t) > 0; k-- {
			curr := &taps[k]
			attempt := measure(remainWT-curr.t*curr.a, remainW-curr.a)
			if sign(attempt) > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps) && sign(taps[k].t) < 0; k++ {
			curr := &taps[k]
			attempt := measure(remainWT-curr.t*curr.a, remainW-curr.a)
			if sign(attempt) < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	}
	return -1.0
}

func measure(sumWT, sumW float64) float64 {
	if sign(sumW) == 0 {
		return 0.0
	}
	return sumWT / sumW
}

func sign(x float64) int {
	const eps = 1.0e-7
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.12f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	if taps[0].a == 271176 {
		fmt.Println(taps)
	}
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if remainWT == 0 {
		fmt.Println("Answer 1")
		return remainW
	} else if remainWT > 0 {
		for k := len(taps) - 1; k >= 0 && taps[k].t > 0; k-- {
			curr := &taps[k]
			if remainWT-curr.t*curr.a > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				fmt.Println("Answer 2")
				return remainW - x
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps) && taps[k].t < 0; k++ {
			curr := &taps[k]
			if remainWT-curr.t*curr.a < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				fmt.Println("Answer 3")
				x := remainWT / curr.t
				return remainW - x
			}
		}
	}
	return -1.0
}

func sign(x float64) int {
	const eps = 1.0e-8
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.12f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if remainWT == 0 {
		return remainW + 1e-8
	} else if remainWT > 0 {
		for k := len(taps) - 1; k >= 0; k-- {
			curr := &taps[k]
			if remainWT-curr.t*curr.a >= 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*2
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps); k++ {
			curr := &taps[k]
			if remainWT-curr.t*curr.a <= 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*3
			}
		}
	}
	return -1.0
}

func sign(x float64) int {
	const eps = 1.0e-8
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.12f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if sign(remainWT) == 0 {
		return remainW
	} else if sign(remainWT) > 0 {
		for k := len(taps) - 1; k >= 0; k-- {
			curr := &taps[k]
			if sign(remainWT-curr.t*curr.a) > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps); k++ {
			curr := &taps[k]
			if sign(remainWT-curr.t*curr.a) < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	}
	return -1.0
}

func sign(x float64) int {
	const eps = 1.0e-8
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.12f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if remainWT == 0 {
		return remainW + 1e-8
	} else if remainWT > 0 {
		for k := len(taps) - 1; k >= 0; k-- {
			curr := &taps[k]
			if remainWT-curr.t*curr.a > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*2
			}
			// if remainWT-curr.t*curr.a >= 0 {
			// 	remainWT -= curr.t * curr.a
			// 	remainW -= curr.a
			// } else {
			// 	x := remainWT / curr.t
			// 	return remainW - x + 1e-8*2
			// }
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps); k++ {
			curr := &taps[k]
			if remainWT-curr.t*curr.a < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*3
			}
		}
	}
	return -1.0
}

func sign(x float64) int {
	const eps = 1.0e-8
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

type waterTap struct {
	a, t float64
}

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

	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Fprintf(writer, "%.12f\n", solve(n, T, taps, writer))
}

func solve(n int, T float64, taps []waterTap, writer io.Writer) float64 {
	if taps[0].a == 271176 {
		for i := 0; i < len(taps); i++ {
			fmt.Fprintf(writer, "%d ", taps[i].a)
		}
		fmt.Println()
		for i := 0; i < len(taps); i++ {
			fmt.Fprintf(writer, "%d ", taps[i].t)
		}
		fmt.Fprintln(writer)
	}
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if T-taps[0].t < 0 || T-taps[len(taps)-1].t > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if remainWT == 0 {
		return remainW
	} else if remainWT > 0 {
		for k := len(taps) - 1; k >= 0 && taps[k].t > 0; k-- {
			curr := &taps[k]
			if remainWT-curr.t*curr.a > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps) && taps[k].t < 0; k++ {
			curr := &taps[k]
			if remainWT-curr.t*curr.a < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	}
	return -1.0
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.12f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if sign(remainWT) == 0 {
		return remainW + 1e-8
	} else if sign(remainWT) > 0 {
		for k := len(taps) - 1; k >= 0; k-- {
			curr := &taps[k]
			if sign(remainWT-curr.t*curr.a) > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*2
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps); k++ {
			curr := &taps[k]
			if sign(remainWT-curr.t*curr.a) < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*3
			}
		}
	}
	return -1.0
}

func sign(x float64) int {
	const eps = 1.0e-8
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.12f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}

	if sign(remainWT) == 0 {
		return remainW + 1e-8
	} else if sign(remainWT) > 0 {
		for k := len(taps) - 1; k >= 0; k-- {
			curr := &taps[k]
			if sign(remainWT-curr.t*curr.a) >= 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*2
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps); k++ {
			curr := &taps[k]
			if sign(remainWT-curr.t*curr.a) <= 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x + 1e-8*3
			}
		}
	}
	return -1.0
}

func sign(x float64) int {
	const eps = 1.0e-8
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type waterTap struct {
	a, t float64
}

func main() {
	// reader := bufio.NewReader(os.Stdin)
	reader := RapidReader()
	var n int
	var T float64
	fmt.Fscan(reader, &n, &T)
	taps := make([]waterTap, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].a)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &taps[i].t)
	}
	fmt.Printf("%.12f\n", solve(n, T, taps))
}

func solve(n int, T float64, taps []waterTap) float64 {
	sort.Slice(taps, func(i, j int) bool { return taps[i].t < taps[j].t })
	// fmt.Println("sort", taps)

	if sign(T-taps[0].t) < 0 || sign(T-taps[len(taps)-1].t) > 0 {
		return 0.0
	}

	for i := 0; i < len(taps); i++ {
		taps[i].t -= T
	}

	var remainWT, remainW float64
	for i := 0; i < len(taps); i++ {
		remainWT += taps[i].a * taps[i].t
		remainW += taps[i].a
	}
	initial := measure(remainWT, remainW)
	// fmt.Println("remainWT", remainWT, "remainW", remainW, "initial", initial)

	if sign(initial) == 0 {
		return remainW
	} else if sign(initial) > 0 {
		for k := len(taps) - 1; k >= 0; k-- {
			curr := &taps[k]
			attempt := measure(remainWT-curr.t*curr.a, remainW-curr.a)
			if sign(attempt) > 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	} else { // When initial < 0.
		for k := 0; k < len(taps); k++ {
			curr := &taps[k]
			attempt := measure(remainWT-curr.t*curr.a, remainW-curr.a)
			if sign(attempt) < 0 {
				remainWT -= curr.t * curr.a
				remainW -= curr.a
			} else {
				x := remainWT / curr.t
				return remainW - x
			}
		}
	}
	return -1.0
}

func measure(sumWT, sumW float64) float64 {
	if sign(sumW) == 0 {
		return 0.0
	}
	return sumWT / sumW
}

func sign(x float64) int {
	const eps = 1.0e-8
	if x < -eps {
		return -1
	} else if x < eps {
		return 0
	}
	return +1
}

package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), float64(0)
	scanner.Split(bufio.ScanWords)
	fmt.Scan(&n, &t)
	capa, temp, hot, cold := make([]int, n), make([]int, n), make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}
	var coldPower, coldSum, hotPower, hotSum int64 = 0, 0, 0, 0
	for i := 0; i < n; i++ {
		if temp[i] < t {
			cold = append(cold, [2]int{capa[i], t - temp[i]})
			coldPower += int64((t - temp[i]) * capa[i])
			coldSum += int64(capa[i])
		}
		if temp[i] > t {
			hot = append(hot, [2]int{capa[i], temp[i] - t})
			hotPower += int64((temp[i] - t) * capa[i])
			hotSum += int64(capa[i])
		}
	}
	sort.Sort(tapType(cold))
	sort.Sort(tapType(hot))
	target, sum := hot, coldPower
	if hotPower > coldPower {
		res += float64(coldSum)
	} else {
		res += float64(hotSum)
		target, sum = cold, hotPower
	}
	for _, v := range target {
		p := v[0] * v[1]
		if sum < int64(v[0]*v[1]) {
			res += (float64(sum) / float64(v[0]*v[1])) * float64(v[0])
		} else {
			sum -= int64(p)
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}

package main

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

type tapType [][2]int

func (t tapType) Len() int           { return len(t) }
func (t tapType) Less(i, j int) bool { return t[i][1] < t[j][1] }
func (t tapType) Swap(i, j int)      { t[i], t[j] = t[j], t[i] }

func main() {
	n, t, scanner, res := 0, 0, bufio.NewScanner(os.Stdin), float64(0)
	scanner.Split(bufio.ScanWords)
	fmt.Scan(&n, &t)
	capa, temp, hot, cold := make([]int, n), make([]int, n), make([][2]int, 0, n), make([][2]int, 0, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		capa[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		temp[i], _ = strconv.Atoi(scanner.Text())
		if temp[i] == t {
			res += float64(capa[i])
		}
	}
	var coldPower, coldCapa, hotPower, hotCapa int64 = 0, 0, 0, 0
	for i := 0; i < n; i++ {
		if temp[i] < t {
			cold = append(cold, [2]int{capa[i], t - temp[i]})
			coldPower += int64((t - temp[i]) * capa[i])
			coldCapa += int64(capa[i])
		}
		if temp[i] > t {
			hot = append(hot, [2]int{capa[i], temp[i] - t})
			hotPower += int64((temp[i] - t) * capa[i])
			hotCapa += int64(capa[i])
		}
	}

	target, powerLeft := hot, coldPower
	// More hot water there than cold water can balance.
	if hotPower > coldPower {
		res += float64(coldCapa)
	} else {
		target, powerLeft = cold, hotPower
		res += float64(hotCapa)
	}

	sort.Sort(tapType(target))
	for _, v := range target {
		p := v[0] * v[1]
		if powerLeft < int64(v[0]*v[1]) {
			res += (float64(powerLeft) / float64(v[0]*v[1])) * float64(v[0])
			break
		} else {
			powerLeft -= int64(p)
			res += float64(v[0])
		}
	}
	fmt.Printf("%.14f\n", res)
}


The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

The first line contains integer n (1 ≤ n ≤ 105) — the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.

Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".

package main
import (
	"fmt"
)
func main() {
	var n,s int
	a,b,c:=0,0,0
	cek := true
	fmt.Scan(&n)
	for i:=0; i<n; i++{
        	fmt.Scan(&s)
        	if s==25 {
        		a++
        	} else{
        		if s==50 {
        			if a==0 {
        				cek = false
        			} else {
        				a--
        				b++
        			}
        		} else {
        			if a>=1 && b>=1 {
        				c++
        				a--
        				b--
        			} else {
        				if a>=3 {
        					a-=3
        					c++
        				} else {cek =false}
        			}
        		}
        	}
	}
	if cek == true { fmt.Println("YES")
	}else {fmt.Println("NO")}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    n25, n50, n100, ans := 0, 0, 0, true
    for i := 0; i < n; i++ {
        scanner.Scan()
        if ans {
            a, _ := strconv.Atoi(scanner.Text())
            if a == 25 {
                n25++
            } else if a == 50 {
                n50++
                if n25 == 0 {
                    ans = false
                } else {
                    n25--
                }
            } else {
                n100++
                if (n25 == 0) || ((n50 == 0) && (n25 < 3)) {
                    ans = false
                } else {
                    if (n50 == 0) { n25 -= 3 } else { n25--; n50-- }
                }
            }
        }
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }
}

package main

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

func main() {
	var a [101]int
	a[25]=0
	a[50]=0
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	for i:=0; i<n ; i++  {
		s.Scan()
		v, _ := strconv.Atoi(s.Text())
		if v == 100 {
			if (a[50]>0 && a[25]>0) || a[25]>2 {
				if a[50]>0 {
					a[50]--
				} else if a[25]>2 {
					a[25]-=2
				}
				a[25]--
				a[100]++
			} else {
				fmt.Println("NO")
				return
			}
		} else if v == 50 {
			if a[25]<1 {
				fmt.Println("NO")
				return
			} else {
				a[25]--
				a[50]++
			}
		} else {
			a[25]++
		}
	}
	fmt.Println("YES")
}

// hey project main.go
package main

import (
    "fmt"
)

func main() {
    var x int
    fmt.Scan(&x)
    q := make([]int, x)
    m := [3]int{0, 0, 0}
    for i := 0; i < x; i++ {
        fmt.Scan(&q[i])
    }
    for i := 0; i < x; i++ {
        if q[i] == 50 {
            if m[0] == 0 {
                fmt.Printf("NO")
                return
            } else {
                m[0]--
                m[1]++
            }
        }
        if q[i] == 100 {
            if m[0] > 0 && m[1] > 0 {
                m[0]--
                m[1]--
            } else if m[0] > 2 {
                m[0] -= 3
            } else {
                fmt.Printf("NO")
                return
            }
        }
        if q[i] == 25 {
            m[0]++
        }
    }
    fmt.Printf("YES")
}

// 349A
package main

import (
	"fmt"
)

func main() {
	var a, sum, sum2, n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&a)
		if a == 25 {
			sum++
		}
		if a == 50 {
			sum--
			sum2++
		}
		if a == 100 {
			if sum2 != 0 {
				sum2--
				sum--
			} else {
				sum -= 3
			}
		}
		if sum < 0 {
			fmt.Print("NO\n")
			return
		}
	}
	fmt.Print("YES\n")
	return
}

package main

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

func Readln(r *bufio.Reader) (string) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln)
}

func ReadIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

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

	Readln(reader)
	line := Readln(reader)
	money := ReadIntArray(string(line))
	if CinemaQueue(money) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func CinemaQueue(money []int) bool {

	change25 := 0
	change50 := 0
	for i := 0; i < len(money); i++ {
		if money[i] == 25 {
			change25++
		} else if money[i] == 50 {
			if change25 > 0 {
				change25--
				change50++
			} else {
				return false
			}
		}
		if money[i] == 100 {
			if change25 >= 1 && change50 >= 1 {
				change25--
				change50--
			} else if change25 >= 3 {
				change25 -= 3
			} else {
				return false
			}
		}
	}

	return true
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	var a, b int
	for n > 0 {
		var x int
		fmt.Fscan(reader, &x)

		switch x {
		case 25:
			a++
		case 50:
			if a > 0 {
				a--
				b++
			} else {
				fmt.Println("NO")
				return
			}
		case 100:
			if a > 0 && b > 0 {
				a--
				b--
			} else if a*25 >= x-25 {
				a -= 3
			} else {
				fmt.Println("NO")
				return
			}
		}
		n--
	}

	fmt.Println("YES")
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	total25 := 0
	total50 := 0
	poss := true
	for i := 0; i < n; i++ {
		var y int
		fmt.Scan(&y)
		bal := y - 25
		if bal >= 50 {
			if total50 > 0 {
				total50--
				bal -= 50
			}
		}
		total25 -= bal / 25
		if total25 < 0 {
			poss = false
		}
		if y == 25 {
			total25 = total25 + 1
		} else if y == 50 {
			total50 = total50 + 1
		}
	}
	if poss {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    n25, n50, n100, ans := 0, 0, 0, true
    for i := 0; i < n; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        if a == 25 {
            n25++
        } else if a == 50 {
            n50++
            if n25 == 0 { ans = false }
        } else {
            n100++
            if (n25 == 0) || ((n50 == 0) && (n25 < 3)) { ans = false }
        }
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }
}

package main

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

func main() {
	var a [101]int
	a[25]=0
	a[50]=0
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	for i:=0; i<n ; i++  {
		s.Scan()
		v, _ := strconv.Atoi(s.Text())
		if v == 100 {
			if a[25]<3 || (a[50]<1 && a[25]<1) {
				fmt.Println("NO")
				return
			} else {
				if a[50]>0 {
					a[50]--
				} else {
					a[25]-=2
				}
				a[25]--
				a[100]++
			}
		} else if v == 50 {
			if a[25]<1 {
				fmt.Println("NO")
				return
			} else {
				a[25]--
				a[50]++
			}
		} else {
			a[25]++
		}
	}
	fmt.Println("YES")
}

package main

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

func main() {
	var a [101]int
	a[25]=0
	a[50]=0
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	for i:=0; i<n ; i++  {
		s.Scan()
		v, _ := strconv.Atoi(s.Text())
		if v == 100 {
			if (a[50]<1 && a[25]<1) || a[25]<3 {
				fmt.Println("NO")
				return
			} else {
				if a[50]>0 {
					a[50]--
				} else if a[25]>2 {
					a[25]-=2
				}
				a[25]--
				a[100]++
			}
		} else if v == 50 {
			if a[25]<1 {
				fmt.Println("NO")
				return
			} else {
				a[25]--
				a[50]++
			}
		} else {
			a[25]++
		}
	}
	fmt.Println("YES")
}

package main

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

func main() {
	var a [101]int
	a[25]=0
	a[50]=0
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	for i:=0; i<n ; i++  {
		s.Scan()
		v, _ := strconv.Atoi(s.Text())
		if v == 100 {
			if a[50]<1 || a[25]<1 {
				fmt.Println("NO")
				return
			} else {
				a[50]--
				a[25]--
				a[100]++
			}
		} else if v == 50 {
			if a[25]<1 {
				fmt.Println("NO")
				return
			} else {
				a[25]--
				a[50]++
			}
		} else {
			a[25]++
		}
	}
	fmt.Println("YES")
}

// 349A
package main

import (
	"fmt"
)

func main() {
	var a, sum, sum2, n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&a)
		if a == 25 {
			sum++
		}
		if a == 50 {
			sum--
			sum2++
		}
		if a == 100 {
			if sum2 != 0 {
				sum2--
				sum--
			} else {
				sum -= 3
			}
		}
		if sum < 0 {
			fmt.Print("NO\n")
			return
		}
		fmt.Print("YES\n")
		return
	}
}

// 349A
package main

import (
	"fmt"
)

func main() {
	var a, sum, sum2, n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&a)
		if a == 25 {
			sum++
		}
		if a == 50 {
			sum--
			sum2++
		}
		if a == 100 {
			if sum2 != 0 {
				sum2--
				sum--
			} else {
				sum -= 3
			}
			if sum < 0 {
				fmt.Print("NO\n")
				return
			}
		}
		fmt.Print("YES\n")
		return
	}
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	var a int
	for n > 0 {
		var x int
		fmt.Fscan(reader, &x)

		switch x {
		case 25:
			a++
		case 50:
			if a > 0 {
				a--
			} else {
				fmt.Println("NO")
				return
			}
		case 100:
			if a*25 >= x {
				a -= 4
			} else {
				fmt.Println("NO")
				return
			}
		}
		n--
	}

	fmt.Println("YES")
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	var a, b int
	for n > 0 {
		var x int
		fmt.Fscan(reader, &x)

		switch x {
		case 25:
			a++
		case 50:
			if a > 0 {
				a--
				b++
			} else {
				fmt.Println("NO")
				return
			}
		case 100:
			if a*25 >= x-25 {
				a -= 3
			} else if a > 0 && b > 0 {
				a--
				b--
			} else {
				fmt.Println("NO")
				return
			}
		}
		n--
	}

	fmt.Println("YES")
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	var a int
	for n > 0 {
		var x int
		fmt.Fscan(reader, &x)

		switch x {
		case 25:
			a++
		case 50:
			if a > 0 {
				a--
			} else {
				fmt.Println("NO")
				return
			}
		case 100:
			if a > 0 {
				a--
			} else {
				fmt.Println("NO")
				return
			}
		}
		n--
	}

	fmt.Println("YES")
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	var a, b int
	for n > 0 {
		var x int
		fmt.Fscan(reader, &x)

		switch x {
		case 25:
			a++
		case 50:
			if a > 0 {
				a--
				b++
			} else {
				fmt.Println("NO")
				return
			}
		case 100:
			if a*25 >= x {
				a -= 4
			} else if a > 0 && b > 0 {
				a--
				b--
			} else {
				fmt.Println("NO")
				return
			}
		}
		n--
	}

	fmt.Println("YES")
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	var a, b int
	for n > 0 {
		var x int
		fmt.Fscan(reader, &x)

		switch x {
		case 25:
			a++
		case 50:
			if a > 0 {
				a--
			} else {
				fmt.Println("NO")
				return
			}
		case 100:
			if a > 0 && b > 0 {
				a--
				b--
			} else {
				fmt.Println("NO")
				return
			}
		}
		n--
	}

	fmt.Println("YES")
}

package main

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

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

	var n int
	fmt.Fscan(reader, &n)

	var a int
	for n > 0 {
		var x int
		fmt.Fscan(reader, &x)

		switch x {
		case 25:
			a++
		case 50:
			if a > 0 {
				a++
			} else {
				fmt.Println("NO")
				return
			}
		case 100:
			if a*25 >= x-25 {
				a -= 3
			} else {
				fmt.Println("NO")
				return
			}
		}
		n--
	}

	fmt.Println("YES")
}


Print a single integer — the number of rooms where George and Alex can move in.

package main

import (
    "fmt"
    //"strings"
)

func main() {
    var n int = 0
    fmt.Scan(&n)
    var p,q [101]int
    for x:=0;x<n;x++{
        fmt.Scan(&p[x])
        fmt.Scan(&q[x])
    }
    tot:=0
    for x:=0;x<n;x++{
        if p[x]+2<=q[x]{
            tot++
        }
    }
    fmt.Println(tot)

}

package main

import (
	"fmt"
)

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

	var a, b int
	for i:=0; i<n; i++ {
		fmt.Scan(&a, &b)
		if b - a >= 2 {counter++}
	}
	fmt.Println(counter)
}

package main

import (
	"fmt"
)

func main() {
	var n, ans int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scan(&p, &q)
		if q-p >= 2 {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var res, N, x, y int

	fmt.Scanln(&N)
	for i := 0; i < N; i++ {
		fmt.Scanln(&x, &y)
		if y-x >= 2 {
			res++
		}
	}
	fmt.Println(res)
}

package main

import "fmt"

func main() {
	var n, p, q int
	fmt.Scanf("%d\n", &n)
	count := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &p, &q)
		if q-p > 1 {
			count++
		}
	}
	fmt.Println(count)
}

package main

import "fmt"

func main() {
	var num int
	_, _ = fmt.Scanln(&num)
	matrix := make([][2]int32,num)
	count := 0
	for i:=0; i<num; i++ {
		for j:=0;j<2; j++ {
			_, _ = fmt.Scan(&matrix[i][j])
		}
		if matrix[i][0] < matrix[i][1] {
			if matrix[i][1] - matrix[i][0] >= 2 {
				count++
			}
		}
	}
	fmt.Print(count)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

func main() {
	var num uint
	_, _ = fmt.Scanln(&num)
	matrix := make([][2]uint32, num, num+3)
	var count, i uint = 0, 0
	for i = 0; i < num; i++ {
		scanf("%d %d\n", &matrix[i][0], &matrix[i][1])
		if matrix[i][0] < matrix[i][1] {
			if matrix[i][1]-matrix[i][0] >= 2 {
				count++
			}
		}
	}
	fmt.Print(count)
}

package main
import "fmt"

func main(){
	var (
		n, p, q int
		count int
	)
	fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &p, &q)
		if q - p >= 2 {
			count += 1
		}
	}

	fmt.Println(count)
}

package main

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

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

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

	n := nextInt()
	p, q, count := 0, 0, 0

	for i := 0; i < n; i++ {
		p, q = nextInt(), nextInt()

		if q - p >= 2 {
			count++
		}
	}

	println(count)
}

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

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import(
    "fmt"
)

type u32 uint32

func main(){
    var(
        n,a,b,res u32
    )
    fmt.Scan(&n)
    res = 0
    for n>0 {
        fmt.Scan(&a,&b)
        if b-a>=2{
            res++
        }
        n--
    }
    fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {
	var t , i int
	fmt.Scan(&t)
	var cnt int
	    cnt = 0
	for i = 0 ; i < t ; i++ {
	    var p , q int
	    fmt.Scan(&p , &q)
	    if q - p >= 2 {
	        cnt++;
	    }
	}
	fmt.Println(cnt)
}

package main

import "fmt"

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

	total := 0
	var p, q int
	for i := 0; i < count; i++ {
		fmt.Scan(&p, &q)
		if q - p >= 2 {
			total ++
		}
	}

	fmt.Println(total)
}

package main

import "fmt"

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

	total := 0
	for i := 0; i < count; i++ {
		var p, q int
		fmt.Scan(&p, &q)
		if q - p >= 2 {
			total ++
		}
	}

	fmt.Println(total)
}

package main

import (
	"fmt"
)

func main() {
	var n, x, y int
	fmt.Scan(&n)
	res := 0
	for i := 1; i <= n; i++ {
		fmt.Scan(&x, &y)
		if y-x >= 2 {
			res++
		}
	}
	fmt.Println(res)
}

package main

import (
  "fmt"
)

func main() {
  var n, p, c, r int
  fmt.Scan(&n)
  for i := 0; i < n; i++ {
    fmt.Scan(&p,&c)
    if c-p>=2 {
      r++
    }
  }
  fmt.Print(r)
}

package main

import "fmt"

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

	var rooms, p, q int
	for i := 0; i < n; i++ {
		fmt.Scan(&p, &q)
		if q-p > 1 {
			rooms++
		}
	}
	fmt.Print(rooms)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var count int
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scan(&p, &q)
		if q-p >= 2 {
			count++
		}
	}
	fmt.Println(count)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q, cnt int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p, &q)
		if q - p >= 2 {
			cnt++
		}
	}
	fmt.Print(cnt)
}

package main

import "fmt"

func main() {
    n := 0
    ans := 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        a := 0
        b := 0
        fmt.Scan(&a)
        fmt.Scan(&b)
        if b-a >= 2 {
            ans++
        }
    }
    fmt.Println(ans)
}

package main

import "fmt"

func main() {

	var n int
	var p, q int
	sum := 0

	_, _ = fmt.Scanln(&n)

	for i := 0; i < n; i++ {
		_, _ = fmt.Scanln(&p, &q)
		if q - p >= 2 {
			sum ++
		}
	}

	fmt.Println(sum)
}

package main

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

func main() {
	var scanner *bufio.Scanner
	var lines, room []string
	var free int
	var p, q int

	scanner = bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		lines = append(lines, scanner.Text())
	}

	for _, line := range lines[1:] {
		room = strings.Fields(line)
		p, _ = strconv.Atoi(room[0])
		q, _ = strconv.Atoi(room[1])

		if (q - p) >= 2 {
			free++
		}
	}

	fmt.Println(free)
}

package main

import (
	"fmt"
)

var (
	n      int
	p      []int
	q      []int
	result int = 0
)

func in() {
	fmt.Scanln(&n)
	p = make([]int, n)
	q = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &p[i], &q[i])
	}
}

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

func run() {
	for i := 0; i < n; i++ {
		if q[i]-p[i] >= 2 {
			result++
		}
	}
}

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

package main

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

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)
	n := 0
	fmt.Sscanf(readLine(reader), "%d", &n)
	res := 0
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Sscanf(readLine(reader), "%d %d", &p, &q)
		if q - p >= 2 {
			res++
		}
	}
	fmt.Println(res)
}

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

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

package main

import "fmt"

func main() {
	var n, c int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scan(&p, &q)
		if q-p >= 2 {
			c++
		}
	}
	fmt.Print(c)
}

package main
import (
	"fmt"
)
func main() {
	var no, a, b, avail, tmp, sum int
	fmt.Scan(&no)
	avail = 0
	tmp = 0
	arr := []int{}
	arr1 := []int{}
	//total := []int{}
	for i := 0; i < no; i++ {
		fmt.Scan(&a, &b)
		arr = append(arr, a)
		arr1 = append(arr1, b)
	}
	for j := 0; j < len(arr); j++ {
		if arr[j] == arr1[j] {
			tmp = 0
			//total = append(total, avail)
		}
		if arr[j] < arr1[j] {
			if arr1[j] - arr[j] >= 2 {
				avail = avail + 1
				//total = append(total, avail)
			}
		}
	}
	sum = tmp + avail
	fmt.Println(sum)

}

package main

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

func main() {
	total := 0
	scanner := bufio.NewScanner(os.Stdin)
	// Skip first line.
	scanner.Scan()
	var p, q int
	for scanner.Scan() {
		if _, err := fmt.Sscanf(scanner.Text(), "%d %d", &p, &q); err != nil {
			continue
		}
		if q-p >= 2 {
			total++
		}
	}
	fmt.Println(total)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q, r int

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&p, &q)

		if q-p >= 2 {
			r++
		}
	}

	fmt.Println(r)
}

/*
George and Accommodation
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.

George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.

The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.

Output
Print a single integer — the number of rooms where George and Alex can move in.

Sample test(s)
input
3
1 1
2 2
3 3
output
0
input
3
1 10
0 10
10 10
output
2
*/

package main

import (
	"fmt"
)

func main() {
	var n, counter int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scanf("%d %d\n", &p, &q)
		if q - p >= 2 {
			counter++
		}
	}
	fmt.Println(counter)
}

package main

import "fmt"

func main() {
	var dormNum int
	var in, volume int
	var counter int
	fmt.Scan(&dormNum)
	for offset := 0; offset < dormNum; offset++ {
		fmt.Scan(&in, &volume)
		if volume - in >= 2 {
			counter += 1
		}
	}
	fmt.Print(counter)
}

package main
import "fmt"
func main () {
    var h int
    fmt.Scan(&h)
    c:=0
    n:=0
    m:=0
    for i:=0;i<h;i++ {
        fmt.Scan(&n,&m)
        if m-n>1{
            c++
        }
    }
    fmt.Println(c)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q int
	fmt.Scan(&n)
	z := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&p)
		fmt.Scan(&q)
		if q-p >= 2 {
			z++
		}
	}
	fmt.Println(z)
}

package main

import "fmt"

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

	num := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		if y-x >= 2 {
			num += 1
		}
	}

	fmt.Print(num)
}

package main

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

var n int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1<<20)
	fmt.Fscanf(reader, "%d\n", &n)

	ans := 0
	for ; n != 0; n-- {
		var p, q int
		fmt.Fscanf(reader, "%d%d\n", &p, &q)
		if q-p >= 2 {
			ans++
		}
	}

	fmt.Println(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, p, q, c uint8
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; uint8(i) < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &p, &q)
		if q-p > 1 {
			c++
		}
	}
	fmt.Println(c)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q, ctr int
	fmt.Scan(&n)
	for n > 0 {
		fmt.Scan(&p, &q)
		if q-p >= 2 {
			ctr++
		}
		n--
	}
	fmt.Println(ctr)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var cnt int
	for i := 0; i < n; i++ {
		var m, l int
		fmt.Scan(&m, &l)
		if l-m >= 2 {
			cnt++
		}
	}
	fmt.Print(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q, c int
	fmt.Scan(&n)

	for n > 0 {
		fmt.Scan(&p, &q)
		if q-p >= 2 {
			c++
		}
		n--
	}
	fmt.Println(c)
}

package main

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

func cf467a(in io.Reader, out io.Writer) {

	var n, occupied, total, eligible int
	fmt.Fscan(in, &n)
	for n > 0 {
		n--
		fmt.Fscan(in, &occupied, &total)
		if total-occupied >= 2 {
			eligible++
		}
	}
	fmt.Println(eligible)
}

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

package main

import (
    "fmt"
)

func main() {
    var n, p, q, r int

    fmt.Scan(&n)

    for i := 0; i < n; i++ {
        fmt.Scan(&p, &q)

        if q-p >= 2 {
            r++
        }
    }

    fmt.Println(r)
}

package main

import "fmt"

func main() {
	var n, p, q, r int
	fmt.Scan(&n)
	for i := 0; i < n; i ++ {
		fmt.Scan(&p)
		fmt.Scan(&q)
		if q - p >= 2 {
			r ++
		}
	}
	fmt.Println(r)
}

// ░░░░░░░░░░░░░░░SPINDYZEL░░░░░░░░░░░░░░░
// ░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
// ░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
// ░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
// ░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
// ░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
// ░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
// ░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
// ░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
// ░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
// ░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
// ░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░

package main

import "fmt"

func main() {
	var n, p, q int
	ans := 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p, &q)
		if q-p >= 2 {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var room, p, c, res int
	res = 0
	fmt.Scan(&room)
	for room != 0 {
		fmt.Scan(&p, &c)
		if c-p >= 2 {
			res++
		}
		room--
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q int
	a := 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &p, &q)
		if q-p > 1 {
			a++
		}
	}
	fmt.Println(a)
}

package main

import "fmt"

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

    num := 0
    for i := 0; i < n; i++ {
        var p, q int
        fmt.Scan(&p, &q)
        if q - p >= 2 {
            num++
        }
    }

    fmt.Println(num)
}

package main
import (
	"fmt"
)
func main() {
	var n,ct,p,q int
	ct=0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p,&q)
		if q-p >= 2 {
			ct += 1
		}
	}
	fmt.Println(ct)
}

package main

import (
    "fmt"
)

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

    cnt := 0
    for i := 0 ; i < n ; i++ {
        var p, q int
        fmt.Scan(&p, &q)
        if (q - p) >= 2 {
            cnt++
        }
    }
    fmt.Println(cnt)
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var n int
	scanf("%d\n", &n)
	var cnt int
	for i := 0; i < n; i++ {
		var p, q int
		scanf("%d %d\n", &p, &q)
		if q-p >= 2 {
			cnt++
		}
	}
	printf("%d\n", cnt)
}

func printf(format string, x ...interface{}) {
	fmt.Fprintf(os.Stdout, format, x...)
}

func scanf(format string, x ...interface{}) {
	if _, err := fmt.Fscanf(os.Stdin, format, x...); err != nil {
		panic(err)
	}
}

package main

import "fmt"

func main() {
	var n, ret int
	ret = 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scan(&p)
		fmt.Scan(&q)
		if q - p >= 2 {
			ret++
		}
	}

	fmt.Println(ret)
}

package main

import "fmt"

func main() {
	var testcount, a, b, count int
	fmt.Scanf("%d\n", &testcount)
	for i := 0; i < testcount; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		if b-a >= 2 {
			count++
		}
	}
	fmt.Println(count)
}

package main;

import (
  "fmt"
)

func main() {
  var n int;
  fmt.Scanf("%d", &n);
  var ans = 0;
  for i := 0; i < n; i++ {
    var p, q int;
    fmt.Scan(&p, &q);
    if q - p >= 2 {
      ans++;
    }
  }
  fmt.Printf("%d", ans);
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	count := 0
	var p, q int
	for i := 0; i < n; i++ {
		fmt.Scan(&p, &q)
		if q-p > 1 {
			count++
		}
	}
	fmt.Print(count)
}

package main

import (
	"fmt"
)

func main() {
	var n, a, b, ans int
	ans = 0
	fmt.Scanf("%d ", &n)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d %d ", &a, &b)
		if b-a >= 2 {
			ans++
		}
	}
	fmt.Printf("%d\n", ans)
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/467/A
// A. George and Accommodation
// time limit per test
// 1 second
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.

// George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
// Input

// The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.

// The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
// Output

// Print a single integer — the number of rooms where George and Alex can move in.

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

	var nPossible int
	for i := 0; i < n; i++ {
		var pi, qi int
		fmt.Scan(&pi, &qi)

		if qi-pi >= 2 {
			nPossible++
		}
	}

	fmt.Print(nPossible)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    n, _ := strconv.Atoi(scanner.Text())

    ans := 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        arr := strings.Split(scanner.Text(), " ")
        p, _ := strconv.Atoi(arr[0])
        q, _ := strconv.Atoi(arr[1])

        if ((q - p) >= 2) {
            ans++
        }
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
)

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

	ans := 0
	for i:=1; i<=N; i++{
		var p,q int
		fmt.Scan(&p, &q)
		if q-p >= 2 {
			ans++
		}
	}

	fmt.Println(ans)
}

package main

// https://codeforces.com/problemset/problem/467/A

import "fmt"

type room struct {
	size     int
	capasity int
}

func taskSolution(a []room) (ans int) {
	const friends = 2
	for _, r := range a {
		if friends+r.size <= r.capasity {
			ans += 1
		}
	}
	return ans
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	a := []room{}
	for i := 0; i < n; i += 1 {
		var p, q int
		if _, err := fmt.Scan(&p, &q); err != nil {
			panic(err)
		}
		a = append(a, room{p, q})
	}

	fmt.Println(taskSolution(a))
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q int
	fmt.Scanln(&n)

	rooms := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &p, &q)
		if q-p >= 2 {
			rooms++
		}
	}

	fmt.Println(rooms)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q, r int

	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&p, &q)

		if q-p >= 2 {
			r++
		}
	}

	fmt.Println(r)
}

package main

import "fmt"

func main() {
	var num int
	_, _ = fmt.Scanln(&num)
	matrix := make([][2]int32,num)
	count :=0
	for i:=0; i<num; i++ {
		for j:=0;j<2; j++ {
			_, _ = fmt.Scan(&matrix[i][j])
		}
		if matrix[i][0] < matrix[i][1] {
			count++
		}
	}
	fmt.Print(count)
}

package main
import "fmt"

func main(){
	var (
		n, p, q int
		count int
	)
	fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &p, &q)
		if q - p > 2 {
			count += 1
		}
	}

	fmt.Println(count)
}

package main

import "fmt"

func main() {
    n := 0
    ans := 0
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        a := 0
        b := 0
        fmt.Scan(&a)
        fmt.Scan(&b)
        if a < b {
            ans++
        }
    }
    fmt.Println(ans)
}

/*
George and Accommodation
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.

George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.

The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.

Output
Print a single integer — the number of rooms where George and Alex can move in.

Sample test(s)
input
3
1 1
2 2
3 3
output
0
input
3
1 10
0 10
10 10
output
2
*/

package main

import (
	"fmt"
)

func main() {
	var n, p, q, counter int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &p, &q)
		if q - p >= 2 {
			counter++
		}
	}
	fmt.Println(counter)
}

/*
George and Accommodation
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.

George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.

The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.

Output
Print a single integer — the number of rooms where George and Alex can move in.

Sample test(s)
input
3
1 1
2 2
3 3
output
0
input
3
1 10
0 10
10 10
output
2
*/

package main

import (
	"fmt"
)

func main() {
	var n, counter int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scanf("%d %d", &p, &q)
		if q - p >= 2 {
			counter++
		}
	}
	fmt.Println(counter)
}

package main

import "fmt"

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

    num := 0
    for i := 0; i < n; i++ {
        var p, q int
        fmt.Scanf("%d %d\n", &p, &q)
        if q - p >= 2 {
            num++
        }
    }

    fmt.Println(num)
}

package main

import "fmt"

func main() {
	var n, ret int
	ret = 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scanf("%d", &p)
		fmt.Scanf("%d", &q)
		if p < q {
			ret++
		}
	}

	fmt.Println(ret)
}

package main

import "fmt"

func main() {
	var n, ret int
	ret = 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scan(&p)
		fmt.Scan(&q)
		if p < q {
			ret++
		}
	}

	fmt.Println(ret)
}

package main

import "fmt"

func main() {
	var n, ret int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scanf("%d %d", &p, &q)
		if p < q {
			ret++
		}
	}

	fmt.Println(ret)
}

package main

import "fmt"

func main() {
	var n, ret int
	ret = 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var p, q int
		fmt.Scanf("%d %d", &p, &q)
		if p < q {
			ret++
		}
	}

	fmt.Println(ret)
}

package main;

import (
  "fmt"
)

func main() {
  var n int;
  fmt.Scanf("%d", &n);
  var ans = 0;
  for i := 0; i < n; i++ {
    var p, q int;
    fmt.Scanf("%d %d", &p, &q);
    if q - p >= 2 {
      ans++;
    }
  }
  fmt.Printf("%d", ans);
}

package main;

import (
  "fmt"
)

func main() {
  var n int;
  fmt.Scanf("%d", &n);
  var ans = 0;
  for i := 0; i < n; i++ {
    var p, q int;
    fmt.Scanf("%d %d\n", &p, &q);
    if q - p >= 2 {
      ans++;
    }
  }
  fmt.Printf("%d", ans);
}


Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the road where they are placed. Right after passing the sign it is allowed to drive at any speed.It is known that the car of an average Berland citizen has the acceleration (deceleration) speed of a km/h2, and has maximum speed of v km/h. The road has the length of l km, and the speed sign, limiting the speed to w km/h, is placed d km (1 ≤ d < l) away from the capital of Berland. The car has a zero speed at the beginning of the journey. Find the minimum time that an average Berland citizen will need to get from the capital to Bercouver, if he drives at the optimal speed.The car can enter Bercouver at any speed.

The first line of the input file contains two integer numbers a and v (1 ≤ a, v ≤ 10000). The second line contains three integer numbers l, d and w (2 ≤ l ≤ 10000; 1 ≤ d < l; 1 ≤ w ≤ 10000).

Print the answer with at least five digits after the decimal point.

package main

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

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

	var a, v, l, d, w float64

	fmt.Fscanf(reader, "%f %f\n", &a, &v)
	fmt.Fscanf(reader, "%f %f %f\n", &l, &d, &w)

	vx := math.Sqrt(2 * a * d)
	vy := math.Sqrt(a*d + w*w/2)
	var v1, t1, t2 float64

	if vx <= v && vx <= w {
		v1 = vx
		t1 = math.Sqrt(2.0 * d / a)
	} else if vx > v && v <= w {
		v1 = v
		t1 = v/(a) + (d-v*v/(2*a))/v
	} else if w < vx && vy <= v {
		v1 = w
		t1 = (vy*2 - w) / a
	} else if w < vx && vy > v {
		v1 = w
		t1 = (2*a*d + 2*v*v + w*w - 2*w*v) / (2 * a * v)
	}

	d1 := l - d

	s := (v*v - v1*v1) / (2 * a)

	if s >= d1 {
		t2 = (math.Sqrt(2*a*d1+v1*v1) - v1) / a
	} else {
		t2 = (v-v1)/a + (d1-s)/v
	}
	fmt.Printf("%f", t1+t2)
}

package main

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

var debug bool = false

func solve() {
	a := float64(readInt()) // acceleration of car
	v := float64(readInt()) // maximum velocity of car
	l := float64(readInt()) // total length of road
	d := float64(readInt()) // distance from beginning of limit
	w := float64(readInt()) // instantaneous speed limit

	if v < w {
		// If maximum velocity of car < speed limit, we
		// accelerate to maximum speed of car and travel
		// the rest of the way at that speed... or we
		// accelerate the whole way (never reaching max)
		fmt.Println(lastSection(a, v, l, 0.0))
		return
	}

	// time to reach 'd' at full acceleration
	td := math.Sqrt(2.0 * (d / a))

	// velocity at 'd' from full acceleration
	vd := a * td

	if debug {
		fmt.Println("full a td", td, "vd", vd)
	}

	if vd <= w {
		// At full acceleration, we we haven't reached the
		// limit, this is the same simple case as above
		fmt.Println(lastSection(a, v, l, 0.0))
		return
	}

	// Now, we know we can actually reach 'w' before we get to 'd'.
	// So, if we go flat out 'a' from 0 will we reach 'v' before we
	// have to start decelerating to be at 'w' by 'd'.
	//
	// Now we need to figure out whether we accelerate up to 'v',
	// cruise at v for awhile, then decelerate to 'w' OR we accelerate
	// as much as possible then decelerate to 'w'.

	// For now let's assume we'll accelerate and decelerate only
	// (no time spent at 'v').

	t_a := math.Sqrt((d / a) + math.Pow(w, 2.0)/(2.0*math.Pow(a, 2.0)))
	t_d := t_a - w/a
	t_v := 0.0
	t := t_a + t_d + t_v

	v_i := a * t_a

	if debug {
		fmt.Println("a", a, "l", l, "v", v, "d", d, "w", w)
		fmt.Println("vi", v_i, "ta", t_a, "td", t_d)
	}

	if v_i > v {
		// We have to spend some time cruising at 'v'
		t_a = (v - 0.0) / a
		t_d = (v - w) / a

		dl := d
		dl -= 0.5 * (v + 0.0) * t_a
		dl -= 0.5 * (v + w) * t_d
		t_v = dl / v
		if debug {
			fmt.Println("ta", t_a, "td", t_d, "tv", t_v)
		}
		t = t_a + t_d + t_v
		v_i = w
	}

	if debug {
		fmt.Println("T", t)

		fmt.Println("d_a", 0.5*a*t_a*t_a)
		fmt.Println("d_d", 0.5*(w+v_i)*t_d)
	}

	l -= d

	fmt.Println(t + lastSection(a, v, l, w))
}

func lastSection(a, v, l, v0 float64) float64 {
	// simple case, either we accelerate all the way
	// (if we hit v after l), or we hit v and travel
	// the rest of the way at constant velocity 'v'

	// Can we just accelerate to the end? (staying under 'v')
	if debug {
		fmt.Println("last", "a", a, "v", v, "l", l, "v0", v0)
	}

	vend := math.Sqrt(v0*v0 + 2.0*a*l)
	if vend <= v {
		// we reach the end before 'v' matters
		return l / (0.5 * (vend + v0))
	}

	tv := (v - v0) / a // time to reach v (from v0)

	// distance covered during acceleration
	d := 0.5 * (v + v0) * tv
	if debug {
		fmt.Println("tv", tv, "d", d, "l-d", l-d)
	}

	// take away distance covered accelerating to 'v'
	l -= d

	// How long to to cover the remaining distance?
	tl := l / v

	// result is sum of the two
	return (tv + tl)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

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

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

	var a, v, l, d, w float64

	fmt.Fscanf(reader, "%f %f\n", &a, &v)
	fmt.Fscanf(reader, "%f %f %f\n", &l, &d, &w)

	vx := math.Sqrt(2 * a * d)
	vy := math.Sqrt(a*d + w*w/2)
	var v1, t1, t2 float64

	if vx <= v && vx <= w {
		v1 = vx
		t1 = math.Sqrt(2.0 * d / a)
	} else if vx > v && vx <= w {
		v1 = v
		t1 = v/(2*a) + d/v
	} else if w < vx && vy <= v {
		v1 = w
		t1 = (vy*2 - w) / a
	} else if w < vx && vy > v {
		v1 = w
		t1 = (2*a*d + 2*v*v + w*w - 2*w*v) / (2 * a * v)
	}

	d1 := l - d

	s := (v*v - v1*v1) / (2 * a)

	if s >= d1 {
		t2 = (math.Sqrt(2*a*d1+v1*v1) - v1) / a
	} else {
		t2 = (v-v1)/a + (d1-s)/v
	}
	fmt.Printf("%f", t1+t2)
}

package main

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

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

	var a, v, l, d, w float64

	fmt.Fscanf(reader, "%f %f\n", &a, &v)
	fmt.Fscanf(reader, "%f %f %f\n", &l, &d, &w)

	vx := math.Sqrt(2 * a * d)
	vy := math.Sqrt(a*d + w*w/2)
	var v1, t1, t2 float64

	if vx <= v && vx <= w {
		v1 = vx
		t1 = math.Sqrt(2.0 * w / a)
	} else if vx > v && vx <= w {
		v1 = v
		t1 = v/(2*a) + d/v
	} else if w < vx && vy <= v {
		v1 = w
		t1 = (vy*2 - w) / a
	} else if w < vx && vy > v {
		v1 = w
		t1 = (2*a*d + 2*v*v + w*w - 2*w*v) / (2 * a * v)
	}

	d1 := l - d

	s := (v*v - v1*v1) / (2 * a)

	if s >= d1 {
		t2 = (math.Sqrt(2*a*d1+v1*v1) - v1) / a
	} else {
		t2 = (v-v1)/a + (d1-s)/v
	}
	fmt.Printf("%f", t1+t2)
}

package main

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

var debug bool = false

func solve() {
	a := float64(readInt()) // acceleration of car
	v := float64(readInt()) // maximum velocity of car
	l := float64(readInt()) // total length of road
	d := float64(readInt()) // distance from beginning of limit
	w := float64(readInt()) // instantaneous speed limit

	if v < w {
		// If maximum velocity of car < speed limit, we
		// accelerate to maximum speed of car and travel
		// the rest of the way at that speed... or we
		// accelerate the whole way (never reaching max)
		fmt.Println(lastSection(a, v, l, 0.0))
		return
	}

	// time to reach 'd' at full acceleration
	td := math.Sqrt(2.0 * (d / a))

	// velocity at 'd' from full acceleration
	vd := a * td

	if debug {
		fmt.Println("full a td", td, "vd", vd)
	}

	if vd <= w {
		// At full acceleration, we we haven't reached the
		// limit, this is the same simple case as above
		fmt.Println(lastSection(a, v, l, 0.0))
		return
	}

	// Now, we know we can actually reach 'w' before we get to 'd'.
	// So, if we go flat out 'a' from 0 will we reach 'v' before we
	// have to start decelerating to be at 'w' by 'd'.
	//
	// Now we need to figure out whether we accelerate up to 'v',
	// cruise at v for awhile, then decelerate to 'w' OR we accelerate
	// as much as possible then decelerate to 'w'.

	// For now let's assume we'll accelerate and decelerate only
	// (no time spent at 'v').

	t_a := math.Sqrt((d / a) + math.Pow(w, 2.0)/(2.0*math.Pow(a, 2.0)))
	t_d := t_a - w/a
	t := t_a + t_d

	v_i := a * t_a

	if debug {
		fmt.Println("a", a, "l", l, "v", v, "d", d, "w", w)
		fmt.Println("vi", v_i, "ta", t_a, "td", t_d)

		fmt.Println("d_a", 0.5*a*t_a*t_a)
		fmt.Println("d_d", 0.5*(w+v_i)*t_d)
	}

	if v_i > v {
		// We have to spend some time cruising at 'v'
		t_a = v / a
		t_d = (v - w) / a

		if debug {
			fmt.Println("ta", t_a, "td", td)
		}
		dl := d
		dl -= 0.5 * v * t_a
		dl -= 0.5 * t_d * (v - w)
		t_v := dl / v
		t = t_a + t_d + t_v
	}

	if debug {
		fmt.Println("T", t)
	}

	l -= d

	fmt.Println(t + lastSection(a, v, l, w))
}

func lastSection(a, v, l, v0 float64) float64 {
	// simple case, either we accelerate all the way
	// (if we hit v after l), or we hit v and travel
	// the rest of the way at constant velocity 'v'

	// Can we just accelerate to the end? (staying under 'v')
	vend := math.Sqrt(v0*v0 + 2.0*a*l)
	if vend <= v {
		// we reach the end before 'v' matters
		return l / (0.5 * (vend + v0))
	}

	tv := (v - v0) / a // time to reach v (from v0)

	// take away distance covered accelerating to 'v'
	l -= 0.5 * a * tv * tv

	// How long to to cover the remaining distance?
	tl := l / v

	// result is sum of the two
	return (tv + tl)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}


Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden.Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day.You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.

The first line contains a single integer N (1 ≤ N ≤ 105) — the number of days.  The second line contains N integers V1, V2, ..., VN (0 ≤ Vi ≤ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≤ Ti ≤ 109), where Ti is the temperature on the day i.

Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i.

NoteIn the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.

package main

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

func solve() {
	n := readInt()
	v := readIntArray(n)
	t := readIntArray(n)
	a := make([]int64, n)
	acc := int64(0)
	for i := 0; i < n; i++ {
		a[i] = int64(v[i]) + acc
		acc += int64(t[i])
	}
	sort.Sort(Int64(a))
	acc = 0
	start := 0
	cnt := 0
	for i := 0; i < n; i++ {
		total := int64(0)
		prev := acc
		acc += int64(t[i])
		cnt++
		for j := start; j < n; j++ {
			if acc > a[j] {
				total += a[j] - prev
				cnt--
				start = j + 1
			} else {
				break
			}
		}
		total += int64(cnt) * int64(t[i])
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(total)
	}
	fmt.Println()
}

type Int64 []int64

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

func solveBak() {
	n := readInt()
	v := readIntArray(n)
	t := readIntArray(n)
	heap := NewMinHeap(n)
	acc := int64(0)
	for i := 0; i < n; i++ {
		total := int64(0)
		cur := int64(t[i])
		heap.Add(i, int64(v[i])+acc)
		acc += cur
		for heap.Min() < acc {
			val := heap.Min()
			t1 := int64(val) - acc + cur
			total += t1
			heap.Remove(heap.ArgMin())
		}
		total += int64(heap.Size()) * cur
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(total)
	}
	fmt.Println()
}

type MinHeap struct {
	a    []int64
	vmap []int
	imap []int
	n    int
	pos  int
}

const INF = math.MaxInt32

func NewMinHeap(m int) *MinHeap {
	heap := &MinHeap{}
	m += 2
	heap.n = m
	heap.a = make([]int64, heap.n)
	heap.vmap = make([]int, heap.n)
	heap.imap = make([]int, heap.n)
	heap.pos = 1
	for i := 0; i < heap.n; i++ {
		heap.a[i] = INF
		heap.vmap[i] = -1
		heap.imap[i] = -1
	}
	return heap
}

func (h *MinHeap) Add(ind int, x int64) int64 {
	ret := h.imap[ind]
	if h.imap[ind] < 0 {
		h.a[h.pos] = x
		h.vmap[h.pos] = ind
		h.imap[ind] = h.pos
		h.pos++
		h.up(h.pos - 1)
	}
	if ret != -1 {
		return h.a[ret]
	}
	return x
}

func (h *MinHeap) Update(ind int, x int64) int64 {
	ret := h.imap[ind]
	if h.imap[ind] < 0 {
		h.a[h.pos] = x
		h.vmap[h.pos] = ind
		h.imap[ind] = h.pos
		h.pos++
		h.up(h.pos - 1)
	} else {
		h.a[ret] = x
		h.up(ret)
		h.down(ret)
	}
	return x
}

func (h *MinHeap) Remove(ind int) int64 {
	if h.pos == 1 {
		return INF
	}
	if h.imap[ind] == -1 {
		return INF
	}

	h.pos--
	rem := h.imap[ind]
	ret := h.a[rem]
	h.vmap[rem] = h.vmap[h.pos]
	h.imap[h.vmap[h.pos]] = rem
	h.imap[ind] = -1
	h.a[rem] = h.a[h.pos]
	h.a[h.pos] = INF
	h.vmap[h.pos] = -1

	h.up(rem)
	h.down(rem)
	return ret
}

func (h *MinHeap) Min() int64 {
	return h.a[1]
}

func (h *MinHeap) ArgMin() int {
	return h.vmap[1]
}

func (h *MinHeap) Size() int {
	return h.pos - 1
}

func (h *MinHeap) up(cur int) {
	for c, p := cur, cur>>1; p >= 1 && h.a[p] > h.a[c]; c, p = c>>1, p>>1 {
		h.a[p], h.a[c] = h.a[c], h.a[p]
		h.imap[h.vmap[p]], h.imap[h.vmap[c]] = h.imap[h.vmap[c]], h.imap[h.vmap[p]]
		h.vmap[p], h.vmap[c] = h.vmap[c], h.vmap[p]
	}
}

func (h *MinHeap) down(cur int) {
	for c := cur; 2*c < h.pos; {
		b := 0
		if h.a[2*c] < h.a[2*c+1] {
			b = 2 * c
		} else {
			b = 2*c + 1
		}
		if h.a[b] < h.a[c] {
			h.a[c], h.a[b] = h.a[b], h.a[c]
			h.imap[h.vmap[c]], h.imap[h.vmap[b]] = h.imap[h.vmap[b]], h.imap[h.vmap[c]]
			h.vmap[c], h.vmap[b] = h.vmap[b], h.vmap[c]
			c = b
		} else {
			break
		}
	}
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	n := readInt()
	v := readIntArray(n)
	t := readIntArray(n)
	a := make([]int64, n)
	acc := int64(0)
	for i := 0; i < n; i++ {
		a[i] = int64(v[i]) + acc
		acc += int64(t[i])
	}
	sort.Sort(Int64(a))
	acc = 0
	start := 0
	cnt := 0
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		total := int64(0)
		prev := acc
		acc += int64(t[i])
		cnt++
		for j := start; j < n; j++ {
			if acc > a[j] {
				total += a[j] - prev
				cnt--
				start = j + 1
			} else {
				break
			}
		}
		total += int64(cnt) * int64(t[i])
		res[i] = total
	}
	b10 := []byte("")
	for i, v := range res {
		if i > 0 {
			b10 = append(b10, ' ')
		}
		b10 = strconv.AppendInt(b10, v, 10)
	}
	fmt.Println(string(b10))
}

type Int64 []int64

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

func solveBak() {
	n := readInt()
	v := readIntArray(n)
	t := readIntArray(n)
	heap := NewMinHeap(n)
	acc := int64(0)
	for i := 0; i < n; i++ {
		total := int64(0)
		cur := int64(t[i])
		heap.Add(i, int64(v[i])+acc)
		acc += cur
		for heap.Min() < acc {
			val := heap.Min()
			t1 := int64(val) - acc + cur
			total += t1
			heap.Remove(heap.ArgMin())
		}
		total += int64(heap.Size()) * cur
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(total)
	}
	fmt.Println()
}

type MinHeap struct {
	a    []int64
	vmap []int
	imap []int
	n    int
	pos  int
}

const INF = math.MaxInt32

func NewMinHeap(m int) *MinHeap {
	heap := &MinHeap{}
	m += 2
	heap.n = m
	heap.a = make([]int64, heap.n)
	heap.vmap = make([]int, heap.n)
	heap.imap = make([]int, heap.n)
	heap.pos = 1
	for i := 0; i < heap.n; i++ {
		heap.a[i] = INF
		heap.vmap[i] = -1
		heap.imap[i] = -1
	}
	return heap
}

func (h *MinHeap) Add(ind int, x int64) int64 {
	ret := h.imap[ind]
	if h.imap[ind] < 0 {
		h.a[h.pos] = x
		h.vmap[h.pos] = ind
		h.imap[ind] = h.pos
		h.pos++
		h.up(h.pos - 1)
	}
	if ret != -1 {
		return h.a[ret]
	}
	return x
}

func (h *MinHeap) Update(ind int, x int64) int64 {
	ret := h.imap[ind]
	if h.imap[ind] < 0 {
		h.a[h.pos] = x
		h.vmap[h.pos] = ind
		h.imap[ind] = h.pos
		h.pos++
		h.up(h.pos - 1)
	} else {
		h.a[ret] = x
		h.up(ret)
		h.down(ret)
	}
	return x
}

func (h *MinHeap) Remove(ind int) int64 {
	if h.pos == 1 {
		return INF
	}
	if h.imap[ind] == -1 {
		return INF
	}

	h.pos--
	rem := h.imap[ind]
	ret := h.a[rem]
	h.vmap[rem] = h.vmap[h.pos]
	h.imap[h.vmap[h.pos]] = rem
	h.imap[ind] = -1
	h.a[rem] = h.a[h.pos]
	h.a[h.pos] = INF
	h.vmap[h.pos] = -1

	h.up(rem)
	h.down(rem)
	return ret
}

func (h *MinHeap) Min() int64 {
	return h.a[1]
}

func (h *MinHeap) ArgMin() int {
	return h.vmap[1]
}

func (h *MinHeap) Size() int {
	return h.pos - 1
}

func (h *MinHeap) up(cur int) {
	for c, p := cur, cur>>1; p >= 1 && h.a[p] > h.a[c]; c, p = c>>1, p>>1 {
		h.a[p], h.a[c] = h.a[c], h.a[p]
		h.imap[h.vmap[p]], h.imap[h.vmap[c]] = h.imap[h.vmap[c]], h.imap[h.vmap[p]]
		h.vmap[p], h.vmap[c] = h.vmap[c], h.vmap[p]
	}
}

func (h *MinHeap) down(cur int) {
	for c := cur; 2*c < h.pos; {
		b := 0
		if h.a[2*c] < h.a[2*c+1] {
			b = 2 * c
		} else {
			b = 2*c + 1
		}
		if h.a[b] < h.a[c] {
			h.a[c], h.a[b] = h.a[b], h.a[c]
			h.imap[h.vmap[c]], h.imap[h.vmap[b]] = h.imap[h.vmap[b]], h.imap[h.vmap[c]]
			h.vmap[c], h.vmap[b] = h.vmap[b], h.vmap[c]
			c = b
		} else {
			break
		}
	}
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	n := readInt()
	v := readIntArray(n)
	t := readIntArray(n)
	a := make([]int64, n)
	acc := int64(0)
	for i := 0; i < n; i++ {
		a[i] = int64(v[i]) + acc
		acc += int64(t[i])
	}
	sort.Sort(Int64(a))
	acc = 0
	start := 0
	cnt := 0
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		total := int64(0)
		prev := acc
		acc += int64(t[i])
		cnt++
		for j := start; j < n; j++ {
			if acc > a[j] {
				total += a[j] - prev
				cnt--
				start = j + 1
			} else {
				break
			}
		}
		total += int64(cnt) * int64(t[i])
		res[i] = total
	}
	// b10 := []byte("")
	// for i, v := range res {
	// 	if i > 0 {
	// 		b10 = append(b10, ' ')
	// 	}
	// 	b10 = strconv.AppendInt(b10, v, 10)
	// }
	// fmt.Println(string(b10))
	w := bufio.NewWriter(os.Stdout)
	for i, v := range res {
		if i > 0 {
			fmt.Fprint(w, " ")
		}
		fmt.Fprint(w, strconv.FormatInt(v, 10))
	}
	w.Flush() // Don't forget to flush!
}

type Int64 []int64

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

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

// 这段代码演示了如何使用堆接口构建一个整数堆。
package main

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

// IntHeap 是一个由整数组成的最小堆。
type IntHeap []int64

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push 和 Pop 使用 pointer receiver 作为参数，
	// 因为它们不仅会对切片的内容进行调整，还会修改切片的长度。
	*h = append(*h, x.(int64))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

// 这个示例会将一些整数插入到堆里面， 接着检查堆中的最小值，
// 之后按顺序从堆里面移除各个整数。
func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(in, &n)
	var v[100010] int64
	var t[100010] int64
	for i := 1; i<= n; i++{
		fmt.Fscan(in, &v[i])
	}
	for i := 1; i<= n; i++{
		fmt.Fscan(in, &t[i])
	}
	h := &IntHeap{}
	heap.Init(h)

	var totalT,totalQ int64
	totalT = 0
	for i := 1; i <= n; i++{
		heap.Push(h, v[i] + totalT)
		totalQ = totalT
		totalT = totalT + t[i]
		var tmp int64
		tmp = 0
		for ;;{
			if 0 == len(*h){
				break
			}
			if (*h)[0] <= totalT {
				tmp += (*h)[0] - totalQ
				//fmt.Println(i, tmp, (*h)[0])
				heap.Pop(h)
			}else{
				break
			}
		}
		tmp =tmp + t[i] * (int64)(len(*h))
		fmt.Printf("%d", tmp)
		if i == n{
			fmt.Println()
		}else{
			fmt.Print(" ")
		}
	}

}