<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;= 100</code></li>
	<li><code>3 &lt;= n == board[i].length &lt;= 100</code></li>
	<li><code>-10<sup>9</sup> &lt;= board[i][j] &lt;= 10<sup>9</sup></code></li>
</ul>

import numpy as np
class Solution:
    def maximumValueSum(self, board: List[List[int]]) -> int:
        m = len(board)
        n = len(board[0])
        board_index1 = []
        board_index2 = []
        for i in range(m):
            newRow1 = []
            for j in range(n):
                newRow1.append([board[i][j],i,j])
            board_index1.append(newRow1)
        for j in range(n):
            newRow2 = []
            for i in range(m):
                newRow2.append([board[i][j],i,j])
            board_index2.append(newRow2)

        arr = []
        for i in range(m):
            temp = sorted(board_index1[i],reverse = True)
            arr.append(temp[0])
            arr.append(temp[1])
            arr.append(temp[2])
        for i in range(n):
            temp = sorted(board_index2[i],reverse = True)
            arr.append(temp[0])
            arr.append(temp[1])
            arr.append(temp[2])
        distinct_array = [list(sub_array) for sub_array in arr]
        distinct_array = sorted(distinct_array,reverse = True)
        for i in range(len(distinct_array)-1,0,-1):
            if(distinct_array[i][1] == distinct_array[i-1][1]  and distinct_array[i][2] == distinct_array[i-1][2] ):
                del distinct_array[i]
        print(distinct_array)
        ans = -10000000000

        for i in range(min(len(distinct_array)-2,100)):
            for j in range(i+1,min(len(distinct_array)-1,100)):
                sm = set()
                sn = set()
                now = distinct_array[i][0]
                sm.add(distinct_array[i][1])
                sn.add(distinct_array[i][2])
                if(distinct_array[j][1] in sm or distinct_array[j][2] in sn):
                    continue
                else:
                    sm.add(distinct_array[j][1])
                    sn.add(distinct_array[j][2])
                    now+=distinct_array[j][0]
                    for k in range(j+1,min(len(distinct_array),100)):
                        if(distinct_array[k][1] in sm or distinct_array[k][2] in sn):
                            continue
                        else:
                            now+=distinct_array[k][0]
                            ans = max(ans,now)
                            break




        return ans
33791