Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    
    def lcs(x,y):
        lx,ly = len(x),len(y)
        dp = [[0 for _ in range(ly+1)] for _ in range(lx+1)]
        for i in range(lx):
            for j in range(ly):
                if x[i] == y[j]:
                    p = 1
                else:
                    p = 0
                dp[i+1][j+1] = max(dp[i][j]+p,dp[i][j+1],dp[i+1][j])
        return dp[-1][-1]
    
    print(max(lcs(s[:i],s[i:]) for i in range(N)))
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    a,i,j = 0,0,1
    
    while j < N:
        if s[i:j] in s[j:]:
            a = max(a,j-i)
            j += 1
        else:
            i += 1
        if i == j:
            i += 1
            j += 2
            
    print(a)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
import numpy as np

def main():
    N = int(input())
    s = input()
    dp = np.zeros((N+1,N+1),dtype=int)
    for i in range(N):
        for j in range(i+1,N):
            if s[i] == s[j]:
                dp[i+1][j+1] = min(dp[i][j]+1,j-i)

    print(dp.max())

if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    a,i,j = 0,0,1
    
    while j < N:
        if s[i:j] in s[j:]:
            a = max(a,j-i)
            j += 1
        else:
            i += 1
        if i == j:
            i += 1
            j += 2
            
    print(a)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline
import numpy as np

def main():
    N = int(input())
    s = input()
    dp = np.zeros((N+1,N+1),dtype=int)
    for i in range(N):
        for j in range(1,N):
            if s[i] == s[j]:
                dp[i+1][j+1] = min(dp[i][j]+1,j-i)
    
    print(np.max(dp))

if __name__ == "__main__":
    main()

Fixed submission:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    a,i,j = 0,0,1
    
    while j < N:
        if s[i:j] in s[j:]:
            a = max(a,j-i)
            j += 1
        else:
            i += 1
        if i == j:
            i += 1
            j += 2
            
    print(a)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
    for i in range(N):
        for j in range(N):
            if s[i] == s[j]:
                dp[i+1][j+1] = dp[i][j]+1
    
    ans = 0
    for i in range(N+1):
        for j in range(i+1,N+1):
            ans = max(ans,min(dp[i][j],j-i))
    
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    a,i,j = 0,0,1
    
    while j < N:
        if s[i:j] in s[j:]:
            a = max(a,j-i)
            j += 1
        else:
            i += 1
        if i == j:
            i += 1
            j += 2
            
    print(a)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    S = str(input())

    def z_algo(S):
        N = len(S)
        A = [0]*N
        i = 1; j = 0
        A[0] = l = len(S)
        while i < l:
            while i+j < l and S[j] == S[i+j]:
                j += 1
            if not j:
                i += 1
                continue
            A[i] = j
            k = 1
            while l-i > k < j - A[k]:
                A[i+k] = A[k]
                k += 1
            i += k; j -= k
        return A
        
    ans = 0
    for i in range(N-1):
        z = z_algo(S[i:])
        ans = max(ans,max(z[-((N-i)//2):]))
        
    print(ans)
    
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#input = sys.stdin.buffer.readline

def main():
    N = int(input())
    s = input()
    a,i,j = 0,0,1
    
    while j < N:
        if s[i:j] in s[j:]:
            a = max(a,j-i)
            j += 1
        else:
            i += 1
        if i == j:
            i += 1
            j += 2
            
    print(a)

if __name__ == "__main__":
    main()