Baltic OI '09 P6 - Monument

View as PDF

Submit solution


Points: 17
Time limit: 1.0s
Memory limit: 512M

Problem types
Baltic Olympiad in Informatics: 2009 Day 2, Problem 3

A Swedish millionaire wants to build a monument for her family. The names of all of her known ancestors (and later, her future descendants) will be inscribed to the sides of the monument. The form of the monument will be a rectangular block with a \times a bottom/top squares and height b. That is, the bottom and top of the block will be a \times a squares, and each of the four sides of the monument is an a \times b rectangle. The values of a and b should be such that the four sides have as much space as possible, in order to fit as many names as possible.

The monument will be cut from a very special p \times q \times r rectangular stone block that has been crystallised in a regular cubic form. That is, we may view the stone as being composed of 1 \times 1 \times 1 unit blocks (unit cubes). Also, the final monument will be composed of such unit cubes. The raw stone may only be cut perpendicular to the x-, y- or z-axis, along the borders between unit cubes.

The raw stone contains pores, in the form of empty unit cubes. The monument is required to be of high quality and is thus not allowed to contain any pores (empty unit cubes). You are given a 3D-map of the raw stone. The map describes which unit cubes are normal and which empty. Your task is to find such values for the size parameters a and b of the monument such that:

  1. it is possible to cut the monument out of the supplied raw stone block, and

  2. the monument contains the maximal amount of space on its four sides, that is, the value 4ab is as large as possible.

Input Specification

The first line of input contains three positive space-separated integers: the values p, q and r. This is followed by pq lines, each of which contains r characters (and a new line character, no other white space). Each of the r characters is either N (normal) or P (pore). The z-th character on line 1 + (yp + x - p) corresponds to the unit cube with coordinates (x, y, z) within the raw stone, where 1 \le x \le p, 1 \le y \le q and 1 \le z \le r.

Output Specification

Output one integer on one line, containing the maximal value of 4ab.

Sample Input

3 2 5
PNNNN
PNNNN
NPPNP
PNNNP
NNNNP
PPNNP

Sample Output

24

Constraints

1 \le p, q, r \le 150


Comments

There are no comments at the moment.