Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def check(num, s, left, right):

    if right - left <= 1:
        print(left)
        sys.exit()

    half = (left + right) // 2

    # print(half, left, right)

    for i in range(num - half):
        now_str = s[i]

        for j in range(i + half, num):
            if half >= num - j + 1:
                break

            if now_str == s[j]:
                i_ind, j_ind = i, j

                for k in range(half - 1):
                    i_ind += 1
                    j_ind += 1
                    if i_ind >= j or j_ind >= num:
                        break
                    if s[i_ind] != s[j_ind]:
                        break
                else:
                    check(num, s, half, right)
    check(num, s, left, half)

def main():
    num = int(input())
    s = list(input())

    left, right = 0, num

    check(num, s, left, right)




if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def check(num, s, left, right):

    if right - left <= 1:
        print(left)
        sys.exit()

    half = (left + right) // 2

    data_set = set()

    for i in range(num -2 * half  + 1):
        now_str = s[i:i + half]
        data_set.add(now_str)
        if s[i + half : i + 2 * half] in data_set:
            check(num, s, half, right)
    check(num, s, left, half)

def main():
    num = int(input())
    s = input()

    left, right = 0, num // 2 + 1

    check(num, s, left, right)




if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque

ans = 0

def check(ind, num, s, left, right):

    if right - left <= 1:
        global ans
        # print(left, right)
        ans = max(ans, left)
        return

    half = (left + right) // 2

    flg = 1

    for j in range(ind + half, num - half + 1):
        for k in range(half):
            if ind + k >= j or j + k >= num:
                break
            if s[ind + k] != s[j + k]:
                break
        else:
            # print(left, half, right, 'eee')
            check(ind, num, s, half, right)
            flg = 0
        # print(left, half, right)

    if flg:
        check(ind, num, s, left, half)

def main():
    global ans
    num = int(input())
    s = list(input())

    for i in range(num):
        if num - i <= ans:
            break
        left, right = ans, num // 2 + 1
        # print(left, right, 'yyy')
        check(i, num, s, left, right)
    print(ans)




if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def check(num, s, left, right):

    if right - left <= 1:
        print(left)
        sys.exit()

    half = (left + right) // 2

    data_set = set()

    for i in range(num -2 * half  + 1):
        now_str = s[i:i + half]
        data_set.add(now_str)
        if s[i + half : i + 2 * half] in data_set:
            check(num, s, half, right)
    check(num, s, left, half)

def main():
    num = int(input())
    s = input()

    left, right = 0, num // 2 + 1

    check(num, s, left, right)




if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def check(num, s, left, right):

    if right - left <= 1:
        print(left)
        sys.exit()

    half = (left + right) // 2

    # print(half, left, right)

    for i in range(num - half):
        now_str = s[i]

        for j in range(i + half, num):
            if half >= num - j + 1:
                break

            if now_str == s[j]:
                i_ind, j_ind = i, j

                for k in range(half - 1):
                    i_ind += 1
                    j_ind += 1
                    if i_ind >= j or j_ind >= num:
                        break
                    if s[i_ind] != s[j_ind]:
                        break
                else:
                    check(num, s, half, right)
    check(num, s, left, half)

def main():
    num = int(input())
    s = list(input())

    left, right = 0, num

    check(num, s, left, right)




if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def check(num, s, left, right):

    if right - left <= 1:
        print(left)
        sys.exit()

    half = (left + right) // 2

    data_set = set()

    for i in range(num -2 * half  + 1):
        now_str = s[i:i + half]
        data_set.add(now_str)
        if s[i + half : i + 2 * half] in data_set:
            check(num, s, half, right)
    check(num, s, left, half)

def main():
    num = int(input())
    s = input()

    left, right = 0, num // 2 + 1

    check(num, s, left, right)




if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def main():
    num = int(input())
    s = list(input())

    ans = 0
    for i in range(num):
        if ((num - i) // 2) + 2 <= ans:
            break
        now_str = s[i]
        for j in range(i + 1 + ans, num):
            if now_str == s[j]:
                i_ind, j_ind = i, j
                kari = 1

                if ans >= num - j:
                    break

                while 1:
                    i_ind += 1
                    j_ind += 1
                    if i_ind == j or j_ind >= num:
                        break
                    if s[i_ind] == s[j_ind]:
                        kari += 1
                    else:
                        break
                ans = max(ans, kari)

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def check(num, s, left, right):

    if right - left <= 1:
        print(left)
        sys.exit()

    half = (left + right) // 2

    data_set = set()

    for i in range(num -2 * half  + 1):
        now_str = s[i:i + half]
        data_set.add(now_str)
        if s[i + half : i + 2 * half] in data_set:
            check(num, s, half, right)
    check(num, s, left, half)

def main():
    num = int(input())
    s = input()

    left, right = 0, num // 2 + 1

    check(num, s, left, right)




if __name__ == '__main__':
    main()