input: 
  def optimize_equation(equation: str) -> str:
      variables = []
      for term in equation.split('+'):
          var, count = term.strip().split(' ')
          variables.append((var, int(count)))
  
      new_equation = ""
      for var, count in variables:
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]
  
  # Example:
  # >>> optimize_equation('x + x + y + y + y')
  # 'x^2 + y^3'
  
output:     variables_dict = {}
      for var, count in variables:
          if var in variables_dict:
              variables_dict[var] += count
          else:
              variables_dict[var] = count
  
      new_equation = ""
      for var, count in variables_dict.items():
          new_equation += (var + '^' + str(count)) + ' + '
      return new_equation[:-3]