<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>

def find_three_max(arr):
    indexed_arr = [(val, idx) for idx, val in enumerate(arr)]
    sorted_arr = sorted(indexed_arr, key=lambda x: x[0], reverse=True)
    max_values_and_indices = sorted_arr[:3] 
    max_values = [item[0] for item in max_values_and_indices]
    indices = [item[1] for item in max_values_and_indices]   
    return max_values, indices


def get_max_from_three(max_list, index_list):
    max_values = []
    for i in range(len(max_list)-2):
        for i1 in range(i+1, len(max_list)-1):
            for i2 in range(i1+1, len(max_list)):
                for j in range(3):
                    for k in range(3):
                        for m in range(3):
                            v1 = max_list[i][j]
                            v2 = max_list[i1][k]
                            v3 = max_list[i2][m]
                            if index_list[i][j] == index_list[i1][k] or index_list[i][j] == index_list[i2][m] or index_list[i1][k] == index_list[i2][m]:
                                s = v1+v2+v3
                                continue
                            else:
                                max_values.append(v1+v2+v3)
    return max(max_values)

class Solution:
    def maximumValueSum(self, board: List[List[int]]) -> int:
        n = len(board)
        max_values = [[0,0]*3]*n
        index_list = [[0,0]*3]*n
        for i in range(n):
            max_values[i], index_list[i] = find_three_max(board[i])
        r = get_max_from_three(max_values, index_list)   
        return r
125929