# https://leetcode.com/problems/maximal-square/description/
# http://bit.ly/2GVjwMx

class Solution:
  def maximalSquare(self, A):
    for i in range(len(A)):
      for j in range(len(A[i])):
        A[i][j] = int(A[i][j])
        if A[i][j] and i and j:
          A[i][j] = min(A[i - 1][j], A[i - 1][j - 1], A[i][j - 1]) + 1
    return len(A) and max(map(max, A)) ** 2
