





from collections import deque






def     lowerCamelCase__			(__lowerCamelCase	):
     _SCREAMING_SNAKE_CASE       :	List[Any]						    =							len(__lowerCamelCase	)
     _SCREAMING_SNAKE_CASE       :	List[str]						    =							deque()
     _SCREAMING_SNAKE_CASE       :	Tuple						    =							[False for _ in range(__lowerCamelCase	)]
     _SCREAMING_SNAKE_CASE       :	Tuple						    =							[-1 for _ in range(__lowerCamelCase	)]
     _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							index_of[:]

     def strong_connect(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	):
          _SCREAMING_SNAKE_CASE       :	Tuple						    =							index  # the number when this node is seen
          _SCREAMING_SNAKE_CASE       :	str						    =							index  # lowest rank node reachable from here
          index += 1
          stack.append(__lowerCamelCase	)
          _SCREAMING_SNAKE_CASE       :	str						    =							True

          for w in g[v]:
               if index_of[w] == -1:
                    _SCREAMING_SNAKE_CASE       :	Dict						    =							strong_connect(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	)
                    _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							(
                        lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
                    )
               elif on_stack[w]:
                    _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							(
                        lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
                    )

          if lowlink_of[v] == index_of[v]:
               _SCREAMING_SNAKE_CASE       :	str						    =							[]
               _SCREAMING_SNAKE_CASE       :	List[Any]						    =							stack.pop()
               _SCREAMING_SNAKE_CASE       :	Dict						    =							False
               component.append(__lowerCamelCase	)
               while w != v:
                    _SCREAMING_SNAKE_CASE       :	int						    =							stack.pop()
                    _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							False
                    component.append(__lowerCamelCase	)
               components.append(__lowerCamelCase	)
          return index

     _SCREAMING_SNAKE_CASE       :	Dict						    =							[]
     for v in range(__lowerCamelCase	):
          if index_of[v] == -1:
               strong_connect(__lowerCamelCase,       0,       __lowerCamelCase	)

     return components






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase	):
     _SCREAMING_SNAKE_CASE       :	Dict						    =							[[] for _ in range(__lowerCamelCase	)]
     for u, v in edges:
          g[u].append(__lowerCamelCase	)
     return g


if __name__ == "__main__":
       # Test
       UpperCamelCase__      =7
       UpperCamelCase__      =[0, 0, 1, 2, 3, 3, 4, 4, 6]
       UpperCamelCase__      =[1, 3, 2, 0, 1, 4, 5, 6, 5]
       UpperCamelCase__      =[(u, v) for u, v in zip(source, target)]
       UpperCamelCase__      =create_graph(n_vertices, edges)

       assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)






from PIL import Image






def     lowerCamelCase__			(__lowerCamelCase	):
     _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	List[str]						    =							image.size
     _SCREAMING_SNAKE_CASE       :	Tuple						    =							0
     _SCREAMING_SNAKE_CASE       :	Dict						    =							image.load()
     for i in range(__lowerCamelCase	):
          for j in range(__lowerCamelCase	):
               _SCREAMING_SNAKE_CASE       :	List[Any]						    =							pixels[j, i]
               mean += pixel
     mean //= width * height

     for j in range(__lowerCamelCase	):
          for i in range(__lowerCamelCase	):
               _SCREAMING_SNAKE_CASE       :	int						    =							255 if pixels[i, j] > mean else 0
     return image


if __name__ == "__main__":
       UpperCamelCase__      =mean_threshold(Image.open('path_to_image').convert('L'))
       image.save('output_image_path')