input: from collections import Counter
  
  def maximum_length_substring(s: str) -> int:
      """
      Given a string s, return the maximum length of a 
      substring such that it contains at most two occurrences of each character.
  
      Examples:
      >>> s = "bcbbbcba"
      4
      >>> s = "aaaa"
      2
  
      Constraints:
      2 <= s.length <= 100
      s consists only of lowercase English letters.
      """
  
output: 
      char_count = Counter()
      max_length = 0
      start = 0
      
      for end in range(len(s)):
          char_count[s[end]] += 1
          
          while char_count[s[end]] > 2:
              char_count[s[start]] -= 1
              start += 1
          
          max_length = max(max_length, end - start + 1)
      
      return max_length
  