


'''simple docstring'''







import timeit


class  __lowerCamelCase :
    """simple docstring"""


    def __init__(  self			:							List[str]      ,							SCREAMING_SNAKE_CASE			:							Dict):
           if isinstance(SCREAMING_SNAKE_CASE      ,							SCREAMING_SNAKE_CASE):  # Initializes a matrix identical to the one provided.
                  _A     :	Tuple      =					arg
                  _A     :	int      =					len(SCREAMING_SNAKE_CASE)
           else:  # Initializes a square matrix of the given size and set values to zero.
                  _A     :	List[Any]      =					arg
                  _A     :	int      =					[[0 for _ in range(self.n)] for _ in range(self.n)]


    def __mul__(  self			:							List[Any]      ,							SCREAMING_SNAKE_CASE			:							Dict):
           _A     :	str      =					Matrix(self.n)
           for i in range(self.n):
                  for j in range(self.n):
                         for k in range(self.n):
                                matrix.t[i][j] += self.t[i][k] * b.t[k][j]
           return matrix






def       lowerCAmelCase__       (				lowerCamelCase     :			Any  ,lowerCamelCase     :			Tuple   ):
       _A     :	Dict      =					Matrix([[1, 0], [0, 1]]   )
       while b > 0:
              if b & 1:
                     matrix *= a
              a *= a
              b >>= 1
       return matrix






def       lowerCAmelCase__       (				lowerCamelCase     :			List[Any]  ,lowerCamelCase     :			int  ,lowerCamelCase     :			Optional[Any]   ):
       # Trivial Cases
       if n == 1:
              return fa
       elif n == 2:
              return fa
       _A     :	Optional[Any]      =					Matrix([[1, 1], [1, 0]]   )
       _A     :	Tuple      =					modular_exponentiation(lowerCamelCase  ,n - 2   )
       return fa * matrix.t[0][0] + fa * matrix.t[0][1]






def       lowerCAmelCase__       (				lowerCamelCase     :			Tuple  ,lowerCamelCase     :			List[str]  ,lowerCamelCase     :			str   ):
       # Trivial Cases
       if n == 1:
              return fa
       elif n == 2:
              return fa

       _A     :	Optional[Any]      =					fa
       _A     :	Any      =					fa
       n -= 2

       while n > 0:
              _A  , _A     :	Optional[int]      =					fn_a + fn_a, fn_a
              n -= 1

       return fn_a






def       lowerCAmelCase__       (				):
       _A     :	Any      =					'\nfrom random import randint\nfrom __main__ import fibonacci_with_matrix_exponentiation\n'
       _A     :	Tuple      =					'fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)'
       _A     :	int      =					timeit.timeit(setup=lowerCamelCase  ,stmt=lowerCamelCase  ,number=100   )
       print('With matrix exponentiation the average execution time is '  ,exec_time / 100   )
       return exec_time






def       lowerCAmelCase__       (				):
       _A     :	Optional[Any]      =					'\nfrom random import randint\nfrom __main__ import simple_fibonacci\n'
       _A     :	Dict      =					'simple_fibonacci(randint(1,70000), 1, 1)'
       _A     :	int      =					timeit.timeit(setup=lowerCamelCase  ,stmt=lowerCamelCase  ,number=100   )
       print(
           'Without matrix exponentiation the average execution time is '  ,exec_time / 100   )
       return exec_time






def       lowerCAmelCase__       (				):
       matrix_exponentiation_time()
       simple_fibonacci_time()


if __name__ == "__main__":
   main()










'''simple docstring'''







from __future__ import annotations






def       lowerCAmelCase__       (				lowerCamelCase     :			list   ):
       _A     :	Union[str, Any]      =					sorted(lowerCamelCase   )
       _A     :	Tuple      =					len(lowerCamelCase   )
       _A     :	int      =					length >> 1
       return (
           (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
           if length % 2 == 0
           else sorted_list[mid_index]
       )






def       lowerCAmelCase__       (				):
       import doctest

       doctest.testmod()


if __name__ == "__main__":
   main()






