



import unittest

import numpy as np





def 		a__      (		_UpperCamelCase      :			np.ndarray			,_UpperCamelCase      :			np.ndarray			,_UpperCamelCase      :			np.ndarray			,_UpperCamelCase      :			np.ndarray | None = None			,):
   __lowerCamelCase    				=     np.shape(_UpperCamelCase				)
   __lowerCamelCase    				=     np.shape(_UpperCamelCase				)
   __lowerCamelCase    				=     np.shape(_UpperCamelCase				)

   if shape_a[0] != shape_b[0]:
      __lowerCamelCase    				=     (
          '''Expected the same number of rows for A and B. '''
          F"""Instead found A of size {shape_a} and B of size {shape_b}"""
      )
      raise ValueError(_UpperCamelCase				)

   if shape_b[1] != shape_c[1]:
      __lowerCamelCase    				=     (
          '''Expected the same number of columns for B and C. '''
          F"""Instead found B of size {shape_b} and C of size {shape_c}"""
      )
      raise ValueError(_UpperCamelCase				)

   __lowerCamelCase    				=     pseudo_inv
   if a_inv is None:
      try:
         __lowerCamelCase    				=     np.linalg.inv(_UpperCamelCase				)
      except np.linalg.LinAlgError:
         raise ValueError(
             '''Input matrix A is not invertible. Cannot compute Schur complement.'''				)

   return mat_c - mat_b.T @ a_inv @ mat_b



class 			__lowerCAmelCase  (						unittest.TestCase ):




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]					)
    __lowerCamelCase    				=     np.array([[0, 3], [3, 0], [2, 3]]					)
    __lowerCamelCase    				=     np.array([[2, 1], [6, 3]]					)

    __lowerCamelCase    				=     schur_complement(__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					)

    __lowerCamelCase    				=     np.block([[a, b], [b.T, c]]					)

    __lowerCamelCase    				=     np.linalg.det(__UpperCAmelCase					)
    __lowerCamelCase    				=     np.linalg.det(__UpperCAmelCase					)
    __lowerCamelCase    				=     np.linalg.det(__UpperCAmelCase					)

    self.assertAlmostEqual(__UpperCAmelCase						,					det_a * det_s					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]					)
    __lowerCamelCase    				=     np.array([[0, 3], [3, 0], [2, 3]]					)
    __lowerCamelCase    				=     np.array([[2, 1], [6, 3]]					)

    with self.assertRaises(__UpperCAmelCase					):
       schur_complement(__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]					)
    __lowerCamelCase    				=     np.array([[0, 3], [3, 0], [2, 3]]					)
    __lowerCamelCase    				=     np.array([[2, 1, 3], [6, 3, 5]]					)

    with self.assertRaises(__UpperCAmelCase					):
       schur_complement(__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  unittest.main()











from __future__ import annotations

from math import ceil, floor, sqrt





def 		a__      (		_UpperCamelCase      :			int = 2_00_00_00				):
   __lowerCamelCase    				=     [0]
   __lowerCamelCase    				=     42

   for idx in range(1			,ceil(sqrt(target * 2				) * 1.1				)				):
      triangle_numbers.append(triangle_numbers[-1] + idx				)

   # we want this to be as close as possible to target
   __lowerCamelCase    				=     0
   # the area corresponding to the grid that gives the product closest to target
   __lowerCamelCase    				=     0
   # an estimate of b, using the quadratic formula
   __lowerCamelCase    				=     42
   # the largest integer less than b_estimate
   __lowerCamelCase    				=     42
   # the largest integer less than b_estimate
   __lowerCamelCase    				=     42
   # the triangle number corresponding to b_floor
   __lowerCamelCase    				=     42
   # the triangle number corresponding to b_ceil
   __lowerCamelCase    				=     42

   for idx_a, triangle_a in enumerate(triangle_numbers[1:]			,1				):
      __lowerCamelCase    				=     (-1 + sqrt(1 + 8 * target / triangle_a				)) / 2
      __lowerCamelCase    				=     floor(_UpperCamelCase				)
      __lowerCamelCase    				=     ceil(_UpperCamelCase				)
      __lowerCamelCase    				=     triangle_numbers[b_floor]
      __lowerCamelCase    				=     triangle_numbers[b_ceil]

      if abs(target - triangle_b_first_guess * triangle_a				) < abs(
          target - best_product				):
         __lowerCamelCase    				=     triangle_b_first_guess * triangle_a
         __lowerCamelCase    				=     idx_a * b_floor

      if abs(target - triangle_b_second_guess * triangle_a				) < abs(
          target - best_product				):
         __lowerCamelCase    				=     triangle_b_second_guess * triangle_a
         __lowerCamelCase    				=     idx_a * b_ceil

   return area


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






