← Home
package main

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

type Bowl struct {
	h float64
	r float64
	R float64
	k float64
}

func phi(b Bowl, x float64) float64 {
	if x <= b.r {
		return 0
	}
	return b.k * (x - b.r)
}

func delta(a, b Bowl) float64 {
	m := a.R
	if b.R < m {
		m = b.R
	}
	res := phi(a, m) - phi(b, m)
	if b.r <= m {
		t := phi(a, b.r)
		if t > res {
			res = t
		}
	}
	if res < 0 {
		return 0
	}
	return res
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	var n int
	fmt.Fscan(in, &n)

	bowls := make([]Bowl, n)
	for i := 0; i < n; i++ {
		var h, r, R int
		fmt.Fscan(in, &h, &r, &R)
		bowls[i] = Bowl{
			h: float64(h),
			r: float64(r),
			R: float64(R),
			k: float64(h) / float64(R-r),
		}
	}

	pos := make([]float64, n)
	ans := bowls[0].h

	for i := 1; i < n; i++ {
		best := 0.0
		for j := 0; j < i; j++ {
			v := pos[j] + delta(bowls[j], bowls[i])
			if v > best {
				best = v
			}
		}
		pos[i] = best
		if best+bowls[i].h > ans {
			ans = best + bowls[i].h
		}
	}

	out := bufio.NewWriterSize(os.Stdout, 1<<20)
	fmt.Fprintf(out, "%.10f\n", ans)
	out.Flush()
}