You are playing RunEscape. Slayer is an activity where you repeatedly complete tasks of the form "slay $$$x$$$ monsters of type $$$y$$$". You ponder what is the fastest way to train slayer.
There are $$$n$$$ slayer masters you can get tasks from. The $$$i$$$-th slayer master has $$$m_i$$$ tasks they can give you. You know the following information about each task:
You start with 0 slayer points. Calculate $$$e$$$, the maximum possible expected XP gain per minute such that you never go below 0 slayer points, assuming you make all of your choices optimally. See the Note section below for a formal definition of $$$e$$$.
The first line of input contains three integers $$$b$$$ ($$$0\leq b \leq 3\cdot10^4$$$), $$$c$$$ and $$$s$$$ ($$$1\leq c,s \leq 10^4$$$).
The second line of input contains a single integers $$$n$$$ ($$$1\leq n \leq 10^3$$$) — the number of slayer masters. The description of their tasks follows.
The first line for each slayer master contains a single integer $$$m_i$$$ ($$$1 \leq m_i \leq 3\cdot10^4$$$) — the number of tasks the slayer master has.
The following $$$n_i$$$ lines contain three integers $$$f_{ij}$$$, $$$t_{ij}$$$ and $$$e_{ij}$$$ ($$$1 \leq f_{ij}, t_{ij}, e_{ij} \leq 10^4$$$).
It is guaranteed that the sum of all $$$m_i$$$ does not exceed $$$3\cdot10^4$$$.
Print a single floating-point number: $$$e$$$.
Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$$$$\frac{|a-b|}{\max(1,|b|)} \leq 10^{-6}.$$$$$$
0 1 6 2 1 1 1 1 2 1 10 1 1 10 10
7.000000000000
2 1 2 1 4 10 2 1 10 1 1 1 10 1 1 1 10
5.909090909091
We now define $$$e$$$ formally.
Let $$$q$$$ be a natural number. Consider going through the loop for exactly $$$q$$$ iterations. A strategy is a sequence of $$$q$$$ tuples $$$(i_k, B_k, t_k)$$$. The $$$k$$$-th of those tuples describes your actions on the $$$k$$$-th iteration:
Then $$$$$$e = \lim_{q \to \infty} e_q.$$$$$$