




from __future__ import annotations

from math import pi, pow


def 				__SCREAMING_SNAKE_CASE    (     snake_case_		):

						'''simple docstring'''


						if side_length < 0:
												raise ValueError("vol_cube() only accepts non-negative values"		)
						return pow(UpperCAmelCase_      ,       3		)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if height < 0 or radius < 0:
												raise ValueError("vol_spherical_cap() only accepts non-negative values"		)
						# Volume is 1/3 pi * height squared * (3 * radius - height)
						return 1 / 3 * pi * pow(UpperCAmelCase_      ,       2		) * (3 * radius - height)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if radius_a < 0 or radius_a < 0 or centers_distance < 0:
												raise ValueError("vol_spheres_intersect() only accepts non-negative values"		)
						if centers_distance == 0:
												return vol_sphere(min(UpperCAmelCase_      ,       UpperCAmelCase_		)		)

						_UpperCAmelCase						=	(
						    (radius_a - radius_a + centers_distance)
						    * (radius_a + radius_a - centers_distance)
						    / (2 * centers_distance)
						)
						_UpperCAmelCase						=	(
						    (radius_a - radius_a + centers_distance)
						    * (radius_a + radius_a - centers_distance)
						    / (2 * centers_distance)
						)

						return vol_spherical_cap(UpperCAmelCase_      ,       UpperCAmelCase_		) + vol_spherical_cap(UpperCAmelCase_      ,       UpperCAmelCase_		)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if radius_a <= 0 or radius_a <= 0 or centers_distance < 0:
												raise ValueError(
												    "vol_spheres_union() only accepts non-negative values, non-zero radius"		)

						if centers_distance == 0:
												return vol_sphere(max(UpperCAmelCase_      ,       UpperCAmelCase_		)		)

						return (
						    vol_sphere(UpperCAmelCase_		)
						    + vol_sphere(UpperCAmelCase_		)
						    - vol_spheres_intersect(UpperCAmelCase_      ,       UpperCAmelCase_      ,       UpperCAmelCase_		)
						)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if width < 0 or height < 0 or length < 0:
												raise ValueError("vol_cuboid() only accepts non-negative values"		)
						return float(width * height * length		)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if height < 0 or area_of_base < 0:
												raise ValueError("vol_cone() only accepts non-negative values"		)
						return area_of_base * height / 3.0


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if height < 0 or radius < 0:
												raise ValueError("vol_right_circ_cone() only accepts non-negative values"		)
						return pi * pow(UpperCAmelCase_      ,       2		) * height / 3.0


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if height < 0 or area_of_base < 0:
												raise ValueError("vol_prism() only accepts non-negative values"		)
						return float(area_of_base * height		)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if height < 0 or area_of_base < 0:
												raise ValueError("vol_pyramid() only accepts non-negative values"		)
						return area_of_base * height / 3.0


def 				__SCREAMING_SNAKE_CASE    (     snake_case_		):

						'''simple docstring'''


						if radius < 0:
												raise ValueError("vol_sphere() only accepts non-negative values"		)
						# Volume is 4/3 * pi * radius cubed
						return 4 / 3 * pi * pow(UpperCAmelCase_      ,       3		)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_		):

						'''simple docstring'''


						if radius < 0:
												raise ValueError("vol_hemisphere() only accepts non-negative values"		)
						# Volume is radius cubed * pi * 2/3
						return pow(UpperCAmelCase_      ,       3		) * pi * 2 / 3


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if height < 0 or radius < 0:
												raise ValueError("vol_circular_cylinder() only accepts non-negative values"		)
						# Volume is radius squared * height * pi
						return pow(UpperCAmelCase_      ,       2		) * height * pi


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if inner_radius < 0 or outer_radius < 0 or height < 0:
												raise ValueError(
												    "vol_hollow_circular_cylinder() only accepts non-negative values"		)
						if outer_radius <= inner_radius:
												raise ValueError("outer_radius must be greater than inner_radius"		)
						return pi * (pow(UpperCAmelCase_      ,       2		) - pow(UpperCAmelCase_      ,       2		)) * height


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if radius_a < 0 or radius_a < 0 or height < 0:
												raise ValueError("vol_conical_frustum() only accepts non-negative values"		)
						return (
						    1
						    / 3
						    * pi
						    * height
						    * (pow(UpperCAmelCase_      ,       2		) + pow(UpperCAmelCase_      ,       2		) + radius_a * radius_a)
						)


