input: Write a function to optimize an equation. The function should take a string representing the equation, reduce the repeated terms, and return a string with the optimized equation. If no optimization is possible, return the original equation.
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + b + b + c + c + c')=='a^1 + b^2 + c^3'
  assert optimize_equation('d + d + d + d')=='d^4'
  assert optimize_equation('e + e')=='e^2'
  assert optimize_equation('f + g')=='f + g'
output: def optimize_equation(equation):
      from collections import Counter
      terms = equation.split(' + ')
      term_counts = Counter(terms)
      optimized_terms = [f"{term}^{count}" if count > 1 else term for term, count in term_counts.items()]
      return ' + '.join(optimized_terms)