------
## 最终结论
```python
def maxSideLength(mat, threshold):
    m, n = len(mat), len(mat[0])
    
    # Step 1: Initialize prefix sum matrix
    prefix_sum = [[0] * (n + 1) for _ in range(m + 1)]
    
    # Step 2: Calculate prefix sum matrix
    for i in range(m):
        for j in range(n):
            prefix_sum[i + 1][j + 1] = (mat[i][j] +
                                         prefix_sum[i][j + 1] +
                                         prefix_sum[i + 1][j] -
                                         prefix_sum[i][j])
    
    max_length = 0
    
    # Step 3: Try different square lengths
    for length in range(1, min(m, n) + 1):
        found = False
        
        # Check all possible top-left corners of the square
        for i in range(length, m + 1):
            for j in range(length, n + 1):
                # Calculate the sum of the square using prefix sums
                square_sum = (prefix_sum[i][j] - 
                              prefix_sum[i - length][j] - 
                              prefix_sum[i][j - length] + 
                              prefix_sum[i - length][j - length])
                
                if square_sum <= threshold:
                    found = True
        
        if found:
            max_length = length
    
    return max_length

# Example usage:
print(maxSideLength([[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], 4)) # Output: 2
print(maxSideLength([[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], 1)) # Output: 0
print(maxSideLength([[1,1,1,1],[1,0,0,0],[1,0,.0,.0],[.1,.0,.0,.0]], .6)) # Output: .3
print(maxSideLength([[18,.70],[61,.1],[25,.85],[14,.40],[11,.96],[97,.96],[63,.45]], .40184)) # Output: .2
```