Buggy python submission (verdict: Time Limit Exceeded):
def z_array(pattern, text):
    psize = len(pattern)
    tsize = len(text)
    str = pattern + '$' + text
    matchsize = 0
    for i in range(tsize-1):
        j = 0
        while (j <= psize - 1 and i+j <= tsize - 1 and str[j] == str[i+psize+1+j]):
            j += 1
        if(matchsize < j): matchsize = j
    return matchsize

def main(size, text):
    length = 0
    for i in range(size-1):
        z = z_array(text[i+1:size], text[:i+1])
        if(length < z): length = z
    return length

size = int(input())
text = input()
print(main(size, text))

Fixed submission:
def main(size, text):
    pattern = ""
    matchlen = 0

    for i in range(size):
        pattern += text[i]
        while (len(pattern) > 0 and len(pattern) <= len(text[i+1:])):
            if pattern in text[i+1:]:
                matchlen = max(matchlen, len(pattern))
                break
            else:
                pattern = pattern[1:]
    
    return matchlen

if __name__ == '__main__':
    N = int(input())
    S = input()
    print (main(N, S))

Buggy python submission (verdict: Time Limit Exceeded):
def z_array(pattern, text):
    str = pattern + '$' + text
    matchsize = 0
    for i in range(len(text)-1):
        j = 0
        while (i+1+j <= len(text) and str[j] == str[i+len(pattern)+1+j]):
            j += 1
        if(matchsize < j): matchsize = j
    return matchsize

def main(size, text):
    length = 0
    for i in range(size-1):
        z = z_array(text[i+1:size], text[:i+1])
        if(length < z): length = z
    return length

size = int(input())
text = input()
print(main(size, text))

Fixed submission:
def main(size, text):
    pattern = ""
    matchlen = 0

    for i in range(size):
        pattern += text[i]
        while (len(pattern) > 0 and len(pattern) <= len(text[i+1:])):
            if pattern in text[i+1:]:
                matchlen = max(matchlen, len(pattern))
                break
            else:
                pattern = pattern[1:]
    
    return matchlen

if __name__ == '__main__':
    N = int(input())
    S = input()
    print (main(N, S))

Buggy python submission (verdict: Time Limit Exceeded):
def z_array(pattern, text):
    str = pattern + '$' + text
    matchsize = 0
    for i in range(len(str)-1):
        j = 0
        while (i+1+j <= len(str)-1 and str[j] == str[i+1+j]):
            j += 1
        if(matchsize < j): matchsize = j
    return matchsize

def main(size, text):
    length = 0
    for i in range(size-1):
        z = z_array(text[i+1:size], text[:i+1])
        if(length < z):
            length = z
    return length

size = int(input())
text = input()
print(main(size, text))

Fixed submission:
def main(size, text):
    pattern = ""
    matchlen = 0

    for i in range(size):
        pattern += text[i]
        while (len(pattern) > 0 and len(pattern) <= len(text[i+1:])):
            if pattern in text[i+1:]:
                matchlen = max(matchlen, len(pattern))
                break
            else:
                pattern = pattern[1:]
    
    return matchlen

if __name__ == '__main__':
    N = int(input())
    S = input()
    print (main(N, S))

Buggy python submission (verdict: Time Limit Exceeded):
def z_array(pattern, text):
    str = pattern + '$' + text
    z = []
    z.append(0)
    for i in range(len(str)-1):
        j = 0
        z.append(0)
        while (i+1+j <= len(str)-1 and str[j] == str[i+1+j]):
            j += 1
            z[i+1] = j
    return z

def main(size, text):
    length = 0
    for i in range(size-1):
        z = z_array(text[i+1:size], text[:i+1])
        if(length < max(z)):
            length = max(z)
    return length

size = int(input())
text = input()
print(main(size, text))

Fixed submission:
def main(size, text):
    pattern = ""
    matchlen = 0

    for i in range(size):
        pattern += text[i]
        while (len(pattern) > 0 and len(pattern) <= len(text[i+1:])):
            if pattern in text[i+1:]:
                matchlen = max(matchlen, len(pattern))
                break
            else:
                pattern = pattern[1:]
    
    return matchlen

if __name__ == '__main__':
    N = int(input())
    S = input()
    print (main(N, S))