






import unittest

from transformers import BertGenerationConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import BertGenerationDecoder, BertGenerationEncoder

class        lowerCAmelCase_				:







				"""simple docstring"""




				def __init__( self     :Optional[Any]  ,     lowerCamelCase__     :Dict  ,     lowerCamelCase__     :Optional[Any]=13  ,     lowerCamelCase__     :List[str]=7  ,     lowerCamelCase__     :Optional[Any]=True  ,     lowerCamelCase__     :Tuple=True  ,     lowerCamelCase__     :Any=99  ,     lowerCamelCase__     :int=32  ,     lowerCamelCase__     :Union[str, Any]=5  ,     lowerCamelCase__     :Optional[int]=4  ,     lowerCamelCase__     :List[str]=37  ,     lowerCamelCase__     :Any="gelu"  ,     lowerCamelCase__     :Optional[int]=0.1  ,     lowerCamelCase__     :Optional[Any]=0.1  ,     lowerCamelCase__     :str=50  ,     lowerCamelCase__     :int=0.02  ,     lowerCamelCase__     :Optional[Any]=True  ,     lowerCamelCase__     :List[str]=None  ,     ):
					UpperCamelCase__ :Dict						=      parent
					UpperCamelCase__ :Optional[Any]						=      batch_size
					UpperCamelCase__ :Tuple						=      seq_length
					UpperCamelCase__ :Union[str, Any]						=      is_training
					UpperCamelCase__ :str						=      use_input_mask
					UpperCamelCase__ :Any						=      vocab_size
					UpperCamelCase__ :str						=      hidden_size
					UpperCamelCase__ :int						=      num_hidden_layers
					UpperCamelCase__ :Dict						=      num_attention_heads
					UpperCamelCase__ :Union[str, Any]						=      intermediate_size
					UpperCamelCase__ :Optional[int]						=      hidden_act
					UpperCamelCase__ :Optional[int]						=      hidden_dropout_prob
					UpperCamelCase__ :List[Any]						=      attention_probs_dropout_prob
					UpperCamelCase__ :List[Any]						=      max_position_embeddings
					UpperCamelCase__ :Optional[int]						=      initializer_range
					UpperCamelCase__ :str						=      use_labels
					UpperCamelCase__ :Union[str, Any]						=      scope







				def 				__a   ( self     :Optional[Any]     ):
					UpperCamelCase__ :int						=      ids_tensor([self.batch_size, self.seq_length]  ,     self.vocab_size     )

					UpperCamelCase__ :Union[str, Any]						=      None
					if self.use_input_mask:
						UpperCamelCase__ :str						=      random_attention_mask([self.batch_size, self.seq_length]     )

					if self.use_labels:
						UpperCamelCase__ :Optional[Any]						=      ids_tensor([self.batch_size, self.seq_length]  ,     self.vocab_size     )

					UpperCamelCase__ :Dict						=      self.get_config()

					return config, input_ids, input_mask, token_labels







				def 				__a   ( self     :Optional[int]     ):
					return BertGenerationConfig(
					    vocab_size=self.vocab_size  ,     hidden_size=self.hidden_size  ,     num_hidden_layers=self.num_hidden_layers  ,     num_attention_heads=self.num_attention_heads  ,     intermediate_size=self.intermediate_size  ,     hidden_act=self.hidden_act  ,     hidden_dropout_prob=self.hidden_dropout_prob  ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,     max_position_embeddings=self.max_position_embeddings  ,     is_decoder=lowerCamelCase__  ,     initializer_range=self.initializer_range  ,     )







				def 				__a   ( self     :Any     ):
					(
					    (
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		
					) :int						=      self.prepare_config_and_inputs()

					UpperCamelCase__ :Union[str, Any]						=      True
					UpperCamelCase__ :Optional[Any]						=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
					UpperCamelCase__ :Optional[Any]						=      ids_tensor([self.batch_size, self.seq_length]  ,     vocab_size=2     )

					return (
					    config,
					    input_ids,
					    input_mask,
					    token_labels,
					    encoder_hidden_states,
					    encoder_attention_mask,
					)







				def 				__a   ( self     :Dict  ,     lowerCamelCase__     :Optional[int]  ,     lowerCamelCase__     :str  ,     lowerCamelCase__     :Any  ,     lowerCamelCase__     :List[Any]  ,     **lowerCamelCase__     :str  ,     ):
					UpperCamelCase__ :Dict						=      BertGenerationEncoder(config=lowerCamelCase__     )
					model.to(lowerCamelCase__     )
					model.eval()
					UpperCamelCase__ :Optional[Any]						=      model(lowerCamelCase__  ,     attention_mask=lowerCamelCase__     )
					UpperCamelCase__ :Tuple						=      model(lowerCamelCase__     )
					self.parent.assertEqual(result.last_hidden_state.shape  ,     (self.batch_size, self.seq_length, self.hidden_size)     )







				def 				__a   ( self     :Optional[Any]  ,     lowerCamelCase__     :Tuple  ,     lowerCamelCase__     :Tuple  ,     lowerCamelCase__     :Any  ,     lowerCamelCase__     :str  ,     lowerCamelCase__     :List[Any]  ,     lowerCamelCase__     :str  ,     **lowerCamelCase__     :Union[str, Any]  ,     ):
					UpperCamelCase__ :List[str]						=      True
					UpperCamelCase__ :List[str]						=      BertGenerationEncoder(config=lowerCamelCase__     )
					model.to(lowerCamelCase__     )
					model.eval()
					UpperCamelCase__ :Union[str, Any]						=      model(
					    lowerCamelCase__  ,     attention_mask=lowerCamelCase__  ,     encoder_hidden_states=lowerCamelCase__  ,     encoder_attention_mask=lowerCamelCase__  ,     )
					UpperCamelCase__ :Any						=      model(
					    lowerCamelCase__  ,     attention_mask=lowerCamelCase__  ,     encoder_hidden_states=lowerCamelCase__  ,     )
					self.parent.assertEqual(result.last_hidden_state.shape  ,     (self.batch_size, self.seq_length, self.hidden_size)     )







				def 				__a   ( self     :Optional[int]  ,     lowerCamelCase__     :int  ,     lowerCamelCase__     :Any  ,     lowerCamelCase__     :List[Any]  ,     lowerCamelCase__     :Optional[int]  ,     lowerCamelCase__     :Optional[Any]  ,     lowerCamelCase__     :Tuple  ,     **lowerCamelCase__     :Optional[Any]  ,     ):
					UpperCamelCase__ :Union[str, Any]						=      True
					UpperCamelCase__ :int						=      True
					UpperCamelCase__ :List[str]						=      BertGenerationDecoder(config=lowerCamelCase__     ).to(lowerCamelCase__     ).eval()

					# first forward pass
					UpperCamelCase__ :List[str]						=      model(
					    lowerCamelCase__  ,     attention_mask=lowerCamelCase__  ,     encoder_hidden_states=lowerCamelCase__  ,     encoder_attention_mask=lowerCamelCase__  ,     use_cache=lowerCamelCase__  ,     )
					UpperCamelCase__ :List[Any]						=      outputs.past_key_values

					# create hypothetical multiple next token and extent to next_input_ids
					UpperCamelCase__ :List[Any]						=      ids_tensor((self.batch_size, 3)  ,     config.vocab_size     )
					UpperCamelCase__ :List[str]						=      ids_tensor((self.batch_size, 3)  ,     vocab_size=2     )

					# append to next input_ids and
					UpperCamelCase__ :Optional[int]						=      torch.cat([input_ids, next_tokens]  ,     dim=-1     )
					UpperCamelCase__ :Dict						=      torch.cat([input_mask, next_mask]  ,     dim=-1     )

					UpperCamelCase__ :List[str]						=      model(
					    lowerCamelCase__  ,     attention_mask=lowerCamelCase__  ,     encoder_hidden_states=lowerCamelCase__  ,     encoder_attention_mask=lowerCamelCase__  ,     output_hidden_states=lowerCamelCase__  ,     )["""hidden_states"""][0]
					UpperCamelCase__ :Optional[int]						=      model(
					    lowerCamelCase__  ,     attention_mask=lowerCamelCase__  ,     encoder_hidden_states=lowerCamelCase__  ,     encoder_attention_mask=lowerCamelCase__  ,     past_key_values=lowerCamelCase__  ,     output_hidden_states=lowerCamelCase__  ,     )["""hidden_states"""][0]

					# select random slice
					UpperCamelCase__ :Any						=      ids_tensor((1,)  ,     output_from_past.shape[-1]     ).item()
					UpperCamelCase__ :int						=      output_from_no_past[:, -3:, random_slice_idx].detach()
					UpperCamelCase__ :Any						=      output_from_past[:, :, random_slice_idx].detach()

					self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]     )

					# test that outputs are equal for slice
					self.parent.assertTrue(torch.allclose(lowerCamelCase__  ,     lowerCamelCase__  ,     atol=1e-3     )     )







				def 				__a   ( self     :Any  ,     lowerCamelCase__     :Dict  ,     lowerCamelCase__     :str  ,     lowerCamelCase__     :List[Any]  ,     lowerCamelCase__     :Tuple  ,     *lowerCamelCase__     :str  ,     ):
					UpperCamelCase__ :List[Any]						=      BertGenerationDecoder(lowerCamelCase__     )
					model.to(lowerCamelCase__     )
					model.eval()
					UpperCamelCase__ :Optional[Any]						=      model(lowerCamelCase__  ,     attention_mask=lowerCamelCase__  ,     labels=lowerCamelCase__     )
					self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.seq_length, self.vocab_size)     )







				def 				__a   ( self     :Optional[Any]     ):
					UpperCamelCase__				,		UpperCamelCase__				,		UpperCamelCase__				,		UpperCamelCase__ :Union[str, Any]						=      self.prepare_config_and_inputs()
					UpperCamelCase__ :Optional[Any]						=      {"""input_ids""": input_ids, """attention_mask""": input_mask}
					return config, inputs_dict

