input: def optimize_equation(equation: str) -> str:
      """ Optimize an equation by combining like terms.
      >>> optimize_equation('x + x + y + y + y')
      'x^2 + y^3'
      >>> optimize_equation('a + a + b')
      'a^2 + b^1'
      """
output:     terms = {}
      for term in equation.split(' + '):
          if term in terms:
              terms[term] += 1
          else:
              terms[term] = 1
      
      optimized_terms = [f"{term}^{count}" if count > 1 else term for term, count in terms.items()]
      return ' + '.join(optimized_terms)