





from PIL import Image




def     a__ (					lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_						,       UpperCAmelCase_											=image.size
   UpperCAmelCase_											=0
   UpperCAmelCase_											=image.load()
   for i in range(lowercase__  ):
      for j in range(lowercase__  ):
         UpperCAmelCase_											=pixels[j, i]
         mean += pixel
   mean //= width * height

   for j in range(lowercase__  ):
      for i in range(lowercase__  ):
         UpperCAmelCase_											=2_5_5 if pixels[i, j] > mean else 0
   return image


if __name__ == "__main__":
     __lowercase  :   Optional[Any]						      =mean_threshold(Image.open("""path_to_image""").convert("""L"""))
     image.save("""output_image_path""")











from __future__ import annotations




def     a__ (					lowercase__  ,    lowercase__  ):






   '''simple docstring'''






   UpperCAmelCase_						,       UpperCAmelCase_											=set(lowercase__  ), [start]

   while stack:
      UpperCAmelCase_											=stack.pop()
      explored.add(lowercase__  )
      # Differences from BFS:
      # 1) pop last element instead of first one
      # 2) add adjacent elements to stack without exploring them
      for adj in reversed(graph[v]  ):
         if adj not in explored:
            stack.append(lowercase__  )
   return explored


__lowercase  :   Dict						      ={
    """A""": ["""B""", """C""", """D"""],
    """B""": ["""A""", """D""", """E"""],
    """C""": ["""A""", """F"""],
    """D""": ["""B""", """D"""],
    """E""": ["""B""", """F"""],
    """F""": ["""C""", """E""", """G"""],
    """G""": ["""F"""],
}

if __name__ == "__main__":
     import doctest

     doctest.testmod()
     print(depth_first_search(G, """A"""))




