Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()
    dp = [[0 for i in range(n+1)] for j in range(n+1)]
    
    for i in range(n-1,-1,-1):#後ろから
        for j in range(i-1,-1,-1):
            if s[i]!=s[j]:
              	dp[i][j] = 0#continueではない
        	    
            else:
              	dp[i][j] = dp[i+1][j+1] +1
              	"""
              	これでは結局ループしている
                cnt = 0
                for k in range(min(n-j,j-i)):
                    if s[i+k] ==s[j+k]:
                        cnt += 1
                    else:
                        break
                dp[i][j] = cnt
             	"""
    mx = 0
    #print(dp)
    for i in range(n):
      	for j in range(i):###
        	mx = max(mx,min(i-j,dp[i][j]))###
    print(mx)

if __name__ =='__main__':main()
            
            
            


Fixed submission:
def main():
    n = int(input())
    s = input()
    dp = [[0 for i in range(n+1)] for j in range(n+1)]
    
    from itertools import product
    for i,j in product(reversed(range(n)),repeat=2):###for を置き換え
        if j>i:
            continue
        if s[i]!=s[j]:
            dp[i][j] = 0 #continueではない	    
        else:
           	dp[i][j] = dp[i+1][j+1] +1
           	"""
            これでは結局ループしている
            cnt = 0
            for k in range(min(n-j,j-i)):
                if s[i+k] ==s[j+k]:
                    cnt += 1
                else:
                    break
            dp[i][j] = cnt
            """
    mx = 0
    #print(dp)
    for i in range(n):
      	for j in range(i):###
        	mx = max(mx,min(i-j,dp[i][j]))###i-jで抑える
    print(mx)

if __name__ =='__main__':main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    n = int(input())
    s = input()
    dp = [[0 for i in range(n)] for j in range(n)]
    
    for i in range(n):
        for j in range(i,n):
            if s[i]!=s[j]:
                continue
            else:
                cnt = 0
                for k in range(min(n-j,j-i)):
                    if s[i+k] ==s[j+k]:
                        cnt += 1
                    else:
                        break
                dp[i][j] = cnt 
    mx = 0
    for i in range(n):
        mx = max(mx,max(dp[i]))
    print(mx)

if __name__ =='__main__':main()
            
            
            


Fixed submission:
def main():
    n = int(input())
    s = input()
    dp = [[0 for i in range(n+1)] for j in range(n+1)]
    
    from itertools import product
    for i,j in product(reversed(range(n)),repeat=2):###for を置き換え
        if j>i:
            continue
        if s[i]!=s[j]:
            dp[i][j] = 0 #continueではない	    
        else:
           	dp[i][j] = dp[i+1][j+1] +1
           	"""
            これでは結局ループしている
            cnt = 0
            for k in range(min(n-j,j-i)):
                if s[i+k] ==s[j+k]:
                    cnt += 1
                else:
                    break
            dp[i][j] = cnt
            """
    mx = 0
    #print(dp)
    for i in range(n):
      	for j in range(i):###
        	mx = max(mx,min(i-j,dp[i][j]))###i-jで抑える
    print(mx)

if __name__ =='__main__':main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

dp = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    for j in range(i,n):
        if s[i] !=s[j]:
            continue
        else:
            cnt = 0
            for k in range(min(n-j,j-i)):
                if s[i+k] ==s[j+k]:
                    cnt += 1
                else:
                    break
            dp[i][j] = cnt 
mx = 0
for i in range(n):
    mx = max(mx,max(dp[i]))

print(mx)
        

Fixed submission:
def main():
    n = int(input())
    s = input()
    dp = [[0 for i in range(n+1)] for j in range(n+1)]
    
    from itertools import product
    for i,j in product(reversed(range(n)),repeat=2):###for を置き換え
        if j>i:
            continue
        if s[i]!=s[j]:
            dp[i][j] = 0 #continueではない	    
        else:
           	dp[i][j] = dp[i+1][j+1] +1
           	"""
            これでは結局ループしている
            cnt = 0
            for k in range(min(n-j,j-i)):
                if s[i+k] ==s[j+k]:
                    cnt += 1
                else:
                    break
            dp[i][j] = cnt
            """
    mx = 0
    #print(dp)
    for i in range(n):
      	for j in range(i):###
        	mx = max(mx,min(i-j,dp[i][j]))###i-jで抑える
    print(mx)

if __name__ =='__main__':main()