




import logging
import os
from dataclasses import dataclass
from typing import List, Optional, Union

import tqdm
from filelock import FileLock

from transformers import (
    BartTokenizer,
    BartTokenizerFast,
    DataProcessor,
    PreTrainedTokenizer,
    RobertaTokenizer,
    RobertaTokenizerFast,
    XLMRobertaTokenizer,
    is_tf_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE:     str									= logging.getLogger(__name__)



@dataclass(frozen=SCREAMING_SNAKE_CASE__ )
class    lowercase_		:
						lowerCAmelCase__			      =42
						lowerCAmelCase__			      =42
						lowerCAmelCase__			      =None
						lowerCAmelCase__			      =None
						lowerCAmelCase__			      =None



@dataclass(frozen=SCREAMING_SNAKE_CASE__ )
class    lowercase_		:
						lowerCAmelCase__			      =42
						lowerCAmelCase__			      =None
						lowerCAmelCase__			      =None
						lowerCAmelCase__			      =None
						lowerCAmelCase__			      =None


if is_torch_available():
						import torch
						from torch.utils.data import Dataset



						class    lowercase_		(SCREAMING_SNAKE_CASE__ ):
												lowerCAmelCase__			      =42



												def __init__(			self	:   Union[str, Any]					,							snake_case__	:   str					,							snake_case__	:   PreTrainedTokenizer					,							snake_case__	:   str					,							snake_case__	:   Optional[int] = None					,							snake_case__	:   Tuple=False					,							snake_case__	:   bool = False					,							):

														"""simple docstring"""

														SCREAMING_SNAKE_CASE_					      =							hans_processors[task]()

														SCREAMING_SNAKE_CASE_					      =							os.path.join(
														    snake_case__					,							'cached_{}_{}_{}_{}'.format(
														        'dev' if evaluate else 'train'					,							tokenizer.__class__.__name__					,							str(snake_case__  )					,							snake_case__					,							)					,							)
														SCREAMING_SNAKE_CASE_					      =							processor.get_labels()
														if tokenizer.__class__ in (
														    RobertaTokenizer,
														    RobertaTokenizerFast,
														    XLMRobertaTokenizer,
														    BartTokenizer,
														    BartTokenizerFast,
														):
																# HACK(label indices are swapped in RoBERTa pretrained model)
																SCREAMING_SNAKE_CASE_      ,				SCREAMING_SNAKE_CASE_					      =							label_list[2], label_list[1]
														SCREAMING_SNAKE_CASE_					      =							label_list

														# Make sure only the first process in distributed training processes the dataset,
														# and the others will use the cache.
														SCREAMING_SNAKE_CASE_					      =							cached_features_file + '.lock'
														with FileLock(snake_case__  ):
																if os.path.exists(snake_case__  ) and not overwrite_cache:
																		logger.info(f'''Loading features from cached file {cached_features_file}'''  )
																		SCREAMING_SNAKE_CASE_					      =							torch.load(snake_case__  )
																else:
																		logger.info(f'''Creating features from dataset file at {data_dir}'''  )

																		SCREAMING_SNAKE_CASE_					      =							(
																		    processor.get_dev_examples(snake_case__  ) if evaluate else processor.get_train_examples(snake_case__  )
																		)

																		logger.info('Training examples: %s'					,							len(snake_case__  )  )
																		SCREAMING_SNAKE_CASE_					      =							hans_convert_examples_to_features(snake_case__					,							snake_case__					,							snake_case__					,							snake_case__  )
																		logger.info('Saving features into cached file %s'					,							snake_case__  )
																		torch.save(self.features					,							snake_case__  )



												def __len__(			self	:   Optional[Any]  ):

														"""simple docstring"""

														return len(self.features  )



												def __getitem__(			self	:   Any					,							snake_case__	:   List[str]  ):

														"""simple docstring"""

														return self.features[i]






												def 	__a					(			self	:   int  ):

														"""simple docstring"""

														return self.label_list


if is_tf_available():
						import tensorflow as tf



						class    lowercase_		:
												lowerCAmelCase__			      =42



												def __init__(			self	:   Any					,							snake_case__	:   str					,							snake_case__	:   PreTrainedTokenizer					,							snake_case__	:   str					,							snake_case__	:   Optional[int] = 1_28					,							snake_case__	:   Union[str, Any]=False					,							snake_case__	:   bool = False					,							):

														"""simple docstring"""

														SCREAMING_SNAKE_CASE_					      =							hans_processors[task]()
														SCREAMING_SNAKE_CASE_					      =							processor.get_labels()
														if tokenizer.__class__ in (
														    RobertaTokenizer,
														    RobertaTokenizerFast,
														    XLMRobertaTokenizer,
														    BartTokenizer,
														    BartTokenizerFast,
														):
																# HACK(label indices are swapped in RoBERTa pretrained model)
																SCREAMING_SNAKE_CASE_      ,				SCREAMING_SNAKE_CASE_					      =							label_list[2], label_list[1]
														SCREAMING_SNAKE_CASE_					      =							label_list

														SCREAMING_SNAKE_CASE_					      =							processor.get_dev_examples(snake_case__  ) if evaluate else processor.get_train_examples(snake_case__  )
														SCREAMING_SNAKE_CASE_					      =							hans_convert_examples_to_features(snake_case__					,							snake_case__					,							snake_case__					,							snake_case__  )

														def gen():
																for ex_index, ex in tqdm.tqdm(enumerate(self.features  )					,							desc='convert examples to features'  ):
																		if ex_index % 1_00_00 == 0:
																				logger.info('Writing example %d of %d' % (ex_index, len(snake_case__  ))  )

																		yield (
																		    {
																		        "example_id": 0,
																		        "input_ids": ex.input_ids,
																		        "attention_mask": ex.attention_mask,
																		        "token_type_ids": ex.token_type_ids,
																		    },
																		    ex.label,
																		)

														SCREAMING_SNAKE_CASE_					      =							tf.data.Dataset.from_generator(
														    snake_case__					,							(
														        {
														            'example_id': tf.intaa,
														            'input_ids': tf.intaa,
														            'attention_mask': tf.intaa,
														            'token_type_ids': tf.intaa,
														        },
														        tf.intaa,
														    )					,							(
														        {
														            'example_id': tf.TensorShape([]  ),
														            'input_ids': tf.TensorShape([None, None]  ),
														            'attention_mask': tf.TensorShape([None, None]  ),
														            'token_type_ids': tf.TensorShape([None, None]  ),
														        },
														        tf.TensorShape([]  ),
														    )					,							)



												def 	__a					(			self	:   Any  ):

														"""simple docstring"""

														return self.dataset



												def __len__(			self	:   List[Any]  ):

														"""simple docstring"""

														return len(self.features  )



												def __getitem__(			self	:   List[str]					,							snake_case__	:   Dict  ):

														"""simple docstring"""

														return self.features[i]






												def 	__a					(			self	:   Tuple  ):

														"""simple docstring"""

														return self.label_list



class    lowercase_		(SCREAMING_SNAKE_CASE__ ):



						def 	__a					(			self	:   Union[str, Any]					,							snake_case__	:   str  ):

								"""simple docstring"""

								return self._create_examples(self._read_tsv(os.path.join(snake_case__					,							'heuristics_train_set.txt'  )  )					,							'train'  )



						def 	__a					(			self	:   Dict					,							snake_case__	:   Any  ):

								"""simple docstring"""

								return self._create_examples(self._read_tsv(os.path.join(snake_case__					,							'heuristics_evaluation_set.txt'  )  )					,							'dev'  )



						def 	__a					(			self	:   Union[str, Any]  ):

								"""simple docstring"""

								return ["contradiction", "entailment", "neutral"]






						def 	__a					(			self	:   Dict					,							snake_case__	:   int					,							snake_case__	:   List[Any]  ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_					      =							[]
								for i, line in enumerate(snake_case__  ):
										if i == 0:
												continue
										SCREAMING_SNAKE_CASE_					      =							'%s-%s' % (set_type, line[0])
										SCREAMING_SNAKE_CASE_					      =							line[5]
										SCREAMING_SNAKE_CASE_					      =							line[6]
										SCREAMING_SNAKE_CASE_					      =							line[7][2:] if line[7].startswith('ex'  ) else line[7]
										SCREAMING_SNAKE_CASE_					      =							line[0]
										examples.append(InputExample(guid=snake_case__					,							text_a=snake_case__					,							text_b=snake_case__					,							label=snake_case__					,							pairID=snake_case__  )  )
								return examples


def 					_a							(					lowerCAmelCase    ,						lowerCAmelCase    ,						lowerCAmelCase    ,						lowerCAmelCase    ,						)->	Optional[int]:
		SCREAMING_SNAKE_CASE_					      =							{label: i for i, label in enumerate(lowerCAmelCase )}

		SCREAMING_SNAKE_CASE_					      =							[]
		for ex_index, example in tqdm.tqdm(enumerate(lowerCAmelCase )    ,						desc='convert examples to features' ):
				if ex_index % 10000 == 0:
						logger.info('Writing example %d' % (ex_index) )

				SCREAMING_SNAKE_CASE_					      =							tokenizer(
				    example.text_a    ,						example.text_b    ,						add_special_tokens=lowerCAmelCase    ,						max_length=lowerCAmelCase    ,						padding='max_length'    ,						truncation=lowerCAmelCase    ,						return_overflowing_tokens=lowerCAmelCase    ,						)

				SCREAMING_SNAKE_CASE_					      =							label_map[example.label] if example.label in label_map else 0

				SCREAMING_SNAKE_CASE_					      =							int(example.pairID )

				features.append(InputFeatures(**lowerCAmelCase    ,						label=lowerCAmelCase    ,						pairID=lowerCAmelCase ) )

		for i, example in enumerate(examples[:5] ):
				logger.info('*** Example ***' )
				logger.info(F'''guid: {example}''' )
				logger.info(F'''features: {features[i]}''' )

		return features


SCREAMING_SNAKE_CASE:     Tuple									= {
    '''hans''': 3,
}




SCREAMING_SNAKE_CASE:     Union[str, Any]									= {
    '''hans''': HansProcessor,
}





SCREAMING_SNAKE_CASE:     Optional[int]									= {str(digit): digit**5 for digit in range(1_0)}


def 					_a							(					lowerCAmelCase )->	int:
		return sum(DIGITS_FIFTH_POWER[digit] for digit in str(lowerCAmelCase ) )


def 					_a							(					)->	int:
		return sum(
		    number
		    for number in range(1000    ,						1000000 )
		    if number == digits_fifth_powers_sum(lowerCAmelCase ) )


if __name__ == "__main__":
						print(solution())