Magic Land

2.9

7 votes
Problem

You are given a grid of size NM where N and M denotes the number of rows and columns respectively. Each cell of the grid is filled with some number.

Now, We define a quantity called Magic Number for each row and column as the maximum number of consecutive adjacent elements having the same number. Now the password of the entry gate is the defined as the MAX of MR[i]*MC[j] where MR[i] and MC[j] refers to Magic number of ith row and jth column respectively.

Can you find the password ?

Input:

First line containts T denoting number of test cases. For each of the test case, the first line contains N and M. After that N lines having M integers are provided.

Output:

For each test case, output the value of password in a separate line.

Constraints:

1T5

1N,M1000

1A[i]100

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case, only one number is there. So max magic number for both row and column is 1 and so answer is 11=1. For the second test case max magic number for row is 1 and for column is 2. Hence, answer is 12=2.

Editor Image

?