The Cuboid Earth Theory

No attempts yetTime limit1sMemory limit128 MB

Problem

Jaehyun has become convinced that the Earth ought to be shaped like a rectangular box. So he carried out a massive project to reshape the Earth into a rectangular cuboid whose edge lengths are x×y×z\ell_x \times \ell_y \times \ell_z. Now every location on the Earth's surface can be described by 3D Cartesian coordinates, and the cuboid occupies the region 0xx0 \le x \le \ell_x, 0yy0 \le y \le \ell_y, 0zz0 \le z \le \ell_z. Jaehyun built his house at the vertex (0,0,0)(0, 0, 0).

Meanwhile, Seungwon's house was forcibly relocated to the coordinates (x,y,z)(x, y, z) by this project. Seungwon's position always lies on one of the six faces of the cuboid.

Jaehyun wants to travel to Seungwon. Since both houses are on the Earth's surface, Jaehyun may move only along the surface of the cuboid; he cannot pass through its interior. Find the length of the shortest path along the surface from (0,0,0)(0, 0, 0) to (x,y,z)(x, y, z).

For example, if x=1\ell_x = 1, y=2\ell_y = 2, z=1\ell_z = 1 and Seungwon is at (1,2,1)(1, 2, 1), the shortest path goes from (0,0,0)(0, 0, 0) through the surface point (1,1,0)(1, 1, 0) to (1,2,1)(1, 2, 1), and its length is 8\sqrt{8}.

Input

The input consists of several test cases. Each test case is given on a single line as six integers x\ell_x, y\ell_y, z\ell_z, xx, yy, zz (1x,y,z10001 \le \ell_x, \ell_y, \ell_z \le 1000). The coordinates (x,y,z)(x, y, z) are guaranteed to lie on one of the six faces of the cuboid. The last line of the input is x=y=z=x=y=z=0\ell_x = \ell_y = \ell_z = x = y = z = 0, and no answer should be printed for it.

Output

For each test case, print on a single line the square of the length of the shortest surface path, as an integer. (The square of the shortest path length is always an integer, so you must print the exact integer value, not an approximation.)