

import logging

import torch
from torch import nn
from torch.nn import CrossEntropyLoss, MSELoss

from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
from transformers.models.albert.modeling_albert import (
    ALBERT_INPUTS_DOCSTRING,
    ALBERT_START_DOCSTRING,
    AlbertModel,
    AlbertPreTrainedModel,
    AlbertTransformer,
)


_a	 =     logging.getLogger(__name__)






class 							A_				(	snake_case__      ):


     def 						UpperCAmelCase						(							self    :	int    ,						UpperCAmelCase    :	Optional[int]    ,						UpperCAmelCase    :	Tuple    ,						UpperCAmelCase    :	List[Any]=None    ,						UpperCAmelCase    :	Optional[Any]=None      )							->			Any:
      if current_layer == 0:
       __lowerCAmelCase:     Optional[Any]     			=   self.embedding_hidden_mapping_in(UpperCAmelCase      )
      else:
       __lowerCAmelCase:     List[str]     			=   hidden_states[0]

      __lowerCAmelCase:     Tuple     			=   int(self.config.num_hidden_layers / self.config.num_hidden_groups      )

      # Index of the hidden group
      __lowerCAmelCase:     Union[str, Any]     			=   int(current_layer / (self.config.num_hidden_layers / self.config.num_hidden_groups)      )

      __lowerCAmelCase:     str     			=   self.albert_layer_groups[group_idx](
          UpperCAmelCase    ,						UpperCAmelCase    ,						head_mask[group_idx * layers_per_group : (group_idx + 1) * layers_per_group]    ,						)
      __lowerCAmelCase:     Tuple     			=   layer_group_output[0]

      return (hidden_states,)







@add_start_docstrings(
    'The bare ALBERT Model transformer with PABEE outputting raw hidden-states without any specific head on top.'							,			snake_case__							,			)
