#P3361. Cool loves maids

Cool loves maids

Description

Cool has now figured out the layout of the women’s dormitory. The dormitory consists of many buildings, which can be abstracted as a 20×2020\times 20 grid.

The places where Cool’s maids are located can be represented by real-valued coordinates. A maid (x,y)(x, y) is in building (i,j)(i, j) if and only if ix<i+1i \le x < i + 1, jy<j+1j \le y < j + 1, i,jZi, j \in \Z. The distance between two maids is defined if and only if both the row and column indices of one maid’s building are strictly less than those of the other maid’s building; in that case, their distance is the Manhattan distance between their own coordinates.

Now Cool wants to compile a big statistic: compute the sum of all distances among nn maids.

Input Format

To avoid spending too much time on reading due to large input files that cannot be uploaded, this problem uses a data generation scheme.

The input contains two lines:

  • The first line contains an integer nn.
  • The second line contains 66 integers $\mathrm{rxa}, \mathrm{rxc}, \mathrm{rya}, \mathrm{ryc}, \mathrm{rza}, \mathrm{rzc}$.

All real numbers are generated as follows:

  1. Initialize x=y=z=0x = y = z = 0.
  2. Repeat the following process:
    • $x = (y \times \mathrm{rxa} + \mathrm{rxc}) \bmod \mathrm{rp}$;
    • $y = (z \times \mathrm{rya} + \mathrm{ryc}) \bmod \mathrm{rp}$;
    • $z = (x \times \mathrm{rza} + \mathrm{rzc}) \bmod \mathrm{rp}$.

Each time, the real number obtained is $(x \bmod 20) + (y \bmod 10) \div 10 + (z \bmod 10) \div 100$. rp=2333333\mathrm{rp} = 2333333.

The ii-th maid uses the (2i1)(2i - 1)-th generated real number as the xx-coordinate, and the 2i2i-th generated real number as the yy-coordinate.

Output Format

Output a single real number on one line, representing the average of all distances among the nn maids, with 55 decimal places.

6
3 5 7 11 13 17
17.52167

Hint

Constraints

For all testdata, it is guaranteed that 1n5×1061 \le n \le 5 \times 10^6.

Translated by ChatGPT 5