





from __future__ import annotations

import numpy as np
from numpy import floataa
from numpy.typing import NDArray






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:NDArray[floataa]   ,   SCREAMING_SNAKE_CASE		:NDArray[floataa]   ,   SCREAMING_SNAKE_CASE		:list[int]   ,   SCREAMING_SNAKE_CASE		:int   ,   )      ->   list[float]:
 __lowerCAmelCase					:	List[Any]      =       coefficient_matrix.shape
 __lowerCAmelCase					:	List[str]      =       constant_matrix.shape

 if rowsa != colsa:
  __lowerCAmelCase					:	Dict      =       F'''Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}'''
  raise ValueError(SCREAMING_SNAKE_CASE   )

 if colsa != 1:
  __lowerCAmelCase					:	Any      =       F'''Constant matrix must be nx1 but received {rowsa}x{colsa}'''
  raise ValueError(SCREAMING_SNAKE_CASE   )

 if rowsa != rowsa:
  __lowerCAmelCase					:	str      =       (
      """Coefficient and constant matrices dimensions must be nxn and nx1 but """
      F'''received {rowsa}x{colsa} and {rowsa}x{colsa}'''
  )
  raise ValueError(SCREAMING_SNAKE_CASE   )

 if len(SCREAMING_SNAKE_CASE   ) != rowsa:
  __lowerCAmelCase					:	Dict      =       (
      """Number of initial values must be equal to number of rows in coefficient """
      F'''matrix but received {len(SCREAMING_SNAKE_CASE   )} and {rowsa}'''
  )
  raise ValueError(SCREAMING_SNAKE_CASE   )

 if iterations <= 0:
  raise ValueError("""Iterations must be at least 1"""   )

 __lowerCAmelCase					:	NDArray[floataa]      =       np.concatenate(
     (coefficient_matrix, constant_matrix)   ,   axis=1   )

 __lowerCAmelCase					:	int      =       table.shape

 strictly_diagonally_dominant(SCREAMING_SNAKE_CASE   )

 # Iterates the whole matrix for given number of times
 for _ in range(SCREAMING_SNAKE_CASE   ):
  __lowerCAmelCase					:	Tuple      =       []
  for row in range(SCREAMING_SNAKE_CASE   ):
   __lowerCAmelCase					:	Optional[int]      =       0
   for col in range(SCREAMING_SNAKE_CASE   ):
    if col == row:
     __lowerCAmelCase					:	int      =       table[row][col]
    elif col == cols - 1:
     __lowerCAmelCase					:	Optional[int]      =       table[row][col]
    else:
     temp += (-1) * table[row][col] * init_val[col]
   __lowerCAmelCase					:	Optional[Any]      =       (temp + val) / denom
   new_val.append(SCREAMING_SNAKE_CASE   )
  __lowerCAmelCase					:	Optional[int]      =       new_val

 return [float(SCREAMING_SNAKE_CASE   ) for i in new_val]






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:NDArray[floataa]   )      ->   bool:
 __lowerCAmelCase					:	Any      =       table.shape

 __lowerCAmelCase					:	str      =       True

 for i in range(0   ,   SCREAMING_SNAKE_CASE   ):
  __lowerCAmelCase					:	Any      =       0
  for j in range(0   ,   cols - 1   ):
   if i == j:
    continue
   else:
    total += table[i][j]

  if table[i][i] <= total:
   raise ValueError("""Coefficient matrix is not strictly diagonally dominant"""   )

 return is_diagonally_dominant


# Test Cases
if __name__ == "__main__":
      import doctest

      doctest.testmod()






def 	_SCREAMING_SNAKE_CASE		(      SCREAMING_SNAKE_CASE		:list[int]   )      ->   int:
 if not numbers:
  return 0

 if not isinstance(SCREAMING_SNAKE_CASE   ,   (list, tuple)   ) or not all(
     isinstance(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   ) for number in numbers   ):
  raise ValueError("""numbers must be an iterable of integers"""   )

 __lowerCAmelCase					:	int      =       numbers[0]

 for i in range(1   ,   len(SCREAMING_SNAKE_CASE   )   ):
  # update the maximum and minimum subarray products
  __lowerCAmelCase					:	List[str]      =       numbers[i]
  if number < 0:
   __lowerCAmelCase ,					__lowerCAmelCase					:	Union[str, Any]      =       min_till_now, max_till_now
  __lowerCAmelCase					:	Optional[int]      =       max(SCREAMING_SNAKE_CASE   ,   max_till_now * number   )
  __lowerCAmelCase					:	List[Any]      =       min(SCREAMING_SNAKE_CASE   ,   min_till_now * number   )

  # update the maximum product found till now
  __lowerCAmelCase					:	List[str]      =       max(SCREAMING_SNAKE_CASE   ,   SCREAMING_SNAKE_CASE   )

 return max_prod