input: Write a function to optimize an equation where terms are represented by a variable and its count in the format "variable count". The function should return a string where each variable is raised to the power of its count and terms are separated by ' + '. If the input is 'x + x + y + y + y', the output should be 'x^2 + y^3'.
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + a + b + b')=='a^3 + b^2'
  assert optimize_equation('z + z + z + z + z')=='z^5'
  assert optimize_equation('')==''
  assert optimize_equation('c + c + c + d + d + d + d')=='c^3 + d^4'
output: def optimize_equation(equation):
      from collections import Counter
      terms = equation.split(' + ')
      count = Counter(terms)
      result = ' + '.join(f'{var}^{cnt}' if cnt > 1 else var for var, cnt in count.items())
      return result