

import argparse
import json

import torch

from diffusers import AutoencoderKL, DDPMPipeline, DDPMScheduler, UNetaDModel, VQModel







def  UpperCAmelCase_   (_lowerCAmelCase :		List[str]     ,			_lowerCAmelCase :		str=1		):
			if n_shave_prefix_segments >= 0:
						return ".".join(path.split("."		)[n_shave_prefix_segments:]		)
			else:
						return ".".join(path.split("."		)[:n_shave_prefix_segments]		)







def  UpperCAmelCase_   (_lowerCAmelCase :		int     ,			_lowerCAmelCase :		Any=0		):
			__UpperCamelCase    :    Tuple								=      []
			for old_item in old_list:
						__UpperCamelCase    :    Dict								=      old_item
						__UpperCamelCase    :    int								=      new_item.replace("block."     ,			"resnets."		)
						__UpperCamelCase    :    int								=      new_item.replace("conv_shorcut"     ,			"conv1"		)
						__UpperCamelCase    :    List[str]								=      new_item.replace("in_shortcut"     ,			"conv_shortcut"		)
						__UpperCamelCase    :    List[Any]								=      new_item.replace("temb_proj"     ,			"time_emb_proj"		)

						__UpperCamelCase    :    Any								=      shave_segments(_lowerCAmelCase     ,			n_shave_prefix_segments=_lowerCAmelCase		)

						mapping.append({"old": old_item, "new": new_item}		)

			return mapping







def  UpperCAmelCase_   (_lowerCAmelCase :		List[Any]     ,			_lowerCAmelCase :		int=0     ,			_lowerCAmelCase :		Optional[int]=False		):
			__UpperCamelCase    :    Optional[int]								=      []
			for old_item in old_list:
						__UpperCamelCase    :    List[str]								=      old_item

						# In `model.mid`, the layer is called `attn`.
						if not in_mid:
									__UpperCamelCase    :    Optional[int]								=      new_item.replace("attn"     ,			"attentions"		)
						__UpperCamelCase    :    Optional[int]								=      new_item.replace(".k."     ,			".key."		)
						__UpperCamelCase    :    Optional[Any]								=      new_item.replace(".v."     ,			".value."		)
						__UpperCamelCase    :    List[Any]								=      new_item.replace(".q."     ,			".query."		)

						__UpperCamelCase    :    Any								=      new_item.replace("proj_out"     ,			"proj_attn"		)
						__UpperCamelCase    :    Any								=      new_item.replace("norm"     ,			"group_norm"		)

						__UpperCamelCase    :    List[Any]								=      shave_segments(_lowerCAmelCase     ,			n_shave_prefix_segments=_lowerCAmelCase		)
						mapping.append({"old": old_item, "new": new_item}		)

			return mapping