@require_torch
class        lowerCAmelCase_				(      lowercase						,      lowercase						,      lowercase						,      unittest.TestCase	):







				"""simple docstring"""




				_snake_case				:   Dict        =			(BertGenerationEncoder, BertGenerationDecoder) if is_torch_available() else ()
				_snake_case				:   Any        =			(BertGenerationDecoder,) if is_torch_available() else ()
				_snake_case				:   Optional[int]        =			(
				    {"""feature-extraction""": BertGenerationEncoder, """text-generation""": BertGenerationDecoder}
				    if is_torch_available()
				    else {}
				)







				def 				__a   ( self     :List[Any]     ):
					UpperCamelCase__ :int						=      BertGenerationEncoderTester(self     )
					UpperCamelCase__ :Union[str, Any]						=      ConfigTester(self  ,     config_class=lowerCamelCase__  ,     hidden_size=37     )







				def 				__a   ( self     :Any     ):
					self.config_tester.run_common_tests()







				def 				__a   ( self     :Union[str, Any]     ):
					UpperCamelCase__ :List[Any]						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowerCamelCase__     )







				def 				__a   ( self     :Tuple     ):
					UpperCamelCase__				,		UpperCamelCase__				,		UpperCamelCase__				,		UpperCamelCase__ :Optional[Any]						=      self.model_tester.prepare_config_and_inputs()
					UpperCamelCase__ :Optional[Any]						=      """bert"""
					self.model_tester.create_and_check_model(lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__     )







				def 				__a   ( self     :List[str]     ):
					UpperCamelCase__ :Union[str, Any]						=      self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_model_as_decoder(*lowerCamelCase__     )







				def 				__a   ( self     :Union[str, Any]     ):
					UpperCamelCase__ :Union[str, Any]						=      self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_decoder_model_past_large_inputs(*lowerCamelCase__     )







				def 				__a   ( self     :Dict     ):
					# This regression test was failing with PyTorch < 1.3
					(
					    (
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		(
					    UpperCamelCase__
					)				,		
					) :int						=      self.model_tester.prepare_config_and_inputs_for_decoder()

					UpperCamelCase__ :Optional[int]						=      None

					self.model_tester.create_and_check_model_as_decoder(
					    lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__  ,     )







				def 				__a   ( self     :str     ):
					UpperCamelCase__ :int						=      self.model_tester.prepare_config_and_inputs_for_decoder()
					self.model_tester.create_and_check_for_causal_lm(*lowerCamelCase__     )







				@slow
				def 				__a   ( self     :Tuple     ):
					UpperCamelCase__ :Any						=      BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""     )
					self.assertIsNotNone(lowerCamelCase__     )

