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 '?', you need to minimize the value of s by replacing all occurrences of '?' with lowercase English letters.
  
      Define cost(i) for an index i as the number of characters equal to s[i] that appear before it (in the range [0, i-1]). The value of the string is the sum of cost(i) over all indices i.
  
      Your task is to replace '?' in s to minimize the string value. If there are multiple solutions that yield the minimum value, return the lexicographically smallest one.
  
      Examples:
      >>> s = "???"
      abc
      >>> s = "a?a?"
      abac
  
      Constraints:
      1 <= s.length <= 10^5
      s[i] is either a lowercase English letter or '?'.
      """
output:     
      # Initialize the result list with the characters from 's'
      result = list(s)
      n = len(s)
  
      # Helper function to find the smallest lexicographical character not equal to prev_char or next_char
      def find_smallest_char(prev_char, next_char):
          for char in ascii_lowercase:
              if char != prev_char and char != next_char:
                  return char
          return 'a'  # fallback case, though we should always find a suitable char
  
      # Traverse the list and replace '?' with the appropriate character
      for i in range(n):
          if result[i] == '?':
              prev_char = result[i-1] if i > 0 else ''
              next_char = result[i+1] if i < n-1 else ''
              result[i] = find_smallest_char(prev_char, next_char)
  
      # Join the list to form the final string and return it
      return ''.join(result)
  