COCI 2008/2009, Contest #2

Task KORNISLAV

Kornislav the turtle never has anything interesting to do. Since he's going to live for three hundred years, he keeps trying to find way to kill time. This weekend he started playing "enclose the largest rectangle".

To start with, Kornislav needs four positive integers. He tries to enclose a rectangle by moving in one direction, then turning 90 degrees, then walking in the new direction etc. Kornislav makes a total of three 90-degree turns and walks four segments.

When walking in some direction, the number of steps he takes must be equal to one of the four chosen integers and each integer must be used exactly once. Depending on the order in which Kornislav uses the integers, his walk will make various shapes, some of which don't contain enclosed rectangles. Write a program that calculates the largest rectangle the turtle can enclose with its walk.

Input

The first line contains four positive integers A, B, C and D (0 < A, B, C, D < 100), the four chosen integers.

Output

Output the largest area.

Examples

Input

1 2 3 4

Output

3

Input

4 4 3 4

Output

12

In the first example, one possible way for Kornislav to enclose a rectangle of area 3:

  • Make 4 steps forward;
  • Turn right;
  • Make 1 step forward;
  • Turn right;
  • Make 3 steps forward;
  • Turn right;
  • Make 2 steps forward.

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Nov 21, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Is there ANOTHER algorithm for this problem?

can someone answer my question?

Every problem has an algorithm, because an algorithm is defined to be a precisely stated method for solving a precisely stated problem (generally in a finite number of steps). You should not expect to find the magic algorithm for this problem in a book somewhere. Be creative and maybe you'll discover an algorithm that works (yes, there can be multiple correct ways to solve a problem).

they're all 5 liners

and this one is ACTUALLY a FIVE liner

ya lmao i love this problem