Rice Company
Old man Vasyl, a new Ukrainian farmer, owns a rectangular plot of land measuring N by M. This plot is divided into unit squares, each growing a different variety of rice. For simplicity, these rice varieties are numbered from 1 to N*M.
Recently, Vasyl secured a contract with the International Rice Corporation (IPC) for T days. Under this agreement, he must deliver rice of a specified variety each day.
When the IPC requests rice of variety K, Vasyl follows a specific strategy: he identifies the largest possible rectangular area on his N by M plot where only rice of variety K is grown. Vasyl harvests rice exclusively from these rectangular areas.
For the IPC, it's crucial to know the maximum quantity of rice Vasyl can supply for each request. From each unit square, Vasyl harvests one unit of rice, meaning from an area of size S, he collects S units of rice. Additionally, Vasyl can repeatedly harvest rice from a given area as many times as needed.
Input
The first line contains two integers N and M, where 1 ≤ N, M ≤ 1000, representing the dimensions of Vasyl's plot. The following N lines each contain M integers, a[i][j], indicating the variety of rice growing in the j-th square of the i-th row, with 1 ≤ a[i][j] ≤ N*M.
Next, the number T is provided, representing the number of days Vasyl must supply rice to the company, where 1 ≤ T ≤ 20. The following T lines each contain one integer K, specifying the variety of rice ordered by the company, with 1 ≤ K ≤ N*M.
Output
Output T numbers, each representing the maximum amount of rice Vasyl can collect for each request from the IPC company.