input: Write a function to optimize an equation by combining the same variables with their respective counts. If the input equation is empty, return an empty string.
  assert optimize_equation('x + x + y + y + y')=='x^2 + y^3'
  assert optimize_equation('a + a + a + b + c + c')=='a^3 + b^1 + c^2'
  assert optimize_equation('')==''
  assert optimize_equation('d + d + d + d + d')=='d^5'
  assert optimize_equation('p + q + r + s')=='p^1 + q^1 + r^1 + s^1'
output: def optimize_equation(equation):
      if not equation:
          return ''
      terms = equation.split(' + ')
      counts = {}
      for term in terms:
          if term in counts:
              counts[term] += 1
          else:
              counts[term] = 1
      result = ' + '.join(f'{term}^{counts[term]}' if counts[term] > 1 else term for term in counts)
      return result