Luxury burrow

Time limit2sMemory limit64 MB

Summary
Find the rectangle of area at least K whose minimum cell price is largest, breaking ties by larger area.
Level

Medium7 of 10

Topics
Binary search, Stack, Matrix
Solved
No attempts yet

Problem

The hobbit Bilbo is worn out from his adventures and has decided to build a new burrow. The hill where he plans to buy land is a rectangle, and it can be written as a table with NN rows and MM columns. Rows and columns are numbered from 1, where row 1 is the topmost row and column 1 is the leftmost column. Each cell of the table is one 1×11 \times 1 piece of land. Hobbits like simple shapes, so Bilbo buys a rectangular plot whose sides are parallel to the sides of the hill. He picks x1x_1, x2x_2, y1y_1, y2y_2 with x1≤x2x_1 \le x_2 and y1≤y2y_1 \le y_2, then buys every cell (x,y)(x, y) with x1≤x≤x2x_1 \le x \le x_2 and y1≤y≤y2y_1 \le y \le y_2.

After his adventures Bilbo is rich, so the total price does not worry him. His reputation does, so the price of the cheapest cell he buys must be as high as possible. The burrow also has to hold all of his furniture, so the area of the plot must be at least KK. If several plots satisfy both conditions, Bilbo takes the one with the largest area.

Find the best plot for Bilbo.

Input

The first line contains the integers NN, MM and KK, separated by one space each: the number of rows, the number of columns, and the smallest area Bilbo can live on. Each of the next NN lines contains MM integers. The jj-th number on line i+1i + 1 is the price of cell (i,j)(i, j).

NN and MM are positive integers not greater than 10001000, KK is a positive integer not greater than the total number of cells, and every price is between 11 and 10910^9, inclusive.

Output

Print two integers on one line, separated by a single space. The first is the price of the cheapest cell in the chosen plot. The second is the area of that plot.

Examples8

  1. Example 1

    Input
    3 3 3
    1 1 1
    1 2 2
    1 2 2
    
    Expected output
    2 4
    
  2. Example 2

    Input
    1 10 5
    4 3 2 5 10 7 6 5 1 100
    
    Expected output
    5 5
    
  3. Example 3

    Input
    3 5 2
    5 7 5 5 5
    8 5 5 7 5
    8 5 8 8 8
    
    Expected output
    8 3
    
  4. Example 4

    Input
    1 1 1
    1000000000
    
    Expected output
    1000000000 1
    
  5. Example 5

    Input
    4 4 16
    9 4 7 6
    5 3 8 2
    6 6 6 6
    7 1 9 4
    
    Expected output
    1 16
    
  6. Example 6

    Input
    4 5 1
    5 5 5 5 5
    5 5 5 5 5
    5 5 5 5 5
    5 5 5 5 5
    
    Expected output
    5 20
    
  7. Example 7

    Input
    5 4 5
    9 1 2 1
    9 2 1 3
    9 1 4 2
    9 3 1 1
    9 2 2 4
    
    Expected output
    9 5
    
  8. Example 8

    Input
    1 12 1
    3 9 9 1 9 9 9 2 8 8 1 9
    
    Expected output
    9 3