

import numpy as np
from matplotlib import pyplot as plt







def _a				( SCREAMING_SNAKE_CASE	:    Any	)					->					Any:

 """simple docstring"""






 return 1 / (1 + np.exp(-1 * x	))






class 							A_				:


     def __init__(							self    :	Any    ,						UpperCAmelCase    :	Tuple    ,						UpperCAmelCase    :	Dict=None    ,						UpperCAmelCase    :	Union[str, Any]=None    ,						UpperCAmelCase    :	List[Any]=False      )							->			Dict:
      __lowerCAmelCase:     Dict     			=   units
      __lowerCAmelCase:     int     			=   None
      __lowerCAmelCase:     Any     			=   None
      __lowerCAmelCase:     Optional[int]     			=   activation
      if learning_rate is None:
       __lowerCAmelCase:     int     			=   0.3
      __lowerCAmelCase:     List[Any]     			=   learning_rate
      __lowerCAmelCase:     Any     			=   is_input_layer


     def 						UpperCAmelCase						(							self    :	List[str]    ,						UpperCAmelCase    :	str      )							->			Tuple:
      __lowerCAmelCase:     Dict     			=   np.asmatrix(np.random.normal(0    ,						0.5    ,						(self.units, back_units)      )      )
      __lowerCAmelCase:     int     			=   np.asmatrix(np.random.normal(0    ,						0.5    ,						self.units      )      ).T
      if self.activation is None:
       __lowerCAmelCase:     Dict     			=   sigmoid


     def 						UpperCAmelCase						(							self    :	Optional[int]      )							->			Any:
      # activation function may be sigmoid or linear
      if self.activation == sigmoid:
       __lowerCAmelCase:     List[Any]     			=   np.dot(self.output    ,						(1 - self.output).T      )
       __lowerCAmelCase:     int     			=   np.diag(np.diag(UpperCAmelCase      )      )
      else:
       __lowerCAmelCase:     List[Any]     			=   1
      return gradient_activation


     def 						UpperCAmelCase						(							self    :	Any    ,						UpperCAmelCase    :	str      )							->			List[str]:
      __lowerCAmelCase:     Optional[Any]     			=   xdata
      if self.is_input_layer:
       # input layer
       __lowerCAmelCase:     Optional[int]     			=   xdata
       __lowerCAmelCase:     Any     			=   xdata
       return xdata
      else:
       __lowerCAmelCase:     List[str]     			=   np.dot(self.weight    ,						self.xdata      ) - self.bias
       __lowerCAmelCase:     Any     			=   self.activation(self.wx_plus_b      )
       return self.output


     def 						UpperCAmelCase						(							self    :	Optional[int]    ,						UpperCAmelCase    :	List[str]      )							->			List[Any]:
      __lowerCAmelCase:     Dict     			=   self.cal_gradient()  # i * i 维
      __lowerCAmelCase:     Optional[Any]     			=   np.asmatrix(np.dot(gradient.T    ,						UpperCAmelCase      )      )

      __lowerCAmelCase:     Any     			=   np.asmatrix(self.xdata      )
      __lowerCAmelCase:     List[Any]     			=   -1
      __lowerCAmelCase:     Dict     			=   self.weight

      __lowerCAmelCase:     str     			=   np.dot(gradient.T    ,						self._gradient_weight.T      )
      __lowerCAmelCase:     List[str]     			=   gradient * self._gradient_bias
      __lowerCAmelCase:     List[str]     			=   np.dot(UpperCAmelCase    ,						self._gradient_x      ).T
      # upgrade: the Negative gradient direction
      __lowerCAmelCase:     Dict     			=   self.weight - self.learn_rate * self.gradient_weight
      __lowerCAmelCase:     List[Any]     			=   self.bias - self.learn_rate * self.gradient_bias.T
      # updates the weights and bias according to learning rate (0.3 if undefined)
      return self.gradient







