input: 
  class Matrix:
      def __init__(self, m, n, lst):
          """ Initialize a matrix with dimensions m x n using elements from the list lst.
          """
          self.m = m
          self.n = n
          self.mat = []
    
          c = 0
          for i in range(self.m): 
              a =[] 
              for j in range(self.n): 
                      a.append(lst[c]) 
                      c += 1
              self.mat.append(a) 
    
      def __str__(self): 
          """ Return a string representation of the matrix.
          """
          output = ""
          for i in self.mat: 
              for j in i: 
                  output += str(j) + " "
              output += '\n'
          return output 
    
      def add(self, mat2): 
          """ Add matrix mat2 to the current matrix. Only valid if both matrices have the same dimensions.
          >>> A = Matrix(2, 2, [1, 2, 3, 4])
          >>> B = Matrix(2, 2, [5, 6, 7, 8])
          >>> A.add(B)
          >>> print(A)
          6 8 
          10 12 
          """
          if self.m != mat2.m or self.n != mat2.n:
              raise ValueError("Matrices must have the same dimensions for addition.")
          for i in range(self.m): 
              for j in range(self.n): 
                  self.mat[i][j] += mat2.mat[i][j] 
    
      def sub(self, mat2): 
          """ Subtract matrix mat2 from the current matrix. Only valid if both matrices have the same dimensions.
          >>> A = Matrix(2, 2, [1, 2, 3, 4])
          >>> B = Matrix(2, 2, [5, 6, 7, 8])
          >>> A.sub(B)
          >>> print(A)
          -4 -4 
          -4 -4 
          """
          if self.m != mat2.m or self.n != mat2.n:
              raise ValueError("Matrices must have the same dimensions for subtraction.")
          for i in range(self.m): 
              for j in range(self.n): 
                  self.mat[i][j] -= mat2.mat[i][j]
      
      def mul(self, mat2): 
          """ Multiply the current matrix by matrix mat2. Only valid if the number of columns in the current matrix
          matches the number of rows in mat2.
          >>> A = Matrix(2, 3, [1, 2, 3, 4, 5, 6])
          >>> B = Matrix(3, 2, [7, 8, 9, 10, 11, 12])
          >>> A.mul(B)
          >>> print(A)
          58 64 
          139 154 
          """
          if self.n != mat2.m:
              raise ValueError("The number of columns in the first matrix must match the number of rows in the second matrix for multiplication.")
          result = [] 
          for i in range(self.m): 
              a =[] 
              for j in range(mat2.n): 
                  s = 0
                  for k in range(self.n): 
                      s += self.mat[i][k] * mat2.mat[k][j] 
                  a.append(s) 
              result.append(a) 
          self.mat = result 
          self.m = len(result) 
          self.n = len(result[0]) 
    
      def transpose(self):
          """ Transpose the current matrix.
          >>> A = Matrix(2, 3, [1, 2, 3, 4, 5, 6])
          >>> A.transpose()
          >>> print(A)
          1 4 
          2 5 
          3 6 
          """
          result = [[self.mat[j][i] for j in range(len(self.mat))] for i in range(len(self.mat[0]))]
          self.mat = result 
          self.m = len(result) 
          self.n = len(result[0])
  
output:     def det(self):
          """ Calculate the determinant of the current matrix. Only valid for square matrices.
          >>> A = Matrix(2, 2, [1, 2, 3, 4])
          >>> print(A.det())
          -2
          """
          if self.m != self.n:
              raise ValueError("Determinant can only be calculated for square matrices.")
          if self.m == 1:
              return self.mat[0][0]
          if self.m == 2:
              return self.mat[0][0] * self.mat[1][1] - self.mat[0][1] * self.mat[1][0]
          determinant = 0
          for c in range(self.n):
              sub_mat = [row[:c] + row[c+1:] for row in self.mat[1:]]
              sub_matrix = Matrix(self.m - 1, self.n - 1, [item for sublist in sub_mat for item in sublist])
              determinant += ((-1) ** c) * self.mat[0][c] * sub_matrix.det()
          return determinant