After returning to shore, uncle Bogdan usually visits the computer club "The Rock", to solve tasks in a pleasant company. One day, uncle Bogdan met his good old friend who told him one unusual task...There are $$$n$$$ non-intersecting horizontal segments with ends in integers points on the plane with the standard cartesian coordinate system. All segments are strictly above the $$$OX$$$ axis. You can choose an arbitrary vector ($$$a$$$, $$$b$$$), where $$$b < 0$$$ and coordinates are real numbers, and project all segments to $$$OX$$$ axis along this vector. The projections shouldn't intersect but may touch each other.Find the minimum possible difference between $$$x$$$ coordinate of the right end of the rightmost projection and $$$x$$$ coordinate of the left end of the leftmost projection.

The first line contains the single integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of segments. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$xl_i$$$, $$$xr_i$$$ and $$$y_i$$$ ($$$-10^6 \le xl_i < xr_i \le 10^6$$$; $$$1 \le y_i \le 10^6$$$) — coordinates of the corresponding segment. It's guaranteed that the segments don't intersect or touch.

Print the minimum possible difference you can get. Your answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, if your answer is $$$a$$$ and jury's answer is $$$b$$$ then your answer will be considered correct if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.

NoteIn the first example if we project segments along the vector $$$(1, -1)$$$ then we get an answer $$$12-3=9$$$ and (it can be proven) it is impossible to get less.   It is optimal to project along the vector $$$(1, -3)$$$ in the second example. The answer is $$$8\frac{2}{3}-2\frac{1}{3}=6\frac{1}{3}$$$

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	op := []float64{-1e9}
	active := make([]int, n)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 && (len(op) == 0 || math.Abs(ev.angle-op[len(op)-1]) > eps) {
			op = append(op, ev.angle)
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(op[m1]) < cost(op[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	op := []float64{-1e9}
	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 && (len(op) == 0 || math.Abs(ev.angle-op[len(op)-1]) > eps) {
			op = append(op, ev.angle)
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(op[m1]) < cost(op[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y float64
	}
	type Event struct {
		angle float64
		d     int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{float64(io.nextInt()), float64(io.nextInt()), float64(io.nextInt())}
	}

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

	var mx, mn ConvexHull
	for _, s := range a {
		mx.add(Line{s.y, s.xr})
	}
	for i := n - 1; i >= 0; i-- {
		mn.add(Line{-a[i].y, -a[i].xl})
	}

	var e []Event
	for _, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := (q.xl - p.xr) / (p.y - q.y)
				r := (q.xr - p.xl) / (p.y - q.y)
				e = append(e, Event{l, 1}, Event{r, -1})
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.d < b.d
	})

	ans := mx.query(-1e9) + mn.query(-1e9)
	total := 0
	for _, ev := range e {
		total += ev.d
		if total == 0 || total == ev.d {
			cur := mx.query(ev.angle) + mn.query(ev.angle)
			if cur < ans {
				ans = cur
			}
		}
	}

	fmt.Fprintf(io, "%.10f\n", ans)
}

type Line struct {
	m, c float64
}

func (l *Line) eval(x float64) float64     { return l.m*x + l.c }
func (l *Line) intersectX(o *Line) float64 { return (l.c - o.c) / (o.m - l.m) }

// Max convex hull; add lines in increasing order of slope; query in increasing order.
type ConvexHull []Line

func (cc *ConvexHull) add(l Line) {
	c := *cc
	if len(c) > 0 && c[len(c)-1].m == l.m {
		if c[len(c)-1].c >= l.c {
			return
		}
		c = c[:len(c)-1]
	}
	for len(c) > 1 && c[len(c)-1].intersectX(&l) <= c[len(c)-1].intersectX(&c[len(c)-2]) {
		c = c[:len(c)-1]
	}
	*cc = append(c, l)
}

func (cc *ConvexHull) query(x float64) float64 {
	c := *cc
	for len(c) > 1 && c[0].eval(x) <= c[1].eval(x) {
		c = c[1:]
	}
	*cc = c
	return c[0].eval(x)
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]*Seg, n)
	for i := 0; i < n; i++ {
		a[i] = &Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []*Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, &Event{l, false, i}, &Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var op []float64
	if zeroOk {
		op = append(op, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 && (len(op) == 0 || math.Abs(ev.angle-op[len(op)-1]) > eps) {
			op = append(op, ev.angle)
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m := (lo + hi) / 2
		if cost(op[m]) < cost(op[m+1]) {
			hi = m
		} else {
			lo = m + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		d     int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	var e []Event
	for _, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, 1}, Event{r, -1})
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.d < b.d
	})

	op := []float64{-1e9}
	total := 0
	for _, ev := range e {
		total += ev.d
		if (total == 0 || total == ev.d) && math.Abs(ev.angle-op[len(op)-1]) > eps {
			op = append(op, ev.angle)
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(op[m1]) < cost(op[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if len(options) == 0 || math.Abs(ev.angle-options[len(options)-1]) > eps {
				options = append(options, ev.angle)
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[hi]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		d     int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	var e []Event
	for _, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, 1}, Event{r, -1})
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.d < b.d
	})

	op := []float64{-1e9}
	total := 0
	for _, ev := range e {
		total += ev.d
		if (total == 0 || total == ev.d) && (len(op) == 0 || math.Abs(ev.angle-op[len(op)-1]) > eps) {
			op = append(op, ev.angle)
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(op[m1]) < cost(op[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var op []float64
	if zeroOk {
		op = append(op, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 && (len(op) == 0 || math.Abs(ev.angle-op[len(op)-1]) > eps) {
			op = append(op, ev.angle)
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(op[m1]) < cost(op[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-9

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if len(options) == 0 || ev.angle-options[len(options)-1] > eps {
				options = append(options, ev.angle)
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[hi]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-9

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if len(options) == 0 || math.Abs(ev.angle-options[len(options)-1]) > eps {
				options = append(options, ev.angle)
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[hi]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > 1e-9 {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	active := make(map[int]int)
	total := 0
	lbest, rbest := -1e9, 1e9
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if ev.angle < 0 {
				if ev.angle > lbest {
					lbest = ev.angle
				}
			} else {
				if ev.angle < rbest {
					rbest = ev.angle
				}
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	best := rbest
	if -lbest < rbest {
		best = lbest
	}
	if zeroOk {
		best = 0
	}

	left, right := 1e9, -1e9
	for _, s := range a {
		lt := float64(s.xl) + float64(s.y)*best
		rt := float64(s.xr) + float64(s.y)*best
		if lt < left {
			left = lt
		}
		if rt > right {
			right = rt
		}
	}

	fmt.Fprintf(io, "%.10f\n", right-left)
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if a.angle != b.angle {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var op []float64
	if zeroOk {
		op = append(op, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 && (len(op) == 0 || ev.angle-op[len(op)-1] > eps) {
			op = append(op, ev.angle)
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(op[m1]) < cost(op[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = -1e8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if len(options) == 0 || ev.angle-options[len(options)-1] > eps {
				options = append(options, ev.angle)
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[hi]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}

	var op []float64
	if zeroOk {
		op = append(op, 0)
	} else {
		sort.Slice(e, func(i, j int) bool {
			a, b := e[i], e[j]
			if math.Abs(a.angle-b.angle) > eps {
				return a.angle < b.angle
			}
			return a.right && !b.right
		})
		active := make(map[int]int)
		total := 0
		for _, ev := range e {
			if ev.right {
				active[ev.idx]--
				if active[ev.idx] == 0 {
					total--
				}
			}
			if total == 0 && (len(op) == 0 || math.Abs(ev.angle-op[len(op)-1]) > eps) {
				op = append(op, ev.angle)
			}
			if !ev.right {
				if active[ev.idx] == 0 {
					total++
				}
				active[ev.idx]++
			}
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e18, -1e18
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(op)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(op[m1]) < cost(op[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(op[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > 1e-9 {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	active := make(map[int]int)
	total := 0
	lbest, rbest := -1e9, 1e9
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if ev.angle < 0 {
				if ev.angle > lbest {
					lbest = ev.angle
				}
			} else {
				if ev.angle < rbest {
					rbest = ev.angle
				}
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	best := []float64{lbest, rbest}
	if zeroOk {
		best = []float64{0}
	}

	ans := 1e9
	for _, b := range best {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*b
			rt := float64(s.xr) + float64(s.y)*b
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		if right-left < ans {
			ans = right - left
		}
	}

	fmt.Fprintf(io, "%.10f\n", ans)
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if len(options) == 0 || ev.angle-options[len(options)-1] > eps {
				options = append(options, ev.angle)
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[hi]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-7

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if len(options) == 0 || math.Abs(ev.angle-options[len(options)-1]) > eps {
				options = append(options, ev.angle)
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[hi]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > 1e-9 {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			options = append(options, ev.angle)
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[lo]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		xl, xr, y int
	}
	type Event struct {
		angle float64
		right bool
		idx   int
	}
	const eps = 1e-8

	n := io.nextInt()
	a := make([]Seg, n)
	for i := 0; i < n; i++ {
		a[i] = Seg{io.nextInt(), io.nextInt(), io.nextInt()}
	}

	zeroOk := true
	var e []Event
	for i, p := range a {
		for _, q := range a {
			if p.y > q.y {
				l := float64(q.xl-p.xr) / float64(p.y-q.y)
				r := float64(q.xr-p.xl) / float64(p.y-q.y)
				e = append(e, Event{l, false, i}, Event{r, true, i})
				if l < 0 && r > 0 {
					zeroOk = false
				}
			}
		}
	}
	sort.Slice(e, func(i, j int) bool {
		a, b := e[i], e[j]
		if math.Abs(a.angle-b.angle) > eps {
			return a.angle < b.angle
		}
		return a.right && !b.right
	})

	var options []float64
	if zeroOk {
		options = append(options, 0)
	}

	active := make(map[int]int)
	total := 0
	for _, ev := range e {
		if ev.right {
			active[ev.idx]--
			if active[ev.idx] == 0 {
				total--
			}
		}
		if total == 0 {
			if len(options) == 0 || math.Abs(ev.angle-options[len(options)-1]) > eps {
				options = append(options, ev.angle)
			}
		}
		if !ev.right {
			if active[ev.idx] == 0 {
				total++
			}
			active[ev.idx]++
		}
	}

	cost := func(angle float64) float64 {
		left, right := 1e9, -1e9
		for _, s := range a {
			lt := float64(s.xl) + float64(s.y)*angle
			rt := float64(s.xr) + float64(s.y)*angle
			if lt < left {
				left = lt
			}
			if rt > right {
				right = rt
			}
		}
		return right - left
	}

	lo, hi := 0, len(options)-1
	for lo < hi {
		m1 := (lo + hi) / 2
		if cost(options[m1]) < cost(options[m1+1]) {
			hi = m1
		} else {
			lo = m1 + 1
		}
	}

	fmt.Fprintf(io, "%.10f\n", cost(options[hi]))
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}


You are given a book with $$$n$$$ chapters.Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list.Currently you don't understand any of the chapters. You are going to read the book from the beginning till the end repeatedly until you understand the whole book. Note that if you read a chapter at a moment when you don't understand some of the required chapters, you don't understand this chapter.Determine how many times you will read the book to understand every chapter, or determine that you will never understand every chapter no matter how many times you read the book.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of chapters. Then $$$n$$$ lines follow. The $$$i$$$-th line begins with an integer $$$k_i$$$ ($$$0 \le k_i \le n-1$$$) — number of chapters required to understand the $$$i$$$-th chapter. Then $$$k_i$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i, k_i}$$$ ($$$1 \le a_{i, j} \le n, a_{i, j} \ne i, a_{i, j} \ne a_{i, l}$$$ for $$$j \ne l$$$) follow — the chapters required to understand the $$$i$$$-th chapter. It is guaranteed that the sum of $$$n$$$ and sum of $$$k_i$$$ over all testcases do not exceed $$$2\cdot10^5$$$.

For each test case, if the entire book can be understood, print how many times you will read it, otherwise print $$$-1$$$.

NoteIn the first example, we will understand chapters $$$\{2, 4\}$$$ in the first reading and chapters $$$\{1, 3\}$$$ in the second reading of the book.In the second example, every chapter requires the understanding of some other chapter, so it is impossible to understand the book.In the third example, every chapter requires only chapters that appear earlier in the book, so we can understand everything in one go.In the fourth example, we will understand chapters $$$\{2, 3, 4\}$$$ in the first reading and chapter $$$1$$$ in the second reading of the book.In the fifth example, we will understand one chapter in every reading from $$$5$$$ to $$$1$$$.

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Node struct {
	edges []int
	count int
}

type Graph []Node

func NewGraph(nodes int) Graph {
	return make(Graph, nodes)
}

func (g Graph) addEdge(a, b int) {
	g[a].edges = append(g[a].edges, b)
	g[b].count++
}

func topoSort(g Graph) ([]int, bool) {
	q := []int{}
	for i := 0; i < len(g); i++ {
		if g[i].count <= 0 {
			q = append(q, i)
		}
	}

	for i := 0; i < len(q); i++ {
		node := q[i]
		for _, next := range g[node].edges {
			g[next].count--
			if g[next].count == 0 {
				q = append(q, next)
			}
		}
	}

	if len(q) < len(g) {
		return nil, false
	}
	return q, true
}

func solve(g Graph) int {
	order, exists := topoSort(g)
	if !exists {
		return -1
	}

	time := make([]int, len(g))
	for _, node := range order {
		for _, next := range g[node].edges {
			nextTime := time[node]
			if next < node {
				nextTime++
			}

			if nextTime > time[next] {
				time[next] = nextTime
			}
		}
	}

	res := 0
	for _, t := range time {
		if t > res {
			res = t
		}
	}
	return res+1
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		n := stdin.Int()
		graph := NewGraph(n)
		for j := 0; j < n; j++ {
			k := stdin.Int()
			for _, node := range stdin.Ints(k) {
				graph.addEdge(node-1, j)
			}
		}
		fmt.Println(solve(graph))
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
type hp struct{ sort.IntSlice }
func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]int, n)
		d := make([]int, n)
		h := hp{}
		for w := range d {
			Fscan(in, &d[w])
			for i := 0; i < d[w]; i++ {
				Fscan(in, &v)
				g[v-1] = append(g[v-1], w)
			}
			if d[w] == 0 {
				h.IntSlice = append(h.IntSlice, w)
			}
		}
		ans, c := 0, 0
		for nxt := []int{}; h.Len() > 0; nxt = nil {
			for h.Len() > 0 {
				c++
				v := heap.Pop(&h).(int)
				for _, w := range g[v] {
					if d[w]--; d[w] == 0 {
						if w > v {
							heap.Push(&h, w)
						} else {
							nxt = append(nxt, w)
						}
					}
				}
			}
			h.IntSlice = nxt
			heap.Init(&h)
			ans++
		}
		if c < n {
			ans = -1
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type hp struct{ sort.IntSlice }
func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]int, n)
		d := make([]int, n)
		h := hp{}
		for w := range d {
			Fscan(in, &d[w])
			for i := 0; i < d[w]; i++ {
				Fscan(in, &v)
				g[v-1] = append(g[v-1], w)
			}
			if d[w] == 0 {
				h.IntSlice = append(h.IntSlice, w)
			}
		}
		ans, c := 0, 0
		for nxt := []int{}; h.Len() > 0; nxt = nil {
			for h.Len() > 0 {
				c++
				v := heap.Pop(&h).(int)
				for _, w := range g[v] {
					if d[w]--; d[w] == 0 {
						if w > v {
							heap.Push(&h, w)
						} else {
							nxt = append(nxt, w)
						}
					}
				}
			}
			for _, v := range nxt {
				heap.Push(&h, v)
			}
			ans++
		}
		if c < n {
			ans = -1
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]int, n)
		d := make([]int, n)
		var cur, nxt []int
		for w := range d {
			Fscan(in, &d[w])
			for i := 0; i < d[w]; i++ {
				Fscan(in, &v)
				g[v-1] = append(g[v-1], w)
			}
			if d[w] == 0 {
				cur = append(cur, w)
			}
		}
		ans, c := 0, 0
		for len(cur) > 0 {
			for len(cur) > 0 {
				c++
				v, cur = cur[0], cur[1:]
				for _, w := range g[v] {
					if d[w]--; d[w] == 0 {
						if w > v {
							cur = append(cur, w)
						} else {
							nxt = append(nxt, w)
						}
					}
				}
			}
			cur, nxt = nxt, nil
			ans++
		}
		if c < n {
			ans = -1
		}
		Fprintln(out, ans)
	}
}

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


You are given an array $$$a$$$ of $$$n$$$ integers and an integer $$$s$$$. It is guaranteed that $$$n$$$ is odd.In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to $$$s$$$.The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array $$$6, 5, 8$$$ is equal to $$$6$$$, since if we sort this array we will get $$$5, 6, 8$$$, and $$$6$$$ is located on the middle position.

The first line contains two integers $$$n$$$ and $$$s$$$ ($$$1\le n\le 2\cdot 10^5-1$$$, $$$1\le s\le 10^9$$$) — the length of the array and the required value of median. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1\le a_i \le 10^9$$$) — the elements of the array $$$a$$$. It is guaranteed that $$$n$$$ is odd.

In a single line output the minimum number of operations to make the median being equal to $$$s$$$.

NoteIn the first sample, $$$6$$$ can be increased twice. The array will transform to $$$8, 5, 8$$$, which becomes $$$5, 8, 8$$$ after sorting, hence the median is equal to $$$8$$$.In the second sample, $$$19$$$ can be increased once and $$$15$$$ can be increased five times. The array will become equal to $$$21, 20, 12, 11, 20, 20, 12$$$. If we sort this array we get $$$11, 12, 12, 20, 20, 20, 21$$$, this way the median is $$$20$$$.

package main

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

// fmt.Scanf ???

func main() {
	in := bufio.NewReader(os.Stdin)
	var s, n int
	const maxn int = 200000
	fmt.Fscanf(in, "%d %d\n", &n, &s)
	var a [] int = make([]int, n, n)
	for i:=0; i<n; i++ {
		if i == 0 {
			fmt.Fscanf(in, "%d", &a[i])
		} else {
			fmt.Fscanf(in, " %d", &a[i])
		}

	}

	sort.Ints(a)
	var mid_place int = n / 2
	var sum int64 = 0
	if a[mid_place] <= s {
		for i:=mid_place; i<n; i++ {
			if a[i] >= s {
				break
			}
			sum = sum + int64(s - a[i])
		}
	} else {
		for i:=mid_place; i>=0; i-- {
			if a[i] <= s {
				break
			}
			sum = sum + int64(a[i] - s)
		}
	}

	fmt.Println(sum)
}

package main

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

const N = 200011
const inf = 2000000000
// Runs MergeSort algorithm on a slice single
func MergeSort(slice []int) []int {

	if len(slice) < 2 {
		return slice
	}
	mid := (len(slice)) / 2
	return Merge(MergeSort(slice[:mid]), MergeSort(slice[mid:]))
}

// Merges left and right slice into newly created slice
func Merge(left, right []int) []int {

	size, i, j := len(left)+len(right), 0, 0
	slice := make([]int, size, size)

	for k := 0; k < size; k++ {
		if i > len(left)-1 && j <= len(right)-1 {
			slice[k] = right[j]
			j++
		} else if j > len(right)-1 && i <= len(left)-1 {
			slice[k] = left[i]
			i++
		} else if left[i] < right[j] {
			slice[k] = left[i]
			i++
		} else {
			slice[k] = right[j]
			j++
		}
	}
	return slice
}
func main() {
	in := bufio.NewReader(os.Stdin)
	large := make([]int, N, N)
	small := make([]int, N, N)
	for i := 0; i < N; i++ {
		large[i] = inf
		small[i] = inf
	}
	var n, s int
	//fmt.Scan(&n, &s)
	fmt.Fscanf(in, "%d %d\n", &n, &s)
	c, l := 0, 0
	for i := 0; i < n; i++ {
		var x int
		if(i == 0) {
			fmt.Fscanf(in, "%d", &x)
		} else {
			fmt.Fscanf(in, " %d", &x)
		}
		//fmt.Scan(&x)
		if x < s {
			small[c] = x
			c ++
		} else if x > s {
		//	large = append(large, x)
			large[l] = x
			l ++
		}
	}
	x := n / 2 + 1
	var res int64
	res = 0
	if c >= x {
		small = MergeSort(small)
		for i := c - 1; i > x - 2; i -- {
			res += (int64) (s - small[i])
		}

	}
	if l >= x {
		large = MergeSort(large)
		for i, j := 0, l - 1; i < j; i, j = i + 1, j - 1 {
			large[i], large[j] = large[j], large[i]
		}
		for i := l - 1; i > x - 2; i -- {
			res += (int64) (large[i] - s)
		}
	}
	fmt.Println(res)
}

package main

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

const N = 200011
const inf = 2000000000
// Runs MergeSort algorithm on a slice single
func MergeSort(slice []int) []int {

	if len(slice) < 2 {
		return slice
	}
	mid := (len(slice)) / 2
	return Merge(MergeSort(slice[:mid]), MergeSort(slice[mid:]))
}

// Merges left and right slice into newly created slice
func Merge(left, right []int) []int {

	size, i, j := len(left)+len(right), 0, 0
	slice := make([]int, size, size)

	for k := 0; k < size; k++ {
		if i > len(left)-1 && j <= len(right)-1 {
			slice[k] = right[j]
			j++
		} else if j > len(right)-1 && i <= len(left)-1 {
			slice[k] = left[i]
			i++
		} else if left[i] < right[j] {
			slice[k] = left[i]
			i++
		} else {
			slice[k] = right[j]
			j++
		}
	}
	return slice
}
func main() {
	in := bufio.NewReader(os.Stdin)
	large := make([]int, 0, N)
	small := make([]int, 0, N)
	var n, s int
	//fmt.Scan(&n, &s)
	fmt.Fscanf(in, "%d %d\n", &n, &s)
	c, l := 0, 0
	for i := 0; i < n; i++ {
		var x int
		if(i == 0) {
			fmt.Fscanf(in, "%d", &x)
		} else {
			fmt.Fscanf(in, " %d", &x)
		}
		//fmt.Scan(&x)
		if x < s {
			small = append(small, x)
			c ++
		} else if x > s {
		//	large = append(large, x)
			large = append(large, x)
			l ++
		}
	}
	x := n / 2 + 1
	var res int64
	res = 0
	if c >= x {
		//small = MergeSort(small)
		sort.Ints(small)
		for i := c - 1; i > x - 2; i -- {
			res += (int64) (s - small[i])
		}

	}
	if l >= x {
		//large = MergeSort(large)
		sort.Ints(large)
		for i, j := 0, l - 1; i < j; i, j = i + 1, j - 1 {
			large[i], large[j] = large[j], large[i]
		}
		for i := l - 1; i > x - 2; i -- {
			res += (int64) (large[i] - s)
		}
	}
	fmt.Println(res)
}

package main

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

func main()  {

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

	var n int
	var s int64
	fmt.Fscan(in, &n, &s)

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

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

	lessPos, greaterPos := -1, n
	for i := 0; i < n; i++ {
		if arr[i] < s {
			lessPos = i
		}
		if arr[i] > s && greaterPos == n {
			greaterPos = i
		}
	}

	sum := int64(0)
	for i := n / 2; i <= lessPos; i++ {
		sum += s - arr[i]
	}

	for i := greaterPos; i <= n / 2; i++ {
		sum += arr[i] - s
	}
	fmt.Fprintln(out, sum)

}

package main

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

const inf = 2000000000

var large [200011]int
var small [200011]int
var _tmp [200011]int

func _sort(st, ed int, s []int) {
	// fmt.Println(st, ed, len(s))
	if ed-st < 1 {
		return
	}

	var mid int
	mid = (st + ed) / 2
	_sort(st, mid, s[:])
	_sort(mid+1, ed, s[:])
	for l, r, _idx := st, mid+1, 0; l <= mid || r <= ed; _idx++ {
		if l <= mid && r <= ed {
			if s[l] < s[r] {
				_tmp[_idx] = s[l]
				l++
			} else {
				_tmp[_idx] = s[r]
				r++
			}
		} else if l <= mid {
			_tmp[_idx] = s[l]
			l++
		} else if r <= ed {
			_tmp[_idx] = s[r]
			r++
		}
	}
	// fmt.Println(_tmp[:ed-st+1])
	for i, _idx := st, 0; i <= ed; i, _idx = i+1, _idx+1 {
		s[i] = _tmp[_idx]
	}
	return
}

func main() {

	// x := []int{1, 9, 3, 4, 10, 6, 7, 8, 5, 2}
	// _sort(0, len(x)-1, x[0:len(x)])
	// fmt.Println(x)
	in := bufio.NewReader(os.Stdin)
	var n, s int
	// fmt.Scan(&n, &s)

	fmt.Fscanf(in, "%d %d\n", &n, &s)

	// fmt.Println(n, s)
	c, l := 0, 0
	var x int
	for i := 0; i < n; i++ {
		// fmt.Scan(&x)
		if i == 0 {
			fmt.Fscanf(in, "%d", &x)
		} else {
			fmt.Fscanf(in, " %d", &x)
		}
		// fmt.Println(x)
		if x < s {
			small[c] = x
			c++
		} else if x > s {
			large[l] = x
			l++
		}
	}

	x = n/2 + 1
	var res int64
	res = 0

	if c >= x {
		_sort(0, c-1, small[0:c])
		for i := c - 1; i > x-2; i-- {
			res += (int64)(s - small[i])
		}

	}
	if l >= x {
		_sort(0, l-1, large[0:l])
		for i, j := 0, l-1; i < j; i, j = i+1, j-1 {
			large[i], large[j] = large[j], large[i]
		}
		for i := l - 1; i > x-2; i-- {
			res += (int64)(large[i] - s)
		}
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
	"sort"
)

const N = 200010
var small, large [N] int
func main() {
	var n, s int
	c , l := 0, 0
	fmt.Scan(&n, &s)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		if x < s {
			small[c] = x
			c ++
		} else if x > s {
			large[l] = x
			l ++
		}
	}
	x := n / 2 + 1
	//fmt.Println("x is", x)
	var res int64
	res = 0
	//fmt.Println(c, l)
	if c >= x {
		sml := small[0 : c]
		sort.Ints(sml)
		for i := c - 1; i > x - 2; i -- {
			//fmt.Println(s - sml[i])
			res += (int64) (s - sml[i])
		}

	}
	if l >= x {
		var lrg []int = large[0 : l]
		//sort.Ints(lrg)
		k := l
		i := 0
		for k >= x {
			res += (int64) ( lrg[i] - s)
			k -= 1
			i += 1
		}
	}
	fmt.Println(res)
}

package main

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

func main()  {

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

	var n int
	var s int64
	fmt.Fscan(in, &n, &s)

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

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

	lessPos, greaterPos := 0, n
	for i := 0; i < n; i++ {
		if arr[i] < s {
			lessPos = i
		}
		if arr[i] > s && greaterPos == -1 {
			greaterPos = i
		}
	}

	sum := int64(0)
	for i := n / 2; i <= lessPos; i++ {
		sum += s - arr[i]
	}

	for i := greaterPos; i <= n / 2; i++ {
		sum += arr[i] - s
	}
	fmt.Fprintln(out, sum)

}


A telephone number is a sequence of exactly $$$11$$$ digits such that its first digit is 8.Vasya and Petya are playing a game. Initially they have a string $$$s$$$ of length $$$n$$$ ($$$n$$$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $$$s$$$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).

The first line contains one integer $$$n$$$ ($$$13 \le n < 10^5$$$, $$$n$$$ is odd) — the length of string $$$s$$$. The second line contains the string $$$s$$$ ($$$|s| = n$$$) consisting only of decimal digits.

If Vasya has a strategy that guarantees him victory, print YES. Otherwise print NO.

NoteIn the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all.

package main

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

func solve(j Jam) {
	n, s := j.Int(), []rune(j.Str())
	eights := int64(0)
	for i := int64(0); i+10 < n; i++ {
		if s[i] == '8' {
			eights += 1
		}
	}
	toDelete := n - 11
	moves := toDelete / 2
	petyaDeletesAllEights := eights <= moves
	vasyaDeletesAllNonEights := (toDelete - eights) <= moves
	if vasyaDeletesAllNonEights && !petyaDeletesAllEights {
		j.P("YES\n")
	} else {
		j.P("NO\n")
	}
}

func main() {
	jam, closeFunc := JamNew()
	defer closeFunc()
	solve(jam)
}

type Jam interface {
	Scanner() *bufio.Scanner
	Writer() *bufio.Writer
	Close()

	Str() string
	Int() int64
	Float() float64

	P(format string, values ...interface{})
	PF(format string, values ...interface{})
}

func JamNew() (Jam, func()) {
	if len(os.Args) > 1 {
		panic("running with input file path is not supported")
	}

	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

	var writer = bufio.NewWriter(os.Stdout)
	jam := &jam{scanner, writer}
	return jam, jam.Close
}

type jam struct {
	sc *bufio.Scanner
	wr *bufio.Writer
}

func (j *jam) Close() {
	if err := j.wr.Flush(); err != nil {
		panic(err)
	}
}

func (j *jam) Scanner() *bufio.Scanner {
	return j.sc
}

func (j *jam) Writer() *bufio.Writer {
	return j.wr
}

func (j *jam) Str() string {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	return j.sc.Text()
}

func (j *jam) Int() int64 {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(j.sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}

	return res
}

func (j *jam) Float() float64 {
	j.sc.Scan()
	res, err := strconv.ParseFloat(j.sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (j *jam) P(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
}

func (j *jam) PF(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
	if err = j.wr.Flush(); err != nil {
		panic(err)
	}
}

//	GoLang shorthand methods for math go below
//	TODO wipe unused methods before submitting

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

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

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

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

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

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

package main

import (
	"fmt"
)

func main() {
	len, s := 0, ""
	fmt.Scanf("%d\n%s", &len, &s)

	turns := (len - 11) / 2
	vasya, petya := turns, turns

	for i := 0; i < len; i++ {
		val := s[i]

		// petya has moves to remove the 8
		if val == '8' {
			petya--
			if petya < 0 {
				fmt.Println("YES")
				return
			}
			continue
		}

		// vasya must remove non-8
		vasya--
		if vasya < 0 {
			fmt.Println("NO")
			return
		}
	}
}


You're given an array $$$a$$$ of length $$$2n$$$. Is it possible to reorder it in such way so that the sum of the first $$$n$$$ elements isn't equal to the sum of the last $$$n$$$ elements?

The first line contains an integer $$$n$$$ ($$$1 \le n \le 1000$$$), where $$$2n$$$ is the number of elements in the array $$$a$$$. The second line contains $$$2n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{2n}$$$ ($$$1 \le a_i \le 10^6$$$) — the elements of the array $$$a$$$.

If there's no solution, print "-1" (without quotes). Otherwise, print a single line containing $$$2n$$$ space-separated integers. They must form a reordering of $$$a$$$. You are allowed to not change the order.

NoteIn the first example, the first $$$n$$$ elements have sum $$$2+1+3=6$$$ while the last $$$n$$$ elements have sum $$$1+1+2=4$$$. The sums aren't equal.In the second example, there's no solution.

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, 2*n)
	for i := 0; i < 2*n; i++ {
		fmt.Scan(&a[i])
	}
	b := a[:]
	sort.Ints(b)
	if a[0] == a[2*n-1] {
		fmt.Println(-1)
		return
	}
	for i := 0; i < 2*n-1; i++ {
		fmt.Printf("%v ", a[i])
	}
	fmt.Printf("%v\n", a[2*n-1])
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n , x int
	fmt.Fscan(in,&n)
	a := make([]int,0)
	for i := 0 ; i < 2 * n ;i ++{
		fmt.Fscan(in,&x)
		a = append(a,x)
	}
	sort.Ints(a)
	var left,right int
	for i := 0 ; i <  n ;i ++{
		left += a[i]
	}
	for i := n  ;i < 2 * n ;i ++{
		right += a[i]
	}
	if(left != right){
		for i := 0 ;i  < 2 * n;i++{
			fmt.Fprint(out,a[i]," ")
		}
		return
	}
	fmt.Fprint(out,-1)

}

package main

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

func swap(a, b []int32) bool {
	for i, v := range a {
		if v != b[0] {
			b[0], a[i] = a[i], b[0]
			return true
		}
	}
	for i, v := range b {
		if v != a[0] {
			a[0], b[i] = b[i], a[0]
			return true
		}
	}
	return false
}

func (io *IO) Solve() {
	n := io.Int()
	arr0 := make([]int32, n)
	var sum0 int32
	for i := 0; i < n; i++ {
		arr0[i] = io.Int32()
		sum0 += arr0[i]
	}
	arr1 := make([]int32, n)
	var sum1 int32
	for i := 0; i < n; i++ {
		arr1[i] = io.Int32()
		sum1 += arr1[i]
	}
	if sum0 == sum1 {
		if !swap(arr0, arr1) {
			io.Print("-1\n")
			return
		}
	}
	for _, v := range arr0 {
		io.Printf("%v ", v)
	}
	for _, v := range arr1 {
		io.Printf("%v ", v)
	}
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	n *= 2
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")
	sort.Ints(a)
	if a[0] == a[n-1] {
		fmt.Fprintf(out, "%d\n", -1)
		return
	}
	for i := 0; i < n-1; i++ {
		fmt.Fprintf(out, "%d ", a[i])
	}
	fmt.Fprintf(out, "%d\n", a[n-1])

	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

package main

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

func main() {
	reader := getReader()
	for reader.Scan() {
		halfSize, _ := strconv.Atoi(reader.Text())
		reader.Scan()
		vals := strings.Split(reader.Text(), " ")
		arr := make([]int, halfSize*2)
		for i, v := range vals {
			val, _ := strconv.Atoi(v)
			arr[i] = val
		}
		//sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
		sort.Ints(arr)
		var first, second int

		for i := 0; i < halfSize; i++ {
			first = first + arr[i]
		}

		for i := halfSize; i < len(arr); i++ {
			second = second + arr[i]
		}
		if second != first {
			//print array
			for _, v := range arr {
				fmt.Print(v)
				fmt.Print(" ")
			}
		} else {
			//print -1
			fmt.Println(-1)
		}
		//fmt.Println(arr)
		//fmt.Println(first)
		//fmt.Println(second)
	}
}

func getReader() *bufio.Scanner {
	if isOnline() {
		return bufio.NewScanner(os.Stdin)
	}
	file, _ := os.Open("data.txt")
	return bufio.NewScanner(file)
}

func isOnline() bool {
	env := os.Getenv("ONLINE_JUDGE")
	return env != "false"
}

package main

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

func main() {
	var t int
	lastVal := -1
	can := false
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	fmt.Scanf("%d", &t)
	arr := make([]int, 2*t)
	for i := 0; i < 2*t; i++ {
		scanner.Scan()
		arr[i], _ = strconv.Atoi(scanner.Text())
		if lastVal >= 0 && lastVal != arr[i] {
			can = true
		}
		lastVal = arr[i]
	}
	if can {
		sort.Ints(arr)
		for i:=0;i<2*t ;i++  {
			fmt.Printf("%d ",arr[i])
		}
	} else {
		fmt.Println(-1)
	}
}

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

package main

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

type Solution struct {
	Exists bool
	Array  []int
}

func sum(a []int) int {
	total := 0
	for _, elem := range a {
		total += elem
	}
	return total
}

func Solve(n int, a []int) Solution {
	sort.Ints(a)
	if sum(a[:n]) == sum(a[n:]) {
		return Solution{Exists: false, Array: []int{}}
	}
	return Solution{Exists: true, Array: a}
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, 2*n)
	for i := 0; i < 2*n; i++ {
		fmt.Fscanf(reader, "%d ", &a[i])
	}

	solution := Solve(n, a)
	if !solution.Exists {
		fmt.Fprintf(writer, "-1\n")
	} else {
		for _, elem := range solution.Array {
			fmt.Fprintf(writer, "%d ", elem)
		}
		fmt.Fprintf(writer, "\n")
	}
}


You are given an array $$$a_1, a_2, \dots, a_n$$$, consisting of $$$n$$$ integers. You are also given an integer value $$$x$$$.Let $$$f(k)$$$ be the maximum sum of a contiguous subarray of $$$a$$$ after applying the following operation: add $$$x$$$ to the elements on exactly $$$k$$$ distinct positions. An empty subarray should also be considered, it has sum $$$0$$$.Note that the subarray doesn't have to include all of the increased elements.Calculate the maximum value of $$$f(k)$$$ for all $$$k$$$ from $$$0$$$ to $$$n$$$ independently.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of testcases. The first line of the testcase contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 5000$$$; $$$0 \le x \le 10^5$$$) — the number of elements in the array and the value to add. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^5 \le a_i \le 10^5$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$5000$$$.

For each testcase, print $$$n + 1$$$ integers — the maximum value of $$$f(k)$$$ for all $$$k$$$ from $$$0$$$ to $$$n$$$ independently.

NoteIn the first testcase, it doesn't matter which elements you add $$$x$$$ to. The subarray with the maximum sum will always be the entire array. If you increase $$$k$$$ elements by $$$x$$$, $$$k \cdot x$$$ will be added to the sum.In the second testcase:   For $$$k = 0$$$, the empty subarray is the best option.  For $$$k = 1$$$, it's optimal to increase the element at position $$$3$$$. The best sum becomes $$$-1 + 5 = 4$$$ for a subarray $$$[3, 3]$$$.  For $$$k = 2$$$, it's optimal to increase the element at position $$$3$$$ and any other element. The best sum is still $$$4$$$ for a subarray $$$[3, 3]$$$.  For $$$k = 3$$$, you have to increase all elements. The best sum becomes $$$(-2 + 5) + (-7 + 5) + (-1 + 5) = 5$$$ for a subarray $$$[1, 3]$$$.

package main

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

/*

 */

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

	a := make([]int, n)
	prefixSum := make([]int64, n)

	for i := range a {
		scanf("%d", &a[i])
		prefixSum[i] = int64(a[i])
		if i > 0 {
			prefixSum[i] += prefixSum[i-1]
		}
	}
	scanf("\n")

	lenToMaxSum := make([]int64, n+1)

	for l := 1; l <= n; l++ {
		lenToMaxSum[l] = int64(minInt)

		for i := 0; i <= n-l; i++ {
			sum := prefixSum[i+l-1] - prefixSum[i] + int64(a[i])

			if sum > lenToMaxSum[l] {
				lenToMaxSum[l] = sum
			}
		}
	}

	for k := 0; k <= n; k++ {
		maxFk := int64(0)

		for l, maxSum := range lenToMaxSum {
			maxFk = max(maxFk, maxSum+int64(min(k, l))*int64(x))
		}

		fmt.Fprintf(writer, "%d ", maxFk)
	}
	fmt.Fprintln(writer)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func findSet(parent []int, v int) int {
	if v == parent[v] {
		return v
	}

	parent[v] = findSet(parent, parent[v])

	return parent[v]
}

//goland:noinspection GoUnusedFunction
func unionSets(parent []int, v, u int) {
	v = findSet(parent, v)
	u = findSet(parent, u)

	if v != u {
		parent[v] = u
	}
}

package main

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

func solve(x int, arr []int) {
	prefix := make([]int, len(arr)+1)
	for i := range arr {
		prefix[i+1] = prefix[i] + arr[i]
	}
	// key: k, value: the index of the end subarray has maximum sum
	dp := make(map[int]int)
	dp[0] = 0
	for i := 1; i <= len(arr); i++ {
		dp[i] = prefix[i] - prefix[0]
		for j := i; j <= len(arr); j++ {
			dp[i] = int(math.Max(float64(dp[i]), float64(prefix[j]-prefix[j-i])))
		}
	}
	mxSoFar := 0
	for k := 0; k <= len(arr); k++ {
		ans := dp[0]
		for j := k; j <= len(arr); j++ {
			if j == 0 {
				continue
			}
			ans = int(math.Max(float64(ans), float64(dp[j]+k*x)))
		}
		mxSoFar = int(math.Max(float64(mxSoFar), float64(ans)))
		fmt.Printf("%d ", mxSoFar)
	}
	fmt.Println()
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		N, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		arr := make([]int, N)
		for j := 0; j < N; j++ {
			scanner.Scan()
			arr[j], _ = strconv.Atoi(scanner.Text())
		}
		solve(k, arr)
	}

}

package main

import "fmt"

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

func main() {
	var t int
	fmt.Scan(&t)
	for tt := 0; tt < t; tt++ {
		var n, x, v int
		fmt.Scan(&n, &x)
		res := make([]int, n+1, n+1)
		dp := make([][]int, 2)
		dp[0] = make([]int, 5005, 5005)
		dp[1] = make([]int, 5005, 5005)
		cur := 0
		for i := 1; i <= n; i++ {
			fmt.Scan(&v)
			for k := 0; k <= i; k++ {
				if k != i {
					//fmt.Printf("%d %d\n", dp[cur^1][k], v)
					dp[cur][k] = Max(dp[cur][k], dp[cur^1][k]+v)
				}
				if k > 0 {
					dp[cur][k] = Max(dp[cur][k], dp[cur^1][k-1]+v+x)
				}
				//fmt.Printf("i:%d k:%d val:%d\n", i, k, dp[cur][k])
				res[k] = Max(res[k], dp[cur][k])
			}
			dp[cur^1] = make([]int, 5005, 5005)
			cur ^= 1

		}

		ans := 0
		for d := 0; d <= n; d++ {
			if d != 0 {
				fmt.Print(" ")
			}
			ans = Max(ans, res[d])
			fmt.Printf("%d", ans)
		}
		fmt.Println("")
	}
}

package main

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

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

	var T, n, x, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &x)
		s := make([]int, n+1)
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			s[i+1] = s[i] + v
		}
		mx := make([]int, n+1)
		mx[n] = s[n]
		for l := n - 1; l >= 0; l-- {
			mx[l] = mx[l+1]
			for i := l; i <= n; i++ {
				mx[l] = max(mx[l], s[i]-s[i-l])
			}
		}
		ans := 0
		for i, v := range mx {
			ans = max(ans, v+i*x)
			Fprint(out, ans, " ")
		}
		Fprintln(out)
	}
}

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

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

package main

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

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

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

	c := 0
	fmt.Fscan(in, &c)
	n, x := int64(0), int64(0)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n, &x)
		arr := make([]int64, n)
		prefix := make([]int64, n+1)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
			prefix[i+1] = prefix[i] + arr[i]
		}
		p := make([]int64, n+1)
		for i := range p {
			p[i] = math.MinInt32
		}
		p[0] = 0
		for i := int64(1); i <= n; i++ {
			p[1] = max(p[1], arr[i-1])
			for j := i - 1; j > 0; j-- {
				p[i-j+1] = max(p[i-j+1], prefix[i]-prefix[j-1])
			}
		}
		//dp	dp[i]表示可以替换i个x时候的最大值
		dp := make([]int64, n+1)
		for i := range p { //初始化dp数组dp[0]
			dp[0] = max(dp[0], p[i])
		}
		fmt.Fprint(out, dp[0], " ")
		for i := int64(1); i <= n; i++ {
			dp[i] = dp[i-1]
			tmp := i * x
			for j := i; j <= n; j++ {
				dp[i] = max(dp[i], p[j]+tmp)
			}
			fmt.Fprint(out, dp[i], " ")
		}
		fmt.Fprintln(out)
	}
}

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

package main

import "fmt"

var a, b, c [5005]int

func main() {
	var t, n, m, x, maxn int
	fmt.Scan(&t)
	for cs := 0; cs < t; cs++ {
		fmt.Scan(&n, &m)
		for i := 1; i <= n; i++ {
			b[i] = -0x3f3f3f3f
			maxn = -0x3f3f3f3f
		}
		for i := 1; i <= n; i++ {
			fmt.Scan(&x)
			a[i] = 0
			for j := 1; j <= i; j++ {
				a[j] += x
				b[i-j+1] = max(b[i-j+1], a[j])
			}
		}
		for i := n; i >= 0; i-- {
			maxn = max(maxn, b[i])
			c[i] = maxn + m*i
		}
		for i := 1; i <= n; i++ {
			c[i] = max(c[i], c[i-1])
		}
		for i := 0; i <= n; i++ {
			fmt.Printf("%d ", c[i])
		}
		fmt.Printf("\n")
	}
}
func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}


The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him.Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size:   the size he wanted, if he specified one size;  any of the two neibouring sizes, if he specified two sizes. If it is possible, the program should find any valid distribution of the t-shirts.

The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000. The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants. The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring.

If it is not possible to present a t-shirt to each participant, print «NO» (without quotes). Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input. If there are multiple solutions, print any of them.

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

var shirtSizes = []string{"S", "M", "L", "XL", "XXL", "XXXL"}

func getId(s string) int {
	for i := 0; i < len(shirtSizes); i++ {
		if shirtSizes[i] == s {
			return i
		}
	}
	return -1
}

func no() {
	fmt.Fprintf(bufout, "NO\n")
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	cnt := make([]int, 6)
	for i := 0; i < 6; i++ {
		fmt.Fscanf(bufin, "%d\n", &cnt[i])
	}

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

	res := make([]string, n)
	pos := make([][]int, 5)
	var cs string

	for i := 0; i < n; i++ {
		fmt.Fscanf(bufin, "%s\n", &cs)

		ss := strings.Split(cs, ",")
		id := getId(ss[0])

		if len(ss) == 1 {
			if cnt[id] > 0 {
				res[i] = ss[0]
				cnt[id]--
			} else {
				no()
				return
			}
		} else {
			pos[id] = append(pos[id], i)
		}
	}

	for i := 0; i < 5; i++ {
		l := len(pos[i])
		for j := 0; j < l; j++ {
			p := pos[i][j]
			if cnt[i] > 0 {
				res[p] = shirtSizes[i]
				cnt[i]--
			} else if cnt[i+1] > 0 {
				res[p] = shirtSizes[i+1]
				cnt[i+1]--
			} else {
				no()
				return
			}
		}
	}

	fmt.Fprintf(bufout, "YES\n")
	for i := 0; i < n; i++ {
		fmt.Fprintf(bufout, "%s\n", res[i])
	}
}

package main

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

var scanner *bufio.Scanner

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

func display(a []int) {
  fmt.Printf("%d", a[0])
  for i := 1; i < len(a); i++ {
    fmt.Printf(" %d", a[i])
  }
  fmt.Printf("\n")
}

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

  names := []string{ "S", "M", "L", "XL", "XXL", "XXXL" }
  namePos := map[string]int{}
  for i, name := range names {
    namePos[name] = i
  }
  counts := make([]int, 6)
  for i := range counts {
    counts[i] = getI()
  }
  pending := make([][]int, 5)
  for i := range pending {
    pending[i] = []int{}
  }
  n := getI()
  shirts := make([]string, n)
  for i := 0; i < n; i++ {
    s := getS()
    parts := strings.Split(s, ",")
    if len(parts) == 1 {
      name := parts[0]
      shirts[i] = name
      counts[namePos[name]]--
    } else {
      pos := namePos[parts[0]]
      pending[pos] = append(pending[pos], i)
    }
  }
  //display(counts)
  okay := true
  for i := range pending {
    for j := i; j <= i + 1; j++ {
      name := names[j]
      for len(pending[i]) > 0 && counts[j] > 0 {
        shirts[pending[i][0]] = name
        pending[i] = pending[i][1:]
        counts[j]--
      }
    }
    if len(pending[i]) > 0 || counts[i] < 0 {
      okay = false
      break
    }
  }
  //display(counts)
  if counts[5] < 0 {
    okay = false
  }
  if !okay {
    writer.WriteString("NO\n")
  } else {
    writer.WriteString("YES\n")
    for _, name := range shirts {
      writer.WriteString(fmt.Sprintf("%s\n", name))
    }
  }
}

package main

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

var sizes = []string{"S", "M", "L", "XL", "XXL", "XXXL"}

func main() {
	var counts [6]int

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	for i, x := range strings.Split(scanner.Text(), " ") {
		counts[i], _ = strconv.Atoi(x)
	}

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	result := make([]string, n)
	tmpShirts := make([]int, n)
	for i := range tmpShirts {
		tmpShirts[i] = -1
	}
	possible := true
	for i := 0; i < n; i++ {
		scanner.Scan()
		splits := strings.Split(scanner.Text(), ",")
		if len(splits) == 1 {
			sizeIndex := getIndex(splits[0])
			counts[sizeIndex]--
			if counts[sizeIndex] < 0 {
				possible = false
				break
			}
			result[i] = splits[0]
		} else {
			tmpShirts[i] = getIndex(splits[0])
		}
	}

	for i := 0; i < 5; i++ {
		for j := 0; j < n; j++ {
			if tmpShirts[j] == i {
				if counts[i] > 0 {
					counts[i]--
					result[j] = sizes[i]
				} else if counts[i+1] > 0 {
					counts[i+1]--
					result[j] = sizes[i+1]
				} else {
					possible = false
					break
				}
			}
		}
	}

	if possible {
		fmt.Println("YES")
		for _, s := range result {
			fmt.Println(s)
		}
	} else {
		fmt.Println("NO")
	}
}

func getIndex(s string) int {
	for i, x := range sizes {
		if x == s {
			return i
		}
	}
	return 0
}