FSEATS - Finding Seats

A group of K friends is going to see a movie. However, they are too late to get good tickets, so they are looking for a good way to sit all nearby. Since they are all science students, they decided to come up with an optimization problem instead of going on with informal arguments to decide which tickets to buy.

The movie theater has R rows of C seats each, and they can see a map with the currently available seats marked. They decided that seating close to each other is all that matters, even if that means seating in the front row where the screen is so big it’s impossible to see it all at once. In order to have a formal criteria, they thought they would buy seats in order to minimize the extension of their group.

The extension is defined as the area of the smallest rectangle with sides parallel to the seats that contains all bought seats. The area of a rectangle is the number of seats contained in it. They’ve taken out a laptop and pointed at you to help them find those desired seats.

Input

Each test case will consist on several lines. The first line will contain three positive integers R, C and K as explained above (1 <= R,C <= 300, 1 <= K <= R × C). The next R lines will contain exactly C characters each. The j-th character of the i-th line will be ‘X’ if the j-th seat on the i-th row is taken or ‘.’ if it is available. There will always be at least K available seats in total.

Input is terminated with R = C = K = 0.

Output

For each test case, output a single line containing the minimum extension the group can have.

Example

Input:
3 5 5
...XX
.X.XX
XX...
5 6 6
..X.X.
.XXX..
.XX.X.
.XXX.X
.XX.XX
0 0 0

Output:
6
9

Added by:Camilo Andrés Varela León
Date:2007-12-02
Time limit:0.209s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:The 2007 ACM South American Programming Contest

hide comments
2019-02-02 17:31:27
nice problem
2016-04-19 22:54:43 farhad chowdhury
phew finally after this optimization i got AC
1.petar Bosnjak
2.if the rectangle's value is less than K then break. this is from boba5551 in topcoder forum
2015-11-16 15:53:58 gogo40
There are a O(R^2) solution... You can try to solve this problem firstly: http://www.spoj.com/problems/HISTOGRA/
2015-02-09 14:36:15 Petar Bosnjak
Time limit is too strict...
O(min(R,C)^2*max(R,C)) can't pass
2014-07-25 20:45:21 sasha sami
O(R*R*C) can pass with some optimization
2013-12-27 22:22:06 Alex Abbas
The time limit is unbelievable i tried
switching between O(R*C*C/2) and O(R*R*C/2) with optimized input (I don't know anything faster than getchar_unlocked()) and I get TLE anyawy.
2013-10-30 09:26:31 LeBron
O(R*C*C) works fine.
2011-10-27 13:11:28 Vlade087
The time limit is very strict O(R*C*C) no run in time!!!!!!!!!!!!
2010-06-07 06:10:21 chetan bademi
Does O(R*R*C) pass?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.