input: Write a function to optimize an equation by combining like terms. The function should take a string representing an equation as input and return a new string representing the optimized equation. The input equation is given in the form of a sum of terms, where each term consists of a variable and its count, separated by spaces. If a variable appears multiple times, its counts should be combined into a single term with an exponent representing the total count.
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + a + b')=='a^3 + b'
  assert optimize_equation('z + z + z + z')=='z^4'
  assert optimize_equation('w + x + y')=='w + x + y'
  assert optimize_equation('a + b + c')=='a + b + c'
output: def optimize_equation(equation):
      terms = equation.split()
      counts = {}
      for term in terms:
          if term in counts:
              counts[term] += 1
          else:
              counts[term] = 1
      optimized_terms = []
      for term, count in counts.items():
          if count > 1:
              optimized_terms.append(f"{term}^{count}")
          else:
              optimized_terms.append(term)
      return ' + '.join(optimized_terms)