@require_torch
class        lowerCAmelCase_				(      unittest.TestCase	):







				"""simple docstring"""




				@slow
				def 				__a   ( self     :List[Any]     ):
					UpperCamelCase__ :Union[str, Any]						=      BertGenerationEncoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""     )
					UpperCamelCase__ :List[str]						=      torch.tensor([[1_01, 75_92, 10_10, 20_26, 38_99, 20_03, 1_01_40, 1_02]]     )
					with torch.no_grad():
						UpperCamelCase__ :str						=      model(lowerCamelCase__     )[0]
					UpperCamelCase__ :Optional[int]						=      torch.Size([1, 8, 10_24]     )
					self.assertEqual(output.shape  ,     lowerCamelCase__     )
					UpperCamelCase__ :Tuple						=      torch.tensor(
					    [[[0.1775, 0.0083, -0.0321], [1.6002, 0.1287, 0.3912], [2.1473, 0.5791, 0.6066]]]     )
					self.assertTrue(torch.allclose(output[:, :3, :3]  ,     lowerCamelCase__  ,     atol=1e-4     )     )

@require_torch
class        lowerCAmelCase_				(      unittest.TestCase	):







				"""simple docstring"""




				@slow
				def 				__a   ( self     :int     ):
					UpperCamelCase__ :str						=      BertGenerationDecoder.from_pretrained("""google/bert_for_seq_generation_L-24_bbc_encoder"""     )
					UpperCamelCase__ :Optional[Any]						=      torch.tensor([[1_01, 75_92, 10_10, 20_26, 38_99, 20_03, 1_01_40, 1_02]]     )
					with torch.no_grad():
						UpperCamelCase__ :Optional[Any]						=      model(lowerCamelCase__     )[0]
					UpperCamelCase__ :str						=      torch.Size([1, 8, 5_03_58]     )
					self.assertEqual(output.shape  ,     lowerCamelCase__     )
					UpperCamelCase__ :Dict						=      torch.tensor(
					    [[[-0.5788, -2.5994, -3.7054], [0.0438, 4.7997, 1.8795], [1.5862, 6.6409, 4.4638]]]     )
					self.assertTrue(torch.allclose(output[:, :3, :3]  ,     lowerCamelCase__  ,     atol=1e-4     )     )




'''simple docstring'''
from math import ceil






def A__       (	UpperCAmelCase_ = 1_0_0_1				):
						_UpperCamelCase   :						int												=  1

						for i in range(1    ,    int(ceil(n / 2.0				)				)				):
												_UpperCamelCase   :						Dict												=  2 * i + 1
												_UpperCamelCase   :						Tuple												=  2 * i
												_UpperCamelCase   :						Any												=  total + 4 * odd**2 - 6 * even

						return total


if __name__ == "__main__":
					import sys

					if len(sys.argv) == 1:
										print(solution())
					else:
										try:
															snake_case_					:      Tuple    			=    int(sys.argv[1])
															print(solution(n))
										except ValueError:
															print('Invalid entry - please enter a number')


