Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 3,822 Bytes
7acee6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Come one, come all! The most famous circus troupe in all the land is on tour!
Having just arrived in a new location, they're eager to set up their big top
and showcase world-class acts of acrobatics and comedy for their audience.

Looking at the tent from the side (as a cross section), it will be set up
along a one-dimensional strip of ground. **N** vertical poles will be placed
in the ground, one after another, with the _i_th pole at a position **Xi**
meters to the right of an arbitrary reference point, and reaching a height of
**Hi** meters. No two poles will be at the same position.

After each pole is placed, the shape of the tent will be updated to fit the
current set of poles. In particular, the upper outline of the tent will be a
function with the following properties:

  1. it's defined over all positions from negative infinity to positive infinity 
  2. its height is always non-negative 
  3. it's made up entirely of a series of connected line segments, with each one having a slope with absolute value no greater than 1 (meaning that the function is continuous, and its height may never change from left to right at an angle of more than 45 degrees up/down) 
  4. it doesn't intersect with any of the poles (meaning that, at each pole's position, the function's height must be no smaller than that of the pole) 

The cross-sectional area of the tent is the area under this function. Despite
their popularity, the circus troupe doesn't exactly have money to spare on
tent materials (with most of their budget allocated to feeding their flying
elephant star). As such, they'd like to minimize the cross-sectional area of
their tent after placing each of the **N** poles. They'd like you to calculate
the sum of these **N** minimal areas for them.

In this example, three poles are placed one after another. The first is at X =
20 with height 10. The minimum area of the tent is 100 m2. The second pole is
placed at X = 30 with a height of 15. The minimum area of the tent is now
268.75 m2. The third pole is at X = 24 with a height of 3. This doesn't change
the minimum area of the tent, which is still 268.75 m2.

![]({{PHOTO_ID:1437352136460846}}) ![]({{PHOTO_ID:1162015730825186}})
![]({{PHOTO_ID:262229418531119}})

You're given **X1**, and **X2..N** may then be calculated as follows, using
given constants **Ax**, **Bx**, and **Cx** (note that it is guaranteed that
**X1..N** will be distinct):

**Xi** = ((**Ax** * **Xi-1** \+ **Bx**) % **Cx**) + 1 

Similarly, you're given **H1**, and **H2..N** may then be calculated as
follows, using given constants **Ah**, **Bh**, and **Ch**:

**Hi** = ((**Ah** * **Hi-1** \+ **Bh**) % **Ch**) + 1 

### Input

Input begins with an integer **T**, the number of different tents that the
circus troupe will set up. For each tent, there is first a line containing the
single integer **N**. Then there is a line containing the four space-separated
integers **X1**, **Ax**, **Bx**, and **Cx**. Then there is a line containing
the four space-separated integers **H1**, **Ah**, **Bh**, and **Ch**.

### Output

For the _i_th tent, print a line containing "Case #**i**: " followed by one
real number. This number is the sum of **N** values, the _j_th of which is the
minimum possible cross-sectional area of the tent after poles 1 through _j_
have been placed.

Answers that have a relative error of up to 10-6 will be accepted as correct.

### Constraints

1 ≤ **T** ≤ 150  
1 ≤ **N** ≤ 800,000  
1 ≤ **X1** ≤ 10,000,000  
0 ≤ **Ax**, **Bx** ≤ 10,000,000  
1 ≤ **Cx** ≤ 10,000,000  
1 ≤ **H1** ≤ 100,000  
0 ≤ **Ah**, **Bh** ≤ 100,000  
1 ≤ **Ch** ≤ 100,000  

### Explanation of Sample

In the first case, the cross-sectional areas of the tent after each pole is
erected are 1.0, 1.75, 2.5, 3.25, and 4.0 for a total of 12.50.