def 				__SCREAMING_SNAKE_CASE    (     snake_case_      ,       snake_case_		):

						'''simple docstring'''


						if torus_radius < 0 or tube_radius < 0:
												raise ValueError("vol_torus() only accepts non-negative values"		)
						return 2 * pow(UpperCAmelCase_      ,       2		) * torus_radius * pow(UpperCAmelCase_      ,       2		)


def 				__SCREAMING_SNAKE_CASE    (     ):

						'''simple docstring'''


						print("Volumes:"		)
						print(f"""Cube: {vol_cube(2		) = }"""		)  # = 8
						print(f"""Cuboid: {vol_cuboid(2      ,       2      ,       2		) = }"""		)  # = 8
						print(f"""Cone: {vol_cone(2      ,       2		) = }"""		)  # ~= 1.33
						print(f"""Right Circular Cone: {vol_right_circ_cone(2      ,       2		) = }"""		)  # ~= 8.38
						print(f"""Prism: {vol_prism(2      ,       2		) = }"""		)  # = 4
						print(f"""Pyramid: {vol_pyramid(2      ,       2		) = }"""		)  # ~= 1.33
						print(f"""Sphere: {vol_sphere(2		) = }"""		)  # ~= 33.5
						print(f"""Hemisphere: {vol_hemisphere(2		) = }"""		)  # ~= 16.75
						print(f"""Circular Cylinder: {vol_circular_cylinder(2      ,       2		) = }"""		)  # ~= 25.1
						print(f"""Torus: {vol_torus(2      ,       2		) = }"""		)  # ~= 157.9
						print(f"""Conical Frustum: {vol_conical_frustum(2      ,       2      ,       4		) = }"""		)  # ~= 58.6
						print(f"""Spherical cap: {vol_spherical_cap(1      ,       2		) = }"""		)  # ~= 5.24
						print(f"""Spheres intersetion: {vol_spheres_intersect(2      ,       2      ,       1		) = }"""		)  # ~= 21.21
						print(f"""Spheres union: {vol_spheres_union(2      ,       2      ,       1		) = }"""		)  # ~= 45.81
						print(
						    f"""Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1      ,       2      ,       3		) = }"""		)  # ~= 28.3


if __name__ == "__main__":
				main()





"""simple docstring"""







import dataclasses
import enum
import functools
import math
import re

# The following script is adapted from the script of TaPas.
# Original: https://github.com/google-research/tapas/master/wikisql_utils.py
from typing import Any, List, Text


_a	:	List[Any]=					"none"
_a	:	List[str]=					"none"
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[int]     ,				UpperCAmelCase_       :							Tuple    )				->     Dict:

	'''simple docstring'''





	__snake_case     :				int 						=					value.split(UpperCAmelCase_    )
	return len(UpperCAmelCase_    ) > 1 and any((len(UpperCAmelCase_    ) == 3 for x in split)    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[Any]    )				->     Tuple:

	'''simple docstring'''





	if isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ):
		return value
	if isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ):
		return float(UpperCAmelCase_    )
	if not isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ):
		raise ValueError('Argument value is not a string. Can\'t parse it as float'    )
	__snake_case     :				Any 						=					value

	try:
		# Example: 1,000.7
		if "." in sanitized and "," in sanitized:
			return float(sanitized.replace(','     ,				''    )    )
		# 1,000
		if "," in sanitized and _split_thousands(','     ,				UpperCAmelCase_    ):
			return float(sanitized.replace(','     ,				''    )    )
		# 5,5556
		if "," in sanitized and sanitized.count(','    ) == 1 and not _split_thousands(','     ,				UpperCAmelCase_    ):
			return float(sanitized.replace(','     ,				'.'    )    )
		# 0.0.0.1
		if sanitized.count('.'    ) > 1:
			return float(sanitized.replace('.'     ,				''    )    )
		# 0,0,0,1
		if sanitized.count(','    ) > 1:
			return float(sanitized.replace(','     ,				''    )    )
		return float(UpperCAmelCase_    )
	except ValueError:
		# Avoid adding the sanitized value in the error message.
		raise ValueError('Unable to convert value to float'    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							str    )				->     Any:

	'''simple docstring'''





	if answer is None:
		return None
	try:
		__snake_case     :				Dict 						=					convert_to_float(UpperCAmelCase_    )
		if isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    ) and math.isnan(UpperCAmelCase_    ):
			return None
		return value
	except ValueError:
		return answer.lower()


