Temple Build

Time limit3sMemory limit128 MB

Problem

The dwarves are master builders. They discovered that, above ground, the structures most resistant to attack were truncated square pyramids: a square pyramid that does not rise all the way to a point but is instead cut off with a flat square top.

Knowing the height they wanted and the side lengths of the square base at the bottom and at the top, the dwarves fixed the ideal shape of a building. They had three sizes of cubic bricks to work with, and their goal was to maximize the building's volume under the following rules.

The building is assembled from layers. Each layer is a single square made of bricks of one size: a layer built from bricks of side $c$ is an $n \times n$ arrangement of those cubes, so it has height $c$ and a square footprint of side $n \cdot c$. No part of any brick may stick out of the ideal shape, either through the sides or above the top. The finished structure has jagged sides and may be shorter than the ideal shape, but every brick must lie completely inside the ideal design.

The ideal shape's cross-section is a square whose side length changes linearly with height, equal to the bottom base at height $0$ and to the top base at the ideal height, and it is centered on the vertical axis. Layers are stacked contiguously starting from the ground. There is no limit on how many bricks of each size may be used.

Print the maximum total volume that can be achieved.

Input

Each line contains six integers separated by single spaces: the ideal height of the building, the side length of the square base at the bottom, and the side length of the square base at the top (these three are non-negative integers, each at most 1,000,000), followed by the side lengths of the three available cubic bricks (each a non-negative integer at most 10,000). Input continues until end of file.

Output

For each line of input, print on its own line the maximum volume that can be built under the rules.