'''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[str]						   ='''none'''
_A		:      Union[str, Any]						   ='''none'''







def 				__UpperCamelCase (					__UpperCAmelCase  :					Optional[Any] ,   __UpperCAmelCase  :					List[str]			)							->	List[str]:
  lowercase				:							Dict									=   value.split(__UpperCAmelCase			)
  return len(__UpperCAmelCase			) > 1 and any((len(__UpperCAmelCase			) == 3 for x in split)			)







def 				__UpperCamelCase (					__UpperCAmelCase  :					Dict			)							->	Optional[int]:
  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'''			)
  lowercase				:							Optional[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  :					Dict			)							->	Optional[Any]:
  if answer is None:
    return None
  try:
    lowercase				:							Dict									=   convert_to_float(__UpperCAmelCase			)
    if isinstance(__UpperCAmelCase ,   __UpperCAmelCase			) and math.isnan(__UpperCAmelCase			):
      return None
    return value
  except ValueError:
    return answer.lower()


_A		:      str						   ={
    '''text''': lambda x: x,
    '''real''': convert_to_float,
}




class _lowerCAmelCase			(	enum.Enum					):
      UpperCAmelCase_	:						List[str]	 =       0
      UpperCAmelCase_	:						Any	 =       1
      UpperCAmelCase_	:						Tuple	 =       2
      UpperCAmelCase_	:						str	 =       3
      UpperCAmelCase_	:						Optional[Any]	 =       4
      UpperCAmelCase_	:						Dict	 =       5





class _lowerCAmelCase			(	enum.Enum					):
      UpperCAmelCase_	:						Any	 =       0
      UpperCAmelCase_	:						Tuple	 =       1
      UpperCAmelCase_	:						int	 =       2





@dataclasses.dataclass
class _lowerCAmelCase			:
      UpperCAmelCase_	:						Text
      UpperCAmelCase_	:						_Operator
      UpperCAmelCase_	:						Any





_A		:      Dict						   =re.compile(r'''\w+|[^\w\s]+''', re.UNICODE | re.MULTILINE | re.DOTALL)







def 				__UpperCamelCase (					__UpperCAmelCase  :					List[Any]			)							->	str:
  return list(_TOKENIZER.findall(x.lower()			)			)







def 				__UpperCamelCase (					__UpperCAmelCase  :					List[Any] ,   __UpperCAmelCase  :					Optional[Any] ,   __UpperCAmelCase  :					List[str]			)							->	Optional[Any]:
  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  :					Dict ,   __UpperCAmelCase  :					List[Any] ,   __UpperCAmelCase  :					List[Any]			)							->	Any:
  lowercase				:							Tuple									=   table['''types''']
  return _TYPE_CONVERTER[types[column]](__UpperCAmelCase			)







def 				__UpperCamelCase (					__UpperCAmelCase  :					Any			)							->	Any:
  return isinstance(__UpperCAmelCase ,   __UpperCAmelCase			)







