



'''simple docstring'''






def 				snake_case_  (      _lowerCAmelCase						:		int = 1000						)   ->     int:
							UpperCAmelCase				: Tuple											=	-1
							UpperCAmelCase				: Optional[Any]											=	0
							for a in range(1     ,   n // 3						):
														# Solving the two equations a**2+b**2=c**2 and a+b+c=N eliminating c
														UpperCAmelCase				: int											=	(n * n - 2 * a * n) // (2 * n - 2 * a)
														UpperCAmelCase				: Any											=	n - a - b
														if c * c == (a * a + b * b):
																					UpperCAmelCase				: Optional[int]											=	a * b * c
																					if candidate >= product:
																												UpperCAmelCase				: str											=	candidate
							return product


if __name__ == "__main__":
						print(F"{solution() = }")










'''simple docstring'''






import argparse
import re
from typing import Dict

import torch
from datasets import Audio, Dataset, load_dataset, load_metric

from transformers import AutoFeatureExtractor, pipeline


def 				snake_case_  (      _lowerCAmelCase						:		Dataset     ,   _lowerCAmelCase						:		Dict[str, str]						)   ->     str:
							UpperCAmelCase				: Optional[int]											=	args.log_outputs
							UpperCAmelCase				: Any											=	'''_'''.join(args.dataset.split('''/'''						) + [args.config, args.split]						)

							# load metric
							UpperCAmelCase				: Union[str, Any]											=	load_metric('''wer'''						)
							UpperCAmelCase				: Dict											=	load_metric('''cer'''						)

							# compute metrics
							UpperCAmelCase				: Any											=	wer.compute(references=result['''target''']     ,   predictions=result['''prediction''']						)
							UpperCAmelCase				: str											=	cer.compute(references=result['''target''']     ,   predictions=result['''prediction''']						)

							# print & log results
							UpperCAmelCase				: Tuple											=	f"""WER: {wer_result}\nCER: {cer_result}"""
							print(_lowerCAmelCase						)

							with open(f"""{dataset_id}_eval_results.txt"""     ,   '''w'''						) as f:
														f.write(_lowerCAmelCase						)

							# log all results in text file. Possibly interesting for analysis
							if log_outputs is not None:
														UpperCAmelCase				: Union[str, Any]											=	f"""log_{dataset_id}_predictions.txt"""
														UpperCAmelCase				: Optional[Any]											=	f"""log_{dataset_id}_targets.txt"""

														with open(_lowerCAmelCase     ,   '''w'''						) as p, open(_lowerCAmelCase     ,   '''w'''						) as t:
																					# mapping function to write output
																					def write_to_file(_lowerCAmelCase						:		int     ,   _lowerCAmelCase						:		str						):
																												p.write(f"""{i}""" + '''\n'''						)
																												p.write(batch['''prediction'''] + '''\n'''						)
																												t.write(f"""{i}""" + '''\n'''						)
																												t.write(batch['''target'''] + '''\n'''						)

																					result.map(_lowerCAmelCase     ,   with_indices=_lowerCAmelCase						)


def 				snake_case_  (      _lowerCAmelCase						:		str						)   ->     str:
							UpperCAmelCase				: Optional[int]											=	'''[,?.!\-\;\:"“%‘”�—’…–]'''  # noqa: W605 IMPORTANT: this should correspond to the chars that were ignored during training

							UpperCAmelCase				: List[Any]											=	re.sub(_lowerCAmelCase     ,   ''''''     ,   text.lower()						)

							# In addition, we can normalize the target text, e.g. removing new lines characters etc...
							# note that order is important here!
							UpperCAmelCase				: str											=	['''\n\n''', '''\n''', '''   ''', '''  ''']

							for t in token_sequences_to_ignore:
														UpperCAmelCase				: List[Any]											=	''' '''.join(text.split(_lowerCAmelCase						)						)

							return text


def 				snake_case_  (      _lowerCAmelCase						:		Optional[Any]						)   ->     Union[str, Any]:
							# load dataset
							UpperCAmelCase				: Optional[int]											=	load_dataset(args.dataset     ,   args.config     ,   split=args.split     ,   use_auth_token=_lowerCAmelCase						)

							# for testing: only process the first two examples as a test
							# dataset = dataset.select(range(10))

							# load processor
							UpperCAmelCase				: Any											=	AutoFeatureExtractor.from_pretrained(args.model_id						)
							UpperCAmelCase				: Optional[Any]											=	feature_extractor.sampling_rate

							# resample audio
							UpperCAmelCase				: Tuple											=	dataset.cast_column('''audio'''     ,   Audio(sampling_rate=_lowerCAmelCase						)						)

							# load eval pipeline
							if args.device is None:
														UpperCAmelCase				: List[Any]											=	0 if torch.cuda.is_available() else -1
							UpperCAmelCase				: List[Any]											=	pipeline('''automatic-speech-recognition'''     ,   model=args.model_id     ,   device=args.device						)

							# map function to decode audio
							def map_to_pred(_lowerCAmelCase						:		List[str]						):
														UpperCAmelCase				: Optional[int]											=	asr(
														    batch['''audio''']['''array''']     ,   chunk_length_s=args.chunk_length_s     ,   stride_length_s=args.stride_length_s						)

														UpperCAmelCase				: str											=	prediction['''text''']
														UpperCAmelCase				: int											=	normalize_text(batch['''sentence''']						)
														return batch

							# run inference on all examples
							UpperCAmelCase				: Tuple											=	dataset.map(_lowerCAmelCase     ,   remove_columns=dataset.column_names						)

							# compute and log_results
							# do not change function below
							log_results(_lowerCAmelCase     ,   _lowerCAmelCase						)


if __name__ == "__main__":
						UpperCamelCase__:     List[Any]										=    argparse.ArgumentParser()

						parser.add_argument(
						    "--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers"
						)
						parser.add_argument(
						    "--dataset",
						    type=str,
						    required=True,
						    help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets",
						)
						parser.add_argument(
						    "--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'`  for Common Voice"
						)
						parser.add_argument("--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`")
						parser.add_argument(
						    "--chunk_length_s", type=float, default=None, help="Chunk length in seconds. Defaults to 5 seconds."
						)
						parser.add_argument(
						    "--stride_length_s", type=float, default=None, help="Stride of the audio chunks. Defaults to 1 second."
						)
						parser.add_argument(
						    "--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis."
						)
						parser.add_argument(
						    "--device",
						    type=int,
						    default=None,
						    help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
						)
						UpperCamelCase__:     List[str]										=    parser.parse_args()

						main(args)





