title: search quadruples in matrix efficiently
body: <p>I have a matrix of different numbers and I need an efficient algorithm to find all quadruples (four entries where each two are at the same row and each two at the same column),  where all four numbers are positive. For example:</p>
  
  <ul>
  <li>1 2 0 0</li>
  <li>1 1 0 0</li>
  <li>0 0 1 1</li>
  </ul>
  
  <p>Here we have one quadruple like this </p>
  
  <ul>
  <li>1 2</li>
  <li>1 1</li>
  </ul>
  
  <p>It is easy to find a non-efficient solution but I need something efficient. I would be really grateful for any idea!</p>