You are given a table A with N rows and M columns. Each cell contains a single digit.
Yeondu wants to choose one or more distinct cells. When the chosen cells are listed in the order they are picked, their row numbers must form an arithmetic sequence, and their column numbers must also form an arithmetic sequence. Concatenating the digits written in the chosen cells, in the order they were picked, forms a single integer.
Find the largest perfect square among the integers Yeondu can form. A perfect square is a number obtained by squaring some integer.