input: Write a function to optimize an equation by combining like terms. The function should take a string representing the equation with terms separated by '+', where each term is in the form 'variable count', and return a string with combined terms in the form 'variable^count'. If the input equation is empty, return an empty string.
  
  def optimize_equation(equation):
      if not equation:
          return ""
      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 + b + a') == 'a^2 + b^1'
  assert optimize_equation('c + c + c + d') == 'c^3 + d^1'
  assert optimize_equation('') == ''
  assert optimize_equation('m') == 'm^1'
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 += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]