input: Write a function to optimize an equation by combining like terms. The input is a string where each term is separated by a plus sign and has an integer coefficient. The output should be a string representing the optimized equation.
  
  def optimize_equation(equation):
      variables = []
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          variables.append((var, int(count)))
  
      new_equation = ""
      for var, count in variables:
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]
  
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + b + b + b + c')=='a^2 + b^3 + c^1'
  assert optimize_equation('x + y + z + z')=='x^1 + y^1 + z^2'
  assert optimize_equation('p + p + p + q')=='p^3 + q^1'
  assert optimize_equation('')==''
output: def optimize_equation(equation):
      if not equation:
          return ""
      
      term_dict = {}
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          count = int(count)
          if var in term_dict:
              term_dict[var] += count
          else:
              term_dict[var] = count
  
      new_equation = []
      for var, count in term_dict.items():
          new_equation.append(f"{var}^{count}")
      
      return ' + '.join(new_equation)