input: Write a function to optimize an equation by combining like terms. The function should take a string equation as an input, which consists of terms separated by '+'. Each term is a variable followed by a space and a count. The function should return the optimized equation as a string where each variable is raised to the power of its count and terms are combined.
  
  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]
  
  equation = 'x + x + y + y + y'
  assert optimize_equation(equation) == 'x^2 + y^3'
  
  equation = 'a + b + a + c + b + b'
  assert optimize_equation(equation) == 'a^2 + b^3 + c^1'
  
  equation = 'p + p + p + q + q'
  assert optimize_equation(equation) == 'p^3 + q^2'
  
  equation = 'x + y + z'
  assert optimize_equation(equation) == 'x^1 + y^1 + z^1'
  
  equation = 'm + m + m + m + m'
  assert optimize_equation(equation) == 'm^5'
output: def optimize_equation(equation):
      from collections import defaultdict
      variables = defaultdict(int)
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          variables[var] += int(count)
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]