input: from typing import List
  
  
  def optimize_equation(equation: str) -> str:
      """You are required to write a Python program to optimize an equation by reducing
      repeated variables. Given an equation in the format 'x + x + y + y + y', where each
      term is a variable followed by a space and a count, the function will return an
      optimized equation in the format 'x^2 + y^3'.
      >>> optimize_equation('x + x + y + y + y')
      'x^2 + y^3'
      >>> optimize_equation('a + a + a + b + b')
      'a^3 + b^2'
      """
output:     from collections import defaultdict
      
      terms = equation.split(' + ')
      count_dict = defaultdict(int)
      
      for term in terms:
          var, count = term.split()
          count_dict[var] += int(count)
      
      optimized_terms = [f"{var}^{count}" for var, count in count_dict.items()]
      return ' + '.join(optimized_terms)