input: from typing import List
  from collections import Counter
  from functools import cache
  def highest_total_damage(spell_power: List[int]) -> int:
      """
      A magician possesses various spells.
  
      Given an array spell_power, where each element signifies the damage of a spell. Different spells may have the same damage.
  
      It is known that if a magician chooses to cast a spell with damage spell_power[i], they cannot subsequently cast any spell with damage spell_power[i] - 2, spell_power[i] - 1, spell_power[i] + 1, or spell_power[i] + 2.
  
      Each spell can be used only once.
  
      Return the maximum achievable total damage that a magician can deal.
  
      Examples:
      >>> spell_power = [1,1,3,4]
      6
      >>> spell_power = [7,1,6,6]
      13
  
      Constraints:
      1 <= spell_power.length <= 10^5
      1 <= spell_power[i] <= 10^9
      """
output:     spell_counter = Counter(spell_power)
      unique_spells = sorted(spell_counter.keys())
  
      @cache
      def dp(index:int) -> int:
          if index < 0:
              return 0
          skip_current = dp(index - 1)
          use_current = unique_spells[index] * spell_counter[unique_spells[index]]
          if index > 0 and unique_spells[index] == unique_spells[index - 1] + 1:
              use_current += dp(index - 2)
          else:
              use_current += dp(index - 1)
          return max(skip_current, use_current)
  
      return dp(len(unique_spells) - 1)