Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve():
    N = int(input())
    S = input()
    sdict = dict()
    lens = len(S)
    for i in range(lens): sdict[i] = S[i]
    
    DP = [[0 for j in range(lens)] for i in range(lens - 1)]
    maxlength = 0
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if sdict[i] == sdict[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1
                maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    N = int(input())
    S = input()
    lens = len(S)
    alp = ["a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",\
        "v","w","x","y","z"]
    
    DP = [[0 for j in range(lens)] for i in range(lens)]
    DP[lens - 2][lens - 1] = (1 if S[lens-2] == S[lens - 1] else 0)
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if S[i] == S[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1

    maxlength = 0
    for i in range(lens):
        for j in range(i+1, lens):
            maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve():
    N = int(input())
    S = input()
    lens = len(S)
    alp = ["a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",\
        "v","w","x","y","z"]
    
    DP = [[0 for j in range(lens)] for i in range(lens)]
    DP[lens - 2][lens - 1] = (1 if S[lens-2] == S[lens - 1] else 0)
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if S[i] == S[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1

    maxlength = 0
    for i in range(lens):
        for j in range(i+1, lens):
            maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    N = int(input())
    S = input()
    lens = len(S)
    alp = ["a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",\
        "v","w","x","y","z"]
    
    DP = [[0 for j in range(lens)] for i in range(lens)]
    DP[lens - 2][lens - 1] = (1 if S[lens-2] == S[lens - 1] else 0)
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if S[i] == S[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1

    maxlength = 0
    for i in range(lens):
        for j in range(i+1, lens):
            maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve():
    N = int(input())
    S = input()
    words = dict()
    longest = 0
    for i in range(N-1):
        if (N - i) // 2 < longest: break
        else:
            current = S[i]
            if current in words: longest = max(longest, 1)
            else: words[current] = i
            for j in range(1, N - i):
                current += S[i + j]
                if current in words:
                    if words[current] + j + 1 <= i: longest = max(longest, j + 1)
                else: words[current] = i
    if S[N-1] in words: longest = max(longest, 1)

    #print(words)

    print(longest)

    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    N = int(input())
    S = input()
    lens = len(S)
    alp = ["a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",\
        "v","w","x","y","z"]
    
    DP = [[0 for j in range(lens)] for i in range(lens)]
    DP[lens - 2][lens - 1] = (1 if S[lens-2] == S[lens - 1] else 0)
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if S[i] == S[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1

    maxlength = 0
    for i in range(lens):
        for j in range(i+1, lens):
            maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

if __name__ == "__main__":
    solve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

def solve():
    N = int(input())
    S = input()
    words = dict()
    longest = 0
    for i in range(N-1):
        current = S[i]
        if current in words: longest = max(longest, 1)
        else: words[current] = i
        for j in range(1, N - i):
            current += S[i + j]
            if current in words:
                if words[current] + j + 1 <= i: longest = max(longest, j + 1)
            else: words[current] = i
    if S[N-1] in words: longest = max(longest, 1)

    #print(words)

    print(longest)

    return 0

if __name__ == "__main__":
    solve()

Fixed submission:
import sys

def solve():
    N = int(input())
    S = input()
    lens = len(S)
    alp = ["a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",\
        "v","w","x","y","z"]
    
    DP = [[0 for j in range(lens)] for i in range(lens)]
    DP[lens - 2][lens - 1] = (1 if S[lens-2] == S[lens - 1] else 0)
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if S[i] == S[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1

    maxlength = 0
    for i in range(lens):
        for j in range(i+1, lens):
            maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

if __name__ == "__main__":
    solve()