class 							A_				:


     def __init__(							self    :	Optional[Any]      )							->			Tuple:
      __lowerCAmelCase:     int     			=   []
      __lowerCAmelCase:     Optional[int]     			=   []
      __lowerCAmelCase:     Any     			=   plt.figure()
      __lowerCAmelCase:     List[str]     			=   self.fig_loss.add_subplot(1    ,						1    ,						1      )


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


     def 						UpperCAmelCase						(							self    :	List[Any]      )							->			Any:
      for i, layer in enumerate(self.layers[:]      ):
       if i < 1:
        __lowerCAmelCase:     List[Any]     			=   True
       else:
        layer.initializer(self.layers[i - 1].units      )


     def 						UpperCAmelCase						(							self    :	str      )							->			int:
      for i, layer in enumerate(self.layers[:]      ):
       print(F'''------- layer {i} -------'''      )
       print('weight.shape '    ,						np.shape(layer.weight      )      )
       print('bias.shape '    ,						np.shape(layer.bias      )      )


     def 						UpperCAmelCase						(							self    :	Tuple    ,						UpperCAmelCase    :	int    ,						UpperCAmelCase    :	str    ,						UpperCAmelCase    :	Union[str, Any]    ,						UpperCAmelCase    :	Any      )							->			Any:
      __lowerCAmelCase:     Any     			=   train_round
      __lowerCAmelCase:     List[Any]     			=   accuracy

      self.ax_loss.hlines(self.accuracy    ,						0    ,						self.train_round * 1.1      )

      __lowerCAmelCase:     Dict     			=   np.shape(UpperCAmelCase      )
      for _ in range(UpperCAmelCase      ):
       __lowerCAmelCase:     List[Any]     			=   0
       for row in range(x_shape[0]      ):
        __lowerCAmelCase:     str     			=   np.asmatrix(xdata[row, :]      ).T
        __lowerCAmelCase:     Union[str, Any]     			=   np.asmatrix(ydata[row, :]      ).T

        # forward propagation
        for layer in self.layers:
         __lowerCAmelCase:     Union[str, Any]     			=   layer.forward_propagation(_xdata      )

        __lowerCAmelCase			,							__lowerCAmelCase:     List[str]     			=   self.cal_loss(_ydata    ,						_xdata      )
        __lowerCAmelCase:     Tuple     			=   all_loss + loss

        # back propagation: the input_layer does not upgrade
        for layer in self.layers[:0:-1]:
         __lowerCAmelCase:     Union[str, Any]     			=   layer.back_propagation(UpperCAmelCase      )

       __lowerCAmelCase:     List[Any]     			=   all_loss / x_shape[0]
       self.train_mse.append(UpperCAmelCase      )

       self.plot_loss()

       if mse < self.accuracy:
        print('----达到精度----'      )
        return mse
      return None


     def 						UpperCAmelCase						(							self    :	int    ,						UpperCAmelCase    :	List[str]    ,						UpperCAmelCase    :	Optional[Any]      )							->			Optional[int]:
      __lowerCAmelCase:     int     			=   np.sum(np.power((ydata - ydata_)    ,						2      )      )
      __lowerCAmelCase:     Union[str, Any]     			=   2 * (ydata_ - ydata)
      # vector (shape is the same as _ydata.shape)
      return self.loss, self.loss_gradient


     def 						UpperCAmelCase						(							self    :	Union[str, Any]      )							->			List[str]:
      if self.ax_loss.lines:
       self.ax_loss.lines.remove(self.ax_loss.lines[0]      )
      self.ax_loss.plot(self.train_mse    ,						'r-'      )
      plt.ion()
      plt.xlabel('step'      )
      plt.ylabel('loss'      )
      plt.show()
      plt.pause(0.1      )







def _a				( )					->					str:

 """simple docstring"""






 __lowerCAmelCase:     Optional[Any]     			=   np.random.randn(10					,      10	)
 __lowerCAmelCase:     List[Any]     			=   np.asarray(
     [
         [0.8, 0.4],
         [0.4, 0.3],
         [0.3_4, 0.4_5],
         [0.6_7, 0.3_2],
         [0.8_8, 0.6_7],
         [0.7_8, 0.7_7],
         [0.5_5, 0.6_6],
         [0.5_5, 0.4_3],
         [0.5_4, 0.1],
         [0.1, 0.5],
     ]	)
 __lowerCAmelCase:     Optional[Any]     			=   BPNN()
 for i in (10, 20, 30, 2):
  model.add_layer(DenseLayer(SCREAMING_SNAKE_CASE	)	)
 model.build()
 model.summary()
 model.train(xdata=SCREAMING_SNAKE_CASE					,      ydata=SCREAMING_SNAKE_CASE					,      train_round=1_00					,      accuracy=0.0_1	)


if __name__ == "__main__":
  example()








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()))}")