def  UpperCAmelCase_   (_lowerCAmelCase :		str     ,			_lowerCAmelCase :		List[Any]     ,			_lowerCAmelCase :		Tuple     ,			_lowerCAmelCase :		Tuple=None     ,			_lowerCAmelCase :		Union[str, Any]=None     ,			_lowerCAmelCase :		List[Any]=None		):
			assert isinstance(_lowerCAmelCase     ,			_lowerCAmelCase		), "Paths should be a list of dicts containing 'old' and 'new' keys."

			if attention_paths_to_split is not None:
						if config is None:
									raise ValueError("Please specify the config if setting 'attention_paths_to_split' to 'True'."		)

						for path, path_map in attention_paths_to_split.items():
									__UpperCamelCase    :    List[str]								=      old_checkpoint[path]
									__UpperCamelCase    :    Optional[Any]								=      old_tensor.shape[0] // 3

									__UpperCamelCase    :    Optional[Any]								=      (-1, channels) if len(old_tensor.shape		) == 3 else (-1)

									__UpperCamelCase    :    int								=      old_tensor.shape[0] // config.get("num_head_channels"     ,			1		) // 3

									__UpperCamelCase    :    Union[str, Any]								=      old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:]		)
									__UpperCamelCase							,				__UpperCamelCase							,				__UpperCamelCase    :    Dict								=      old_tensor.split(channels // num_heads     ,			dim=1		)

									__UpperCamelCase    :    Optional[Any]								=      query.reshape(_lowerCAmelCase		).squeeze()
									__UpperCamelCase    :    Any								=      key.reshape(_lowerCAmelCase		).squeeze()
									__UpperCamelCase    :    List[str]								=      value.reshape(_lowerCAmelCase		).squeeze()

			for path in paths:
						__UpperCamelCase    :    Dict								=      path["new"]

						if attention_paths_to_split is not None and new_path in attention_paths_to_split:
									continue

						__UpperCamelCase    :    str								=      new_path.replace("down."     ,			"down_blocks."		)
						__UpperCamelCase    :    Dict								=      new_path.replace("up."     ,			"up_blocks."		)

						if additional_replacements is not None:
									for replacement in additional_replacements:
												__UpperCamelCase    :    List[str]								=      new_path.replace(replacement["old"]     ,			replacement["new"]		)

						if "attentions" in new_path:
									__UpperCamelCase    :    List[Any]								=      old_checkpoint[path["old"]].squeeze()
						else:
									__UpperCamelCase    :    Any								=      old_checkpoint[path["old"]]







def  UpperCAmelCase_   (_lowerCAmelCase :		Dict     ,			_lowerCAmelCase :		List[str]		):
			__UpperCamelCase    :    Union[str, Any]								=      {}

			__UpperCamelCase    :    str								=      checkpoint["temb.dense.0.weight"]
			__UpperCamelCase    :    Union[str, Any]								=      checkpoint["temb.dense.0.bias"]
			__UpperCamelCase    :    Any								=      checkpoint["temb.dense.1.weight"]
			__UpperCamelCase    :    Union[str, Any]								=      checkpoint["temb.dense.1.bias"]

			__UpperCamelCase    :    List[Any]								=      checkpoint["norm_out.weight"]
			__UpperCamelCase    :    Optional[Any]								=      checkpoint["norm_out.bias"]

			__UpperCamelCase    :    Optional[Any]								=      checkpoint["conv_in.weight"]
			__UpperCamelCase    :    str								=      checkpoint["conv_in.bias"]
			__UpperCamelCase    :    List[str]								=      checkpoint["conv_out.weight"]
			__UpperCamelCase    :    List[Any]								=      checkpoint["conv_out.bias"]

			__UpperCamelCase    :    Optional[int]								=      len({".".join(layer.split("."		)[:2]		) for layer in checkpoint if "down" in layer}		)
			__UpperCamelCase    :    str								=      {
			    layer_id: [key for key in checkpoint if F'''down.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)
			}

			__UpperCamelCase    :    Optional[int]								=      len({".".join(layer.split("."		)[:2]		) for layer in checkpoint if "up" in layer}		)
			__UpperCamelCase    :    Optional[int]								=      {layer_id: [key for key in checkpoint if F'''up.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)}

			for i in range(_lowerCAmelCase		):
						__UpperCamelCase    :    Union[str, Any]								=      (i - 1) // (config["layers_per_block"] + 1)

						if any("downsample" in layer for layer in down_blocks[i]		):
									__UpperCamelCase    :    Union[str, Any]								=      checkpoint[
									    F'''down.{i}.downsample.op.weight'''
									]
									__UpperCamelCase    :    Tuple								=      checkpoint[F'''down.{i}.downsample.op.bias''']
						#            new_checkpoint[f'down_blocks.{i}.downsamplers.0.op.weight'] = checkpoint[f'down.{i}.downsample.conv.weight']
						#            new_checkpoint[f'down_blocks.{i}.downsamplers.0.op.bias'] = checkpoint[f'down.{i}.downsample.conv.bias']

						if any("block" in layer for layer in down_blocks[i]		):
									__UpperCamelCase    :    int								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			2		).split("."		)[:2]		) for layer in down_blocks[i] if "block" in layer}		)
									__UpperCamelCase    :    Any								=      {
									    layer_id: [key for key in down_blocks[i] if F'''block.{layer_id}''' in key]
									    for layer_id in range(_lowerCAmelCase		)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"]		):
															__UpperCamelCase    :    Optional[int]								=      renew_resnet_paths(blocks[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase		)

						if any("attn" in layer for layer in down_blocks[i]		):
									__UpperCamelCase    :    Dict								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			2		).split("."		)[:2]		) for layer in down_blocks[i] if "attn" in layer}		)
									__UpperCamelCase    :    int								=      {
									    layer_id: [key for key in down_blocks[i] if F'''attn.{layer_id}''' in key]
									    for layer_id in range(_lowerCAmelCase		)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"]		):
															__UpperCamelCase    :    Union[str, Any]								=      renew_attention_paths(attns[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			config=_lowerCAmelCase		)

			__UpperCamelCase    :    Optional[int]								=      [key for key in checkpoint if "mid.block_1" in key]
			__UpperCamelCase    :    Tuple								=      [key for key in checkpoint if "mid.block_2" in key]
			__UpperCamelCase    :    Optional[Any]								=      [key for key in checkpoint if "mid.attn_1" in key]

			# Mid new 2
			__UpperCamelCase    :    Tuple								=      renew_resnet_paths(_lowerCAmelCase		)
			assign_to_checkpoint(
			    _lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_1", "new": "resnets.0"}]     ,			)

			__UpperCamelCase    :    Optional[int]								=      renew_resnet_paths(_lowerCAmelCase		)
			assign_to_checkpoint(
			    _lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_2", "new": "resnets.1"}]     ,			)

			__UpperCamelCase    :    List[str]								=      renew_attention_paths(_lowerCAmelCase     ,			in_mid=_lowerCAmelCase		)
			assign_to_checkpoint(
			    _lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "attn_1", "new": "attentions.0"}]     ,			)

			for i in range(_lowerCAmelCase		):
						__UpperCamelCase    :    List[str]								=      num_up_blocks - 1 - i

						if any("upsample" in layer for layer in up_blocks[i]		):
									__UpperCamelCase    :    Any								=      checkpoint[
									    F'''up.{i}.upsample.conv.weight'''
									]
									__UpperCamelCase    :    Optional[int]								=      checkpoint[F'''up.{i}.upsample.conv.bias''']

						if any("block" in layer for layer in up_blocks[i]		):
									__UpperCamelCase    :    Any								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			2		).split("."		)[:2]		) for layer in up_blocks[i] if "block" in layer}		)
									__UpperCamelCase    :    Dict								=      {
									    layer_id: [key for key in up_blocks[i] if F'''block.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"] + 1		):
															__UpperCamelCase    :    Tuple								=      {"old": F'''up_blocks.{i}''', "new": F'''up_blocks.{block_id}'''}
															__UpperCamelCase    :    Optional[int]								=      renew_resnet_paths(blocks[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[replace_indices]		)

						if any("attn" in layer for layer in up_blocks[i]		):
									__UpperCamelCase    :    Union[str, Any]								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			2		).split("."		)[:2]		) for layer in up_blocks[i] if "attn" in layer}		)
									__UpperCamelCase    :    Optional[int]								=      {
									    layer_id: [key for key in up_blocks[i] if F'''attn.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"] + 1		):
															__UpperCamelCase    :    List[str]								=      {"old": F'''up_blocks.{i}''', "new": F'''up_blocks.{block_id}'''}
															__UpperCamelCase    :    Union[str, Any]								=      renew_attention_paths(attns[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[replace_indices]		)

			__UpperCamelCase    :    List[str]								=      {k.replace("mid_new_2"     ,			"mid_block"		): v for k, v in new_checkpoint.items()}
			return new_checkpoint







def  UpperCAmelCase_   (_lowerCAmelCase :		List[Any]     ,			_lowerCAmelCase :		int		):
			__UpperCamelCase    :    Optional[Any]								=      {}

			__UpperCamelCase    :    int								=      checkpoint["encoder.norm_out.weight"]
			__UpperCamelCase    :    Tuple								=      checkpoint["encoder.norm_out.bias"]

			__UpperCamelCase    :    Any								=      checkpoint["encoder.conv_in.weight"]
			__UpperCamelCase    :    Union[str, Any]								=      checkpoint["encoder.conv_in.bias"]
			__UpperCamelCase    :    List[Any]								=      checkpoint["encoder.conv_out.weight"]
			__UpperCamelCase    :    Union[str, Any]								=      checkpoint["encoder.conv_out.bias"]

			__UpperCamelCase    :    int								=      checkpoint["decoder.norm_out.weight"]
			__UpperCamelCase    :    Dict								=      checkpoint["decoder.norm_out.bias"]

			__UpperCamelCase    :    Union[str, Any]								=      checkpoint["decoder.conv_in.weight"]
			__UpperCamelCase    :    str								=      checkpoint["decoder.conv_in.bias"]
			__UpperCamelCase    :    List[str]								=      checkpoint["decoder.conv_out.weight"]
			__UpperCamelCase    :    Tuple								=      checkpoint["decoder.conv_out.bias"]

			__UpperCamelCase    :    List[Any]								=      len({".".join(layer.split("."		)[:3]		) for layer in checkpoint if "down" in layer}		)
			__UpperCamelCase    :    Tuple								=      {
			    layer_id: [key for key in checkpoint if F'''down.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)
			}

			__UpperCamelCase    :    Optional[int]								=      len({".".join(layer.split("."		)[:3]		) for layer in checkpoint if "up" in layer}		)
			__UpperCamelCase    :    List[Any]								=      {layer_id: [key for key in checkpoint if F'''up.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)}

			for i in range(_lowerCAmelCase		):
						__UpperCamelCase    :    Any								=      (i - 1) // (config["layers_per_block"] + 1)

						if any("downsample" in layer for layer in down_blocks[i]		):
									__UpperCamelCase    :    Dict								=      checkpoint[
									    F'''encoder.down.{i}.downsample.conv.weight'''
									]
									__UpperCamelCase    :    List[Any]								=      checkpoint[
									    F'''encoder.down.{i}.downsample.conv.bias'''
									]

						if any("block" in layer for layer in down_blocks[i]		):
									__UpperCamelCase    :    int								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			3		).split("."		)[:3]		) for layer in down_blocks[i] if "block" in layer}		)
									__UpperCamelCase    :    List[str]								=      {
									    layer_id: [key for key in down_blocks[i] if F'''block.{layer_id}''' in key]
									    for layer_id in range(_lowerCAmelCase		)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"]		):
															__UpperCamelCase    :    Tuple								=      renew_resnet_paths(blocks[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase		)

						if any("attn" in layer for layer in down_blocks[i]		):
									__UpperCamelCase    :    Dict								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			3		).split("."		)[:3]		) for layer in down_blocks[i] if "attn" in layer}		)
									__UpperCamelCase    :    Optional[Any]								=      {
									    layer_id: [key for key in down_blocks[i] if F'''attn.{layer_id}''' in key]
									    for layer_id in range(_lowerCAmelCase		)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"]		):
															__UpperCamelCase    :    Optional[Any]								=      renew_attention_paths(attns[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			config=_lowerCAmelCase		)

			__UpperCamelCase    :    List[Any]								=      [key for key in checkpoint if "mid.block_1" in key]
			__UpperCamelCase    :    List[str]								=      [key for key in checkpoint if "mid.block_2" in key]
			__UpperCamelCase    :    Union[str, Any]								=      [key for key in checkpoint if "mid.attn_1" in key]

			# Mid new 2
			__UpperCamelCase    :    Any								=      renew_resnet_paths(_lowerCAmelCase		)
			assign_to_checkpoint(
			    _lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_1", "new": "resnets.0"}]     ,			)

			__UpperCamelCase    :    Union[str, Any]								=      renew_resnet_paths(_lowerCAmelCase		)
			assign_to_checkpoint(
			    _lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "block_2", "new": "resnets.1"}]     ,			)

			__UpperCamelCase    :    Optional[int]								=      renew_attention_paths(_lowerCAmelCase     ,			in_mid=_lowerCAmelCase		)
			assign_to_checkpoint(
			    _lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[{"old": "mid.", "new": "mid_new_2."}, {"old": "attn_1", "new": "attentions.0"}]     ,			)

			for i in range(_lowerCAmelCase		):
						__UpperCamelCase    :    Tuple								=      num_up_blocks - 1 - i

						if any("upsample" in layer for layer in up_blocks[i]		):
									__UpperCamelCase    :    Optional[int]								=      checkpoint[
									    F'''decoder.up.{i}.upsample.conv.weight'''
									]
									__UpperCamelCase    :    int								=      checkpoint[
									    F'''decoder.up.{i}.upsample.conv.bias'''
									]

						if any("block" in layer for layer in up_blocks[i]		):
									__UpperCamelCase    :    Tuple								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			3		).split("."		)[:3]		) for layer in up_blocks[i] if "block" in layer}		)
									__UpperCamelCase    :    Any								=      {
									    layer_id: [key for key in up_blocks[i] if F'''block.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)
									}

									if num_blocks > 0:
												for j in range(config["layers_per_block"] + 1		):
															__UpperCamelCase    :    List[str]								=      {"old": F'''up_blocks.{i}''', "new": F'''up_blocks.{block_id}'''}
															__UpperCamelCase    :    List[str]								=      renew_resnet_paths(blocks[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[replace_indices]		)

						if any("attn" in layer for layer in up_blocks[i]		):
									__UpperCamelCase    :    str								=      len(
									    {".".join(shave_segments(_lowerCAmelCase     ,			3		).split("."		)[:3]		) for layer in up_blocks[i] if "attn" in layer}		)
									__UpperCamelCase    :    List[Any]								=      {
									    layer_id: [key for key in up_blocks[i] if F'''attn.{layer_id}''' in key] for layer_id in range(_lowerCAmelCase		)
									}

									if num_attn > 0:
												for j in range(config["layers_per_block"] + 1		):
															__UpperCamelCase    :    str								=      {"old": F'''up_blocks.{i}''', "new": F'''up_blocks.{block_id}'''}
															__UpperCamelCase    :    Dict								=      renew_attention_paths(attns[j]		)
															assign_to_checkpoint(_lowerCAmelCase     ,			_lowerCAmelCase     ,			_lowerCAmelCase     ,			additional_replacements=[replace_indices]		)

			__UpperCamelCase    :    Optional[int]								=      {k.replace("mid_new_2"     ,			"mid_block"		): v for k, v in new_checkpoint.items()}
			__UpperCamelCase    :    Optional[int]								=      checkpoint["quant_conv.weight"]
			__UpperCamelCase    :    List[Any]								=      checkpoint["quant_conv.bias"]
			if "quantize.embedding.weight" in checkpoint:
						__UpperCamelCase    :    Union[str, Any]								=      checkpoint["quantize.embedding.weight"]
			__UpperCamelCase    :    Dict								=      checkpoint["post_quant_conv.weight"]
			__UpperCamelCase    :    List[Any]								=      checkpoint["post_quant_conv.bias"]

			return new_checkpoint


if __name__ == "__main__":
					lowercase     :       Union[str, Any]        =       argparse.ArgumentParser()

					parser.add_argument(
					    "--checkpoint_path", default=None, type=str, required=True, help="Path to the checkpoint to convert."
					)

					parser.add_argument(
					    "--config_file",
					    default=None,
					    type=str,
					    required=True,
					    help="The config json file corresponding to the architecture.",
					)

					parser.add_argument("--dump_path", default=None, type=str, required=True, help="Path to the output model.")

					lowercase     :       Tuple        =       parser.parse_args()
					lowercase     :       Tuple        =       torch.load(args.checkpoint_path)

					with open(args.config_file) as f:
										lowercase     :       Any        =       json.loads(f.read())

					# unet case
					lowercase     :       Optional[int]        =       {key.split(".")[0] for key in checkpoint.keys()}
					if "encoder" in key_prefix_set and "decoder" in key_prefix_set:
										lowercase     :       Dict        =       convert_vq_autoenc_checkpoint(checkpoint, config)
					else:
										lowercase     :       int        =       convert_ddpm_checkpoint(checkpoint, config)

					if "ddpm" in config:
										del config["ddpm"]

					if config["_class_name"] == "VQModel":
										lowercase     :       Dict        =       VQModel(**config)
										model.load_state_dict(converted_checkpoint)
										model.save_pretrained(args.dump_path)
					elif config["_class_name"] == "AutoencoderKL":
										lowercase     :       int        =       AutoencoderKL(**config)
										model.load_state_dict(converted_checkpoint)
										model.save_pretrained(args.dump_path)
					else:
										lowercase     :       Optional[Any]        =       UNetaDModel(**config)
										model.load_state_dict(converted_checkpoint)

										lowercase     :       List[str]        =       DDPMScheduler.from_config("/".join(args.checkpoint_path.split("/")[:-1]))

										lowercase     :       str        =       DDPMPipeline(unet=model, scheduler=scheduler)
										pipe.save_pretrained(args.dump_path)


from collections.abc import Callable

lowercase     :       Optional[Any]        =       Callable[[float], float]  # type alias for a real -> real function







def  UpperCAmelCase_   (_lowerCAmelCase :		RealFunc     ,			_lowerCAmelCase :		RealFunc     ,			_lowerCAmelCase :		int     ,			):
			__UpperCamelCase    :    Any								=      float(_lowerCAmelCase		)
			while True:
						try:
									__UpperCamelCase    :    List[Any]								=      prev_guess - function(_lowerCAmelCase		) / derivative(_lowerCAmelCase		)
						except ZeroDivisionError:
									raise ZeroDivisionError("Could not find root"		) from None
						if abs(prev_guess - next_guess		) < 10**-5:
									return next_guess
						__UpperCamelCase    :    Tuple								=      next_guess







def  UpperCAmelCase_   (_lowerCAmelCase :		float		):
			return (x**3) - (2 * x) - 5







def  UpperCAmelCase_   (_lowerCAmelCase :		float		):
			return 3 * (x**2) - 2


if __name__ == "__main__":
					print(newton(f, fa, 3))