def rabin_karp_match(text, pat,d,q):
    n = len(text)
    m = len(pat)
    p = 0  
    t = 0  
    h = 1
    matches = []
    for i in range(m - 1):
        h = (h * d) % q
    for i in range(m):
        p = (d * p + ord(pat[i])-ord('a')) % q 
        t = (d * t + ord(text[i])-ord('a')) % q
    for i in range(n - m + 1):
        if p == t:
            if text[i:i + m] == pat:
                matches.append(i)
            else:
                print("Spurious hits at location ", i)
        if i < n - m:
            t = (d * (t - (ord(text[i])-ord('a')) * h) + ord(text[i + m])-ord('a')) % q

            if t < 0:
                t += q

    return matches
text = """The world is changing exponentially and so are we. 
Cambridge Institute of Technology have always been in the forefront 
among providers of quality education in Karnataka and leaders in 
transforming more than 15000 lives. Meeting the fast pace of 
global change, CIT is accelerating the transformation within 
the institution to make a better innovative world. 
"""
pattern = "the"
result = rabin_karp_match(text, pattern,26,1000000007)
print(f"Pattern found at indices: {result}")
