





from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import tensorflow as tf

 from transformers import (
     TFFunnelBaseModel,
     TFFunnelForMaskedLM,
     TFFunnelForMultipleChoice,
     TFFunnelForPreTraining,
     TFFunnelForQuestionAnswering,
     TFFunnelForSequenceClassification,
     TFFunnelForTokenClassification,
     TFFunnelModel,
 )







class      lowerCamelCase:
     '''simple docstring'''


     def __init__(    self				,     snake_case_				,     snake_case_=13				,     snake_case_=7				,     snake_case_=True				,     snake_case_=True				,     snake_case_=True				,     snake_case_=True				,     snake_case_=99				,     snake_case_=[1, 1, 2]				,     snake_case_=1				,     snake_case_=32				,     snake_case_=4				,     snake_case_=8				,     snake_case_=37				,     snake_case_="gelu_new"				,     snake_case_=0.1				,     snake_case_=0.1				,     snake_case_=0.0				,     snake_case_=512				,     snake_case_=3				,     snake_case_=0.02				,     snake_case_=3				,     snake_case_=4				,     snake_case_=None				,     snake_case_=False				,     ):
         _A     =							parent
         _A     =							batch_size
         _A     =							seq_length
         _A     =							is_training
         _A     =							use_input_mask
         _A     =							use_token_type_ids
         _A     =							use_labels
         _A     =							vocab_size
         _A     =							block_sizes
         _A     =							num_decoder_layers
         _A     =							d_model
         _A     =							n_head
         _A     =							d_head
         _A     =							d_inner
         _A     =							hidden_act
         _A     =							hidden_dropout
         _A     =							attention_dropout
         _A     =							activation_dropout
         _A     =							max_position_embeddings
         _A     =							type_vocab_size
         _A     =							2
         _A     =							num_labels
         _A     =							num_choices
         _A     =							scope
         _A     =							initializer_std

         # Used in the tests to check the size of the first attention layer
         _A     =							n_head
         # Used in the tests to check the size of the first hidden state
         _A     =							self.d_model
         # Used in the tests to check the number of output hidden states/attentions
         _A     =							sum(self.block_sizes							) + (0 if base else self.num_decoder_layers)
         # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
         # the last hidden state of the first block (which is the first hidden state of the decoder).
         if not base:
             _A     =							self.num_hidden_layers + 2




     def        lowerCAmelCase__		(    self							):
         _A     =							ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size							)

         _A     =							None
         if self.use_input_mask:
             _A     =							random_attention_mask([self.batch_size, self.seq_length]							)

         _A     =							None
         if self.use_token_type_ids:
             _A     =							ids_tensor([self.batch_size, self.seq_length]				,     self.type_vocab_size							)

         _A     =							None
         _A     =							None
         _A     =							None
         if self.use_labels:
             _A     =							ids_tensor([self.batch_size]				,     self.type_sequence_label_size							)
             _A     =							ids_tensor([self.batch_size, self.seq_length]				,     self.num_labels							)
             _A     =							ids_tensor([self.batch_size]				,     self.num_choices							)

         _A     =							FunnelConfig(
             vocab_size=self.vocab_size				,     block_sizes=self.block_sizes				,     num_decoder_layers=self.num_decoder_layers				,     d_model=self.d_model				,     n_head=self.n_head				,     d_head=self.d_head				,     d_inner=self.d_inner				,     hidden_act=self.hidden_act				,     hidden_dropout=self.hidden_dropout				,     attention_dropout=self.attention_dropout				,     activation_dropout=self.activation_dropout				,     max_position_embeddings=self.max_position_embeddings				,     type_vocab_size=self.type_vocab_size				,     initializer_std=self.initializer_std				,     )

         return (
             config,
             input_ids,
             token_type_ids,
             input_mask,
             sequence_labels,
             token_labels,
             choice_labels,
         )




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							TFFunnelModel(config=snake_case_							)
         _A     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         _A     =							model(snake_case_							)

         _A     =							[input_ids, input_mask]
         _A     =							model(snake_case_							)

         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.d_model)							)

         _A     =							False
         _A     =							TFFunnelModel(config=snake_case_							)
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.d_model)							)

         _A     =							False
         _A     =							TFFunnelModel(config=snake_case_							)
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.d_model)							)




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							TFFunnelBaseModel(config=snake_case_							)
         _A     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         _A     =							model(snake_case_							)

         _A     =							[input_ids, input_mask]
         _A     =							model(snake_case_							)

         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, 2, self.d_model)							)

         _A     =							False
         _A     =							TFFunnelBaseModel(config=snake_case_							)
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, 3, self.d_model)							)

         _A     =							False
         _A     =							TFFunnelBaseModel(config=snake_case_							)
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, 2, self.d_model)							)




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							TFFunnelForPreTraining(config=snake_case_							)
         _A     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length)							)




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							TFFunnelForMaskedLM(config=snake_case_							)
         _A     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.vocab_size)							)




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							self.num_labels
         _A     =							TFFunnelForSequenceClassification(config=snake_case_							)
         _A     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_labels)							)




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							self.num_choices
         _A     =							TFFunnelForMultipleChoice(config=snake_case_							)
         _A     =							tf.tile(tf.expand_dims(snake_case_				,     1							)				,     (1, self.num_choices, 1)							)
         _A     =							tf.tile(tf.expand_dims(snake_case_				,     1							)				,     (1, self.num_choices, 1)							)
         _A     =							tf.tile(tf.expand_dims(snake_case_				,     1							)				,     (1, self.num_choices, 1)							)
         _A     =							{
             'input_ids': multiple_choice_inputs_ids,
             'attention_mask': multiple_choice_input_mask,
             'token_type_ids': multiple_choice_token_type_ids,
         }
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.num_choices)							)




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							self.num_labels
         _A     =							TFFunnelForTokenClassification(config=snake_case_							)
         _A     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.num_labels)							)




     def        lowerCAmelCase__		(    self				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     snake_case_				,     ):
         _A     =							TFFunnelForQuestionAnswering(config=snake_case_							)
         _A     =							{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         _A     =							model(snake_case_							)
         self.parent.assertEqual(result.start_logits.shape				,     (self.batch_size, self.seq_length)							)
         self.parent.assertEqual(result.end_logits.shape				,     (self.batch_size, self.seq_length)							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.prepare_config_and_inputs()
         (
             (
             _A
         ),			(
             _A
         ),			(
             _A
         ),			(
             _A
         ),			(
             _A
         ),			(
             _A
         ),			(
             _A
         ),			
         )     =							config_and_inputs
         _A     =							{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
         return config, inputs_dict







@require_tf
class      lowerCamelCase(						__snake_case			, __snake_case			, unittest.TestCase	):
     '''simple docstring'''


     __magic_name__   =			(
         (
             TFFunnelModel,
             TFFunnelForMaskedLM,
             TFFunnelForPreTraining,
             TFFunnelForQuestionAnswering,
             TFFunnelForTokenClassification,
         )
         if is_tf_available()
         else ()
     )
     __magic_name__   =			(
         {
             'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
             'fill-mask': TFFunnelForMaskedLM,
             'question-answering': TFFunnelForQuestionAnswering,
             'text-classification': TFFunnelForSequenceClassification,
             'token-classification': TFFunnelForTokenClassification,
             'zero-shot': TFFunnelForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     __magic_name__   =			False
     __magic_name__   =			False




     def        lowerCAmelCase__		(    self							):
         _A     =							TFFunnelModelTester(self							)
         _A     =							ConfigTester(self				,     config_class=snake_case_							)




     def        lowerCAmelCase__		(    self							):
         self.config_tester.run_common_tests()




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*snake_case_							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_pretraining(*snake_case_							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*snake_case_							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_token_classification(*snake_case_							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*snake_case_							)







@require_tf
class      lowerCamelCase(						__snake_case			, unittest.TestCase	):
     '''simple docstring'''


     __magic_name__   =			(
         (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
     )
     __magic_name__   =			False
     __magic_name__   =			False




     def        lowerCAmelCase__		(    self							):
         _A     =							TFFunnelModelTester(self				,     base=snake_case_							)
         _A     =							ConfigTester(self				,     config_class=snake_case_							)




     def        lowerCAmelCase__		(    self							):
         self.config_tester.run_common_tests()




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_base_model(*snake_case_							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*snake_case_							)




     def        lowerCAmelCase__		(    self							):
         _A     =							self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*snake_case_							)












from collections import defaultdict
from math import ceil, sqrt





def 				__lowerCAmelCase(       _SCREAMING_SNAKE_CASE = 1_000_000							,     _SCREAMING_SNAKE_CASE = 10				)							-> int:




    """simple docstring"""




    _A     =							defaultdict(_SCREAMING_SNAKE_CASE				)

    for outer_width in range(3							,     (t_limit // 4) + 2				):
        if outer_width * outer_width > t_limit:
            _A     =							max(
                ceil(sqrt(outer_width * outer_width - t_limit				)				)							,     1				)
        else:
            _A     =							1

        hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2

        for hole_width in range(_SCREAMING_SNAKE_CASE							,     outer_width - 1							,     2				):
            count[outer_width * outer_width - hole_width * hole_width] += 1

    return sum(1 for n in count.values() if 1 <= n <= 10				)


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





