input: 
  def optimize_equation(equation: str) -> str:
      """Given an equation where each term is in the form "number + number + ... + number",
      optimize it by collapsing repeated terms into a single term raised to the appropriate power.
      >>> optimize_equation('x + x + y + y + y')
      'x^2 + y^3'
      >>> optimize_equation('a + a + a + b + b')
      'a^3 + b^2'
      """
  
output:     from collections import Counter
      
      terms = equation.split(' + ')
      term_counts = Counter(terms)
      
      optimized_terms = []
      for term, count in term_counts.items():
          if count > 1:
              optimized_terms.append(f"{term}^{count}")
          else:
              optimized_terms.append(term)
      
      return ' + '.join(optimized_terms)