


from __future__ import annotations

from collections.abc import Iterable

class 			lowerCamelCase_					:





							def __init__(							self			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    ):
								a_			, a_     			=   float(lowercase__    ), float(lowercase__    )





							def __eq__(							self			,       _SCREAMING_SNAKE_CASE    ):
								return self.x == other.x and self.y == other.y





							def __ne__(							self			,       _SCREAMING_SNAKE_CASE    ):
								return not self == other





							def __gt__(							self			,       _SCREAMING_SNAKE_CASE    ):



								if self.x > other.x:
									return True
								elif self.x == other.x:
									return self.y > other.y
								return False





							def __lt__(							self			,       _SCREAMING_SNAKE_CASE    ):
								return not self > other





							def __ge__(							self			,       _SCREAMING_SNAKE_CASE    ):



								if self.x > other.x:
									return True
								elif self.x == other.x:
									return self.y >= other.y
								return False





							def __le__(							self			,       _SCREAMING_SNAKE_CASE    ):



								if self.x < other.x:
									return True
								elif self.x == other.x:
									return self.y <= other.y
								return False





							def __repr__(							self    ):
								return f"""({self.x}, {self.y})"""





							def __hash__(							self    ):
								return hash(self.x    )







def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Any     ,					)     ->	Any:



	"""simple docstring"""






	a_     			=   []
	if list_of_tuples:
		for p in list_of_tuples:
			if isinstance(lowerCAmelCase__     ,					lowerCAmelCase__	):
				points.append(lowerCAmelCase__	)
			else:
				try:
					points.append(Point(p[0]     ,					p[1]	)	)
				except (IndexError, TypeError):
					print(
					    F"""Ignoring deformed point {p}. All points"""
					    """ must have at least 2 coordinates."""	)
	return points

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Optional[Any]	)     ->	List[Any]:



	"""simple docstring"""






	if not hasattr(lowerCAmelCase__     ,					"""__iter__"""	):
		a_     			=   F"""Expecting an iterable object but got an non-iterable type {points}"""
		raise ValueError(lowerCAmelCase__	)

	if not points:
		a_     			=   F"""Expecting a list of points but got {points}"""
		raise ValueError(lowerCAmelCase__	)

	return _construct_points(lowerCAmelCase__	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Union[str, Any]     ,					UpperCamelCase		:      int     ,					UpperCamelCase		:      Tuple	)     ->	int:



	"""simple docstring"""






	a_     			=   (a.x * b.y + b.x * c.y + c.x * a.y) - (a.y * b.x + b.y * c.x + c.y * a.x)
	return det

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Union[str, Any]	)     ->	int:



	"""simple docstring"""






	a_     			=   sorted(_validate_input(lowerCAmelCase__	)	)
	a_     			=   len(lowerCAmelCase__	)
	a_     			=   set()

	for i in range(n - 1	):
		for j in range(i + 1     ,					lowerCAmelCase__	):
			a_     			=   a_     			=   False
			a_     			=   True
			for k in range(lowerCAmelCase__	):
				if k != i and k != j:
					a_     			=   _det(points[i]     ,					points[j]     ,					points[k]	)

					if det_k > 0:
						a_     			=   True
					elif det_k < 0:
						a_     			=   True
					else:
						# point[i], point[j], point[k] all lie on a straight line
						# if point[k] is to the left of point[i] or it's to the
						# right of point[j], then point[i], point[j] cannot be
						# part of the convex hull of A
						if points[k] < points[i] or points[k] > points[j]:
							a_     			=   False
							break

				if points_left_of_ij and points_right_of_ij:
					a_     			=   False
					break

			if ij_part_of_convex_hull:
				convex_set.update([points[i], points[j]]	)

	return sorted(lowerCAmelCase__	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Optional[Any]	)     ->	Any:



	"""simple docstring"""






	a_     			=   sorted(_validate_input(lowerCAmelCase__	)	)
	a_     			=   len(lowerCAmelCase__	)

	# divide all the points into an upper hull and a lower hull
	# the left most point and the right most point are definitely
	# members of the convex hull by definition.
	# use these two anchors to divide all the points into two hulls,
	# an upper hull and a lower hull.

	# all points to the left (above) the line joining the extreme points belong to the
	# upper hull
	# all points to the right (below) the line joining the extreme points below to the
	# lower hull
	# ignore all points on the line joining the extreme points since they cannot be
	# part of the convex hull

	a_     			=   points[0]
	a_     			=   points[n - 1]

	a_     			=   {left_most_point, right_most_point}
	a_     			=   []
	a_     			=   []

	for i in range(1     ,					n - 1	):
		a_     			=   _det(lowerCAmelCase__     ,					lowerCAmelCase__     ,					points[i]	)

		if det > 0:
			upper_hull.append(points[i]	)
		elif det < 0:
			lower_hull.append(points[i]	)

	_construct_hull(lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__	)
	_construct_hull(lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__	)

	return sorted(lowerCAmelCase__	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Optional[int]     ,					UpperCamelCase		:      str     ,					UpperCamelCase		:      List[str]     ,					UpperCamelCase		:      Optional[int]	)     ->	List[Any]:



	"""simple docstring"""






	if points:
		a_     			=   None
		a_     			=   float("""-inf"""	)
		a_     			=   []

		for p in points:
			a_     			=   _det(lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__	)

			if det > 0:
				candidate_points.append(lowerCAmelCase__	)

				if det > extreme_point_distance:
					a_     			=   det
					a_     			=   p

		if extreme_point:
			_construct_hull(lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__	)
			convex_set.add(lowerCAmelCase__	)
			_construct_hull(lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__     ,					lowerCAmelCase__	)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Union[str, Any]	)     ->	Optional[int]:



	"""simple docstring"""






	a_     			=   sorted(_validate_input(lowerCAmelCase__	)	)
	a_     			=   len(lowerCAmelCase__	)

	a_     			=   points[:2]
	for i in range(2     ,					lowerCAmelCase__	):
		a_     			=   _det(convex_hull[1]     ,					convex_hull[0]     ,					points[i]	)
		if det > 0:
			convex_hull.insert(0     ,					points[i]	)
			break
		elif det < 0:
			convex_hull.append(points[i]	)
			break
		else:
			a_     			=   points[i]
	i += 1

	for j in range(lowerCAmelCase__     ,					lowerCAmelCase__	):
		if (
		    _det(convex_hull[0]     ,					convex_hull[-1]     ,					points[j]	) > 0
		    and _det(convex_hull[-1]     ,					convex_hull[0]     ,					points[1]	) < 0
		):
			# The point lies within the convex hull
			continue

		convex_hull.insert(0     ,					points[j]	)
		convex_hull.append(points[j]	)
		while _det(convex_hull[0]     ,					convex_hull[1]     ,					convex_hull[2]	) >= 0:
			del convex_hull[1]
		while _det(convex_hull[-1]     ,					convex_hull[-2]     ,					convex_hull[-3]	) <= 0:
			del convex_hull[-2]

    # `convex_hull` is contains the convex hull in circular order
	return sorted(convex_hull[1:] if len(lowerCAmelCase__	) > 3 else convex_hull	)

