input: Write a function to optimize an equation by converting it into a form where each term is represented by a variable raised to its respective count, separated by '+'. Return the optimized equation as a string. If the input string is empty, return the string '0'.
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + a + a')=='a^4'
  assert optimize_equation('p + q')=='p^1 + q^1'
  assert optimize_equation('')=='0'
  assert optimize_equation('z')=='z^1'
output: def optimize_equation(s):
      if not s:
          return '0'
      from collections import Counter
      terms = s.split(' + ')
      counts = Counter(terms)
      result = ' + '.join(f'{term}^{count}' if count > 1 else f'{term}^1' for term, count in counts.items())
      return result