[Question]
  [
## 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](/questions/tagged/code-golf "show questions tagged '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}
```
  
[Answer]
# [K (ngn/k)](https://gitlab.com/n9n/k), 39 bytes
```
{a@&y=x{+//x*(&/'b)&\:&/b:~x=y}/:a:,/x}
```
[Try it online!](https://tio.run/##PU/LboJQFNz7FbNoLLRauDzkck9N/Qh3lkRsxBoNWMQUYvDX6SCmm/OYzMw5c5jmu7zrMnNNF@NmXl9fHad@scbO88Yef5qxszG3et60jknNxKnbbmcyIbtcvJfmY7eqpUlaOPgt09NpWyK75F/VvshRFTgXZTW95PsfVN9blNvz5ViNlub6tGpupcnwhlrWxUGsdZbuj0IrKe2kHS1XljWDQigKHrTE0JxncBHYEttEw@ROiuBxIRjZMgkGTHkIqfJFRVAKSkPbEvgk/IsUVS4dXSjiiuJ@esh5l5t4rC7t@06ENDp4AyeM@JDvQweiA0QaKoYKeIQVWsEn3fNn1MQgGEaDrH9Mi3@vvN9nYpshGhpjBAzH10HTxyWOLiVMLpqpPFt0/@1AolHS/QE "K (ngn/k) – Try It Online")
*thanks @Adám for this explanation*:
`{`…`}` function, `x` is *M* and `y` is *S*
 `,/x` flatten *M* (these are the *k* candidates)
 `a:` assign to `a`
 `x{`…`}/:` apply the following function to each while using *M* as fixed left argument (`x`):
  `x=y` Boolean matrix indicating where elements of *M* equal the current *k* candidate
  `~` negate that 
  `b:` assign that to `b`
  `&/` AND reduction (finds columns without that *k*)
  `(`…`)&\:` AND that with each of the following:
   `&/'b` AND reduction of each (finds rows without that *k*)
  `x*` multiply *M* by that
  `+//` grand sum
 `y=` list of Booleans indicating where *S* equals those sums
 `&` indices of Trues
 `a@` use that to index into the elements (the *k* candidates)
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~35~~ ~~33~~ 28 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
-7 thanks to ngn.
Anonymous infix lambda. Takes *S* as left argument and *M* as right argument.
```
{⍵[⍸⍺=(+/∘,⍵×∧/∘.∧∧⌿)¨⍵≠⊂⍵]}
```
[Try it online!](https://tio.run/##bVA9SwNBEO39FemiOOrNzt7tXmFlYywMeHbHFQGJTUBbERuFEIMXtBAt7bSzEsQmEP/J/JHz7UabnHDcm483b2bf4Hy0dXIxGJ2dNs2l1h@l1p9af@2ub@7o5JlQ@X7SyWtItoHhu5tvLN7Q0NsXnV4jqK6aoY7vtZ7p7LHX1@nN4l10/ICsONrD/3i/VzR5Z9hZFg@K/mG3LDNiSisqmQx5YE4@5hklZKuqu@ZWJxyZyI9dK6ttNpRCSwLHETOxhzCo/I8SR6kkbkyIJfJaijgRTVAMMInrQ4Rq4BvJVidSh1eIkLegekvOE@fEIbMCJM8kcdi2DAnnByPkF3Hd0hEEGbm/IL7etxaTxVFhOLiH3XDCgPkD "APL (Dyalog Unicode) – Try It Online")
`{`…`}` "dfn", `⍺` and `⍵` are left and right arguments (*S* and *M*) respectively:
 `⍵[`…`]` index *M* with the following coordinates:
  `⊂⍵` enclose *M* to treat it as a single element
  `⍵=` compare each element (i.e. *k* candidate) of *M* to that entire *M*
  `(`…`)¨` apply the following tacit function to each:
   `∧⌿` vertical AND reduction (finds columns without that *k* candidate)
…`∘.∧` Cartesian Boolean product with:
    `∧/` horizontal AND reduction (finds rows without that *k* candidate)
   `⍵×` multiply *M* with that mask
   `+/∘,` sum the flattened matrix
  `⍺=` Boolean indicating where *S* equals those sums
  `⍸` indices where that's true
[Answer]
# [R](https://www.r-project.org/), ~~78~~ 73 bytes
```
function(m,s)m[Map(function(y)sum(m[(w=-which(m==y,T))[,1],w[,2]]),m)==s]
```
[Try it online!](https://tio.run/##XZBBisMwDEX3cxIL/oBlO7Gz8BG66y5k0QmEZuF2SFoyOX1GTqGtiy0LxH@y9KdtiNtwv/S38XpRCTOl9nD6Vc/SSvM9qdSqJX4v57E/qxTjiiNRC@6wtDBdR0gU49xtg0qn2zT@qV7VYFQSBgGNRIUaGo7g8LNO1yUeCQ19vRFetJwV5qXwhYKNtDGwYA9mcEAo1M5@NBSAtTAabEm4p5I/GsvHeh9WyzF7lkqJFETlZSdrEVy@PoAbsJMJ8hsYtoSNrQs8LyL8/sqE2R5JNfwjiQnV21qlT5VYqIUVNwWUYYufAm3/ "R – Try It Online")
Does not sort or deduplicate the output.
Credit to J.Doe & Giuseppe for -5 bytes.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~20~~ ~~19~~ ~~17~~ ~~15~~ 14 bytes
```
pZnⱮFȦ€€ḋFẹƓịF
```
This is a monadic link that takes **M** as argument and reads **S** from STDIN.
[Try it online!](https://tio.run/##TVAxTgMxEOz3FX6Ai9tbX3z3geMPsVzSoAilTUtDkZI/UCGkdIGUkRDfuHzEzO7ZgGRpx7Mz61k/3O92h1L228fb6X3@fr09veEs5@O8fH58vSyX41yuz6DuykSRghBHYuplQ2GisaSUNt6xd0P2LqH23o0KJ9TKQtB5F3L25FKK0FRtoximwaxiHUgYbR511q@LV1tXp6KytAEWQRnt9Aa7@s5603YVD9GiiaAEVYzBuwiGkZmNCaIIfdik@daQtpz8Qc3TFlWMZeM/3FaEPGiE1WzfoS/b0n3OlH8A "Jelly – Try It Online")
### How it works
```
pZnⱮFȦ€€ḋFẹƓịF  Main link. Argument: M
 Z              Zip; transpose the rows and columns of M.
p               Take the Cartesian product of M and its transpose, yielding all pairs
                (r, c) of rows and columns of M.
    F           Flatten; yield the elements of M.
  nⱮ            Not equal map; for each element e of M, compare the elements of the
                pairs (r, c) with e.
     Ȧ€€        All each each; for each array of Booleans corresponding to an (r, c)
                pair, test if all of them are true.
         F      Flatten; yield the elements of M.
        ḋ       Take the dot product of each list of resulting Booleans and the
                elements of M.
           Ɠ    Read an integer S from STDIN.
          ẹ     Find all indices of S in the dot products.
             F  Flatten; yield the elements of M.
            ị   Retrieve the elements of the right at the indices from the left.
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~88~~ ~~86~~ ~~84~~ 77 bytes
* -2 bytes thanks to [BWO](https://codegolf.stackexchange.com/questions/171550/get-me-out-of-here/171698?noredirect=1#comment414551_171698)
* -7 bytes thanks to [Tesseract](https://codegolf.stackexchange.com/users/82692/tesseract)
```
m!s=[k|k<-m>>=id,s==sum[x|r<-m,all(/=k)r,(i,x)<-zip[0..]r,all((/=k).(!!i))m]]
```
[Verify all testcases](https://tio.run/##XZFRasMwDIbfewoH9hDDny6OndiFpjfYCTwzAhvMJC4haaGM3j2T3Q6W@EWy9OmXLH93c/81DMsSsrm1/b0/FuF0av0n5radr8He7hOF0A1D/tr2fELucePH4sePttzv3ZRSKbfPs8xzHpxb/Hm8XmbWMrtjz5Nb20CgdrACFQzZA0y6NyihnAM7cPznNapEp5xe50SFmmRkBDSEgDCkSZySWxGRVMrUqoSQkRJbORqNckRUZMvUOHoUTfiarjVNLiWMIswoaANxgIg3JcnCCMhUWMlmXRrHjm@XT0tzPZZATgP956Qnq80@aigaJ9bGfVFnWkAVQcMT5na70PkzrT1049sHy9/zADZzVpzYOPnzhb2wwLIYeXzQ8gs "Haskell – Try It Online").
## Explanation
```
m ! s =                                         -- function !, taking m and s as input
    [k |                                        -- the list of all k's such that
        k <- m >>= id,                          -- * k is an entry of m
        s == sum                                -- * s equals the sum of
            [x |                                --     the list of x's such that
                r <- m,                         --     * r is a row of m
                all (/= k) r,                   --     * r does not contain k
                (i, x) <- zip [0 ..] r,         --     * i is a valid column index; also let x = r[i]
                all ((/= k) . (!! i)) m         --     * none of the rows contain k at index i
            ]
    ]
```
[Answer]
# [Pyth](https://pyth.readthedocs.io), ~~27 23 22 21~~ 20 bytes
```
fqvzss.DRsxLTQ-I#TQs
```
**[Test suite!](https://pyth.herokuapp.com/?code=fqvzss.DRsxLTQ-I%23TQs&input=%5B%5B6%2C1%2C5%5D%2C%5B1%2C2%2C8%5D%2C%5B9%2C8%2C5%5D%2C%5B6%2C0%2C4%5D%5D%0A9&test_suite=1&test_suite_input=%5B%5B6%2C+1%2C+5%5D%2C+%5B1%2C+2%2C+8%5D%2C+%5B9%2C+8%2C+5%5D%2C+%5B6%2C+0%2C+4%5D%5D%0A9%0A%0A%5B%5B7%2C+2%5D%2C+%5B1%2C+4%5D%5D%0A7%0A%0A%5B%5B12%2C+5%2C+2%2C+3%5D%2C+%5B17%2C+11%2C+18%2C+8%5D%5D%0A43%0A%0A%5B%5B7%2C+12%5D%2C+%5B10%2C+5%5D%2C+%5B0%2C+13%5D%5D%0A17%0A%0A%5B%5B1%2C+1%2C+0%2C+1%5D%2C+%5B2%2C+0%2C+0%2C+2%5D%2C+%5B2%2C+0%2C+1%2C+0%5D%5D%0A1%0A%0A%5B%5B57%2C+8%2C+33%2C+84%5D%2C+%5B84%2C+78%2C+19%2C+14%5D%2C+%5B43%2C+14%2C+81%2C+30%5D%5D%0A236%0A%0A%5B%5B2%2C+5%2C+8%5D%2C+%5B3%2C+5%2C+8%5D%2C+%5B10%2C+8%2C+5%5D%2C+%5B10%2C+6%2C+7%5D%2C+%5B10%2C+6%2C+4%5D%5D%0A49%0A%0A%5B%5B5%2C+4%2C+0%5D%2C+%5B3%2C+0%2C+4%5D%2C+%5B8%2C+2%2C+2%5D%5D%0A8%0A&debug=0&input_size=3)**
Does not deduplicate.
### How it works?
```
fqvzss.DRsxLTQ-I#TQs     Full program.
f                  s     Flatten M and keep only those elements T which satisfy:
 qvzss.DRsxLTQ-I#TQ      The filtering function. Breakdown:
              -I#TQ      Discard the rows that contain T. More elaborate explanation:
                # Q         |-> In M, keep only those elements that are...
               I            |-> Invariant under (equal to themselves after...)
              -  T          |-> Removing T.
                         Let's call the result of this expression CR (chopped rows).
          xLTQ           Map over the rows M and retrieve all indices of T.
         s               Collect indices in 1D list (flatten). Call this I.
      .DR                For each row left in CR, remove the elements at indices in I.
    ss                   Sum all the elements of this matrix flattened.
 qvz                     And then finally check whether they equal S.
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~114~~ 108 bytes
```
lambda m,s:{a for a in sum(m,[])if s==sum(v for l in m for i,v in enumerate(l)if{a}-set(l)-set(zip(*m)[i]))}
```
[Try it online!](https://tio.run/##XVDLaoRAELzvVwzkoqECzkNnDPglxoMhSgTHFXUXEvHbTU@7IZhTv6qqu2v8Wj6vg9rb4m3va//@UQuP@XWtRXudRC26Qcw3H3mUVdy1Yi6KUN552oep57TDPRTNcPPNVC9N1BN6rbeXuVko5/DdjdGzj8uuiuNtH6duWEQblWUGibRCKaHgKOZwXGdIYKoKIo8vT2Il0Ha5/NEsFJMYYhliTgCpkJKkDigLKSEd6RPYaEb/l5Osl/DuBFIHqDyEQ3nWppupSUhFMeFTQkZdpjFLnSippb@0hjOEdQbWQeaQoTKaIpyEZrbS2fFxDpqk9iQTngou6Uekgw@7KMlgfxN2xRzOkQegfedrqJOwTDCZDiKnVOC4x8MHiXZs@w8 "Python 2 – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~80~~ 74 bytes
```
->\m,\s{grep {s==sum m[m.$_;[[Z](m).$_]]}o{*.grep(:k,!*.grep($_))},m[*;*]}
```
[Try it online!](https://tio.run/##NU/LboMwELz3K1wpqgBNItY22BTRD6ljRT2EHlorEaiHiPDtdG3gtOt57Hju1@G3XsJDvPWiW44f54DzOH0P17uYxq4b/4IILpwOl9a5T5@FnFfv59tUnKIoe//B67YeLnk@I7iiLfy8jF8P0WdPBkV/G14y52oQKg9HkLA8G9j0rlFCew/R5Ig6A5lUCTMrRhIV21QkDIhAlm8wr9VuouQq08kSpCJLu52jGWNG8ixTQNwYTbJVVRn@kVKwmmmrYSyoAcWXVjxhCSoZpKpXS/xW7KK2yflrKV5qmH1JVfTWr4Lm2OiJvTmJi8kosMy3yz8 "Perl 6 – Try It Online")
### Explanation
```
->\m,\s{...}  # Anonymous block taking arguments m and s
  grep {...}o{...},m[*;*]   # Filter matrix elements
                            # with combination of two functions
    *.grep(:k,!*.grep($_))  # (1) Whatever code returning matching rows
    s==sum m[               # (2) s equals sum of elements
      m.$_;                 #     in matched rows
      [                     #     (array supporting multiple iterations)
       [Z](m).$_            #     and matched columns (matched rows
                            #     of m transposed with [Z])
      ]
    ]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 21 bytes
```
²˜ʒQεZ+}øεZ<~}ø_*OO¹Q
```
[Try it online!](https://tio.run/##yy9OTMpM/f//0KbTc05NCjy3NUq79vAOIGVTB6Tjtfz9D@0M/P/fkis62kzHUMc0VifaUMdIxwJIW@pYgPlmOgY6JrGxAA "05AB1E – Try It Online")
Only after I've written this answer have I seen [Kevin's](https://codegolf.stackexchange.com/a/171762/59487). I believe this is substantially different, so I am posting it separately. My intuition says that the optimal byte count is around 18, so I'll have to revisit this and see what else I can do. With the current code, it is impossible to write a test suite but I have verified all test cases myself and the results are correct.
### Cropping Algorithm
To better illustrate the technique used, let's grab an example, with the element to crop \$k=5\$:
$$M=\left(\begin{matrix}6&1&\bbox[green,1pt]{\color{white}{5}}\\1&2&8\\9&8&\bbox[green,1pt]{\color{white}{5}}\\6&0&4\end{matrix}\right)$$
It first generates the matrix of equality with \$k\$:
$$\left(\begin{matrix}0&0&1\\0&0&0\\0&0&1\\0&0&0\end{matrix}\right)$$
Then, it goes through \$M\$ and for each row \$R\$, it adds \$\max(R)\$ to each element in \$R\$, highlighting the necessary rows while still preserving the uniqueness of the horizontal positions of the searched element:
$$\left(\begin{matrix}\color{green}{1}&\color{green}{1}&\bbox[green,1pt]{\color{white}{2}}\\0&0&0\\\color{green}{1}&\color{green}{1}&\bbox[green,1pt]{\color{white}{2}}\\0&0&0\end{matrix}\right)$$
Then, it goes through the transpose of \$M\$ and for each column \$C\$, it performs the operation \$(\max(C)-1)\space ||\space c\space\forall\space c\in C\:\$ (where \$||\$ is 05AB1E's bitwise OR – addition should work too, so replace `~` with `+` if you want to test that too), which results in:
$$\left(\begin{matrix}\color{green}{1}&\color{green}{1}&\bbox[green,1pt]{\color{white}{3}}\\0&0&\color{green}{1}\\\color{green}{1}&\color{green}{1}&\bbox[green,1pt]{\color{white}{3}}\\0&0&\color{green}{1}\end{matrix}\right)$$
Finally, it maps \$0\$ to \$1\$ and all other integers to \$0\$ and performs element-wise multiplication with \$M\$:
$$\left(\begin{matrix}\color{green}{0}&\color{green}{0}&\color{green}{0}\\1&1&\color{green}{0}\\\color{green}{0}&\color{green}{0}&\color{green}{0}\\1&1&\color{green}{0}\end{matrix}\right)\:\longrightarrow\:\left(\begin{matrix}\color{green}{0}&\color{green}{0}&\color{green}{0}\\1&2&\color{green}{0}\\\color{green}{0}&\color{green}{0}&\color{green}{0}\\6&0&\color{green}{0}\end{matrix}\right)$$
After which the sum of the resulting matrix is computed.
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~27~~ 26 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
˜ʒ©¹ε®å_}¹ζʒ®å_}ζ‚ζ€€OPOIQ
```
Does not sort nor uniquify the result.  
Only works in the legacy (for now), because sum-each seems to be doing some odd things when part of the inner lists are integers and other are lists..
[Try it online](https://tio.run/##MzBNTDJM/f//9JxTkw6tPLTz3NZD6w4vja8FsrYBRcDsc9seNcwCEk1rgMg/wN8z8P//6GhDHUMdAx3DWJ1oIyBtoGMEZQFFY2O5DAE) or [verify all test cases](https://tio.run/##NU@7TgMxEOzvK6zUU3j9OPto0kRIqQIF6CLrhIKgzR9EQnwCJaKlQELpkg8IHUj3EfzIMWtAsrwzu7M7uzZubuV@yufLxdXy2vTzmdls78xsviYyZ4Zo@nr5fDq99ePhtP94vdn145G8wvH4/fDM7/Gdb3WxWl9OO0yltBDEAUXgkBk75MpbWIRhaLqmlARXFcoTuThEyr0mE0Qgmb1DE3wVS1XbOsZCPCtS22hFzqxjtHWoImZVQkVMdPceObCUA1KGdBBlwTMiC7yKnW8p1zV0Z/8X6fm7PEGL9A907aB3RARaqV5vowOPcCzmHw).
**Explanation:**
```
˜              # Flatten the (implicit) matrix-input
               #  i.e. [[6,1,5],[1,2,8],[9,8,5],[6,0,4]] → [6,1,5,1,2,8,9,8,5,6,0,4]
 ʒ             # Filter this list by:
  ©            #  Store the current value in a register-variable
   ¹           #  Take the matrix-input
    ε   }      #  Map it to:
     ®å_       #   0 if the current number is in this row, 1 if not
               #    i.e. [[6,1,5],[1,2,8],[9,8,5],[6,0,4]] and 6 → [0,1,1,0]
   ¹           #  Take the matrix-input again
    ζ          #  Swap its rows and columns
               #   i.e. [[6,1,5],[1,2,8],[9,8,5],[6,0,4]] → [[6,1,9,6],[1,2,8,0],[5,8,5,4]]
     ʒ   }     #  Filter it by:
      ®å_      #   Only keep the inner lists that does not contain the current number
               #    i.e. [[6,1,9,6],[1,2,8,0],[5,8,5,4]] and 6 → [[1,2,8,0],[5,8,5,4]]
               #    i.e. [[1,2,2],[1,0,0],[0,0,1],[1,2,0]] and 1 → []
          ζ    #  After filtering, swap it's rows and columns back again
               #   i.e. [[1,2,8,0],[5,8,5,4]] → [[1,5],[2,8],[8,5],[0,4]]
   ‚ζ          #  Pair both lists together and zip them
               #   i.e. [0,1,1,0] and [[1,5],[2,8],[8,5],[0,4]]
               #    → [[0,[1,5]],[1,[2,8]],[1,[8,5]],[0,[0,4]]]
               #   i.e. [0,1,0] and [] → [[0,' '],[1,' '],[0,' ']]
     €         #  Map each inner list / value to:
      €O       #   Sum each
               #    i.e. [[0,[1,5]],[1,[2,8]],[1,[8,5]],[0,[0,4]]]
               #     → [[0,6],[1,10],[1,13],[0,4]]
               #    i.e. [[0,' '],[1,' '],[0,' ']]
               #     → [[0,0],[1,0],[0,0]]
               #  (NOTE: For most test cases just `O` instead of `€€O` would be enough,
               #   but not if we removed ALL zipped inner lists for a number, like the 
               #   second example above with input [[1,1,0,1],[2,0,0,2],[2,0,1,0]] and 1)
        P      #  Now take the product of each inner list
               #   i.e. [[0,6],[1,10],[1,13],[0,4]] → [0,10,13,0]
         O     #  Then take the sum of those
               #   i.e. [0,10,13,0] → 23
          IQ   #  And only keep those that are equal to the number-input
               #   i.e. 23 and 9 → 0 (falsey), so it's removed from the flattened input
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 22 bytes
```
=+Ṁ$€Z$⁺’¬×⁸FS
F³ç=⁹ƲƇ
```
[Try it online!](https://tio.run/##y0rNyan8/99W@@HOBpVHTWuiVB417nrUMPPQmsPTHzXucAvmcju0@fBy20eNO49tOtb@////aDMdQx3TWJ1oQx0jHQsgbaljAeab6RjomMT@twQA "Jelly – Try It Online")
-6 bytes using the general approach from Mr. Xcoder's 05AB1E answer. 
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 33 bytes
```
ＦθＦι⊞υκＩΦυ⁼ηΣＥθ∧¬№λιΣＥλ∧¬№Ｅθ§πξιν
```
[Try it online!](https://tio.run/##XYwxD4IwEIV3f8WN1@RMgJXJEE0cNCSODUMDGBprC6U1/PtaEKLxlnf33veu7oStjVAh3I0FHBgsKle9GoeF8dqhJ3gwxqD0Y/c58l1pZUwKMTo8SeVaOwfHwQs1Ykdw80@8iB4HgoNufn4pAsnYF1D/wNZyZ920E/YE08wvJc22yUPgnKeUUkJpRTyLmlC2btGtquiH/Uu9AQ "Charcoal – Try It Online") Link is to verbose version of code and includes deduplication. Explanation:
```
ＦθＦι⊞υκ
```
Flatten the first input array `q` into the predefined list `u`.
```
  υ                          Flattened array
 Φ                           Filter elements
       θ                     Input array
      Ｅ                      Map over rows
            ι                Current element
           λ                 Current row
          №                  Count matching elements
         ¬                   Logical Not
        ∧                    Logical And
               λ             Current row
              Ｅ              Map over columns
                    θ        Input array
                   Ｅ         Map over rows
                      π      Inner row
                       ξ     Column index
                     §       Inner element
                        ι    Current element
                  №          Count matching elements
                 ¬           Logical Not
                ∧            Logical And
                         ν   Current element
             Σ               Sum
     Σ                       Sum
    η                        Second input
   ⁼                         Equals
Ｉ                            Cast to string
                             Implicitly print each result on its own line
```
For each element of the list, sum the array, but if the row contains the element then use `0` instead of its sum, and when summing rows that don't contain the element, if the column contains the element then use `0` instead of the column's value. This is very slightly golfier than filtering the elements out as Charcoal can't sum an empty list.
[Answer]
# [Clean](https://github.com/Ourous/curated-clean-linux), 92 bytes
```
import StdEnv
$m s=[c\\r<-m,c<-r|sum[b\\a<-m|all((<>)c)a,b<-a&x<-[0..]|all(\u=u!!x<>c)m]==s]
```
[Try it online!](https://tio.run/##RY1NawIxEIbv@ysiSnFhIioqCoknPRR685jkMMZVAklW8iEr@NubBlvoaXhmnvcdbTv0xfWXbDvi0Phi3L0PiZzS5egfzcSRyIWWMjDqQDMaXjE7cZYS6@KF1k6nbN/qFuHMKH4MjIr5bKbeF5l5Ho0GttetU5xHVU4JQ2rG9VMKZiCcCLGBBawViAUsYVvnDrZv3sAcVkpVuWZuXaryrsI1e51M7ytOGv6Pf42/bvnWV4u3WOjnVzk8PTqj4w8 "Clean – Try It Online")
Explained:
```
$ m s                       // the function $ of `m` and `s`
 = [                        // is equal to
  c                         // the value `c`
  \\ r <- m                 // for every row `r` in `m`
  , c <- r                  // for every value `c` in `r`
  | sum [                   // where the sum of
   b                        // the value `b`
   \\ a <- m                // for every row `a` in `m`
   | all ((<>)c) a          // where `c` isn't in `a`
   , b <- a                 // for every value `b` in `a`
   & x <- [0..]             // with every column index `x` from zero
   | all (\u = u!!x <> c) m // where `c` isn't in column `x`
  ] == s                    // equals `s`
 ]
```
[Answer]
## MATLAB - 80 bytes
(*Corrected and*) Compacted:
```
function f(M,s);for k=M(:)';if sum(sum(M(~sum(M==k,2),~sum(M==k))))==s;k,end;end
```
And in a fully developped version:
```
function getthesum(M,s)
for k=M(:)'                         % For each element of M
    x = M==k ;                      % Index elements equal to "k"
    N = M( ~sum(x,2) , ~sum(x) ) ;  % New matrix with only the appropriate rows/columns
    if sum(sum(N))==s               % sum rows and columns and compare to "s"
        k                           % display "k" in console if "k" is valid
    end
end
```
---
Thanks to the comments to highlight my initial mistake. Note that this version does not de-duplicate the output.
It is possible to deduplicate the output with 5 more bytes:
```
% This will only cycle through the unique elements of 'M' (85 bytes):
function f(M,s);for k=unique(M)';if sum(sum(M(~sum(M==k,2),~sum(M==k))))==s;k,end;end
```
]