input: Write a function to optimize an equation by grouping identical variables and representing their counts in a power format. Return the optimized equation as a string.
  
  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') == 'a^3 + b^1'
  assert optimize_equation('p + p + q + q + q + q') == 'p^2 + q^4'
  assert optimize_equation('x + y') == 'x^1 + y^1'
  assert optimize_equation('') == ''
output: def optimize_equation(equation):
      if not equation:
          return ""
      variables = {}
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          count = int(count)
          if var in variables:
              variables[var] += count
          else:
              variables[var] = count
  
      new_equation = ""
      for var, count in variables.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]