input: Write a function optimize_equation to optimize the given equation by combining like terms. The function takes a string as input representing the equation, where each term is composed of a variable and its count separated by spaces, and returns the optimized equation. The optimized equation should be in the form of var^count for each term, separated by ' + '.
  
  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 + a + b + b')=='a^3 + b^2'
  assert optimize_equation('z + z z')=='z^2 z'
  assert optimize_equation('')==''
  assert optimize_equation('p + q')=='p^1 + q^1'
output: def optimize_equation(equation):
      if not equation:
          return ''
      
      terms = equation.split('+')
      term_dict = {}
      
      for term in terms:
          var, count = term.strip().split(' ')
          count = int(count)
          if var in term_dict:
              term_dict[var] += count
          else:
              term_dict[var] = count
      
      optimized_terms = []
      for var, count in term_dict.items():
          optimized_terms.append(f"{var}^{count}")
      
      return ' + '.join(optimized_terms)