from collections import Counter
class Solution(object):
    def longestSubstring(self, s, k):
        if len(s)<k:
            return 0
        ctr=Counter(s)
        for c,v in ctr.items():
            if v<k:
                subs=s.split(c)
                return max(self.longestSubstring(sub,k) for sub in subs)
        return len(s)
s=Solution()
s1 = "weitong"
k = 2
print(s.longestSubstring(s1,k))