def 				__UpperCamelCase (					__UpperCAmelCase  :					Any ,   __UpperCAmelCase  :					Tuple ,   __UpperCAmelCase  :					List[str]			)							->	Union[str, Any]:
  for cond in conditions:
    lowercase				:							Optional[Any]									=   row[cond.column]

    lowercase				:							Union[str, Any]									=   _parse_value(__UpperCAmelCase ,   cond.column ,   cond.cmp_value			)

    if _is_string(__UpperCAmelCase			) and _is_string(__UpperCAmelCase			):
      lowercase				:							Union[str, Any]									=   _normalize_for_match(__UpperCAmelCase			)
      lowercase				:							List[str]									=   _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  :					List[str] ,   __UpperCAmelCase  :					Dict ,   __UpperCAmelCase  :					List[Any]			)							->	Optional[int]:
  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.
  lowercase				:							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  :					str ,   __UpperCAmelCase  :					Optional[Any]			)							->	Tuple:
  lowercase				:							Tuple									=   sql_query['''agg''']
  if aggregation_op_index >= 3:
    lowercase				:							Optional[int]									=   _Aggregation(__UpperCAmelCase			)
  else:
    lowercase				:							int									=   _Aggregation.NONE

  lowercase				:							Union[str, Any]									=   sql_query['''sel''']
  lowercase				:							Union[str, Any]									=   [
      _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''']			)
  ]

  lowercase				:							Tuple									=   []
  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):
    lowercase				:							str									=   {2: min, 1: max}
    lowercase				:							int									=   [(table['''rows'''][i][j], index) for index, (i, j) in enumerate(__UpperCAmelCase			)]
    lowercase				:							Dict									=   functools.reduce(operators[sql_query['''agg''']] ,   __UpperCAmelCase			)

    lowercase				:							Any									=   [indices[reduced[1]]]
    return ret, _Aggregation.NONE

  return indices, aggregation_op







def 				__UpperCamelCase (					__UpperCAmelCase  :					Union[str, Any] ,   __UpperCAmelCase  :					List[str] ,   __UpperCAmelCase  :					List[str]			)							->	List[Any]:
  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  :					List[str] ,   __UpperCAmelCase  :					List[Any]			)							->	List:
  lowercase				,      lowercase				:							Any									=   _get_answer_coordinates(__UpperCAmelCase ,   __UpperCAmelCase			)
  lowercase				:							Optional[int]									=   _get_float_answer(__UpperCAmelCase ,   __UpperCAmelCase ,   __UpperCAmelCase			)
  lowercase				:							Any									=   _get_answer_text(__UpperCAmelCase ,   __UpperCAmelCase ,   __UpperCAmelCase			)
  # keep the original data the same with TaPas
  if len(__UpperCAmelCase			) == 0:
    lowercase				:							Any									=   [EMPTY_ANSWER]
  return answer_text
'''simple docstring'''
def 				__UpperCamelCase (					__UpperCAmelCase  :					float ,   __UpperCAmelCase  :					float ,   __UpperCAmelCase  :					float			)							->	list[int]:
  if hue < 0 or hue > 360:
    raise Exception('''hue should be between 0 and 360'''			)

  if saturation < 0 or saturation > 1:
    raise Exception('''saturation should be between 0 and 1'''			)

  if value < 0 or value > 1:
    raise Exception('''value should be between 0 and 1'''			)

  lowercase				:							List[str]									=   value * saturation
  lowercase				:							Optional[Any]									=   hue / 60
  lowercase				:							Dict									=   chroma * (1 - abs(hue_section % 2 - 1			))
  lowercase				:							List[Any]									=   value - chroma

  if hue_section >= 0 and hue_section <= 1:
    lowercase				:							Optional[int]									=   round(255 * (chroma + match_value)			)
    lowercase				:							List[Any]									=   round(255 * (second_largest_component + match_value)			)
    lowercase				:							int									=   round(255 * (match_value)			)
  elif hue_section > 1 and hue_section <= 2:
    lowercase				:							Optional[Any]									=   round(255 * (second_largest_component + match_value)			)
    lowercase				:							Any									=   round(255 * (chroma + match_value)			)
    lowercase				:							Any									=   round(255 * (match_value)			)
  elif hue_section > 2 and hue_section <= 3:
    lowercase				:							Dict									=   round(255 * (match_value)			)
    lowercase				:							Optional[int]									=   round(255 * (chroma + match_value)			)
    lowercase				:							List[str]									=   round(255 * (second_largest_component + match_value)			)
  elif hue_section > 3 and hue_section <= 4:
    lowercase				:							List[str]									=   round(255 * (match_value)			)
    lowercase				:							List[str]									=   round(255 * (second_largest_component + match_value)			)
    lowercase				:							Tuple									=   round(255 * (chroma + match_value)			)
  elif hue_section > 4 and hue_section <= 5:
    lowercase				:							Optional[int]									=   round(255 * (second_largest_component + match_value)			)
    lowercase				:							Tuple									=   round(255 * (match_value)			)
    lowercase				:							Optional[int]									=   round(255 * (chroma + match_value)			)
  else:
    lowercase				:							int									=   round(255 * (chroma + match_value)			)
    lowercase				:							Optional[Any]									=   round(255 * (match_value)			)
    lowercase				:							Optional[int]									=   round(255 * (second_largest_component + match_value)			)

  return [red, green, blue]







def 				__UpperCamelCase (					__UpperCAmelCase  :					int ,   __UpperCAmelCase  :					int ,   __UpperCAmelCase  :					int			)							->	list[float]:
  if red < 0 or red > 255:
    raise Exception('''red should be between 0 and 255'''			)

  if green < 0 or green > 255:
    raise Exception('''green should be between 0 and 255'''			)

  if blue < 0 or blue > 255:
    raise Exception('''blue should be between 0 and 255'''			)

  lowercase				:							str									=   red / 255
  lowercase				:							Union[str, Any]									=   green / 255
  lowercase				:							Union[str, Any]									=   blue / 255
  lowercase				:							str									=   max(__UpperCAmelCase ,   __UpperCAmelCase ,   __UpperCAmelCase			)
  lowercase				:							int									=   value - min(__UpperCAmelCase ,   __UpperCAmelCase ,   __UpperCAmelCase			)
  lowercase				:							Optional[int]									=   0 if value == 0 else chroma / value

  if chroma == 0:
    lowercase				:							Dict									=   0.0
  elif value == float_red:
    lowercase				:							Tuple									=   60 * (0 + (float_green - float_blue) / chroma)
  elif value == float_green:
    lowercase				:							Optional[int]									=   60 * (2 + (float_blue - float_red) / chroma)
  else:
    lowercase				:							Dict									=   60 * (4 + (float_red - float_green) / chroma)

  lowercase				:							List[str]									=   (hue + 360) % 360

  return [hue, saturation, value]







def 				__UpperCamelCase (					__UpperCAmelCase  :					list[float] ,   __UpperCAmelCase  :					list[float]			)							->	bool:
  lowercase				:							int									=   abs(hsv_a[0] - hsv_a[0]			) < 0.2
  lowercase				:							Optional[int]									=   abs(hsv_a[1] - hsv_a[1]			) < 0.002
  lowercase				:							Dict									=   abs(hsv_a[2] - hsv_a[2]			) < 0.002

  return check_hue and check_saturation and check_value