Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
while l<=r:
    m = (l + r) // 2
#    print("m = ", m)
    for i in range(n-m) :
        # 切り取る
        sub = S[i :i + m]
#        print("sub=", sub)
#        print("i=", i)
        fl = False
        Se = set()
        for j in range(i+m,n - m + 1) :
            sub2 = S[j :j + m]
            Se.add(sub2)
#            print("j=", j, Se)
        if sub in Se:
            fl = True
            l = m+1
            ans = l-1
#            print(l-1,"にて共通部分有")
            break
    else:
        r = m-1
#        print(r+1,"にて共通部分無")
print(ans)


Fixed submission:
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
def check(m):
    Se = set()
    for i in range(n-2*m+1):
        Se.add(S[i:i+m])
        if S[i+m:i+2*m] in Se:
            return True
    return False

while l<=r:
    m = (l + r) // 2
 #   print("m = ", m)
    if check(m):
        fl = True
        l = m+1
        ans = l-1
 #       print(l-1,"にて共通部分有")
    else:
        r = m-1
 #       print(r+1,"にて共通部分無")
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
while l<=r:
    m = (l + r) // 2
#    print("m = ", m)
    for i in range(n-m) :
        # 切り取る
        sub = S[i :i + m]
#        print("sub=", sub)
#        print("i=", i)
        fl = False
        Se = set()
        for j in range(i+m,n - m + 1) :
            sub2 = S[j :j + m]
            Se.add(sub2)
#            print("j=", j, Se)
        if sub in Se:
            fl = True
            l = m+1
            ans = l-1
#            print(l-1,"にて共通部分有")
            break
    else:
        r = m-1
#        print(r+1,"にて共通部分無")
print(ans)

Fixed submission:
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
def check(m):
    Se = set()
    for i in range(n-2*m+1):
        Se.add(S[i:i+m])
        if S[i+m:i+2*m] in Se:
            return True
    return False

while l<=r:
    m = (l + r) // 2
 #   print("m = ", m)
    if check(m):
        fl = True
        l = m+1
        ans = l-1
 #       print(l-1,"にて共通部分有")
    else:
        r = m-1
 #       print(r+1,"にて共通部分無")
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
while l<=r:
    m = (l + r) // 2
#    print("m = ", m)
    for i in range(n-m) :
        # 切り取る
        sub = S[i :i + m]
#        print("sub=", sub)
#        print("i=", i)
        fl = False
        for j in range(i + m, n - m + 1) :
#            print("j=", j)
            sub2 = S[j :j + m]
            if sub == sub2 : #sub==sub2となり共通する部分がある場合
                fl = True
                break
        if fl:
            l = m+1
            ans = l-1
#            print(l-1,"にて共通部分有")
            break
    else:
        r = m-1
#        print(r+1,"にて共通部分無")
print(ans)

Fixed submission:
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
def check(m):
    Se = set()
    for i in range(n-2*m+1):
        Se.add(S[i:i+m])
        if S[i+m:i+2*m] in Se:
            return True
    return False

while l<=r:
    m = (l + r) // 2
 #   print("m = ", m)
    if check(m):
        fl = True
        l = m+1
        ans = l-1
 #       print(l-1,"にて共通部分有")
    else:
        r = m-1
 #       print(r+1,"にて共通部分無")
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
while l<=r:
    m = (l + r) // 2
#    print("m = ", m)
    for i in range(n-m) :
        # 切り取る
        sub = S[i :i + m]
#        print("sub=", sub)
#        print("i=", i)
        fl = False
        for j in range(i + m, n - m + 1) :
#            print("j=", j)
            sub2 = S[j :j + m]
            if sub == sub2 : #sub==sub2となり共通する部分がある場合
                fl = True
                break
        if fl:
            l = m+1
            ans = l-1
#            print(l-1,"にて共通部分有")
            break
    else:
        r = m-1
#        print(r+1,"にて共通部分無")
print(ans)

Fixed submission:
n = int(input())
S = input()
m = n//2
l,r = 0,n-1
ans = 0
def check(m):
    Se = set()
    for i in range(n-2*m+1):
        Se.add(S[i:i+m])
        if S[i+m:i+2*m] in Se:
            return True
    return False

while l<=r:
    m = (l + r) // 2
 #   print("m = ", m)
    if check(m):
        fl = True
        l = m+1
        ans = l-1
 #       print(l-1,"にて共通部分有")
    else:
        r = m-1
 #       print(r+1,"にて共通部分無")
print(ans)