input: Write a Python function to replace all occurrences of '?' in a given string s with lowercase English letters such that the resulting string has the minimal possible value, defined as the sum of the number of preceding identical characters for each position, returning the lexicographically smallest result in case of ties.
output: def replace_question_marks(s: str) -> str:
      letters = 'abcdefghijklmnopqrstuvwxyz'
      s = list(s)
      n = len(s)
      
      for i in range(n):
          if s[i] == '?':
              for letter in letters:
                  if (i > 0 and s[i-1] == letter) or (i < n-1 and s[i+1] == letter):
                      continue
                  s[i] = letter
                  break
      
      return ''.join(s)