Buggy python submission (verdict: Time Limit Exceeded):
class RollingHash:
    def __init__(self, s: str, base: int=1007, mod: int=10**9+7):
        self.s = s
        self.n = len(s)
        self.base = base
        self.mod = mod

        # preprocess
        self.hash_cum = [0] * (self.n + 1) # hash_cum[i] = (hash of s[:i])
        self.base_pow = [1] * (self.n + 1) # base_pow[i] = base ** i
        for i in range(self.n):
            self.hash_cum[i+1] = (self.hash_cum[i] * base + ord(s[i])) % mod
            self.base_pow[i+1] = (self.base_pow[i] * base) % mod

    def get_hash(self, l: int, r: int) -> int:
        hash_val = self.hash_cum[r] - self.hash_cum[l] * self.base_pow[r-l] % self.mod
        if hash_val < 0:
            hash_val += self.mod
        return hash_val


class RollingHashMulti:
    def __init__(self, s: str, base_list: list=[1007, 2009], mod_list: list=[10**9+7, 10**9+9]):
        self.n = len(base_list)
        self.base_list = base_list
        self.rh_list = [RollingHash(s, base_list[i], mod_list[i]) for i in range(self.n)]

    def get_hash(self, l: int, r: int) -> tuple:
        return tuple( self.rh_list[i].get_hash(l, r) for i in range(self.n) )




n = int(input())
s = input()

rh = RollingHashMulti(s)

def check(x):
    for i in range(n-2*x+1):
        for j in range(i+x, n-x+1):
            if rh.get_hash(i, i+x) == rh.get_hash(j, j+x):
                return True
    return False


lb = 0
ub = n // 2 + 1
while ub - lb > 1:
    mid = (ub + lb) // 2
    if check(mid):
        lb = mid
    else:
        ub = mid

print(lb)


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)

Buggy python submission (verdict: Runtime Error):
class RollingHash:
    def __init__(self, s: str, base: int=1007, mod: int=10**9+7):
        self.s = s
        self.n = len(s)
        self.base = base
        self.mod = mod

        # preprocess
        self.hash_cum = [0] * (self.n + 1) # hash_cum[i] = (hash of s[:i])
        self.base_pow = [1] * (self.n + 1) # base_pow[i] = base ** i
        for i in range(self.n):
            self.hash_cum[i+1] = (self.hash_cum[i] * base + ord(s[i])) % mod
            self.base_pow[i+1] = (self.base_pow[i] * base) % mod

    def get_hash(self, l: int, r: int) -> int:
        hash_val = self.hash_cum[r] - self.hash_cum[l] * self.base_pow[r-l] % self.mod
        if hash_val < 0:
            hash_val += self.mod
        return hash_val


class RollingHashMulti:
    def __init__(self, s: str, base_list: list=[1007, 2009], mod_list: list=[10**9+7, 10**9+9]):
        self.n = len(base_list)
        self.base_list = base_list
        self.rh_list = [RollingHash(s, base_list[i], mod_list[i]) for i in range(self.n)]

    def get_hash(self, l: int, r: int) -> tuple:
        return tuple( self.rh_list[i].get_hash(l, r) for i in range(self.n) )




n = int(input())
s = input()

rh = RollingHashMulti(s)

def check(x):
    for i in range(n-2*x+1):
        for j in range(i+x, n-x+i):
            if rh.get_hash(i, i+x) == rh.get_hash(j, j+x):
                return True
    return False


lb = 0
ub = n // 2 + 1
while ub - lb > 1:
    mid = (ub + lb) // 2
    if check(mid):
        lb = mid
    else:
        ub = mid

print(lb)


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)

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

def main():
    input = sys.stdin.readline
    
    n = int(input())
    s = input()

    ans = 0
    for i in range(1, n):
        cnt = 0
        for j in range(n-i):
            if s[i+j] == s[j]:
                cnt += 1
            else:
                if cnt >= i:
                    ans = max(ans, i)
                    break
                else:
                    ans = max(ans, cnt)
                    cnt = 0

        ans = max(ans, min(cnt, i))

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)

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

    ans = 0
    for i in range(1, n):
        cnt = 0
        for j in range(n-i):
            if s[i+j] == s[j]:
                cnt += 1
            else:
                if cnt >= i:
                    ans = max(ans, i)
                    break
                else:
                    ans = max(ans, cnt)
                    cnt = 0

        ans = max(ans, min(cnt, i))

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)

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

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            if cnt >= i:
                ans = max(ans, i)
                break
            else:
                ans = max(ans, cnt)
                cnt = 0

    ans = max(ans, min(cnt, i))

print(ans)


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)

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

    ans = 0
    for i in range(1, n):
        cnt = 0
        for j in range(n-i):
            if s[i+j] == s[j]:
                cnt += 1
            else:
                ans = max(ans, min(cnt, i))
                cnt = 0
        ans = max(ans, min(cnt, i))

    print(ans)

main()


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)

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

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)

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


    def check(l):
        if l == 0:
            return True
        for i in range(n-l*2+1):
            for j in range(i+l, n-l+1):
                cnt = 0
                for k in range(l):
                    if s[i+k] == s[j+k]:
                        cnt += 1
                    else:
                        break

                if cnt == l:
                    # print(l, i, j, cnt,)
                    return True

        return False


    lb = 0
    ub = n // 2 + 1
    # for i in range(ub+1):
    #     print(i, check(i))

    while ub - lb > 1:
        mid = (ub + lb) // 2
        if check(mid):
            lb = mid
        else:
            ub = mid

    print(lb)

main()


Fixed submission:
n = int(input())
s = input()

n += 1
s += "#"

ans = 0
for i in range(1, n):
    cnt = 0
    for j in range(n-i):
        if s[i+j] == s[j]:
            cnt += 1
        else:
            ans = max(ans, min(cnt, i))
            cnt = 0

print(ans)