input: Write a Python function that takes a string `s` where each character is either a lowercase English letter or a question mark '?'. The function should replace all occurrences of '?' with lowercase English letters such that the cost value of the string is minimized. The cost value is defined for each character as the number of times that character has appeared before it in the string. If multiple strings result in the minimal cost, return the lexicographically smallest one.
  
  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 some characters are '?' which can be replaced by any lowercase English letter, 
      write a function to replace each '?' in such a way that the cost value of the string is minimized. 
      The cost value for a character at index i is the count of that character before index i.
      
      For example, for the string t = "aab":
      
      cost(0) = 0
      cost(1) = 1
      cost(2) = 0
     
      The objective is to replace '?' in 's' with characters to minimize the total cost and to return 
      the lexicographically smallest possible string if there are multiple solutions.
      
      Examples:
      >>> s = "???"
      abc
      >>> s = "a?a?"
      abac
  
      Constraints:
      1 <= s.length <= 10^5
      s[i] is either a lowercase English letter or '?'.
      """
output: def minimize_string_value(s: str) -> str:
      count = Counter(s)
      alphabet = sorted(list(ascii_lowercase))
      heap = [(count[letter], letter) for letter in alphabet]
      heapify(heap)
  
      result = []
      for char in s:
          if char == '?':
              min_occurrence, min_char = heap[0]
              result.append(min_char)
              heapreplace(heap, (min_occurrence + 1, min_char))
          else:
              result.append(char)
              idx = alphabet.index(char)
              heap[int(idx)] = (heap[int(idx)][0] + 1, char)
              heapify(heap)
      return ''.join(result)