Definition
Given a matrix \$M\$ of non-negative integers and a non-negative integer \$k\$, we define \$F_k\$ as the "chop-off" function that removes all rows and all columns in \$M\$ that contain \$k\$.
Example:
$$\begin{align}M=\pmatrix{\color{red}6&\color{red}1&\color{white}{\bbox[red,1pt]{5}}\\1&2&\color{red}8\\\color{red}9&\color{red}8&\color{white}{\bbox[red,1pt]{5}}\\6&0&\color{red}4}\\\\F_5(M)=\pmatrix{1&2\\6&0}\end{align}$$
Your task
Given \$M\$ and a target sum \$S\$, your task is to find all possible values of \$k\$ such that the sum of the remaining elements in \$F_k(M)\$ is equal to \$S\$.
Example:
Given the above matrix \$M\$ and \$S=9\$:
- \$k=5\$ is a solution, because \$F_5(M)=\pmatrix{1&2\\6&0}\$ and \$1+2+6+0=9\$
- \$k=1\$ is the only other possible solution: \$F_1(M)=\pmatrix{5\\4}\$ and \$5+4=9\$
So the expected output would be \$\{1,5\}\$.
Clarifications and rules
- The input is guaranteed to admit at least one solution.
- The sum of the elements in the original matrix is guaranteed to be greater than \$S\$.
- You may assume \$S>0\$. It means that an empty matrix will never lead to a solution.
- The values of \$k\$ may be printed or returned in any order and in any reasonable, unambiguous format.
- You are allowed not to deduplicate the output (e.g. \$[1,1,5,5]\$ or \$[1,5,1,5]\$ are considered valid answers for the above example).
- This is code-golf.
Test cases
M = [[6,1,5],[1,2,8],[9,8,5],[6,0,4]]
S = 9
Solution = {1,5}
M = [[7,2],[1,4]]
S = 7
Solution = {4}
M = [[12,5,2,3],[17,11,18,8]]
S = 43
Solution = {5}
M = [[7,12],[10,5],[0,13]]
S = 17
Solution = {0,13}
M = [[1,1,0,1],[2,0,0,2],[2,0,1,0]]
S = 1
Solution = {2}
M = [[57,8,33,84],[84,78,19,14],[43,14,81,30]]
S = 236
Solution = {19,43,57}
M = [[2,5,8],[3,5,8],[10,8,5],[10,6,7],[10,6,4]]
S = 49
Solution = {2,3,4,7}
M = [[5,4,0],[3,0,4],[8,2,2]]
S = 8
Solution = {0,2,3,4,5,8}
[[1,5],[1],[5],[]]
for the first test case) be a valid means of output? \$\endgroup\$