_a	:	Union[str, Any]=					{
    "text": lambda x: x,
    "real": convert_to_float,
}

class 						UpperCamelCase     (       enum.Enum		):
				UpperCAmelCase							: int       =						0
				UpperCAmelCase							: Optional[Any]       =						1
				UpperCAmelCase							: List[Any]       =						2
				UpperCAmelCase							: Dict       =						3
				UpperCAmelCase							: Union[str, Any]       =						4
				UpperCAmelCase							: int       =						5







class 						UpperCamelCase     (       enum.Enum		):
				UpperCAmelCase							: List[str]       =						0
				UpperCAmelCase							: List[str]       =						1
				UpperCAmelCase							: int       =						2







@dataclasses.dataclass
class 						UpperCamelCase     :
				UpperCAmelCase							: Text
				UpperCAmelCase							: _Operator
				UpperCAmelCase							: Any







_a	:	Union[str, Any]=					re.compile(R"\w+|[^\w\s]+", re.UNICODE | re.MULTILINE | re.DOTALL)
def     __UpperCAmelCase							(       UpperCAmelCase_       :							List[str]    )				->     Optional[Any]:

	'''simple docstring'''





	return list(_TOKENIZER.findall(x.lower()    )    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Tuple     ,				UpperCAmelCase_       :							int     ,				UpperCAmelCase_       :							List[Any]    )				->     List[str]:

	'''simple docstring'''





	if operator == _Operator.EQUALS:
		return src == tgt
	elif operator == _Operator.GREATER:
		return src > tgt
	elif operator == _Operator.LESSER:
		return src < tgt
	raise ValueError(F"Unknown operator: {operator}"    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							List[Any]     ,				UpperCAmelCase_       :							int     ,				UpperCAmelCase_       :							Optional[Any]    )				->     Dict:

	'''simple docstring'''





	__snake_case     :				Optional[Any] 						=					table['types']
	return _TYPE_CONVERTER[types[column]](UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							List[Any]    )				->     str:

	'''simple docstring'''





	return isinstance(UpperCAmelCase_     ,				UpperCAmelCase_    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Dict     ,				UpperCAmelCase_       :							Union[str, Any]     ,				UpperCAmelCase_       :							int    )				->     List[Any]:

	'''simple docstring'''





	for cond in conditions:
		__snake_case     :				Any 						=					row[cond.column]

		__snake_case     :				Tuple 						=					_parse_value(UpperCAmelCase_     ,				cond.column     ,				cond.cmp_value    )

		if _is_string(UpperCAmelCase_    ) and _is_string(UpperCAmelCase_    ):
			__snake_case     :				str 						=					_normalize_for_match(UpperCAmelCase_    )
			__snake_case     :				Dict 						=					_normalize_for_match(UpperCAmelCase_    )

		if not isinstance(UpperCAmelCase_     ,				type(UpperCAmelCase_    )    ):
			raise ValueError('Type difference {} != {}'.format(type(UpperCAmelCase_    )     ,				type(UpperCAmelCase_    )    )    )

		if not _compare(cond.operator     ,				UpperCAmelCase_     ,				UpperCAmelCase_    ):
			return False
	return True
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Union[str, Any]     ,				UpperCAmelCase_       :							List[str]     ,				UpperCAmelCase_       :							Optional[int]    )				->     Dict:

	'''simple docstring'''





	if not answer_coordinates:
		if aggregation_op == _Aggregation.COUNT:
			return 0.0
		else:
			return EMPTY_ANSWER_AGG

    # Count can support non numeric answers.
	if aggregation_op == _Aggregation.COUNT:
		return float(len(UpperCAmelCase_    )    )

	# If we have just one answer, if float returns it or try a conversion.
	__snake_case     :				Any 						=					[table['rows'][i][j] for (i, j) in answer_coordinates]
	if len(UpperCAmelCase_    ) == 1:
		try:
			return convert_to_float(values[0]    )
		except ValueError as e:
			if aggregation_op != _Aggregation.NONE:
				raise e

	if aggregation_op == _Aggregation.NONE:
		return None

	# Other aggregation only support numeric values. Bail out if we have strings.
	if not all((isinstance(UpperCAmelCase_     ,				(int, float)    ) for v in values)    ):
		return None

	if aggregation_op == _Aggregation.SUM:
		return float(sum(UpperCAmelCase_    )    )
	elif aggregation_op == _Aggregation.AVERAGE:
		return sum(UpperCAmelCase_    ) / len(UpperCAmelCase_    )
	else:
		raise ValueError(F"Unknown aggregation: {aggregation_op}"    )
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Optional[Any]     ,				UpperCAmelCase_       :							int    )				->     str:

	'''simple docstring'''





	__snake_case     :				int 						=					sql_query['agg']
	if aggregation_op_index >= 3:
		__snake_case     :				Optional[Any] 						=					_Aggregation(UpperCAmelCase_    )
	else:
		__snake_case     :				Any 						=					_Aggregation.NONE

	__snake_case     :				Dict 						=					sql_query['sel']
	__snake_case     :				Dict 						=					[
	    _Condition(UpperCAmelCase_     ,				_Operator(UpperCAmelCase_    )     ,				UpperCAmelCase_    )
	    for column, operator, cmp_value in zip(
	        sql_query['conds']['column_index']     ,				sql_query['conds']['operator_index']     ,				sql_query['conds']['condition']    )
	]

	__snake_case     :				str 						=					[]
	for row in range(len(table['rows']    )    ):
		if _respect_conditions(UpperCAmelCase_     ,				table['rows'][row]     ,				UpperCAmelCase_    ):
			indices.append((row, target_column)    )

	if not indices:
		return [], aggregation_op

	if len(UpperCAmelCase_    ) == 1:
		return indices, aggregation_op

	# Parsing of MIN/MAX.
	if aggregation_op_index in (1, 2):
		__snake_case     :				Union[str, Any] 						=					{2: min, 1: max}
		__snake_case     :				Optional[Any] 						=					[(table['rows'][i][j], index) for index, (i, j) in enumerate(UpperCAmelCase_    )]
		__snake_case     :				Tuple 						=					functools.reduce(operators[sql_query['agg']]     ,				UpperCAmelCase_    )

		__snake_case     :				str 						=					[indices[reduced[1]]]
		return ret, _Aggregation.NONE

	return indices, aggregation_op
def     __UpperCAmelCase							(       UpperCAmelCase_       :							Dict     ,				UpperCAmelCase_       :							List[Any]     ,				UpperCAmelCase_       :							Any    )				->     Optional[Any]:

	'''simple docstring'''





	if float_answer is not None:
		return [str(UpperCAmelCase_    )]
	return [str(table['real_rows'][r][c]    ) for r, c in answer_coordinates]

def     __UpperCAmelCase							(       UpperCAmelCase_       :							int     ,				UpperCAmelCase_       :							Tuple    )				->     List:

	'''simple docstring'''





	__snake_case						,							__snake_case     :				List[Any] 						=					_get_answer_coordinates(UpperCAmelCase_     ,				UpperCAmelCase_    )
	__snake_case     :				Optional[int] 						=					_get_float_answer(UpperCAmelCase_     ,				UpperCAmelCase_     ,				UpperCAmelCase_    )
	__snake_case     :				Union[str, Any] 						=					_get_answer_text(UpperCAmelCase_     ,				UpperCAmelCase_     ,				UpperCAmelCase_    )
	# keep the original data the same with TaPas
	if len(UpperCAmelCase_    ) == 0:
		__snake_case     :				List[str] 						=					[EMPTY_ANSWER]
	return answer_text





