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