input: Write a function to optimize an equation by converting it into a form where each variable is raised to the power of its count in the original equation. If the given equation is empty then return an empty string.
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + b + b + b + b')=='a^2 + b^4'
  assert optimize_equation('')==''
  assert optimize_equation('z + z + z + z + z + z + z')=='z^7'
  assert optimize_equation('p + q')=='p^1 + q^1'
output: def optimize_equation(equation):
      if not equation:
          return ''
      terms = equation.split(' + ')
      count_dict = {}
      for term in terms:
          if term in count_dict:
              count_dict[term] += 1
          else:
              count_dict[term] = 1
      result = []
      for term, count in count_dict.items():
          if count > 1:
              result.append(f"{term}^{count}")
          else:
              result.append(f"{term}^1")
      return ' + '.join(result)