Note c > 1 condition is required to make sure that a single column row is not counted twice ( Note that a single column row is sorted both in increasing and decreasing order )
if ( $ c > 1 && $ j == 0 ) $ result ++ ; } return $ result ; }