'''simple docstring'''

def      UpperCamelCase_						(					snake_case_       :       list[list]      )					->     list[list]:






 '''simple docstring'''

 __lowerCAmelCase											=						current_set.copy()
 for row_index, row in enumerate(snake_case_      ):
  __lowerCAmelCase											=						row[0]
  for column_index, column in enumerate(snake_case_      ):
   if magnitude == 0:
    __lowerCAmelCase											=						column
    continue
   __lowerCAmelCase											=						column / magnitude
    # Subtract to cancel term
 __lowerCAmelCase											=						current_set[0]
 __lowerCAmelCase											=						[first_row]
 __lowerCAmelCase											=						current_set[1::]
 for row in current_set:
  __lowerCAmelCase											=						[]
  # If first term is 0, it is already in form we want, so we preserve it
  if row[0] == 0:
   final_set.append(snake_case_      )
   continue
  for column_index in range(len(snake_case_      )      ):
   temp_row.append(first_row[column_index] - row[column_index]      )
  final_set.append(snake_case_      )
 # Create next recursion iteration set
 if len(final_set[0]      ) != 3:
  __lowerCAmelCase											=						final_set[0]
  __lowerCAmelCase											=						[]
  __lowerCAmelCase											=						[]
  for row in final_set[1::]:
   current_first_column.append(row[0]      )
   next_iteration.append(row[1::]      )
  __lowerCAmelCase											=						simplify(snake_case_      )
  for i in range(len(snake_case_      )      ):
   resultant[i].insert(0						,		current_first_column[i]      )
  resultant.insert(0						,		snake_case_      )
  __lowerCAmelCase											=						resultant
 return final_set







def      UpperCamelCase_						(					snake_case_       :       list[list]      )					->     list:






 '''simple docstring'''

 if len(snake_case_      ) == 0:
  raise IndexError("""solve_simultaneous() requires n lists of length n+1"""      )
 __lowerCAmelCase											=						len(snake_case_      ) + 1
 if any(len(snake_case_      ) != _length for item in equations      ):
  raise IndexError("""solve_simultaneous() requires n lists of length n+1"""      )
 for row in equations:
  if any(not isinstance(snake_case_						,		(int, float)      ) for column in row      ):
   raise ValueError("""solve_simultaneous() requires lists of integers"""      )
 if len(snake_case_      ) == 1:
  return [equations[0][-1] / equations[0][0]]
 __lowerCAmelCase											=						equations.copy()
 if any(0 in row for row in data_set      ):
  __lowerCAmelCase											=						data_set.copy()
  __lowerCAmelCase											=						[]
  for row_index, row in enumerate(snake_case_      ):
   if 0 not in row:
    __lowerCAmelCase											=						data_set.pop(snake_case_      )
    break
  if not full_row:
   raise ValueError("""solve_simultaneous() requires at least 1 full equation"""      )
  data_set.insert(0						,		snake_case_      )
 __lowerCAmelCase											=						data_set.copy()
 __lowerCAmelCase											=						simplify(snake_case_      )
 __lowerCAmelCase											=						simplified[::-1]
 __lowerCAmelCase											=						[]
 for row in simplified:
  __lowerCAmelCase											=						row[-1]
  if not solutions:
   if row[-2] == 0:
    solutions.append(0      )
    continue
   solutions.append(current_solution / row[-2]      )
   continue
  __lowerCAmelCase											=						row.copy()[: len(snake_case_      ) - 1 :]
  while temp_row[0] == 0:
   temp_row.pop(0      )
  if len(snake_case_      ) == 0:
   solutions.append(0      )
   continue
  __lowerCAmelCase											=						temp_row[1::]
  __lowerCAmelCase											=						temp_row[::-1]
  for column_index, column in enumerate(snake_case_      ):
   current_solution -= column * solutions[column_index]
  solutions.append(snake_case_      )
 __lowerCAmelCase											=						[]
 for item in solutions:
  final.append(float(round(snake_case_						,		5      )      )      )
 return final[::-1]


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 _A			:      List[str]					      =				[
     [2, 1, 1, 1, 1, 4],
     [1, 2, 1, 1, 1, 5],
     [1, 1, 2, 1, 1, 6],
     [1, 1, 1, 2, 1, 7],
     [1, 1, 1, 1, 2, 8],
 ]
 print(solve_simultaneous(eq))
 print(solve_simultaneous([[4, 2]]))







'''simple docstring'''

def      UpperCamelCase_						(					snake_case_       :       list[int]						,		snake_case_       :       list[int]      )					->     tuple[float, float]:






 '''simple docstring'''

 if not len(snake_case_      ) == len(snake_case_      ) == 3:
  raise ValueError("""Please enter a valid equation."""      )
 if equationa[0] == equationa[1] == equationa[0] == equationa[1] == 0:
  raise ValueError("""Both a & b of two equations can't be zero."""      )

 # Extract the coefficients
 __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase											=						equationa
 __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase											=						equationa

 # Calculate the determinants of the matrices
 __lowerCAmelCase											=						aa * ba - aa * ba
 __lowerCAmelCase											=						ca * ba - ca * ba
 __lowerCAmelCase											=						aa * ca - aa * ca

 # Check if the system of linear equations has a solution (using Cramer's rule)
 if determinant == 0:
  if determinant_x == determinant_y == 0:
   raise ValueError("""Infinite solutions. (Consistent system)"""      )
  else:
   raise ValueError("""No solution. (Inconsistent system)"""      )
 else:
  if determinant_x == determinant_y == 0:
   # Trivial solution (Inconsistent system)
   return (0.0, 0.0)
  else:
   __lowerCAmelCase											=						determinant_x / determinant
   __lowerCAmelCase											=						determinant_y / determinant
   # Non-Trivial Solution (Consistent system)
   return (x, y)






