input: from typing import List
  from collections import Counter
  from heapq import heapify, heapreplace
  from string import ascii_lowercase
  
  def minimize_string_value(s: str) -> str:
      """
      Given a string s where each character is either a lowercase English letter or '?', replace all '?' with lowercase English letters to minimize the string's value.
  
      For a string t of length m with only lowercase English letters, define cost(i) for any index i as the count of characters identical to t[i] that appear before it in the substring [0, i - 1].
  
      The value of t is the sum of cost(i) for all indices i.
  
      For instance, for t = "abcd":
      
      cost(0) = 0
      cost(1) = 0
      cost(2) = 0
      cost(3) = 0
      Thus, the value of "abcd" is 0 + 0 + 0 + 0 = 0.
  
      The task is to replace all '?' in s with lowercase letters to minimize the string's value and return the lexicographically smallest string possible.
  
      Examples:
      >>> s = "???"
      abc
      >>> s = "a?a?"
      abca
  
      Constraints:
      1 <= s.length <= 100000
      s[i] is either a lowercase English letter or '?'.
      """
output:     
      if not s:
          return s
      
      # Count the frequency of each character not '?'
      freq = Counter(c for c in s if c != '?')
      
      # Write a min-heap of (count, char)
      heap = [(freq[c], c) for c in ascii_lowercase]
      heapify(heap)
      
      out = []
      for i, char in enumerate(s):
          if char == '?':
              # Find the least frequent character that should replace '?'
              min_freq, min_char = heapreplace(heap, (freq[min_char]+1, min_char)) if heap else (0, 'a')
              out.append(min_char)
              freq[min_char] += 1
              heapreplace(heap, (freq[min_char], min_char))
          else:
              out.append(char)
  
      return ''.join(out)
  