<p>You are given a <code>m x n</code> 2D array <code>board</code> representing a chessboard, where <code>board[i][j]</code> represents the <strong>value</strong> of the cell <code>(i, j)</code>.</p>

<p>Rooks in the <strong>same</strong> row or column <strong>attack</strong> each other. You need to place <em>three</em> rooks on the chessboard such that the rooks <strong>do not</strong> <strong>attack</strong> each other.</p>

<p>Return the <strong>maximum</strong> sum of the cell <strong>values</strong> on which the rooks are placed.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">board = </span>[[-3,1,1,1],[-3,1,-3,1],[-3,2,1,1]]</p>

<p><strong>Output:</strong> 4</p>

<p><strong>Explanation:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/08/rooks2.png" style="width: 294px; height: 450px;" /></p>

<p>We can place the rooks in the cells <code>(0, 2)</code>, <code>(1, 3)</code>, and <code>(2, 1)</code> for a sum of <code>1 + 1 + 2 = 4</code>.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">board = [[1,2,3],[4,5,6],[7,8,9]]</span></p>

<p><strong>Output:</strong> <span class="example-io">15</span></p>

<p><strong>Explanation:</strong></p>

<p>We can place the rooks in the cells <code>(0, 0)</code>, <code>(1, 1)</code>, and <code>(2, 2)</code> for a sum of <code>1 + 5 + 9 = 15</code>.</p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">board = [[1,1,1],[1,1,1],[1,1,1]]</span></p>

<p><strong>Output:</strong> <span class="example-io">3</span></p>

<p><strong>Explanation:</strong></p>

<p>We can place the rooks in the cells <code>(0, 2)</code>, <code>(1, 1)</code>, and <code>(2, 0)</code> for a sum of <code>1 + 1 + 1 = 3</code>.</p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>3 &lt;= m == board.length &lt;= 500</code></li>
	<li><code>3 &lt;= n == board[i].length &lt;= 500</code></li>
	<li><code>-10<sup>9</sup> &lt;= board[i][j] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def maximumValueSum(self, board: List[List[int]]) -> int:
        m,n = len(board),len(board[0])
        F0,F1,F2,F3 = [[-inf] * n for i in range(m)],[[-inf] * n for i in range(m)],[[-inf] * n for i in range(m)],[[-inf] * n for i in range(m)]
        for i in range(1,m):
            for j in range(1,n):
                F0[i][j] = max(F0[i][j-1],F0[i-1][j],board[i-1][j-1])
        for i in range(1,m):
            for j in range(n-2,-1,-1):
                F1[i][j] = max(F1[i][j+1],F1[i-1][j],board[i-1][j+1])
        for i in range(m-2,-1,-1):
            for j in range(1,n):
                F2[i][j] = max(F2[i][j-1],F2[i+1][j],board[i+1][j-1])
        for i in range(m-2,-1,-1):
            for j in range(n-2,-1,-1):
                F3[i][j] = max(F3[i][j+1],F3[i+1][j],board[i+1][j+1])
        q = []
        for i in range(m):
            for j in range(n):
                heappush(q,(-board[i][j],i,j))
        L = min(len(q),2*(m+n))
        q2 = []
        for i in range(L):
            q2.append(heappop(q))
        res = -inf
        for i in range(L):
            for j in range(i+1,L):
                v1,x1,y1 = q2[i]
                v2,x2,y2 = q2[j]
                if x1 == x2 or y1 == y2:continue
                xmn,xmx,ymn,ymx = min(x1,x2),max(x1,x2),min(y1,y2),max(y1,y2)
                A = max(F0[xmn][ymn],F1[xmn][ymx],F2[xmx][ymn],F3[xmx][ymx])
                res = max(res,-v1-v2+A)
        return res
64831