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