<jupyter_start><jupyter_text>Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters.For example, given s = "abcba" and k = 2, the longest substring with k distinct characters is "bcb".<jupyter_code>#brute force

def substring(string,k):
    longestString=""
    for i in range(len(string)):
        for j in range(i+1,len(string)+1):
            subs=string[i:j]
            if len(set(subs))<=k and len(longestString)<len(subs):
                longestString=subs
    return len(longestString)

string = input()
k=int(input())
substring(string,k)
def substring(s,k):
    
    if k==0:
        return 0
    
    bounds = (0,0)
    h={}
    max_length=0
    for i,char in enumerate(s):
        h[char]=i
        if len(h) <= k:
            new_lower_bound = bounds[0]
        else:
            key_to_pop = min(h , key=h.get)
            new_lower_bound = h.pop(key_to_pop)+1
            
        bounds = (new_lower_bound , bounds[1]+1)
        max_length = max(max_length,bounds[1] - bounds[0])
    
    return max_length
  
string = input()
k=int(input())
substring(string,k)
def findNumber(li1,li2):
    c=1
    for i in range(len(li1)):
        for j in range(len(li2)):
            su=li1[i]+li2[j]
            if c==1:
                if su not in li1 or su not in li2:
                    print(li1[i],li2[j])
                    c=0
            

n=int(input())
li1=[int(x) for x in input().split()]
m=int(input())
li2=[int(y) for y in input().split()]
findNumber(li1,li2)
# cook your dish here
def find(power,*li):
    
    
    count=0
    while power>0 and len(li)>0:
        m=min(li)
        if m<power:
            power=2*(power-m)
            i=li.index(m)
            li[i]=999999999
            count+=1
        else:
            power=0
    print(count)

t=int(input())
for _ in range(t):
    li=[int(x) for x in input().split()]
    N=li[0]
    Q=li[1]
    li2=[int(y) for y in input().split()]
    for _ in range(Q):
        power=int(input())
        find(power,li2)
        
def findall(li,n):
    firsthalf=0
    secondhalf=0
    half=n//2
    for j in range(len(li)):
        for i in range(0,half):
            lii=list(li[j])
            if lii[j]=='1':
                firsthalf+=1
        for jj in range(half,len(li)):
            lli=list(li[j])
            if lli[jj]=='1':
                secondhalf+=1
    pp=abs(firsthalf-secondhalf)
    if pp==0:
        print(pp)
        
    elif pp==1:
        print(pp)
        
    elif pp==2:
        print(pp)
        
    else:
        
    print(firsthalf,secondhalf)    
    
t=int(input())
for _ in range(t):
    n=int(input())
    li=[]
    for _ in range(n):
        st=input()
        li.append(st)
        
    findall(li,n)
abs(-8)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13975817923186346, 'fraction_numerical': 0.022048364153627313, 'mean_word_length': 1.8851282051282052, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '27472', 'license': 'Apache-2.0', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1010, 'n_words': 231, 'path': 'Daily_Coding_Problem#13.ipynb', 'repo_name': 'priyanshu-coder/Coding-Practise', 'size': '2812'}