input: from typing import List
  
  def optimize_equation(equation: str) -> str:
      """ Given an equation in the form of terms separated by ' + ', where each term is 
      a variable name followed by a space and a count, optimize the equation by removing
      redundant terms and summing their counts. 
      
      >>> optimize_equation('x + x + y + y + y')
      'x^2 + y^3'
      >>> optimize_equation('a + b + b + a + b + c + c')
      'a^2 + b^3 + c^2'
      """
output:     terms = equation.split(' + ')
      term_count = {}
      
      for term in terms:
          var, count = term.split()
          count = int(count)
          if var in term_count:
              term_count[var] += count
          else:
              term_count[var] = count
      
      optimized_terms = [f"{var}^{count}" if count > 1 else var for var, count in term_count.items()]
      return ' + '.join(sorted(optimized_terms))