using
System;
using
System.Collections.Generic;
class
GFG{
static
int
histo(List<
int
> q)
{
Stack<
int
> q1 =
new
Stack<
int
>();
int
n = q.Count;
int
[] pre_smaller =
new
int
[q.Count];
int
[] next_smaller =
new
int
[q.Count];
for
(
int
i = 0; i < n; i++)
{
pre_smaller[i] = -1;
next_smaller[i] = n;
}
for
(
int
i = 0; i < n; i++)
{
while
(q1.Count > 0 && q[q1.Peek()] > q[i])
{
next_smaller[q1.Peek()] = i;
q1.Pop();
}
q1.Push(i);
}
while
(q1.Count > 0)
{
q1.Pop();
}
for
(
int
i = n - 1; i >= 0; i--)
{
while
(q1.Count > 0 && q[q1.Peek()] > q[i])
{
pre_smaller[q1.Peek()] = i;
q1.Pop();
}
q1.Push(i);
}
int
ans = 0;
for
(
int
i = 0; i < n; i++)
{
ans = Math.Max(ans, (next_smaller[i] -
pre_smaller[i] - 1) * q[i]);
}
return
ans;
}
static
int
findLargest(List<List<
int
>> arr)
{
int
n = arr.Count;
int
m = arr[0].Count;
int
[,] pre =
new
int
[n, m];
int
ans = 0;
for
(
int
i = 0; i < n; i++)
{
for
(
int
j = 0; j < m; j++)
{
if
(j == 0)
{
pre[i, j] = 1;
continue
;
}
if
(arr[i][j] > arr[i][j - 1])
{
pre[i, j] = pre[i,j - 1] + 1;
}
else
{
pre[i, j] = 1;
}
}
}
for
(
int
j = 0; j < m; j++)
{
for
(
int
i = 0; i < n; i++)
{
int
k = i + 1;
List<
int
> q =
new
List<
int
>();
q.Add(pre[i, j]);
while
(k < n && arr[k][0] > arr[k - 1][0])
{
q.Add(pre[k, j]);
k++;
}
ans = Math.Max(ans, histo(q));
i = k - 1;
}
}
return
ans;
}
static
public
void
Main()
{
List<List<
int
>> arr =
new
List<List<
int
>>();
arr.Add(
new
List<
int
>(){1, 2, 3});
arr.Add(
new
List<
int
>(){4, 5, 6 });
arr.Add(
new
List<
int
>(){1, 2, 3});
Console.WriteLine(findLargest(arr));
}
}