





def __UpperCAmelCase       (		__A ,						__A ,						__A ,						__A			)						->					int:



       '''simple docstring'''





       UpperCAmelCase__						,			UpperCAmelCase__										=     len(__A			), len(grid[0]			)
       if (
           min(__A ,						__A			) < 0
           or row == row_length
           or col == col_length
           or (row, col) in visit
           or grid[row][col] == 1
       ):
              return 0
       if row == row_length - 1 and col == col_length - 1:
              return 1

       visit.add((row, col)			)

       UpperCAmelCase__										=     0
       count += depth_first_search(__A ,						row + 1 ,						__A ,						__A			)
       count += depth_first_search(__A ,						row - 1 ,						__A ,						__A			)
       count += depth_first_search(__A ,						__A ,						col + 1 ,						__A			)
       count += depth_first_search(__A ,						__A ,						col - 1 ,						__A			)

       visit.remove((row, col)			)
       return count


if __name__ == "__main__":
    import doctest

    doctest.testmod()









class     lowercase__  :






  def __init__(					self      :					List[str]		,						_lowercase      :					list ):




         """simple docstring"""







         UpperCAmelCase__										=     set_counts
         UpperCAmelCase__										=     max(_lowercase )
         UpperCAmelCase__										=     len(_lowercase )
         UpperCAmelCase__										=     [1] * num_sets
         UpperCAmelCase__										=     list(range(_lowercase ) )






  def 			_UpperCAmelCase  (					self      :					Dict		,						_lowercase      :					int		,						_lowercase      :					int ):




         """simple docstring"""







         UpperCAmelCase__										=     self.get_parent(_lowercase )
         UpperCAmelCase__										=     self.get_parent(_lowercase )

         if src_parent == dst_parent:
                return False

         if self.ranks[dst_parent] >= self.ranks[src_parent]:
                self.set_counts[dst_parent] += self.set_counts[src_parent]
                UpperCAmelCase__										=     0
                UpperCAmelCase__										=     dst_parent
                if self.ranks[dst_parent] == self.ranks[src_parent]:
                       self.ranks[dst_parent] += 1
                UpperCAmelCase__										=     self.set_counts[dst_parent]
         else:
                self.set_counts[src_parent] += self.set_counts[dst_parent]
                UpperCAmelCase__										=     0
                UpperCAmelCase__										=     src_parent
                UpperCAmelCase__										=     self.set_counts[src_parent]

         UpperCAmelCase__										=     max(self.max_set		,						_lowercase )
         return True






  def 			_UpperCAmelCase  (					self      :					Optional[Any]		,						_lowercase      :					int ):




         """simple docstring"""







         if self.parents[disj_set] == disj_set:
                return disj_set
         UpperCAmelCase__										=     self.get_parent(self.parents[disj_set] )
         return self.parents[disj_set]