class 							A_				(	snake_case__      ):


     def __init__(							self    :	List[str]    ,						UpperCAmelCase    :	str      )							->			Union[str, Any]:
      super().__init__(UpperCAmelCase      )

      __lowerCAmelCase:     List[Any]     			=   AlbertTransformerWithPabee(UpperCAmelCase      )

      self.init_weights()
      __lowerCAmelCase:     Any     			=   0
      __lowerCAmelCase:     Optional[int]     			=   0
      __lowerCAmelCase:     Optional[Any]     			=   0

      __lowerCAmelCase:     Any     			=   0


     def 						UpperCAmelCase						(							self    :	Dict    ,						UpperCAmelCase    :	Optional[int]      )							->			Optional[Any]:
      __lowerCAmelCase:     Any     			=   threshold


     def 						UpperCAmelCase						(							self    :	Any    ,						UpperCAmelCase    :	Any      )							->			Optional[Any]:
      __lowerCAmelCase:     List[Any]     			=   patience


     def 						UpperCAmelCase						(							self    :	Optional[int]      )							->			Union[str, Any]:
      __lowerCAmelCase:     List[str]     			=   0
      __lowerCAmelCase:     int     			=   0


     def 						UpperCAmelCase						(							self    :	Tuple      )							->			int:
      __lowerCAmelCase:     Dict     			=   self.inference_layers_num / self.inference_instances_num
      __lowerCAmelCase:     str     			=   (
          F'''*** Patience = {self.patience} Avg. Inference Layers = {avg_inf_layers:.2f} Speed Up ='''
          F''' {1 - avg_inf_layers / self.config.num_hidden_layers:.2f} ***'''
      )
      print(UpperCAmelCase      )


     @add_start_docstrings_to_model_forward(UpperCAmelCase      )
     def 						UpperCAmelCase						(							self    :	Dict    ,						UpperCAmelCase    :	Optional[Any]=None    ,						UpperCAmelCase    :	Optional[int]=None    ,						UpperCAmelCase    :	List[Any]=None    ,						UpperCAmelCase    :	int=None    ,						UpperCAmelCase    :	Optional[int]=None    ,						UpperCAmelCase    :	List[str]=None    ,						UpperCAmelCase    :	int=None    ,						UpperCAmelCase    :	List[str]=None    ,						UpperCAmelCase    :	Any=False    ,						)							->			List[Any]:

      if input_ids is not None and inputs_embeds is not None:
       raise ValueError('You cannot specify both input_ids and inputs_embeds at the same time'      )
      elif input_ids is not None:
       __lowerCAmelCase:     Optional[int]     			=   input_ids.size()
      elif inputs_embeds is not None:
       __lowerCAmelCase:     Tuple     			=   inputs_embeds.size()[:-1]
      else:
       raise ValueError('You have to specify either input_ids or inputs_embeds'      )

      __lowerCAmelCase:     List[str]     			=   input_ids.device if input_ids is not None else inputs_embeds.device

      if attention_mask is None:
       __lowerCAmelCase:     Optional[int]     			=   torch.ones(UpperCAmelCase    ,						device=UpperCAmelCase      )
      if token_type_ids is None:
       __lowerCAmelCase:     List[Any]     			=   torch.zeros(UpperCAmelCase    ,						dtype=torch.long    ,						device=UpperCAmelCase      )

      __lowerCAmelCase:     int     			=   attention_mask.unsqueeze(1      ).unsqueeze(2      )
      __lowerCAmelCase:     List[Any]     			=   extended_attention_mask.to(dtype=self.dtype      )  # fp16 compatibility
      __lowerCAmelCase:     Union[str, Any]     			=   (1.0 - extended_attention_mask) * -10000.0
      __lowerCAmelCase:     List[str]     			=   self.get_head_mask(UpperCAmelCase    ,						self.config.num_hidden_layers      )

      __lowerCAmelCase:     int     			=   self.embeddings(
          UpperCAmelCase    ,						position_ids=UpperCAmelCase    ,						token_type_ids=UpperCAmelCase    ,						inputs_embeds=UpperCAmelCase      )
      __lowerCAmelCase:     str     			=   embedding_output

      if self.training:
       __lowerCAmelCase:     Optional[Any]     			=   []
       for i in range(self.config.num_hidden_layers      ):
        __lowerCAmelCase:     Any     			=   self.encoder.adaptive_forward(
            UpperCAmelCase    ,						current_layer=UpperCAmelCase    ,						attention_mask=UpperCAmelCase    ,						head_mask=UpperCAmelCase    ,						)

        __lowerCAmelCase:     Optional[int]     			=   self.pooler_activation(self.pooler(encoder_outputs[0][:, 0]      )      )
        __lowerCAmelCase:     List[Any]     			=   output_layers[i](output_dropout(UpperCAmelCase      )      )
        res.append(UpperCAmelCase      )
      elif self.patience == 0:  # Use all layers for inference
       __lowerCAmelCase:     str     			=   self.encoder(UpperCAmelCase    ,						UpperCAmelCase    ,						head_mask=UpperCAmelCase      )
       __lowerCAmelCase:     str     			=   self.pooler_activation(self.pooler(encoder_outputs[0][:, 0]      )      )
       __lowerCAmelCase:     List[str]     			=   [output_layers[self.config.num_hidden_layers - 1](UpperCAmelCase      )]
      else:
       __lowerCAmelCase:     Tuple     			=   0
       __lowerCAmelCase:     Optional[Any]     			=   None
       __lowerCAmelCase:     int     			=   0
       for i in range(self.config.num_hidden_layers      ):
        calculated_layer_num += 1
        __lowerCAmelCase:     Any     			=   self.encoder.adaptive_forward(
            UpperCAmelCase    ,						current_layer=UpperCAmelCase    ,						attention_mask=UpperCAmelCase    ,						head_mask=UpperCAmelCase    ,						)

        __lowerCAmelCase:     int     			=   self.pooler_activation(self.pooler(encoder_outputs[0][:, 0]      )      )
        __lowerCAmelCase:     Optional[int]     			=   output_layers[i](UpperCAmelCase      )
        if regression:
         __lowerCAmelCase:     Union[str, Any]     			=   logits.detach()
         if patient_result is not None:
          __lowerCAmelCase:     str     			=   patient_result.detach()
         if (patient_result is not None) and torch.abs(patient_result - labels      ) < self.regression_threshold:
          patient_counter += 1
         else:
          __lowerCAmelCase:     Optional[Any]     			=   0
        else:
         __lowerCAmelCase:     Any     			=   logits.detach().argmax(dim=1      )
         if patient_result is not None:
          __lowerCAmelCase:     List[str]     			=   patient_result.detach().argmax(dim=1      )
         if (patient_result is not None) and torch.all(labels.eq(UpperCAmelCase      )      ):
          patient_counter += 1
         else:
          __lowerCAmelCase:     Dict     			=   0

        __lowerCAmelCase:     List[Any]     			=   logits
        if patient_counter == self.patience:
         break
       __lowerCAmelCase:     List[str]     			=   [patient_result]
       self.inference_layers_num += calculated_layer_num
       self.inference_instances_num += 1

      return res







