Checking if not going out of matrix and next cell value is less than current cell value .
if ( newx >= 0 and newx < n and newy >= 0 and newy < n and mat [ newx ] [ newy ] < mat [ x ] [ y ] ) : NEW_LINE INDENT ans += CountDecreasingPathsCell ( mat , dp , n , newx , newy ) NEW_LINE DEDENT