def 			__SCREAMING_SNAKE_CASE		(		)     ->	Dict:



	"""simple docstring"""






	a_     			=   [
	    (0, 3),
	    (2, 2),
	    (1, 1),
	    (2, 1),
	    (3, 0),
	    (0, 0),
	    (3, 3),
	    (2, -1),
	    (2, -4),
	    (1, -3),
	]
	# the convex set of points is
	# [(0, 0), (0, 3), (1, -3), (2, -4), (3, 0), (3, 3)]
	a_     			=   convex_hull_bf(lowerCAmelCase__	)

	a_     			=   convex_hull_recursive(lowerCAmelCase__	)
	assert results_bf == results_recursive

	a_     			=   convex_hull_melkman(lowerCAmelCase__	)
	assert results_bf == results_melkman

	print(lowerCAmelCase__	)


if __name__ == "__main__":
			main()
import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp






def  __lowerCamelCase						(		):
       lowerCAmelCase__	      =   ArgumentParser(
           description=(
               'PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes'
           )      )

       # Optional arguments for the launch helper
       parser.add_argument('--num_cores'      ,    type=lowerCAmelCase__      ,    default=1      ,    help='Number of TPU cores to use (1 or 8).'      )

       # positional
       parser.add_argument(
           'training_script'      ,    type=lowerCAmelCase__      ,    help=(
               'The full path to the single TPU training '
               'program/script to be launched in parallel, '
               'followed by all the arguments for the '
               'training script'
           )      ,    )

       # rest from the training program
       parser.add_argument('training_script_args'      ,    nargs=lowerCAmelCase__      )

       return parser.parse_args()






def  __lowerCamelCase						(		):
       lowerCAmelCase__	      =   parse_args()

       # Import training_script as a module.
       lowerCAmelCase__	      =   Path(args.training_script      )
       sys.path.append(str(script_fpath.parent.resolve()      )      )
       lowerCAmelCase__	      =   script_fpath.stem
       lowerCAmelCase__	      =   importlib.import_module(lowerCAmelCase__      )

       # Patch sys.argv
       lowerCAmelCase__	      =   [args.training_script] + args.training_script_args + ['--tpu_num_cores', str(args.num_cores      )]

       xmp.spawn(mod._mp_fn      ,    args=()      ,    nprocs=args.num_cores      )


if __name__ == "__main__":
    main()