@add_start_docstrings(
    'Albert Model transformer with PABEE and a sequence classification/regression head on top (a linear layer on top of\n    the pooled output) e.g. for GLUE tasks. '							,			snake_case__							,			)
class 							A_				(	snake_case__      ):


     def __init__(							self    :	Tuple    ,						UpperCAmelCase    :	Optional[int]      )							->			int:
      super().__init__(UpperCAmelCase      )
      __lowerCAmelCase:     Union[str, Any]     			=   config.num_labels

      __lowerCAmelCase:     Dict     			=   AlbertModelWithPabee(UpperCAmelCase      )
      __lowerCAmelCase:     Any     			=   nn.Dropout(config.classifier_dropout_prob      )
      __lowerCAmelCase:     Any     			=   nn.ModuleList(
          [nn.Linear(config.hidden_size    ,						self.config.num_labels      ) for _ in range(config.num_hidden_layers      )]      )

      self.init_weights()


     @add_start_docstrings_to_model_forward(UpperCAmelCase      )
     def 						UpperCAmelCase						(							self    :	Dict    ,						UpperCAmelCase    :	List[str]=None    ,						UpperCAmelCase    :	Union[str, Any]=None    ,						UpperCAmelCase    :	List[Any]=None    ,						UpperCAmelCase    :	Tuple=None    ,						UpperCAmelCase    :	Any=None    ,						UpperCAmelCase    :	int=None    ,						UpperCAmelCase    :	Optional[Any]=None    ,						)							->			Dict:
      __lowerCAmelCase:     str     			=   self.albert(
          input_ids=UpperCAmelCase    ,						attention_mask=UpperCAmelCase    ,						token_type_ids=UpperCAmelCase    ,						position_ids=UpperCAmelCase    ,						head_mask=UpperCAmelCase    ,						inputs_embeds=UpperCAmelCase    ,						output_dropout=self.dropout    ,						output_layers=self.classifiers    ,						regression=self.num_labels == 1    ,						)

      __lowerCAmelCase:     List[str]     			=   (logits[-1],)

      if labels is not None:
       __lowerCAmelCase:     Dict     			=   None
       __lowerCAmelCase:     Any     			=   0
       for ix, logits_item in enumerate(UpperCAmelCase      ):
        if self.num_labels == 1:
         #  We are doing regression
         __lowerCAmelCase:     str     			=   MSELoss()
         __lowerCAmelCase:     List[Any]     			=   loss_fct(logits_item.view(-1      )    ,						labels.view(-1      )      )
        else:
         __lowerCAmelCase:     List[Any]     			=   CrossEntropyLoss()
         __lowerCAmelCase:     List[Any]     			=   loss_fct(logits_item.view(-1    ,						self.num_labels      )    ,						labels.view(-1      )      )
        if total_loss is None:
         __lowerCAmelCase:     Dict     			=   loss
        else:
         total_loss += loss * (ix + 1)
        total_weights += ix + 1
       __lowerCAmelCase:     Optional[Any]     			=   (total_loss / total_weights,) + outputs

      return outputs








from math import floor, sqrt







def _a				( SCREAMING_SNAKE_CASE	:    int	)					->					int:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   0.0
 __lowerCAmelCase:     Any     			=   1.0
 __lowerCAmelCase:     List[str]     			=   int(sqrt(SCREAMING_SNAKE_CASE	)	)
 __lowerCAmelCase:     Union[str, Any]     			=   root
 __lowerCAmelCase:     List[str]     			=   0
 while integer_part != 2 * root:
  __lowerCAmelCase:     List[str]     			=   denominator * integer_part - numerator
  __lowerCAmelCase:     Optional[int]     			=   (n - numerator**2) / denominator
  __lowerCAmelCase:     Union[str, Any]     			=   int((root + numerator) / denominator	)
  period += 1
 return period







def _a				( SCREAMING_SNAKE_CASE	:    int = 1_00_00	)					->					int:

 """simple docstring"""






 __lowerCAmelCase:     Optional[int]     			=   0
 for i in range(2					,      n + 1	):
  __lowerCAmelCase:     List[str]     			=   sqrt(SCREAMING_SNAKE_CASE	)
  if sr - floor(SCREAMING_SNAKE_CASE	) != 0 and continuous_fraction_period(SCREAMING_SNAKE_CASE	) % 2 == 1:
   count_odd_periods += 1
 return count_odd_periods


if __name__ == "__main__":
  print(f"{solution(int(input().strip()))}")





