## COCI '08 Contest 2 #1 Kornislav

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 Specification

The first line contains four positive integers and , the four chosen integers.

#### Output Specificaiton

Output the largest area.

#### Sample Input 1

1 2 3 4

#### Sample Output 1

3

#### Sample Input 2

4 4 3 4

#### Sample Output 2

12

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

• Make steps forward;
• Turn right;
• Make step forward;
• Turn right;
• Make steps forward;
• Turn right;
• Make steps forward.