Buggy python submission (verdict: Time Limit Exceeded):
class RollingHash:
    def __init__(self,text):
        self.mod=10**17+3
        self.p=10007
        self.n=len(text)
        self.table=[0]*(self.n+1)
        for i in range(self.n):
            self.table[i+1]=(self.table[i]*self.p+ord(text[i]))%self.mod
        self.pp=[1]*(self.n+1)
        for i in range(self.n):
            self.pp[i+1]=(self.pp[i]*self.p)%self.mod
    def hash(self, i, j):
        return (self.table[j]-self.table[i]*self.pp[j-i])%self.mod
    def lcp(self, i, j):
        l,r=0,min(self.n-i,self.n-j)+1
        while r-l>1:
            m=(l+r)//2
            if self.hash(i,i+m)==self.hash(j,j+m):
                l=m
            else:
                r=m
        return l

n=int(input())
hs=RollingHash(input())
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans=max(ans,min(j-i,hs.lcp(i,j)))
print(ans)

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
class RollingHash:
    def __init__(self,text):
        self.mod=10**17+3
        self.p=10007
        self.n=len(text)
        self.table=[0]*(self.n+1)
        for i in range(self.n):
            self.table[i+1]=(self.table[i]*self.p+ord(text[i]))%self.mod
        self.pp=[1]*(self.n+1)
        for i in range(self.n):
            self.pp[i+1]=(self.pp[i]*self.p)%self.mod
    def hash(self, i, j):
        return (self.table[j]-self.table[i]*self.pp[j-i])%self.mod
    def lcp(self, i, j):
        l,r=0,min(self.n-i,self.n-j)
        while r-l>0:
            m=(l+r)//2+1
            if self.hash(i,i+m)==self.hash(j,j+m):
                l=m
            else:
                r=m-1
        return l

n=int(input())
hs=RollingHash(input())
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans=max(ans,min(j-i,hs.lcp(i,j)))
print(ans)

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
class RollingHash:
    def __init__(self,text):
        self.mod=10**17+3
        self.p=10007
        self.n=len(text)
        self.table=[0]*(self.n+1)
        for i in range(self.n):
            self.table[i+1]=(self.table[i]*self.p+ord(text[i]))%self.mod
        self.pp=[1]*(self.n+1)
        for i in range(self.n):
            self.pp[i+1]=(self.pp[i]*self.p)%self.mod
    def hash(self, i, j):
        return (self.table[j]-self.table[i]*self.pp[j-i])%self.mod
    def lcp(self, i, j):
        l,r=0,min(self.n-i,self.n-j)
        while r-l>0:
            m=(l+r)//2+1
            if self.hash(i,i+m)==self.hash(j,j+m):
                l=m
            else:
                r=m-1
        return l

n=int(input())
hs=RollingHash(input())
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans=max(ans,min(j-i,hs.lcp(i,j)))
print(ans)

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
dp=[[0]*n for _ in range(n)]
ans=0
for i in range(n-1,-1,-1):
    for j in range(n-1,i,-1):
        if s[i]==s[j]:
            dp[i][j]=dp[i+1][j+1]+(i+1+dp[i+1][j+1]!=j+1) if j<n-1 else 1
    ans=max(ans,max(dp[i]))
print(ans)

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    list=[]
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in list:
            if t in s[:i]:
                flg=True
                break
        else:
            list.append(t)
    if flg:
        l=m
    else:
        r=m-1
print(l)

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    list=[]
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in list:
            if t in s[s.index(t)+m:]:
                flg=True
                break
        else:
            list.append(t)
    if flg:
        l=m
    else:
        r=m-1
print(l)

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
def sol():
    n=int(input())
    s=input()
    ans=0
    for i in range(n):
        if i<n-1:
            if s[i]==s[i+1]:
                ans=max(ans,1)
        for j in range(i+2,n):
            if s[i]==s[j] and j-i>1:
                ii=i
                jj=j
                if j<n-1:
                    while s[ii+1]==s[jj+1]:
                        ii+=1
                        jj+=1
                        if ii==j-1 or jj==n-1:
                            break
                    ans=max(ans,ii-i+1)
    return ans
print(sol())

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=0
for i in range(n):
    if i<n-1:
        if s[i]==s[i+1]:
            ans=max(ans,1)
    for j in range(i+2,n):
        if s[i]==s[j] and j-i>1:
            ii=i
            jj=j
            if j<n-1:
                while s[ii+1]==s[jj+1]:
                    ii+=1
                    jj+=1
                    if ii==j-1 or jj==n-1:
                        break
                ans=max(ans,ii-i+1)
print(ans)

Fixed submission:
n=int(input())
s=input()
l=0
r=n//2
while r-l>=1:
    m=(r+l+1)//2
    d={}
    flg=False
    for i in range(n-m+1):
        t=s[i:i+m]
        if t in d:
            if d[t]+m-1<i:
                flg=True
                break
        else:
            d[t]=i
    if flg:
        l=m
    else:
        r=m-1
print(l)