input: def MatrixOperations(m: int, n: int, lst: List[int], operation: str, mat2: 'Matrix' = None) -> str:
      """
      Perform various matrix operations on a given matrix (represented by a list of integers) 
      such as addition, subtraction, multiplication, and transpose.
      >>> MatrixOperations(2, 2, [1, 2, 3, 4], "add", Matrix(2, 2, [1, 1, 1, 1]))
      '2 3 \n4 5 \n'
      >>> MatrixOperations(2, 2, [1, 2, 3, 4], "mul", Matrix(2, 2, [2, 0, 1, 1]))
      '4 2 \n10 7 \n'
      >>> MatrixOperations(2, 2, [1, 2, 3, 4], "transpose", None)
      '1 3 \n2 4 \n'
      >>> MatrixOperations(2, 2, [1, 2, 3, 4], "sub", Matrix(2, 2, [1, 1, 1, 1]))
      '0 1 \n2 3 \n'
      """
      matrix = Matrix(m, n, lst)
      if operation == "add":
          matrix.add(mat2)
      elif operation == "sub":
          matrix.sub(mat2)
      elif operation == "mul":
          matrix.mul(mat2)
      elif operation == "transpose":
          matrix.transpose()
      return str(matrix)
output:     class Matrix:
          def __init__(self, m, n, lst):
              self.m = m
              self.n = n
              self.data = lst
          
          def add(self, other):
              for i in range(self.m * self.n):
                  self.data[i] += other.data[i]
          
          def sub(self, other):
              for i in range(self.m * self.n):
                  self.data[i] -= other.data[i]
          
          def mul(self, other):
              result = [0] * (self.m * other.n)
              for i in range(self.m):
                  for j in range(other.n):
                      for k in range(self.n):
                          result[i * other.n + j] += self.data[i * self.n + k] * other.data[k * other.n + j]
              self.data = result
              self.n = other.n
          
          def transpose(self):
              new_data = [0] * (self.m * self.n)
              for i in range(self.m):
                  for j in range(self.n):
                      new_data[j * self.m + i] = self.data[i * self.n + j]
              self.data = new_data
              self.m, self.n = self.n, self.m
          
          def __str__(self):
              result = ""
              for i in range(self.m):
                  for j in range(self.n):
                      result += str(self.data[i * self.n + j]) + " "
                  result = result.strip() + "\n"
              return result.strip()