

"""simple docstring"""




from __future__ import annotations

import math







class   __lowercase      :

  def __init__(	self		:      Tuple       ,A		:      int     ):






   '''simple docstring'''
   UpperCAmelCase__       :	str        =       size
   # approximate the overall size of segment tree with given value
   UpperCAmelCase__       :	Any        =       [0 for i in range(0       ,4 * size     )]
   # create array to store lazy update
   UpperCAmelCase__       :	Dict        =       [0 for i in range(0       ,4 * size     )]
   UpperCAmelCase__       :	List[Any]        =       [0 for i in range(0       ,4 * size     )]  # flag for lazy update

  def  __lowercase							(	self		:      int       ,A		:      int     ):






   '''simple docstring'''
   return idx * 2

  def  __lowercase							(	self		:      Tuple       ,A		:      int     ):






   '''simple docstring'''
   return idx * 2 + 1

  def  __lowercase							(	self		:      Union[str, Any]       ,A		:      int       ,A		:      int       ,A		:      int       ,A		:      list[int]     ):






   '''simple docstring'''
   if left_element == right_element:
    UpperCAmelCase__       :	Optional[int]        =       a[left_element - 1]
   else:
    UpperCAmelCase__       :	Dict        =       (left_element + right_element) // 2
    self.build(self.left(A     )       ,A       ,A       ,A     )
    self.build(self.right(A     )       ,mid + 1       ,A       ,A     )
    UpperCAmelCase__       :	Union[str, Any]        =       max(
        self.segment_tree[self.left(A     )]       ,self.segment_tree[self.right(A     )]     )

  def  __lowercase							(	self		:      Optional[int]       ,A		:      int       ,A		:      int       ,A		:      int       ,A		:      int       ,A		:      int       ,A		:      int     ):






   '''simple docstring'''
   if self.flag[idx] is True:
    UpperCAmelCase__       :	Dict        =       self.lazy[idx]
    UpperCAmelCase__       :	int        =       False
    if left_element != right_element:
     UpperCAmelCase__       :	List[str]        =       self.lazy[idx]
     UpperCAmelCase__       :	List[Any]        =       self.lazy[idx]
     UpperCAmelCase__       :	List[Any]        =       True
     UpperCAmelCase__       :	Any        =       True

   if right_element < a or left_element > b:
    return True
   if left_element >= a and right_element <= b:
    UpperCAmelCase__       :	Any        =       val
    if left_element != right_element:
     UpperCAmelCase__       :	str        =       val
     UpperCAmelCase__       :	List[str]        =       val
     UpperCAmelCase__       :	Tuple        =       True
     UpperCAmelCase__       :	Optional[int]        =       True
    return True
   UpperCAmelCase__       :	Optional[int]        =       (left_element + right_element) // 2
   self.update(self.left(A     )       ,A       ,A       ,A       ,A       ,A     )
   self.update(self.right(A     )       ,mid + 1       ,A       ,A       ,A       ,A     )
   UpperCAmelCase__       :	List[str]        =       max(
       self.segment_tree[self.left(A     )]       ,self.segment_tree[self.right(A     )]     )
   return True

  def  __lowercase							(	self		:      List[str]       ,A		:      int       ,A		:      int       ,A		:      int       ,A		:      int       ,A		:      int     ):






   '''simple docstring'''
   if self.flag[idx] is True:
    UpperCAmelCase__       :	Any        =       self.lazy[idx]
    UpperCAmelCase__       :	Optional[int]        =       False
    if left_element != right_element:
     UpperCAmelCase__       :	List[Any]        =       self.lazy[idx]
     UpperCAmelCase__       :	Union[str, Any]        =       self.lazy[idx]
     UpperCAmelCase__       :	Optional[int]        =       True
     UpperCAmelCase__       :	Optional[int]        =       True
   if right_element < a or left_element > b:
    return -math.inf
   if left_element >= a and right_element <= b:
    return self.segment_tree[idx]
   UpperCAmelCase__       :	Dict        =       (left_element + right_element) // 2
   UpperCAmelCase__       :	Tuple        =       self.query(self.left(A     )       ,A       ,A       ,A       ,A     )
   UpperCAmelCase__       :	Any        =       self.query(self.right(A     )       ,mid + 1       ,A       ,A       ,A     )
   return max(A       ,A     )




  def __str__(	self		:      str     ):






   '''simple docstring'''
   return str([self.query(1       ,1       ,self.size       ,A       ,A     ) for i in range(1       ,self.size + 1     )]     )


if __name__ == "__main__":
      __UpperCAmelCase			=					[1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
      __UpperCAmelCase			=					15
      __UpperCAmelCase			=					SegmentTree(size)
      segt.build(1, 1, size, A)
      print(segt.query(1, 1, size, 4, 6))
      print(segt.query(1, 1, size, 7, 11))
      print(segt.query(1, 1, size, 7, 12))
      segt.update(1, 1, size, 1, 3, 111)
      print(segt.query(1, 1, size, 1, 15))
      segt.update(1, 1, size, 7, 8, 235)
      print(segt)












from __future__ import annotations

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





def  __magic_name__  (				lowercase				,       lowercase				,       lowercase				,       lowercase				,       )				-> list[float]:

							"""simple docstring"""



							lowercase_				,		lowercase_	:   List[str]  				=     coefficient_matrix.shape
							lowercase_				,		lowercase_	:   Any  				=     constant_matrix.shape

							if rowsa != colsa:
														lowercase_	:   List[Any]  				=     f"""Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}"""
														raise ValueError(lowercase				)

							if colsa != 1:
														lowercase_	:   Optional[int]  				=     f"""Constant matrix must be nx1 but received {rowsa}x{colsa}"""
														raise ValueError(lowercase				)

							if rowsa != rowsa:
														lowercase_	:   Tuple  				=     (
														    """Coefficient and constant matrices dimensions must be nxn and nx1 but """
														    f"""received {rowsa}x{colsa} and {rowsa}x{colsa}"""
														)
														raise ValueError(lowercase				)

							if len(lowercase				) != rowsa:
														lowercase_	:   int  				=     (
														    """Number of initial values must be equal to number of rows in coefficient """
														    f"""matrix but received {len(lowercase				)} and {rowsa}"""
														)
														raise ValueError(lowercase				)

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

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

							lowercase_				,		lowercase_	:   Dict  				=     table.shape

							strictly_diagonally_dominant(lowercase				)

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

							return [float(lowercase				) for i in new_val]





def  __magic_name__  (				lowercase				)				-> bool:

							"""simple docstring"""



							lowercase_				,		lowercase_	:   str  				=     table.shape

							lowercase_	:   str  				=     True

							for i in range(0				,       lowercase				):
														lowercase_	:   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()