• + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # Complete the 'alternate' function below.
    #
    # The function is expected to return an INTEGER.
    # The function accepts STRING s as parameter.
    #
    def consecutive_chars(s):
        for i in range(len(s) - 1):
            if s[i] == s[i + 1]:
                return 0
        return len(s)
        
    def alternate(s):
        # Write your code here
        tmp_list = list(set(s))
        if len(tmp_list) < 2:
            return 0
        tmp_list = sorted(tmp_list)
        length_list = []
        for i in range(len(tmp_list) - 1):
            for j in range(i+1, len(tmp_list)):
                new_s = [char for char in s if char == tmp_list[i] or char == tmp_list[j]]
                length_list.append(consecutive_chars(new_s))
        return max(length_list)
            
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        l = int(input().strip())
    
        s = input()
    
        result = alternate(s)
    
        fptr.write(str(result) + '\n')
    
        fptr.close()