- All Contests
- ProjectEuler+
- Project Euler #212: Combined Volume of Cuboids

# Project Euler #212: Combined Volume of Cuboids

# Project Euler #212: Combined Volume of Cuboids

_{This problem is a programming version of Problem 212 from projecteuler.net}

An *axis-aligned cuboid*, specified by parameters { }, consists of all points such that , , . The volume of the cuboid is the product, . The *combined volume* of a collection of cuboids is the volume of their union and will be less than the sum of the individual volumes if any cuboids overlap.

Let be a collection of axis-aligned cuboids such that has parameters

modulo

modulo

modulo

modulo

modulo

modulo

where come from the "Lagged Fibonacci Generator":

For modulo

For modulo

For example, if and , then has parameters {}, has parameters {}, and so on.

With such , and , the combined volume of the first cuboids, , is .

What is the combined volume of cuboids, ?

**Input Format**

The only line of each test file contains exactly seven space-separated integers: , and .

**Constraints**

**Output Format**

Print exactly one number: the combined volume of cuboids.

**Sample Input 0**

```
53 54 48 257 51 81 2
```

**Sample Output 0**

```
88970
```

**Explanation 0**

With the given and the cuboid has parameters { } and the cuboid has parameters { }.

It is clear that the cuboid is within the boundaries of the cuboid therefore the combined volume of the two cuboids equals to the volume of the second cuboid which is

.

**Sample Input 1**

```
4649 7681 6382 113 75 93 2
```

**Sample Output 1**

```
538384
```

**Explanation 1**

With the given and the cuboid has parameters { } and the cuboid has parameters { }.

With such small cuboid sizes, it is clear that the cuboids have no overlap therefore the combined volume of the two cuboids equals to the sum of their volumes which is

.

**Sample Input 2**

```
10000 10000 10000 399 399 399 100
```

**Sample Output 2**

```
723581599
```

**Explanation 2**

As noted in the problem statement.