Pitch Performance

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

After a recent disaster at the Easter party karaoke, you are working on improving your singing. To gauge how well you are doing, you would like to measure how much the pitch and timing of your singing differs from the target melody you were trying to perform.

We model the melody in a simplified manner as a piecewise-constant function ff, where at time xx the melody has pitch f(x)f(x). In other words from time 00 up to some time x_1x\_1, f(x)f(x) is some constant value y_1y\_1, and then at time x_1x\_1 it changes to some other value y_2y\_2 and remains at that value until some time x_2>x_1x\_2 > x\_1, and so on.

Your voice, on the other hand, is of a more wavering nature, and you may generally not be able to hold an exact constant pitch for any period of time, sometimes breaking off into an unwelcome falsetto and sometimes croaking on those low tones.  The pitch of your voice can be modeled in a highly simplistic way as a piecewise-quadratic function gg. In other words from time 00 up to x_1x\_1 (not necessarily the same x_1x\_1 as for the function ff), your pitch g(x)g(x) agrees with some quadratic polynomial, and then from time x_1x\_1 to x_2x\_2 with some other quadratic polynomial, and so on.

The difference between your performance gg and the target melody ff is the area between these two functions.  See Figure \ref{fig:pitch} for an example.  Given the melody ff and your performance gg, compute their difference.

Illustration of Sample Input 1.  The difference between ff and gg is the area of the shaded region in the figure.

입력

The first line of input contains an integer nn (1n5001 \le n \le 500), the number of pieces in the target melody function ff.  Then follow nn lines describing ff.  The ii'th such line contains two integers x_ix\_i and y_iy\_i (x_i1<x_i104x\_{i-1} < x\_i \le 10^4 and 0y_i1040 \le y\_i \le 10^4).  For all xx in the half-open interval \[x_i1,x_i)\[x\_{i-1}, x\_i), the value of f(x)f(x) equals y_iy\_i.  For the first interval we define x_0=0x\_0 = 0.

Then follows a line containing an integer mm (1m5001 \le m \le 500), the number of pieces in the function gg describing your performance.  The next mm lines contain the description of gg.  The ii'th such line contains four integers x_ix'\_i, a_ia\_i, b_ib\_i and c_ic\_i (x_i1<x_i104x'\_{i-1} < x'\_i \le 10^4 and 107a_i,b_i,c_i107-10^{7} \le a\_i, b\_i, c\_i \le 10^{7}). For all xx in the half-open interval \[x_i1,x_i)\[x'\_{i-1}, x'\_i), the value of g(x)g(x) equals a_ix2+b_ix+c_ia\_ix^2 + b\_ix + c\_i.  For the first interval we define x_0=0x'\_0 = 0.

You may assume that 0g(x)1040 \le g(x) \le 10^4 for all x_0xx_mx'\_0 \le x \le x'\_m and that the two functions end at the same time (i.e., x_n=x_mx\_n = x'\_m).

출력

Output the difference between ff and gg.  Your output should be correct to within an absolute or relative error of at most 10610^{-6}.